Logo Questions Linux Laravel Mysql Ubuntu Git Menu

sockaddr - print all information which sa_data holds - c++





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?


like image 838
gln Avatar asked Feb 25 '23 14:02


1 Answers

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, 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.

like image 147
Steve Hibbert Avatar answered Mar 05 '23 00:03

Steve Hibbert