tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject DO NOT REPLY [Bug 39621] Strange result in getRemoteAddr() and Access Logs using APR
Date Mon, 26 Jul 2010 05:48:48 GMT

--- Comment #7 from Lalit Mishra <> 2010-07-26 01:48:36
EDT ---
Created an attachment (id=25801)
 --> (

We faced this problem with RedHat 9 only when IPv6 is disabled.
Linux #1 SMP Tue Jun 10 17:56:55 IST 2008 i686 i686 i386 GNU/Linux
(this is not the stock kernel in RH 9).

APR version 1.3.9.

Absence of AI_ADDRCONFIG flag for getaddrinfo in glibc is the root cause. 
>From man getaddrinfo -

    If hints.ai_flags includes the AI_ADDRCONFIG flag, then IPv4 addresses are
returned in the list pointed to by result only if the  local system has at lea
st one IPv4 address configured, and IPv6 addresses are only returned if the
local system has at least one IPv6 address configured.

When tomcat searches for local address to bind, it finally calls call_resolver
function of sockaddr.c in APR with hostname=null. As AI_ADDRCONFIG flag is not
present, getaddrinfo returns "::" and in the list of available
addresses.  The tcnative method (, see address.c) prefers the IPv6
(::) address among these and returns this to Tomcat, and Tomcat specifies this
address to bind to the socket (surprisingly, the kernel does not complain when
binding an IPv6 address to an AF_INET socket). Therefore, APR code falsely ends
up setting AF_INET6 to local_addr->family and (later when accept returns) to
remote_addr->family as well. Thus when an IPv4 host connects, though accept
returns proper IPv4 address to APR, APR still believes it to be IPv6 address
and messes up while translating to presentation format.

If AI_ADDRCONFIF flag is not present, we need to determine if IPv6 is
*actually* available or not. This can be achieved by trying to open an IPv6
socket. If this fails then set hints.ai_family to AF_INET so that getaddrinfo
returns IPv4 addresses only. Of course do this only when family has been
specified as AF_UNSPEC. We do not want to return IPv4 addresses when asked
specifically for IPv6 addresses.
Please see attached patch (for APR 1.3.9).

Configure bugmail:
------- You are receiving this mail because: -------
You are the assignee for the bug.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message