/* These patches are written by Dark@Igor for Dutch Mountains, in December
1995. The MERC license applies to them. */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main()
{
char buf[80];
char *p;
struct hostent *hostent;
long addr;
while ( fgets( buf, 80, stdin ) ) {
p = strchr( buf, '\n' );
if ( p )
{
*p = '\0';
}
/* Strange. inet_addr officially returns an unsigned long,
* but the error code is -1. */
addr = inet_addr( buf );
if ( addr != -1 )
{
hostent = gethostbyaddr( (char *) &addr, sizeof(addr), AF_INET );
/* h_errno is not defined on all systems. */
if ( !hostent /* && h_errno == TRY_AGAIN */ )
{
sleep( 5 );
hostent =
gethostbyaddr( (char *) &addr, sizeof(addr), AF_INET );
}
printf( "%s %s\n", buf, hostent ? hostent->h_name : buf );
fflush( stdout );
}
}
return 0;
}