[Top][All Lists]

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

FWD: Winsock initialisation is incorrect ...

From: Mats Erik Andersson
Subject: FWD: Winsock initialisation is incorrect ...
Date: Fri, 25 Sep 2015 19:06:51 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

Hello there,

the following message [1] has been received by the Shishi list.
It seems that Gnulib is the relevant realm for this matter, in
particular the file 'lib/sockets.h' and gl_sockets_startup() are
being touch by complaints and suggestions. I know absolutely
nothing about Winsocks and MinGW, so please evaluate the claims
made by this anonymous user. He maintains a view that the byte
order applied to the macros SOCKETS_#_# is incorrect.

Best regards,
  Mats Erik Andersson, on behalf of Shishi

[1] http://lists.gnu.org/archive/html/help-shishi/2015-09/msg00001.html

----- Beginning of forwarded text -----

To whom it may concern:

I built shishi-1.0.2 using MinGW and MSYS. All `make check' tests failed
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

>From MSDN

*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

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,
you already told it the highest version that you can accept. Therefore, if
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.

----- End of forwarded text -----

reply via email to

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