Skip to content

Instantly share code, notes, and snippets.

@thongntit
Created July 4, 2018 10:11
Show Gist options
  • Save thongntit/220d30210fe7a8833859e1b60b82742a to your computer and use it in GitHub Desktop.
Save thongntit/220d30210fe7a8833859e1b60b82742a to your computer and use it in GitHub Desktop.
Gethostbyname Small app that prints of IP address of input domain name
#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