[107157] in North American Network Operators' Group

home help back first fref pref prev next nref lref last post

Re: interger to I P address

daemon@ATHENA.MIT.EDU (Colin Alston)
Wed Aug 27 13:01:23 2008

Date: Wed, 27 Aug 2008 19:01:02 +0200
From: Colin Alston <karnaugh@karnaugh.za.net>
To: Dave Israel <davei@otd.com>
In-Reply-To: <48B57126.6060402@otd.com>
X-MailScanner-From: karnaugh@karnaugh.za.net
Cc: NANOG list <nanog@nanog.org>
Errors-To: nanog-bounces@nanog.org

On 2008/08/27 05:22 PM Dave Israel wrote:
> 
> Normally, I don't participate in this sort of thing, but I'm a sucker 
> for a "there's more than one way to do it" challenge.

Aww come on, C gets way more "fun" than that ;)

#define _u8 unsigned char
#define _u32 unsigned long

int main(void) {
     _u32 ipn = 1089055123;
     _u8 ipa[3];
     _u8 oct = 0;


     for (oct=0; oct <4; oct++){
         ipa[oct] = (char)(
             (ipn & (0xFF000000 >> (8*oct))) >> (8*(3-oct))
         );
     }

     printf("%d.%d.%d.%d\n", ipa[0], ipa[1], ipa[2], ipa[3]);

     return 0;
}




home help back first fref pref prev next nref lref last post