locked
Using PROTOCOL_INFO structure with WSASocket RRS feed

  • Question

  • Hi,
    
    I'm trying to create a socket for a dedicated Winsock Provider (on Windows Mobile 5). Because this was unsuccessful i tried to
    create a socket for each available Provider, again without success: static const int MaxProtocolEntries = 50; DWORD wBufferLength = MaxProtocolEntries * sizeof(WSAPROTOCOL_INFO); LPWSAPROTOCOL_INFO lpProtocolBuffer = (LPWSAPROTOCOL_INFO) malloc (wBufferLength); WSADATA ws2data; int numProtocols; LPWSAPROTOCOL_INFO found = 0; if (::WSAStartup (MAKEWORD(2,2), &ws2data) == 0) { numProtocols = WSAEnumProtocols (0, lpProtocolBuffer, &wBufferLength); if (numProtocols != SOCKET_ERROR) { for (int i = 0; i < numProtocols; ++i) { LPWSAPROTOCOL_INFO pi = lpProtocolBuffer + i; if (_tcscmp (pi->szProtocol, TEXT("Windows CE MS Tcpip [TCP/IP]")) == 0) { found = pi; } SOCKET s = ::WSASocket (FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, pi, 0, 0); DWORD err = ::GetLastError(); if (s != INVALID_SOCKET) { ::closesocket (s); } } } } The error value is either 6(ERROR_INVALID_HANDLE) or 10047(WSAEAFNOSUPPORT). It seems that WSASocket is ignoring the PROTOCOL_INFO
    structure, what stands in conflict to the Windows CE 5.0 documentation. By the way, i know that this code will run on a Windows
    desktop platform. Any ideas or suggestions ? Jens
    Wednesday, August 4, 2010 2:57 PM

Answers

  • All you have to do is to fill additionally the first 3 parameter:

    ::WSASocket (pi->iAddressFamily, pi->iSocketType, pi->iProtocol, pi, 0, 0);

    Then WSASocket creates the socket with the requested Winsock Service Provider, you can check this by using getsockopt with SOL_SOCKET and SO_PROTOCOL_INFO.

    Jens

    • Marked as answer by JoBiNo Thursday, August 5, 2010 12:14 PM
    Thursday, August 5, 2010 12:14 PM