* Re: gethostbyaddr() doesn't find host (Digital Unix V3.2c)
[not found] <826554688.24324.0@fersys.demon.co.uk>
@ 1996-03-13 5:00 ` John Sanders
1996-03-14 5:00 ` Mike Iglesias
1996-03-20 5:00 ` Dave Munro
2 siblings, 0 replies; 3+ messages in thread
From: John Sanders @ 1996-03-13 5:00 UTC (permalink / raw)
Yes,
I have exactly the same problem. I can't get the gethostbyaddr to find
my host eather. I'v turned off the bind server and diddled the
/etc/resolv.conf and /etc/svc.conf files and turned off bind in the
/etc/rc.config file. This same code works on a Sun 4.3 os. I'v checked
byte order and data size and just have run out of ideas. Do I need to
write a routine to parse the /etc/hosts file myself?
please advise -
_____________________________________
john sanders <jsanders@globalcom.net>
>- it can be done -<
-------------------------------------
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: gethostbyaddr() doesn't find host (Digital Unix V3.2c)
[not found] <826554688.24324.0@fersys.demon.co.uk>
1996-03-13 5:00 ` gethostbyaddr() doesn't find host (Digital Unix V3.2c) John Sanders
@ 1996-03-14 5:00 ` Mike Iglesias
1996-03-20 5:00 ` Dave Munro
2 siblings, 0 replies; 3+ messages in thread
From: Mike Iglesias @ 1996-03-14 5:00 UTC (permalink / raw)
In article <826554688.24324.0@fersys.demon.co.uk>,
<mlb@fersys.demon.co.uk> wrote:
>I am accepting a socket connection, and trying to ascertain the hostname
>of the source. I'm calling inet_ntoa() on the network address
>[ inetaddr = inet_ntoa (acc_addr.sin_addr); ]
>and then passing the resulting string to gethostbyaddr(), but
>the system does not find my host, even though it's in the host file.
You're misinterpreting the man page for gethostbyaddr(). You want to
pass acc_addr.sin_addr to it rather than the ASCII representation of
the IP address.
--
Mike Iglesias Internet: iglesias@draco.acs.uci.edu
University of California, Irvine phone: (714) 824-6926
Office of Academic Computing FAX: (714) 824-2069
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: gethostbyaddr() doesn't find host (Digital Unix V3.2c)
[not found] <826554688.24324.0@fersys.demon.co.uk>
1996-03-13 5:00 ` gethostbyaddr() doesn't find host (Digital Unix V3.2c) John Sanders
1996-03-14 5:00 ` Mike Iglesias
@ 1996-03-20 5:00 ` Dave Munro
2 siblings, 0 replies; 3+ messages in thread
From: Dave Munro @ 1996-03-20 5:00 UTC (permalink / raw)
Your program doesnt work because your inetaddr is not really a string
but string pointer to exactly 4 characters where each "character" is
an decimal number between 0 and 255 - in other words the ip number
"packed" into 32 bits.
Here is your prog. revised to use the inet_addr(3) macro which
converts your string into an unsigned integer
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
main ()
{
char inetaddr[16]; /* internet address of
source */
struct hostent *hp;
unsigned int ip_no ;
/* addresses changed from real examples.
* I've tried swapping these, e.g. "1.1.200.160",
"200.160.1.1");
*/
sprintf(inetaddr, "138.251.192.40");
ip_no = inet_addr( inetaddr ) ;
/*
hp = gethostbyaddr (inetaddr, 4, AF_INET);
*/
hp = gethostbyaddr (( char * )&ip_no, 4, AF_INET);
if (hp == NULL)
{
endhostent();
printf ("Source has unknown Internet address (%s)\n",
inetaddr);
exit (1);
} else printf( "Hostnames is %s\n",hp->h_name ) ;
endhostent();
}
Hope this helps
Dave Munro
^ permalink raw reply [flat|nested] 3+ messages in thread