I am developing dual stack client-server communication. And I am curios: Do I have to open two sockets - one for IPv4 and one IPv6, or there is an option to open a socket for IPv6 and it will be able to work with both IPv4 and IPv6 connections? For example, if I open a socket like this:
SOCKET sock = socket(AF_INET6, SOCK_STREAM, 0);
and then call
int mode = 0;
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&mode, sizeof(mode));
Would it accept both IPv4 and IPv6 connections ? And if it will accept it, should I modify subsequent calls, to defining socket family and then do manipulation according to that family? something like:
if (addr->ss_family == AF_INET)
{
}
else if (addr->ss_family == AF_INET6)
{
}
Thanks on advance.