printf(" Dst Address:\n");
for(i = 0;i < 4;i++)
printf(" %d ",((ip->ip_dst.s_addr)&(0x0FF<<(i*8)))>>(i*8));
by this i am able to print the destination ip address as 192.28.2.11 but i want just want the first two numbers 192 and 28 how can i get this two value.?
What’s wrong with just modifying the code you have:
That should give them to you in
a[0]anda[1].The following code shows one way to do it. The IP address is reversed (
0x0b0280c0) due to the x86 little-endian format:It outputs:
and you can see that the components are placed in the individual array elements.