Stuffing four byte octets into a dword.
-
I have four octets of an ip stored as follows. byte octet1,octet2,octet3,octet4 IPAddressCtrl.GetAddress(octet1,octet2,octet3,octet4); What I need to do is get those four bytes into a DWORD in the propor byte order so I can store that DWORD in an SOCKADDR_IN structure like this SOCKADDR_IN saDest; saDest.sin_addr.s_addr = /*Somehow stuff octet1,2,3,4 in*/ Does anyone know how this can be done? Thank you
-
I have four octets of an ip stored as follows. byte octet1,octet2,octet3,octet4 IPAddressCtrl.GetAddress(octet1,octet2,octet3,octet4); What I need to do is get those four bytes into a DWORD in the propor byte order so I can store that DWORD in an SOCKADDR_IN structure like this SOCKADDR_IN saDest; saDest.sin_addr.s_addr = /*Somehow stuff octet1,2,3,4 in*/ Does anyone know how this can be done? Thank you
-
...and if you are messing with network parameters don't forget that it uses network byte order (big endian). Use
htonl()
andntohl()
to convert between network and host byte order. -
I have four octets of an ip stored as follows. byte octet1,octet2,octet3,octet4 IPAddressCtrl.GetAddress(octet1,octet2,octet3,octet4); What I need to do is get those four bytes into a DWORD in the propor byte order so I can store that DWORD in an SOCKADDR_IN structure like this SOCKADDR_IN saDest; saDest.sin_addr.s_addr = /*Somehow stuff octet1,2,3,4 in*/ Does anyone know how this can be done? Thank you