Created
July 4, 2018 10:11
-
-
Save thongntit/220d30210fe7a8833859e1b60b82742a to your computer and use it in GitHub Desktop.
Gethostbyname Small app that prints of IP address of input domain name
This file contains 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 characters
#include <stdio.h> | |
#include <netdb.h> | |
#include <arpa/inet.h> | |
int main(int argc, char *argv[]) | |
{ | |
struct hostent *lh = gethostbyname(argv[1]); | |
if (lh){ | |
printf("%s",inet_ntoa(*( struct in_addr*)lh->h_addr_list[0])); | |
} | |
else | |
perror("gethostbyname"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment