apr-bugs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 49678] getRemoteAddr() returns IPv6 address on RedHat 9 when IPv6 is disabled
Date Thu, 05 Aug 2010 07:10:32 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=49678

--- Comment #8 from Lalit Mishra <lalit.mishra@airtightnetworks.com> 2010-08-05 03:10:27
EDT ---
(In reply to comment #7)
> Sorry I meant bind() will fail there.

As mentioned in bug description 

> (surprisingly, the kernel does not complain when
binding an IPv6 address to an AF_INET socket).

bind() does not fail.

Let me illustrate the whole problem with a minimal program. This listing is
extension of previous program. Still this code follows the same behavior as
AprEndPoint.init() does.


#include "apr.h"
#include "apr_pools.h"
#include "apr_arch_networkio.h"
#include "apr_network_io.h"
#include "apr_strings.h"
#include "apr_mmap.h"
#include "stdio.h"

int main() {
    apr_pool_t *pool = NULL;
    apr_sockaddr_t *sa, *sl, *bindAddr = NULL;
    apr_int32_t f = 0;
    apr_socket_t *socket, *acceptedSocket;
    int ret_val = 0;

    apr_initialize();
    apr_pool_create(&pool, NULL);

    apr_sockaddr_info_get(&sa, NULL, AF_UNSPEC, 1756, f, pool);

    sl = sa;

        /* if there is an IPv6 address returned, prefer to use that (tcnative
         * has similar behavior).
    while(sl) {
        char addrStr[100];

        memset(addrStr, '\0', 100);

        if(sl->family == AF_INET6) {
            apr_sockaddr_ip_getbuf (addrStr, 99, sl);
            printf("Found IPv6 address %s. Breaking.\n", addrStr);
            bindAddr = sl;
        }

        sl = sl->next;
    }

    if(bindAddr == NULL) 
        bindAddr = sa;

    ret_val = apr_socket_create(&socket, AF_UNSPEC, SOCK_STREAM, APR_PROTO_TCP,
pool);

    ret_val = apr_socket_bind(socket, bindAddr);

    ret_val = apr_socket_listen(socket, 1);

    ret_val = apr_socket_accept(&acceptedSocket, socket, pool);

    {
        char remoteAddrStr[100];
        memset(remoteAddrStr, '\0', 100);
        apr_sockaddr_ip_getbuf(remoteAddrStr, 99, acceptedSocket->remote_addr);
        printf("Remote address %s\n", remoteAddrStr);
    }
}


In both following cases after running this program, I'd simply telnet to the
machine on the chosen port (1756 in this case) from a different machine
(192.168.11.184).

When run on CentOS machine with IPv6 disabled
=============================================

ifconfig 
eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:192.168.8.215  Bcast:192.168.11.255  Mask:255.255.252.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10648137 errors:0 dropped:0 overruns:0 frame:0
          TX packets:272642 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:1111501223 (1.0 GiB)  TX bytes:230566540 (219.8 MiB)
          Memory:d0200000-d0220000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:67332 errors:0 dropped:0 overruns:0 frame:0
          TX packets:67332 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:24496050 (23.3 MiB)  TX bytes:24496050 (23.3 MiB)

./getLocalAddr 
Remote address 192.168.11.184

telnet 192.168.8.215 1756
Trying 192.168.8.215...
Connected to 192.168.8.215.
Escape character is '^]'.
Connection closed by foreign host.

When run on RH9 machine with IPv6 disabled
==========================================

ifconfig 
eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:192.168.8.97  Bcast:192.168.11.255  Mask:255.255.252.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6696363 errors:0 dropped:0 overruns:0 frame:0
          TX packets:205660 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:482996699 (460.6 Mb)  TX bytes:70162877 (66.9 Mb)
          Base address:0x2000 Memory:48180000-481a0000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:214777 errors:0 dropped:0 overruns:0 frame:0
          TX packets:214777 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:47510460 (45.3 Mb)  TX bytes:47510460 (45.3 Mb)


./getLocalAddr 
Found IPv6 address ::. Breaking.
Remote address ::9b1b:0:28b3:fcb7

telnet 192.168.8.97 1756
Trying 192.168.8.97...
Connected to 192.168.8.97.
Escape character is '^]'.
Connection closed by foreign host.

Note the remote address returned on RH9 machine. I hope this clears what is
happening here.
The problem is because apr_socket_t.local_addr is IPv6 and so it believes
apr_socket_t.remote_addr will also be IPv6. So the while converting from
network to presentation format, we are trying to convert bytes which are
actually IPv4 address believing those bytes represent an IPv6 address. There is
no bug in the conversion to presentation format.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


Mime
View raw message