Skip to content

Instantly share code, notes, and snippets.

@jiphex
Created November 11, 2009 11:12
Show Gist options
  • Save jiphex/231871 to your computer and use it in GitHub Desktop.
Save jiphex/231871 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