Networking Forums

Networking Forums > Computer Networking > Linux Networking > help ! gethostbyaddr error

Reply
Thread Tools Display Modes

help ! gethostbyaddr error

 
 
step
Guest
Posts: n/a

 
      06-01-2007, 12:49 PM

hi!
when i use gethostbyaddr £¬it can only own ip's hostname£¬otherip
all can't £¬but gethostbyname is work fine £¬and dns is also fine¡£ my
system is debian £¬kernel is 2.6.18
code is following:

int main(int argc,char **argv)
{
struct sockaddr_in addr;
memset(&addr,0,sizeof(struct sockaddr_in));


addr.sin_family=PF_INET;
addr.sin_port=htons(80);

inet_pton(PF_INET,argv[1],&addr.sin_addr);


struct hostent *h;

h=gethostbyaddr((const void *)&addr.sin_addr,sizeof(struct
in_addr),PF_INET);
//h=gethostbyname(argv[1]);
if(h==NULL)
printf("%s host name is error \n",argv[1]);


struct in_addr a;
a.s_addr=inet_addr(argv[1]);
h=gethostbyaddr((char*)&a,sizeof(a),PF_INET);
if(h!=NULL)
printf("%s host name is %s\n",argv[1],h->h_name);

return 0;
}

 
Reply With Quote
 
 
 
 
step
Guest
Posts: n/a

 
      06-01-2007, 12:53 PM
i means it can only get my own hostname,all other ip'hostname
can't ,it return null and p_errno=1

On 6ÔÂ1ÈÕ, ÏÂÎç8ʱ49·Ö, step <fxl...@gmail.com> wrote:
> hi!
> when i use gethostbyaddr £¬it can only own ip's hostname£¬other ip
> all can't £¬but gethostbyname is work fine £¬and dns is also fine¡£ my
> system is debian £¬kernel is 2.6.18
> code is following:
>
> int main(int argc,char **argv)
> {
> struct sockaddr_in addr;
> memset(&addr,0,sizeof(struct sockaddr_in));
>
> addr.sin_family=PF_INET;
> addr.sin_port=htons(80);
>
> inet_pton(PF_INET,argv[1],&addr.sin_addr);
>
> struct hostent *h;
>
> h=gethostbyaddr((const void *)&addr.sin_addr,sizeof(struct
> in_addr),PF_INET);
> //h=gethostbyname(argv[1]);
> if(h==NULL)
> printf("%s host name is error \n",argv[1]);
>
> struct in_addr a;
> a.s_addr=inet_addr(argv[1]);
> h=gethostbyaddr((char*)&a,sizeof(a),PF_INET);
> if(h!=NULL)
> printf("%s host name is %s\n",argv[1],h->h_name);
>
> return 0;
>
> }



 
Reply With Quote
 
B.Eckstein
Guest
Posts: n/a

 
      06-01-2007, 01:09 PM
step schrub im Jahre 01.06.2007 14:49:
> hi!
> when i use gethostbyaddr £¬it can only own ip's hostname£¬other ip
> all can't £¬but gethostbyname is work fine £¬and dns is also fine¡£ my
> system is debian £¬kernel is 2.6.18


better use getaddrinfo() This will also help in being IPv6-save.
 
Reply With Quote
 
Rick Jones
Guest
Posts: n/a

 
      06-01-2007, 05:30 PM
step <(E-Mail Removed)> wrote:
> i means it can only get my own hostname,all other ip'hostname
> can't ,it return null and p_errno=1


Probably want to check the settings in places like /etc/nsswitch.conf
to see if your "name resolution" stuff is configured to use anything
other than "files" (eg /etc/hosts). I'd have thought it would use the
same entries as gethostbyname, but stranger things have happened I
suppose. You could also try taking a system call trace of your code
to see which files are being examined for settings and/or values.

You could also try the experiment of adding a test entry in your
/etc/hosts file and see if your gethostbyaddr() call can find it.

And as someone else points-out, folks using
gethostbyname/gethostbyaddr should really be using
getaddrinfo/getnodeinfo these days. Even if the application isn't
interested in IPv6 yet, the newer interfaces are IMO nicer to use, and
someday someone, perhaps even you, will want the app to work with IPv6

rick jones
--
firebug n, the idiot who tosses a lit cigarette out his car window
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
 
Reply With Quote
 
step
Guest
Posts: n/a

 
      06-02-2007, 04:07 PM
On 6ÔÂ2ÈÕ, ÉÏÎç1ʱ30·Ö, Rick Jones <rick.jon...@hp.com> wrote:
> step <fxl...@gmail.com> wrote:
> > i means it can only get my own hostname,all other ip'hostname
> > can't ,it return null and p_errno=1

>
> Probably want to check the settings in places like /etc/nsswitch.conf
> to see if your "name resolution" stuff is configured to use anything
> other than "files" (eg /etc/hosts). I'd have thought it would use the
> same entries as gethostbyname, but stranger things have happened I
> suppose. You could also try taking a system call trace of your code
> to see which files are being examined for settings and/or values.
>
> You could also try the experiment of adding a test entry in your
> /etc/hosts file and see if your gethostbyaddr() call can find it.
>
> And as someone else points-out, folks using
> gethostbyname/gethostbyaddr should really be using
> getaddrinfo/getnodeinfo these days. Even if the application isn't
> interested in IPv6 yet, the newer interfaces are IMO nicer to use, and
> someday someone, perhaps even you, will want the app to work with IPv6
>
> rick jones
> --
> firebug n, the idiot who tosses a lit cigarette out his car window
> these opinions are mine, all mine; HP might not want them anyway...
> feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...


thanks,i find the problem, it because dns server don't support ip->
domain resolving,

 
Reply With Quote
 
Rick Jones
Guest
Posts: n/a

 
      06-04-2007, 04:49 PM
step <(E-Mail Removed)> wrote:
> thanks,i find the problem, it because dns server don't support ip->
> domain resolving,


Sounds like it is time to send a nasty note to hostmaster.

rick jones
--
portable adj, code that compiles under more than one compiler
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DCDiag - failed with Error Win32 Error 8420 Alex Windows Networking 8 05-27-2008 11:24 PM
Q:DHCP and gethostbyaddr() Bokyun Na Linux Networking 0 10-20-2005 12:11 PM
Interface error and packet filter error for Remote Access Tony Birnseth Windows Networking 0 09-19-2004 04:28 PM
update install error C++ Runtime error Gabriel Dorta Broadband Hardware 1 08-22-2004 12:14 AM
error message.. netconn has caused error John Hartley Windows Networking 2 10-15-2003 09:22 AM



1 2 3 4 5 6 7 8 9 10 11