#include #include #include #include int main(int argc, char **argv) { if (argc < 2) { fprintf(stderr, "Usage: %s hostname\n", argv[0]); exit(1); } struct hostent *host = malloc(sizeof(struct hostent)); char buffer[1024]; int error; while(1) { if (gethostbyname_r(argv[1],host,buffer,sizeof(buffer),&error) != NULL) { int i=0; printf("%s IPs: \n", host->h_name); while (host->h_addr_list[i] != NULL) { printf("%s \n", inet_ntoa(*(struct in_addr*)(host->h_addr_list[i]))); i++; } } else { printf("gethostbyname_r returned null\n"); } } }