Error in WS2DETECT routine?

Giganews Newsgroups
Subject: Error in WS2DETECT routine?
Posted by:  Scott Bussinger (scot…@opto-pps.com)
Date: Tue, 29 Jul 2003

I'm not sure where to report this, but I think there's an error in the
WS2DETECT.DPR routine for detecting that WinSock2 is installed. The same
issue exists in the .ASM version as well. The pertinent routine is:

    function IsWS2Avail : Cardinal; stdcall;

and the important line is:

    WSAStartup($1010,Data);

If I'm reading the documentation for WSAStartup correctly, this routine
this requests that you'd like to access Winsock version 16.16. The
routine then ignores any error codes from the WSAStartup call and looks
at the returned data to decide what's there. No where in the function
documentation that I can see does it say that the contents of Data are
valid if an error is returned. Also I don't think WSACleanup should be
called if WSAStartup isn't successful.

The code in IdStackWindows uses $202 for the version check and that
makes perfect sense as Winsock version 2.2. I think what the code for
the test should be doing is using $101 for the version check and then
check for a result code of 0 before checking the returned version
number. Here would be my recommendation for the way the routine should
look:

      if WSAStartup($0101,Data) = 0 then
      begin
        If (Hi ( Data.wHighVersion)>1) then
        begin
          Result := 1;
        end;
        WSACleanup;
      end;

Be seeing you.

Replies