IPv6 question

John Burton john.burton at jbmail.com
Sun Feb 15 13:32:06 EST 2004


Martin v. Löwis" <martin at v.loewis.de> wrote in message
news:c0oc6j$592$01$1 at news.t-online.com...
> John Burton wrote:
> > If I need to create an IPv4 socket and IPv6 socket and listen on both
that
> > doesn't
> > seem to work.
> >
> >  sock4 = socket(AF_INET, SOCK_STREAM)
> >  sock4.bind(('', 12345))
> >  sock6 = socket(AF_INET6, SOCK_STREAM)
> >  sock6.bind(('', 12345))
> >
> > I get an error that the address is already in use on the 2nd bind even
> > though it's to a different
> > socket type. This is on linux.
> > Has anyone got this to work? Or am I missing something?
>
> You are missing something important. According to RFC 2553, a PF_INET6
> socket can be used for IPv4 communication, by means of IPV4_MAPPED
> addresses (::FFFF:<IPv4-address>). So an application openening a
> PF_INET6 listening socket will accept both IPv4 and IPv6 incoming
> connections.
>
> If you want a socket that listens only on IPv6 connections, you
> need to set the IPV6_V6ONLY socket option. In your case, it is
> sufficient to just not create the IPv4 socket. When clients connect
> through IPv4, you will find that the peername(2) of the socket
> is an IPv4-mapped address. You should never ever transmit such
> an address over the wire; it is meant for local use only.

Thank you for your reply. That makes a lot of sense and I've had another
try and it does work as you suggest. (I was thinking that Ipv6 sockets
were not receiving connections via ipv4 because as you say they are
reporting an ipv6 style mapped address)

I've got a horrible feeling it doesn't work like this on windows though
(my python build on windows doesn't seem to support ipv6 so I can't
try it)





More information about the Python-list mailing list