1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
int main(int argc, char* argv[], char* env[]) {
packed v; /* this is my "dual-purpose" 32-bit memory location */
v.i = 3232235881UL; /* I assign it an internet address in 32-bit format */
/* next, I'll print out the individual bytes */
printf("the bytes are %d, %d, %d, %d\n", v.b.b0, v.b.b1, v.b.b2, v.b.b3);
/* and just to prove that the 32-bit integer is still there ... print it out too */
printf("the value is %u\n", v.i);
/* just for the heck of it, increment the 32-bit integer */
v.i++;
printf("after v.i++, the bytes are %d, %d, %d, %d\n", v.b.b0, v.b.b1, v.b.b2, v.b.b3);
/* now do the reverse, assign 70.80.90.100 as an ip address */
v.b.b0 = 70;
v.b.b1 = 80;
v.b.b2 = 90;
v.b.b3 = 100;
/* .. and extract the 32-bit integer value */
printf("the value is %u\n", v.i);
/* show that 70.80.90.100 is really what we put in there */
printf("the bytes are %d, %d, %d, %d\n", v.b.b0, v.b.b1, v.b.b2, v.b.b3);
/* ok, we're done here */
return EXIT_SUCCESS;
}
|