VirtualBox

Ignore:
Timestamp:
Dec 18, 2017 3:13:28 PM (7 years ago)
Author:
vboxsync
Message:

IPRT/socket.cpp: Initialize winsock before creating sockets.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/socket.cpp

    r70198 r70205  
    460460    AssertReturn(g_pfnsocket, VERR_NOT_SUPPORTED);
    461461    AssertReturn(g_pfnclosesocket, VERR_NOT_SUPPORTED);
     462    AssertReturn(g_pfnWSAStartup, VERR_NOT_SUPPORTED);
     463
     464    /* Initialize WinSock. */
     465    WORD const  wVersionRequested = MAKEWORD(1, 1);
     466    WSADATA     wsaData;
     467    RT_ZERO(wsaData);
     468    int rcWsa = g_pfnWSAStartup(wVersionRequested, &wsaData);
     469    AssertMsgReturn(wsaData.wVersion >= wVersionRequested && rcWsa == 0,
     470                    ("Wrong winsock version %#x rcWsa=%#x (%d)\n", wsaData.wVersion, rcWsa, rcWsa),
     471                    VERR_NOT_SUPPORTED);
    462472#endif
    463473
     
    688698        || !g_pfngethostbyname)
    689699        return VERR_NOT_SUPPORTED;
    690     WORD    wVersionRequested = MAKEWORD(1, 1);
    691     WSADATA wsaData;
     700    WORD const  wVersionRequested = MAKEWORD(1, 1);
     701    WSADATA     wsaData;
    692702    RT_ZERO(wsaData);
    693     rc = g_pfnWSAStartup(wVersionRequested, &wsaData);
    694     if (wsaData.wVersion != wVersionRequested)
    695     {
    696         AssertMsgFailed(("Wrong winsock version\n"));
    697         return VERR_NOT_SUPPORTED;
    698     }
     703    int rcWsa = g_pfnWSAStartup(wVersionRequested, &wsaData);
     704    AssertMsgReturn(wsaData.wVersion >= wVersionRequested && rcWsa == 0,
     705                    ("Wrong winsock version %#x rcWsa=%#x (%d)\n", wsaData.wVersion, rcWsa, rcWsa),
     706                    VERR_NOT_SUPPORTED);
    699707# define gethostbyname g_pfngethostbyname
    700708#endif
     
    780788        return VERR_NOT_SUPPORTED;
    781789    /** @todo someone should check if we really need 2, 2 here */
    782     WORD    wVersionRequested = MAKEWORD(2, 2);
    783     WSADATA wsaData;
    784     RT_ZERO(wszData);
    785     rc = WSAStartup(wVersionRequested, &wsaData);
    786     if (wsaData.wVersion != wVersionRequested)
    787     {
    788         AssertMsgFailed(("Wrong winsock version\n"));
    789         return VERR_NOT_SUPPORTED;
    790     }
     790    WORD const  wVersionRequested = MAKEWORD(2, 2);
     791    WSADATA     wsaData;
     792    RT_ZERO(wsaData);
     793    int rcWsa = g_pfnWSAStartup(wVersionRequested, &wsaData);
     794    AssertMsgReturn(wsaData.wVersion >= wVersionRequested && rcWsa == 0,
     795                    ("Wrong winsock version %#x rcWsa=%#x (%d)\n", wsaData.wVersion, rcWsa, rcWsa),
     796                    VERR_NOT_SUPPORTED);
    791797#  define getaddrinfo  g_pfngetaddrinfo
    792798#  define freeaddrinfo g_pfnfreeaddrinfo
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette