North American Network Operators Group Date Prev | Date Next | Date Index | Thread Index | Author Index | Historical Re: interger to I P address
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. Shadow wrote: Robert D. Scott wrote: The "ugly, please adjust according to your endianness, etc" way: int *dec; unsigned char *oct1, *oct2, *oct3, *oct4; main(int argc, char **argv) { dec = malloc(sizeof(int)); *dec = 1089055123; oct4 = dec; oct3 = oct4 + sizeof(char); oct2 = oct3 + sizeof(char); oct1 = oct2 + sizeof(char); printf("dec: %lu ip: %hu.%hu.%hu.%hu\n", *dec, *oct1, *oct2, *oct3, *oct4); }
|