in my c++ application I' using sockaddr. I want to see all the infarmation which sockaddr.sa_data[14] holds. for now I just print the ip from sa_data[2].sa_data[3].sa_data[4].sa_data[5].
I want to print in a way that I can understand (and please explain) all the information in the sa_data 14 bytes.
any help?
thanks!
In the sa_data member, for IPv4 on Windows, I have found that the first two bytes hold the port number, and the next four hold the IP address.
For example, if I resolve the address 228.0.0.1:9995
, the sa_data member is...
27 0b e4 00 00 01 00 00 00 00 00 00 00 00
Here, 270b
is the Hex value representation of 9995 in the first two bytes. The next four bytes are the IP address, where 0xe4
is 228, then two zeros, then 0x01
, or 228 0 0 1.
The last eight bytes are unused, which tallies with the comment above about only the first six bytes being used.
Note that sa_data will vary in format with the protocol being used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With