While playing around with getting host entries to work with ldap, I found that my previous code for using gethostbyname was not running clean on puias6. Here is an updated version
#include
#include
#include
#include
#include
#includeint main(int argc, char **argv) {
int i;
struct hostent *hp;
struct in_addr **addr_list;if (argc < 2) {
printf("Usage: %s hostname\n", argv[0]);
exit(1);
}hp = gethostbyname(argv[1]);
if (hp == NULL) {
printf("gethostbyname(%s) failed\n",argv[1]);
} else {
printf("%s has address ", hp->h_name, argv[1],hp->h_addrtype);
addr_list = (struct in_addr **)hp->h_addr_list;for(i = 0; addr_list[i] != NULL; i++) {
printf("%s ",inet_ntoa(*addr_list[i]));
}
printf("\n");
}
}
compile this with gcc -o gethostbyname gethostbyname.c