Problem when using WSAConnectByName, alway return socket error #10109

I tried on a Fresh installed Vista and my working Vista, using the sample code from MSDN help.

here is the source:


SOCKET OpenAndConnect(LPSTR NodeName, LPSTR PortName)
{
SOCKET ConnSocket;
int ipv6only = 0;
int iResult;
BOOL bSuccess;
SOCKADDR_STORAGE LocalAddr = {0};
SOCKADDR_STORAGE RemoteAddr = {0};
DWORD dwLocalAddr = sizeof(LocalAddr);
DWORD dwRemoteAddr = sizeof(RemoteAddr);

ConnSocket = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
if (ConnSocket == INVALID_SOCKET){
return INVALID_SOCKET;
}

iResult = setsockopt(ConnSocket, IPPROTO_IPV6,
IPV6_V6ONLY, (char*)&ipv6only, sizeof(ipv6only) );
if (iResult == SOCKET_ERROR){
closesocket(ConnSocket);
return INVALID_SOCKET;
}

bSuccess = WSAConnectByName(ConnSocket, NodeName,
PortName, &dwLocalAddr,
(SOCKADDR*)&LocalAddr,
&dwRemoteAddr,
(SOCKADDR*)&RemoteAddr,
NULL,
NULL);
if (bSuccess){
return ConnSocket;
} else {
fprintf(stderr,"Error Opening socket, error %d: %s\n",
WSAGetLastError(), PrintError(WSAGetLastError()));
return INVALID_SOCKET;
}
}

[1233 byte] By [wy6688] at [2008-1-10]
# 1

What nodename and servicename are you passing to connectbyname? Also, what is the output of “netsh winsock show catalog” from a command prompt? We have an idea of what might be wrong, but need this information to proceed. Thanks!

GabeFrost[MSFT] at 2007-10-3 > top of Msdn Tech,Windows Networking Development,Network Quality of Service (QoS/qWAVE)...
# 2

the NodeName is the computerName (HostName), The ServiceName is a port number converted to string, "55720".

output for netsh winsock show catalog is too long for post here.


wy6688 at 2007-10-3 > top of Msdn Tech,Windows Networking Development,Network Quality of Service (QoS/qWAVE)...