#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#if 0
#define DEBUG_MESSAGE(list) fprintf list
#else
#define DEBUG_MESSAGE(list)
#endif
main()
{
char buf[80];
long addr;
struct hostent *hp;
char *nl_pnt;
DEBUG_MESSAGE((stderr, "hname starts\n"));
printf("\n");
fflush(stdout);
buf[(sizeof buf) - 1] = '\0';
for(;;) {
if (fgets(buf, (sizeof buf) - 1, stdin) == NULL)
break;
DEBUG_MESSAGE((stderr, "hname got %s.\n", buf));
addr = inet_addr(buf);
if (nl_pnt = strchr(buf, '\n') )
*nl_pnt = '\0';
if (addr != -1) {
hp = gethostbyaddr(&addr, 4, AF_INET);
if (!hp) {
sleep(5);
hp = gethostbyaddr(&addr, 4, AF_INET);
}
if (hp) {
DEBUG_MESSAGE((stderr, "hname sends %s %s...", buf, hp->h_name));
printf("%s %s\n", buf, hp->h_name);
fflush(stdout);
DEBUG_MESSAGE((stderr, "done\n"));
}
}
}
DEBUG_MESSAGE((stderr, "hname exits\n"));
}