Reputation: 21
Is there any support for Ipv6
socket programming by MFC
so that we can connect to a server having Ipv6
address using Microsoft foundation classes? I have read this link but it is not much help to me.
Upvotes: 1
Views: 875
Reputation: 1
The code here works for me:
LPCTSTR lpszHost = L"::1";
CSocket socket;
int nPort = 1234;
ADDRINFOT addrInfo;
memset( &addrInfo, 0, sizeof( addrInfo ) );
addrInfo.ai_family = AF_INET6;
addrInfo.ai_socktype = SOCK_STREAM;
if ( socket.CreateEx( &addrInfo ) )
{
struct sockaddr_in6 addr;
memset( (LPVOID)&addr, 0, sizeof( addr ) );
addr.sin6_family = AF_INET6;
addr.sin6_port = htons( nPort );
InetPtonW( AF_INET6, lpszHost, &addr.sin6_addr );
#ifdef MY_SOCKET_SERVER
// Server
BOOL bSuccess = socket.Bind( reinterpret_cast<const sockaddr*>(&addr), sizeof(sockaddr_in6) );
#else
// Client
BOOL bSuccess = socket.Connect( reinterpret_cast<const sockaddr*>(&addr), sizeof(sockaddr_in6) );
#endif
}
Upvotes: 0
Reputation: 6556
The CAsyncSocket does support IPv6 sort of. There are several methods to do that:
However, I'd suggest using Winsock 2 API directly.
Upvotes: 1