Question about getaddrinfo in Inet4AddressImpl.c

Chris Hegarty chris.hegarty at
Tue Oct 25 02:41:22 PDT 2011

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.

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.


> 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.

More information about the net-dev mailing list