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;
Quote:}