Question

We need to port IPv4 sockets to both IPv4 & IPv6. I would like to create a server IPv6 socket that will be bind in6addr_any. I understand that it can process IPv4 requests but my problem is that we provide an several bind options, one of them for example is bind to address.

We would like to be able to process IPv4 and IPv6 requests and this can be done by using only 1 socket.

Is it going to change when will need to bind the socket to ipv4 address? do we need to open new ipv4 socket?

any suggestion how to support it?

I hope that my question makes some sense. Feel free to ask for more details

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top