Subject: help on gethostbyname()
To: None <netbsd-help@NetBSD.ORG>
From: Grzegorz Wojtowicz <grzesiek@ajax.umcs.lublin.pl>
List: netbsd-help
Date: 07/15/1996 19:55:01
Recently ive noticed a strange thing:
while passing a pointer of any ip address e.g. 100.10.10.10 to
gethostbyname function it doesnt return a NULL pointer (as it should) even
though that address does NOT exist. ( the program is run on a standalone
machine with no DNS , no named , and has no "100.10.10.10" entry in
/etc/hosts)
Lets say:
struct hostent *hostp;
hostp = gethostbyname ( argv [1] ) ; /* where argv[1] is "100.10.10.10"
printf("Host name %s\t Host address %s\n", hostp->h_name ,
inet_ntoa( hostp->h_addr) );
--> It would print on stdout:
Host name 100.10.10.10 Host address 100.10.10.10
Is it a bug or a feature ?????
Normally gethostbyname() should only accepts hostnames ( not host
addresses ) such as those ones in /etc/hosts ( moon , galaxy and so on)
If i would write:
check.c
main(argc,argv)
int argc;
char *argv[];
{
struct hostent *hostp;
unsigned long addr, inet_addr();
int i;
for (i=1 ; i<argc ; i++)
{
if ( (hostp = gethostbyname( argv[i] )) == NULL)
{
addr = inet_addr ( argv[i] );
if ( (hostp = gethostbyaddr( &addr, sizeof(struct
in_addr) , AF_INET ) ) == NULL )
printf("Host not found \n");
else
....
(rest of program)
}
}
}
and run : ./check 100.10.10.10
it will never reach gethostbyaddr() because gethostbyname() will return
not NULL.
What about that ??????
gelo.