Valdis.Kletnieks(a)vt.edu writes:
It *should* behave about the same as gethostbyname() regarding
network
accesses that hang/time out - if one is hanging and the other is not,
that's either a config error or software bug.
I tried the following code:
struct hostent *host_info_ptr;
host_info_ptr = gethostbyname("localhost");
time ./t
7f000001
./t 0.00s user 0.00s system 0% cpu 0.000 total
Then this:
char addrbuf[NI_MAXHOST];
struct addrinfo hints, *res;
int retval;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
retval = getaddrinfo("localhost", NULL, &hints, &res);
time ./t
127.0.0.1
./t 0.00s user 0.00s system 0% cpu 2:30.08 total
The gethostbyname goes straight to the hosts file and returns the
result. The getaddrinfo call first goes through the nameserver. When
that fails, it *then* tries the host file.
For the record I am running Mandrake 7.1 with the 2.4.0-test12 kernel
and glibc-2.1.3-17mdk.
Sean