[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] evhttp client error handling



On 11/13/2012 09:48 PM, Patrick Pelletier wrote:
So, I figured out that the initial error that's occurring is EAFNOSUPPORT. (Now, why that's happening is a separate mystery I need to figure out... it happens when I use "localhost" as the hostname, but not when I use "127.0.0.1".)

It looks like this has to do with the fact that bind_socket_ai (in http.c) assumes AF_INET when ai is NULL:

    /* Create listen socket */
    fd = evutil_socket_(ai ? ai->ai_family : AF_INET,
        SOCK_STREAM|EVUTIL_SOCK_NONBLOCK|EVUTIL_SOCK_CLOEXEC, 0);

(and when bind_socket_ai is called from bind_socket, ai will always be NULL)

using strace, I'm seeing the following activity on this socket:

socket(PF_INET, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = 7
setsockopt(7, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
connect(7, {sa_family=AF_INET6, sin6_port=htons(8421), inet_pton(AF_INET6, "::1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = -1 EAFNOSUPPORT (Address family not supported by protocol) shutdown(7, 1 /* send */) = -1 ENOTCONN (Transport endpoint is not connected)

So it looks like the problem is that the socket is created with PF_INET, but the connect uses AF_INET6. (Because the lookup for "localhost" returns two addresses, "::1" and "127.0.0.1", but since "::1" is first, that's the one that gets used.) Indeed, if I change bind_socket_ai to default to AF_INET6, then it gets past this point.

Not sure what the proper solution is for this, though. I'm not enough of a sockets expert. Although I'm curious why we need to create the socket before we've looked up the name. If we looked up the name first, then we could create the socket with the proper address family in the first place.

--Patrick

***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.