[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#500558: Can't listen to 127.0.0.1 if eth0 has IPv6 only



reassign 500558 libapr1
tags 500558 + upstream
thanks

I traced back that problem to a call in libapr1, in call_resolver()
getaddrinfo("127.0.0.1", NULL, &hints, ...) that returns -9
because hints contains AI_ADDRCONFIG

Without that hint, it works.

Extract from call_resolver:
    if (family == APR_UNSPEC) {
        /* By default, only look up addresses using address types for
         * which a local interface is configured, i.e. no IPv6 if no
         * IPv6 interfaces configured. */
        hints.ai_flags = AI_ADDRCONFIG;
    }

Documentation from getaddrinfo(3):
       If  hints.ai_flags includes the AI_ADDRCONFIG flag, then IPv4 addresses
       are returned in the list pointed to by res only if the local system has
       at  least  one  IPv4  address  configured,  and IPv6 addresses are only
       returned if the local system has at least one IPv6 address configured.

But obviously, having an IPv6 on eth0, and both an IPv4 and IPv6 in lo, is not
enough to enable IPv4 resolution.

Attached is a tiny test case.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>


int main(int argc, char**argv) {
    struct addrinfo hints, *ai_list;
    int error;

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = AI_ADDRCONFIG;

	error = getaddrinfo("127.0.0.1", NULL, &hints, &ai_list);
	printf("error=%d flags=%d\n", error, hints.ai_flags);

    hints.ai_flags = 0;
	error = getaddrinfo("127.0.0.1", NULL, &hints, &ai_list);
	printf("error=%d flags=%d\n", error, hints.ai_flags);

	return 0;
}

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: