getnameinfo() - Reverse DNS lookup (IP Address to hostname) C/C++ -


66.249.68.9 for IPAddress ("DIG-X" correctly "Crawl-66-249-68-9 Tablets "Com") My sweet program claims that this is IP 68-9-0-0.ri.ri.cox.net.

I do not care if I call it down in a way I want to start with just an IPv4 IP address and walk with the hostname.

Bonus question, What is the service? I think I will not need it, and getnameinfo will give NULL but , W "17145" is being output for the serial service buffer.

  #include & lt; string & gt; # Include & lt; iostream & gt; Using Namespace STD; & Lt; netdb.h & gt; // Structure Sockdor, AFXAT, NI_NEMERCD, getnameinfo #include & lt; string H & gt; // memset #include & lt; arpa / inet.h & gt; // inet_pton int main () {Const string ipadress {"66.249.68.9"}; structure soaked stroke co-founder; memeset (& structure soak another, 0, structSockAddr); StructSockAddr.sa_family = AF_INET; Intetphone Returns Vala {inet_pton (AF_INET, IPAddress.c_str (), and structSockAddr.sa_data)}; If (1! = InetPtonReturnValue) {cout & lt; & Lt; "InetPtonReturnValue:" & lt; & Lt; InetPtonReturnValue & lt; & Lt; Endl; // 0 = src is not a valid address, -1 = AF is not a valid family) four host buffers [10000]; Four service buffers [1000]; Int getNameInfoReturnValue {getnameinfo (& amp; structSockAddr, sizeof (structSockAddr), hostBuffer, sizeof (hostBuffer), service buffer, sizeof (serviceBuffer), NI_NAMEREQD)}; If (0! = GetNameInfoReturnValue) {cout & lt; & Lt; "GetNameInfoReturnValue:" & lt; & Lt; GetNameInfoReturnValue & lt; & Lt; Andal & lt; & Lt; "Gai_strerror ():" & lt; & Lt; Gai_strerror (getNameInfoReturnValue) & lt; & Lt; Endl; } And {cout & lt; & Lt; "IPaders:" & lt; & Lt; IP Adapter & lt; & Lt; Andal & lt; & Lt; "Hostbuffer:" & lt; & Lt; HostBuffer & lt; & Lt; Andal & lt; & Lt; "Service buffer:" & lt; & Lt; Service buffer & lt; & Lt; Endl; }}    

When you call a struct sockaddr For calling signing on using inet_pton it is necessary for either a struct in_addr for AF_INET (or struct in6_addr for IPv6 ) And then you have to use it to create a struct sockaddr for later functions.

As currently stands, you are writing some bytes in the field before the actual IP address in the field, so you end up with the previous 2 octet of IP in your Sockdra field.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -