Bug #886
opengetaddrinfo() doesn't return all addresses for hostname
0%
Description
Tested with the following test program:
#include <stdio.h> #include <strings.h> #include <netdb.h> main(ac, av) char **av; { struct addrinfo hints, *res; bzero(&hints, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_ADDRCONFIG|AI_PASSIVE; getaddrinfo(av[1], av[2], &hints, &res); for (; res; res = res->ai_next) { char name[NI_MAXHOST]; getnameinfo(res->ai_addr, res->ai_addrlen, name, sizeof(name), NULL, 0, NI_NUMERICHOST); printf("%s\n", name); } return 0; }
Compile and run:
tamara% gcc gai.c -o gai -lsocket -lnsl tamara% ./gai news-out.nntp.giganews.com 216.196.110.150 216.196.110.151 216.196.110.152 216.196.110.153 216.196.110.167 216.196.118.140 216.196.118.141 216.196.118.148 216.196.118.149 216.196.118.150 216.196.118.151 216.196.118.152 216.196.118.153 216.196.122.140 216.196.122.141 216.196.122.148 216.196.122.149 216.196.122.150 216.196.122.151 216.196.122.152 216.196.122.153 193.201.147.73 193.201.147.77 203.170.30.140 203.170.30.141 203.170.30.148 203.170.30.149 203.170.30.150 203.170.30.151 203.170.30.152 203.170.30.153 216.196.98.128 216.196.98.129 216.196.98.140 216.196.98.141
This returns 35 addresses, while "getent hosts" returns 58:
tamara% ./gai news-out.nntp.giganews.com|wc -l 35 tamara% getent hosts news-out.nntp.giganews.com|wc -l 58
Updated by River Tarnell over 12 years ago
The problem seems to be that getaddrinfo() calls res_gethostbyname(), which allocates a 512-byte buffer and passes it to res_send(). res_send() knows to re-try with a TCP connection, but the buffer is too small to hold the result. The fix is probably to increase the buffer size at http://src.illumos.org/source/xref/illumos-opengrok/usr/src/lib/libresolv/res_gethost.c#60
Apparently this code is different between hosts and ipnodes:
tamara% getent ipnodes news-out.nntp.giganews.com|wc -l
35
tamara% getent hosts news-out.nntp.giganews.com|wc -l
58
... but I'm not sure exactly where.
Updated by Bryan Horstmann-Allen over 12 years ago
- Project changed from OpenIndiana Distribution to illumos gate
- Category deleted (
OS/Net (Kernel and Userland))
Updated by Gary Mills over 12 years ago
- Difficulty set to Medium
- Tags set to needs-triage
I've found out a few things with `truss' and by reading the
source. `getaddrinfo()' calls `getipnodebyname()' internally,
as does `getent ipnodes'. Both truncate the result at 35
addresses. That number appears to come from this
definition in /usr/include/netdb.h:
#define MAXADDRS 35
On the other hand, `gethostbyname()' in a small C program,
as well as `getent hosts', which calls that same function,
produce 58 addresses.
All of these seem to use fixed size buffers to contain the
result. The difference is that `getipnodebyname()' does
V6 to V4 mapping to get the V4 addresses.
As far as I can tell, there's no limit to the number of IP
addresses that can belong to one hostname. There's only
one in almost all cases, though. This situation cries out for
dynamic sizing.