I am trying to create a socket to allow for IPv4-to-IPv4, IPv4-to-IPv6, IPv6-to-IPv4, and IPv6-to-IPv6 address connections.
1.) Are the protocol combinations (e.g. IPv4-to-IPv6, IPv6-to-IPv4) permissible?
2.) If so, do I use the family of the source address or destination address for creating the socket?
Currently I am using the source address and am getting socket error 10014 WSAEFAULT when using IPv6 source address and IPv4 destination address.
Relevant parts of code:
if ( !strchr( srcAddr, '[' ) )
sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
else
sock = socket( AF_INET6, SOCK_STREAM, IPPROTO_TCP );
if ( !strchr( srcAddr, '[' ) )
{
rc = bind( sock, ( struct sockaddr * ) &sAddrSrc,
sizeof( sAddrSrc ) );
}
else
{
rc = bind( sock, ( struct sockaddr * ) &sAddrSrc6,
sizeof( sAddrSrc6 ) );
}
if ( !strchr( destAddr, '[' ) )
{
rc = connect( sock, (struct sockaddr *) &sAddrDest,
sizeof(sAddrDest) );
}
else
{
rc = connect( sock, ( struct sockaddr * ) &sAddrDest6,
sizeof( sAddrDest6 ) );
}