Skip to content

Instantly share code, notes, and snippets.

@stolsma
Created September 26, 2011 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stolsma/1243159 to your computer and use it in GitHub Desktop.
Save stolsma/1243159 to your computer and use it in GitHub Desktop.
Why only IPv6 will also listen for IPv4 on most Linux systems...

The best approach is to create an IPv6 server socket that can also accept IPv4 connections. To do so, create a regular IPv6 socket, turn off the socket option IPV6_V6ONLY, bind it to the "any" address, and start receiving. IPv4 addresses will be presented as IPv6 addresses, in the IPv4-mapped format.

The major difference across systems is whether IPV6_V6ONLY is a) available, and b) turned on or off by default. It is turned off by default on Linux (i.e. allowing dual-stack sockets without setsockopt), and is turned on on most other systems.

In addition, the IPv6 stack on Windows XP doesn't support that option. In these cases, you will need to create two separate server sockets, and place them into select or into multiple threads.

Found on: http://stackoverflow.com/questions/1618240/how-to-support-both-ipv4-and-ipv6-connections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment