H
Harry
Hi ppl
Some problem regarding pointer:
ULONG *addr;
CHAR *ptr=NULL;
addr=new ULONG;
//calling a function and getting the addr value
//ULONG is 4 bytes. I am getting the Ip address which is naturally 4
bytes and
//storing the value in the location given by addr
ptr=(char *)addr;
printf("\n%X\n",*addr); //gives the IP address correctly. total 32
bits
//next line is the problem
printf("%X.%X.%X.%X\n", *ptr, *(ptr+1), *(ptr+2), *(ptr+3));
The above line should give the same value as *addr. But its reading
wrongly from the memory. First the byte position have interchanged(i
converted it to network order and saved this value in addr and *addr
gives the network order but the last line is printing in host order).
Secondly, the last byte read is garbage.
any suggestions??...basically i want to convert the ULONG into
CHAR[4]. Any other way to do it i.e. without casting??
thanks
Harry
Some problem regarding pointer:
ULONG *addr;
CHAR *ptr=NULL;
addr=new ULONG;
//calling a function and getting the addr value
//ULONG is 4 bytes. I am getting the Ip address which is naturally 4
bytes and
//storing the value in the location given by addr
ptr=(char *)addr;
printf("\n%X\n",*addr); //gives the IP address correctly. total 32
bits
//next line is the problem
printf("%X.%X.%X.%X\n", *ptr, *(ptr+1), *(ptr+2), *(ptr+3));
The above line should give the same value as *addr. But its reading
wrongly from the memory. First the byte position have interchanged(i
converted it to network order and saved this value in addr and *addr
gives the network order but the last line is printing in host order).
Secondly, the last byte read is garbage.
any suggestions??...basically i want to convert the ULONG into
CHAR[4]. Any other way to do it i.e. without casting??
thanks
Harry