From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,c09a72d31188ccca,start X-Google-Attributes: gidfee84,public From: Dave Munro Subject: Re: gethostbyaddr() doesn't find host (Digital Unix V3.2c) Date: 1996/03/20 Message-ID: <3150156E.1015@dcs.st-and.ac.uk>#1/1 X-Deja-AN: 143387867 references: <826554688.24324.0@fersys.demon.co.uk> content-type: text/plain; charset=us-ascii organization: University of St Andrews mime-version: 1.0 reply-to: dave@dcs.st-and.ac.uk newsgroups: comp.unix.osf.osf1 x-mailer: Mozilla 2.0 (Macintosh; I; PPC) 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 #include #include #include #include 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