Networking Forums

Networking Forums > Computer Networking > Linux Networking > problem with gethostent

Reply
Thread Tools Display Modes

problem with gethostent

 
 
Ryan
Guest
Posts: n/a

 
      12-12-2010, 03:39 AM
Hi all,
I want to get all interfaces address infomations with
gethostent(3)(NOT with gethostbyname of getaddrinfo).And i use the
Ubuntu10.10,the ipv6 is enabled by default.However,with my code
below,only the ipv4 addresses were returned,really confused :-)
will anyone give me a explanation?Thanks ahead.
code here:
#include "unp.h"

int main()
{

struct hostent *he;
char **sa;
char **alias;
char buf[BUFSIZ];

while((he = gethostent())){
if(he == NULL){
perror("gethostent");
return -1;
}
printf("PROTOCOL: %s\n",he->h_addrtype == AF_INET?\
"AF_INET":"AF_INET6");
printf("canonical name:%s\n",he->h_name);
alias = he->h_aliases;
for(;*alias != NULL;alias++)
printf("alias: %s\n",*alias);

sa = he->h_addr_list;
for(;*sa != NULL;sa++)
printf("address %s\n",inet_ntop(he->h_addrtype,*sa,\
buf,sizeof(buf)));
}
endhostent();
return EXIT_SUCCESS;
}
 
Reply With Quote
 
 
 
 
Jorgen Grahn
Guest
Posts: n/a

 
      12-12-2010, 08:45 AM
On Sun, 2010-12-12, Ryan wrote:
> Hi all,
> I want to get all interfaces address infomations with
> gethostent(3)(NOT with gethostbyname of getaddrinfo).And i use the
> Ubuntu10.10,the ipv6 is enabled by default.However,with my code
> below,only the ipv4 addresses were returned,really confused :-)
> will anyone give me a explanation?


Did you read the manual? In the Linux man page gethostent(3) is barely
mentioned, "does not make much sense", "may be available only when the
library was built without DNS support" and "will ignore ipv6 entries".

Which seems to be a way of saying "we don't believe in providing name
resolvers which only use /etc/hosts".

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Richard Kettlewell
Guest
Posts: n/a

 
      12-12-2010, 09:21 AM
Ryan <(E-Mail Removed)> writes:
> I want to get all interfaces address infomations with
> gethostent(3)(NOT with gethostbyname of getaddrinfo).


gethostent() gives you the contents of the hosts database (usually
/etc/hosts), not interface addresses.

It's essentially useless and has been for the last quarter century.

--
http://www.greenend.org.uk/rjk/
 
Reply With Quote
 
Ryan
Guest
Posts: n/a

 
      12-12-2010, 09:26 AM
On 2010年12月12日 17:45, Jorgen Grahn wrote:
> On Sun, 2010-12-12, Ryan wrote:
>> Hi all,
>> I want to get all interfaces address infomations with
>> gethostent(3)(NOT with gethostbyname of getaddrinfo).And i use the
>> Ubuntu10.10,the ipv6 is enabled by default.However,with my code
>> below,only the ipv4 addresses were returned,really confused :-)
>> will anyone give me a explanation?

>
> Did you read the manual? In the Linux man page gethostent(3) is barely
> mentioned, "does not make much sense", "may be available only when the
> library was built without DNS support" and "will ignore ipv6 entries".
>
> Which seems to be a way of saying "we don't believe in providing name
> resolvers which only use /etc/hosts".
>
> /Jorgen
>

thanks.I didn't noticed that.
 
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
Strange problem: no problem with Linux, when I boot windows 2K network is down... Santa Linux Networking 11 11-29-2004 06:46 AM



1 2 3 4 5 6 7 8 9 10 11