If you create an IPv6 socket with V6ONLY=0
and bind to the wildcard IPv6 address then you can accept both IPv4 and IPv6 connections on that single socket.
If you want to bind to explicit addresses then you need multiple sockets: one for each address. It is probably easiest to create IPv4 sockets for the IPv4 addresses you want to bind to, and IPv6 sockets for the IPv6 addresses, although you could use IPv6 sockets for everything.
In that last case you create an IPv6 socket with V6ONLY=0
for each IPv4 address and bind it to the mapped address. For IPv4 address aaa.bbb.ccc.ddd
you would bind to IPv6 address ::ffff:aaa.bbb.ccc.ddd
(if your implementation accepts this notation) or else to ::ffff:wwxx:yyzz
, where ww
is the hexadecimal representation of aaa
, xx
the hex version of bbb
, etc.