[Xcb] [PATCH] Bug: Can’t connect to localhost without global connectivity

Michael Stapelberg michael+xcb at stapelberg.de
Sat Aug 13 12:54:05 PDT 2011


Hi,

I recently noticed that I cannot use programs which use libxcb with
DISPLAY=127.0.0.1:0 when my system has no IP addresses apart from
127.0.0.1 and ::1 on 'lo'.

A bit of debugging reveals that the problem is the flags which are
used to call getaddrinfo() in src/xcb_util.c:_xcb_open_tcp:301, namely
AI_ADDRCONFIG.

AI_ADDRCONFIG will only return IPv4 addresses if the system has an IPv4
address configured (likewise for IPv6). This also takes place when
resolving localhost (or 127.0.0.0/8 or ::1). Also, as per RFC 3493,
loopback addresses are not considered as valid addresses when
determining whether to return IPv4 or IPv6 addresses.

Basically, we have two possibilities:

1) Drop the AI_ADDRCONFIG flag. This will result in getting IPv4 *and*
   IPv6 addresses for names like "localhost" or any domain name which
   has AAAA and A records. The results will be sorted according to RFC
   3484 so that a system without a configured (and native, as in
   not-tunneled) IPv6 address will try the IPv4 record first.

   So the difference is that if the IPv4 address does not work, systems
   without IPv6 will still try to open a socket and connect via IPv6,
   which will fail immediately. Since XCB does not signal these errors
   anyways (it will only say that the X connection has some error),
   this is not a problem at all.

   The fix in this case is to just remove the AI_ADDRCONFIG flag
   entirely.

2) Drop the AI_ADDRCONFIG flag only when connecting to localhost,
   127.0.0.0/8 or [::1]. This is a work-around, but should do the trick
   for most use cases. I have attached a patch for this.

I think that 1) is the best option. It will fix the problem without any
side-effects for the user. In case you want a more conservative fix (or
work-around), use my patch for 2).

Thanks in advance,
Best regards,
Michael

PS: My use case is http://x11vis.org/ which prefers TCP connections over
    UNIX socket connections because it can identify the remote end when
    using TCP.

PPS: A related ticket (to getaddrinfo() for local addresses and the
     effects of AI_ADDRCONF) can be found at
     http://sourceware.org/bugzilla/show_bug.cgi?id=10083
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-tcp-Use-AI_ADDRCONFIG-only-for-non-localhost.patch
Type: text/x-patch
Size: 2293 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20110813/845b2fc7/attachment.bin>


More information about the Xcb mailing list