BAD pointer in WSADATA

Тема в разделе "WASM.NETWORKS", создана пользователем wsd, 28 мар 2008.

  1. wsd

    wsd New Member

    Публикаций:
    0
    Регистрация:
    8 авг 2007
    Сообщения:
    2.824
    У меня ХР2 build 2600
    socket 2.2

    В структуре WSADATA есть поле
    char FAR* lpVendorInfo

    по мсдн оно нужно для обратной
    совместимости с Socket 1.1
    После инициализации WSAStartup
    это поле инициализируется у меня
    не NULL!!! , a бад
    указателем(на недоступную память).
    Это так и должно быть?
    или это только в моём билде?
     
  2. censored

    censored New Member

    Публикаций:
    0
    Регистрация:
    5 июл 2005
    Сообщения:
    1.615
    Адрес:
    деревня "Анонимные Прокси"
    wsd
    Можно быстро проверить
    Код (Text):
    1. #define STRICT
    2. #define _WIN32_WINNT 0x0500
    3. #include <winsock2.h>
    4. #include <windows.h>
    5. #include <stdio.h>
    6.  
    7. struct wsainit {
    8.   WSADATA wsa;
    9.   explicit wsainit(WORD version) {
    10.     WSAStartup(version, &wsa);
    11.     __try {
    12.       printf((wsa.lpVendorInfo != NULL ? "%p - %02X\n" : "%p"),
    13.         wsa.lpVendorInfo, *(BYTE*)wsa.lpVendorInfo);
    14.     } __except (1) {
    15.       printf("except\n");
    16.     }
    17.   }
    18.   ~wsainit() {
    19.      WSACleanup();
    20.   }  
    21. };
    22.  
    23. int main() {
    24.   wsainit _10(MAKEWORD(1, 0));
    25.   wsainit _11(MAKEWORD(1, 1));
    26.   wsainit _20(MAKEWORD(2, 0));
    27.   wsainit _22(MAKEWORD(2, 2));
    28. }
    29.  
    30. /* [EOF] */
    WinXP SP2 Eng + hotfixes
     
  3. wsd

    wsd New Member

    Публикаций:
    0
    Регистрация:
    8 авг 2007
    Сообщения:
    2.824
    censored
    пипец
    Код (Text):
    1. except
    2. except
    3. except
    4. except
     
  4. IceStudent

    IceStudent Active Member

    Публикаций:
    0
    Регистрация:
    2 окт 2003
    Сообщения:
    4.300
    Адрес:
    Ukraine
    wsd
    А что тебя интересует? Что оно не работает для 1.1? Или то, что не инициализируется нулём в 2.0+? По второму всё просто:

    Код (Text):
    1. Sockeye.c:
    2. // BUGBUG  ignored for 2.0+  ShowStr ("  ", pWSAData->lpVendorInfo);
    3.  
    4. Startup.cpp:
    5.         // The following line is commented-out due to annoying and totally
    6.         // nasty alignment problems in WINSOCK[2].H. The exact location of
    7.         // the lpVendorInfo field of the WSAData structure is dependent on
    8.         // the structure alignment used when compiling the source. Since we
    9.         // cannot change the structure alignment of existing apps, the best
    10.         // way to handle this mess is to just not set this value. This turns
    11.         // out to not be too bad a solution, as neither the WinNT nor the Win95
    12.         // WinSock implementations set this value, and nobody appears to pay
    13.         // any attention to it anyway.
    14.         //
    15.         // lpWSAData->lpVendorInfo = NULL;
    И только в wow32 оно инициализируется нулём.

    censored
    Для чистоты эксперимента надо было бы чуть по-другому написать:
    Код (Text):
    1. printf("%p - ", wsa.lpVendorInfo); if(wsa.lpVendorInfo) printf("%02X\n", *(BYTE*)wsa.lpVendorInfo);
     
  5. wsd

    wsd New Member

    Публикаций:
    0
    Регистрация:
    8 авг 2007
    Сообщения:
    2.824
    IceStudent
    супер
    только M$ надо это в мсдн было запихнуть, а то опять люди подумали
    что их сильно подглючило...
     
  6. IceStudent

    IceStudent Active Member

    Публикаций:
    0
    Регистрация:
    2 окт 2003
    Сообщения:
    4.300
    Адрес:
    Ukraine
    wsd
    В принципе, да. Одним lpvReserved'ом больше бы стало..