in my c ++ application i am using sockaddr. I want to see everything that sockaddr.sa_data has [14]. while I just type ip from sa_data [2] .sa_data [3] .sa_data [4] .sa_data [5].
I want to print in such a way that I can understand (and please explain) all the information in the sa_data file of 14 bytes.
any help?
thank!
One possibility is to use inet_ntop, which should be able to handle IPv4 and IPv6 addresses. It will create a readable address string.
inet_ntop
sa_data IPv4 Windows , , - IP-.
, 228.0.0.1:9995, sa_data...
228.0.0.1:9995
27 0b e4 00 00 01 00 00 00 00 00 00 00 00
270b - 9995 . - IP-, 0xe4 - 228, , 0x01 228 0 0 1., .
270b
0xe4
0x01
, sa_data .
sa_data, 14 , () : sa_family.
AF_INET, , 4 IP- .
PF_PACKET, Ethernet (wither 0800 β IP, 0806 β ARP ..) 4 ( ) . :
std::copy( &sa_data[0], &sa_data[0]+sizeof(sa_data)/sizeof(sa_data[0]), std::ostream_iterator<int>(std::cout, " "));
int . unsigned int, , iomanip , .
The information sockaddrdepends on which socket family and protocol you are using.
sockaddr
If you use IPv4, you need to make a pointer sockaddr sockaddr_in *. Only the first 6 bytes of the address make sense when you use IPv4. The rest should simply be ignored.
sockaddr_in *
To receive and print sa_data member struct sockaddr, please refer to John's answer on Obtaining an IPV4 Address from the sockaddr Structure
sa_data member
struct sockaddr
Source: https://habr.com/ru/post/1780725/More articles:Apache / PHP test server throttle on request - phpDatagramSocket.receive () error with unexpected SocketException - javaRotating a div around a point - jqueryAdvice on proper handling, is it wise? - c ++Introduce Web User Management Using Ninject in WebForms - asp.netFacebook as a field showing duplicate profiles - htmlIs there a documentation generator for test cases for cucumber scripts / functions (test cases?) - testingQuestions regarding loading the DLL into the process address space - windowsHow can I get clojure "def" to re-evaluate without using: reload? - clojurecompare two outlier values ββ- jqueryAll Articles