Hello Chris,
On 10/25/2011 05:41 PM, Chris Hegarty wrote:
On 10/25/11 08:31 AM, Charles Lee wrote:
Hi guys,
I am reading some native code in the jdk repos. I find that in
Inet4AddressImpl.c (folder solaris), gethostbyname is used. Meanwhile in
the Inet6AddressImpl.c. getaddrinfo is used. My question is why inet4
does not use getaddrinfo? Any concern here?
The Inet4AddressImpl implementation clearly only needs to deal with
IPv4 addresses, so gethostbyname is sufficient. Historically, when
this code was added way back we couldn't be guaranteed that the IPv6
API's would be available on all platforms.
getaddrinfo is now part of POSIX standard, and gethostbyname was removed
from POSIX specification by POSIX.1-2008. So the suggested change is a
latest-POSIX-compatible change.
Moreover getaddrinfo supports IPv4 too, so I think it will not bring any
additional dependencies on an platform without IPv6, right?
We do still support building without IPv6 and I would be reluctant to
to put a dependency from Inet4AddressImpl on getaddrinfo for this reason.
If your specific issue is with __GLIBC__, I wonder if it could be
replaced with __LINUX__?? We'd need to look more into this.
-Chris.
There are some pros I can see if getaddrinfo is used in the
Inet4AddressImpl:
1. Code will look more clean and portable :-)
2. __GLIBC__ can be omitted. I have grep the __GLIBC__ in the jdk/src
directories, only Inet4AddressImpl use it.