Skip to content

Instantly share code, notes, and snippets.

@y109
Forked from jiphex/testdns.c
Created May 13, 2016 19:17
Show Gist options
  • Save y109/cfcf4bad27db1f80b3e0b8abc72e1e8c to your computer and use it in GitHub Desktop.
Save y109/cfcf4bad27db1f80b3e0b8abc72e1e8c to your computer and use it in GitHub Desktop.
Barebones dig using inet_ntoa in C
#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