Detecting IPv6 support

Martin v. Löwis loewis at
Wed Sep 18 02:48:52 EDT 2002

Pekka Pessi <Pekka.Pessi at> writes:

> 	I have Redhat 7.3. The prepackaged RPMs have disabled IPv6, but
> 	the underlying OS supports it. So, this is what happens with the
> 	bind() system call, for instance:

I see. Testing for that isn't really supported. A reliable way is to
inspect pyconfig.h, whose location is available through
distutils.sysconfig.get_config_h_filename(); check whether it contains
a line

#define ENABLE_IPV6 1

(more precisely, check whether the line containing ENABLE_IPV6 does
not contain undef, and starts with whitespace*#.

> 	So AF_INET6 is there, and I can create a socket, but everything
> 	dealing with addresses fails. 

That, perhaps, gives a reliable test, too: See whether
socket.getaddrinfo("::",80) succeeds.

Determining whether the system "supports" IPv6 is more tricky: If you
can create an INET6 socket, the system supports the protocol. I don't
know how to find out whether there are any configured non-local
interfaces. I don't think there is a way to determine whether the
system has v6 connectivity to "the world".


More information about the Python-list mailing list