[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Winsock initialisation is incorrect in shishi-1.0.2

From: Test User
Subject: Winsock initialisation is incorrect in shishi-1.0.2
Date: Sat, 12 Sep 2015 11:01:55 -0500

To whom it may concern:

I built shishi-1.0.2 using MinGW and MSYS. All `make check' tests failed with
libshishi: warning: Failed to initialized Windows sockets (2)
I am on Windows 8.1.

There are two problems:
1) Incorrect definition of SOCKET* constants in gl/sockets.h

Your definitions are:
#define SOCKETS_1_0 0x100    don't use - does not work on Windows XP
#define SOCKETS_1_1 0x101
#define SOCKETS_2_0 0x200    don't use - does not work on Windows XP
#define SOCKETS_2_1 0x201
#define SOCKETS_2_2 0x202


wVersionRequested [in]

The highest version of Windows Sockets specification that the caller can use. The high-order byte specifies the minor version number; the low-order byte specifies the major version number.

This means that if you want to request Winsock 2.1 (as you do) wRequested version must be
0x0102, not 0x0201. In lib/init.c, where you have
rc = gl_sockets_startup (SOCKETS_2_1);
you are actually requesting version 1.2.

This leads us to the next problem, which is

2) The test for a compatible version of Winsock is incorrect.

Now let us consider gl_sockets_startup.

int err;

err = WSAStartup (version, &data);
if (err != 0)
  return 1;

if (data.wVersion < version)
  return 2;

Suppose that we were requesting Winsock 2.0
on a system that had only 1.1. Then version (the requested version) would be
0x0002 and the available version would be 0x0101. In this case
data.wVersion < version is
0x0101 < 0x0002 which is false, so you would end up accepting Winsock 1.1
even though you wanted to reject it because it less than the 2.0 that you wanted.

You do not need to rearrange the bytes before comparing them. Remember that
WSAStartup must return the version that you requested or a lower one, because
you already told it the highest version that you can accept. Therefore, if the
version that is returned is different from the version that was requested, it must be
less than the version that was requested.

To fix the problem, you must:
a) define the SOCKETS_* constants as follows:
#define SOCKETS_1_0 0x0001
#define SOCKETS_1_1 0x0101
#define SOCKETS_2_0 0x0002
#define SOCKETS_2_1 0x0102
#define SOCKETS_2_2 0x0202

b) change the definition of gl_sockets_startup to:

int err;

err = WSAStartup (version, &data);
if (err != 0)
  return 1;

if (data.wVersion != version)
    /* Winsock was initialised, but with an unacceptable version
       so we must clean up before we return the error. */

    return 2;

I made those changes and now I have 9 tests out of 15 passing. The remaining 6 failures
may be the subject of future reports, depending on my free time. I just compiled it because
gss-api can use it, and curl (my real goal) can use gss-api.

Test User.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]