[cs631apue] dual stack server

Jan Schaumann jschauma at stevens.edu
Tue Nov 24 20:54:56 EST 2020


Hello,

Since most of you have not set up your http server to
allow for simultaneously accepting connections via
IPv4 and IPv6, I've put together a code example:

https://stevens.netmeister.org/631/dualstack-streamread.c

The trick here is to use an IPv6 socket, and then to
disable the IPv6_ONLY option on it.  As a result, the
socket will allow IPv4 connections, but the IPv4
connections will become so-called "IPv4-mapped IPv6
addresses":
https://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses

There's a few additional considerations when you're
handling a dual-stack server, though many can be
resolved by using a 'struct sockaddr_storage' and then
casting that as needed.

Hope that gets you on the right path...

-Jan


More information about the cs631apue mailing list