Subject: Re: gethostbyname prob
To: None <netbsd-users@netbsd.org>
From: Michael Core <520079546242-0001@t-online.de>
List: netbsd-users
Date: 06/26/2002 23:24:30
prlw1@newn.cam.ac.uk (Patrick Welche) wrote:
> It seems I don't understand struct hostent which has
>
> char **h_addr_list; /* list of addresses from name
> server */
>
> (gdb) print h->h_addr_list
> $9 = (char **) 0x48103180
[...]
>
> In went gethostbyname2 with a host with 2 ipnumbers. Out comes the
> above. 0x7e5d3cc1 is the correct first ip number, but the second
> should look like 0xb1cc6f83 (this is on i386) but I can't see it
> anywhere! There really seems to be just the one entry in h_addr_list.
> Is that right, or am I missing something?
The following program gives me this result:
$ ./gethost pop.btx.dtag.de
Official name: fwdallmx.t-online.com
Aliases: pop.btx.dtag.de
Address type: 2
Address length: 4
Address(es): 194.25.134.88 194.25.134.25 194.25.134.89 194.25.134.26
194.25.1
34.90 194.25.134.27 194.25.134.91 194.25.134.32 194.25.134.96
194.25.134.33 194.
25.134.97 194.25.134.24
gethost.c:
#include <stdlib.h>
#include <stdio.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
extern int h_errno;
#define ADDR_FAMILY AF_INET
int main(int argc, const char *argv[]) {
struct hostent *hostptr;
int i;
char namebuf[1024];
if (argc < 2) {
fprintf(stderr, "usage: gethost HOSTNAME\n");
return EXIT_FAILURE;
}
hostptr = gethostbyname2(argv[1], ADDR_FAMILY);
if (hostptr == NULL) {
herror("gethostbyname2() failed");
return EXIT_FAILURE;
}
printf("Official name: %s\n", hostptr->h_name);
printf("Aliases: ");
for(i = 0; hostptr->h_aliases[i] != NULL; i++)
printf("%s ", hostptr->h_aliases[i]);
printf("\n");
printf("Address type: %d\n", hostptr->h_addrtype);
printf("Address length: %d\n", hostptr->h_length);
printf("Address(es): ");
for(i = 0; hostptr->h_addr_list[i] != NULL; i++)
{
printf("%s ", inet_ntop( ADDR_FAMILY,
hostptr->h_addr_list[i],
namebuf,
sizeof(namebuf) - 1));
}
printf("\n");
return EXIT_SUCCESS;
}
-------------
Therefore, I don't really see your problem. What do nslookup and
dnsquery tell you? Maybe there's some problem with the local or remote
DNS configuration.
Michael