Created
March 7, 2019 09:22
-
-
Save jaysonsantos/e3f7bd6390c9f0d5e378a9ad464e0120 to your computer and use it in GitHub Desktop.
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 <stdlib.h> | |
#include <netdb.h> | |
#include <arpa/inet.h> | |
int main(int argc, char **argv) | |
{ | |
if (argc < 2) { | |
printf("Provide the host to be resolved\n"); | |
return 1; | |
} | |
char *host = argv[1]; | |
struct hostent *hp = gethostbyname(host); | |
if (hp == NULL) | |
{ | |
fprintf(stderr, "Error resolving %s\n", host); | |
return 1; | |
} | |
printf("Host %s resolved to:\n", host); | |
for (size_t i = 0; i < hp->h_length; i++) | |
{ | |
struct in_addr *addr = (struct in_addr *)hp->h_addr_list[i]; | |
if (addr == NULL) | |
break; | |
printf("\t%s\n", inet_ntoa(*addr)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment