Created
March 3, 2019 04:20
-
-
Save ankurparihar/e6eefa4471cdf7ffa5b645d40b400ffd to your computer and use it in GitHub Desktop.
Revisions
-
ankurparihar created this gist
Mar 3, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ /*----- Find host name from IP address -----*/ #include <stdio.h> #include <netdb.h> #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> int main(int argc, char* argv[]){ struct hostent* hent; // host structure struct in_addr ip; // ip structure const char *ipstr = argv[1]; // "172.217.166.228" => www.google.com (domain name) inet_aton(ipstr, &ip); hent = gethostbyaddr((const void *)&ip, sizeof(ip), AF_INET); if(hent){ printf("%s\n", hent->h_name); } else{ printf("Something went wrong...\n"); } return 0; }