-
-
Save y109/cfcf4bad27db1f80b3e0b8abc72e1e8c to your computer and use it in GitHub Desktop.
Barebones dig using inet_ntoa in C
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 characters
#include <netdb.h> | |
#include <stdio.h> | |
int main(int argc, char * argv[]) { | |
if(argc > 1) { | |
int i; | |
struct hostent *hent; | |
hent = gethostbyname(argv[1]); | |
printf("Hostname: %s\n", hent->h_name); | |
for(i = 0; hent->h_addr_list[i] != 0; i+=1) { | |
printf("IP: %s\n", inet_ntoa(*((long *)hent->h_addr_list[i])), i); | |
} | |
} else { printf("Not enough arguments!\n"); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment