Title: WinSock 2 support on Win32 w/ MSVC++ 6 (fix #860134)
Type: Stage:
Components: Extension Modules Versions: Python 2.3
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: jeffconnelly, loewis
Priority: high Keywords: patch

Created on 2004-03-02 23:16 by jeffconnelly, last changed 2004-09-18 16:18 by loewis. This issue is now closed.

File name Uploaded Description Edit
py-winsock-patches.tar jeffconnelly, 2004-03-02 23:16 Use WinSock2 on Win32 Python
Messages (6)
msg45440 - (view) Author: Jeff Connelly aka shellreef (jeffconnelly) Date: 2004-03-02 23:16
WinSock 2 isn't supported on 2.3. The capability is 
there, but the Microsoft C++ version is incorrectly 
specified to the preprocessor, VC++ 6 (the version used 
to build the official Python Win32 executable) misses the 
#if's and links to wsock32.lib, instead. This results in the 
programmer only being able to use WinSock 1, instead of 
WinSock 2's useful functions.

On modern Win32's, WinSock 2 is prevalent, so the 
switch shouldn't cause too much trouble, as well as 
providing additional functionality.

The problem appears to be line 16 of socketmodule.h, 
which includes WinSock 2 #if _MSC_VER >= 1300 and 
WinSock 1 otherwise. (IP_HDRINCL is a part of WinSock 
2.) Apply this patch to use WinSock 2 on MS VC++ 6 
(1200), which is what the Python Win32 builds are 
compiled with. (1300 is .Net? maybe?) pyconfig.h also 
needs to be patched.

Also, the _socket moduleneeds to link with ws2_32.lib 
instead of wsock32.lib. (Project -> Settings -> highlight 
_socket -> Win32 release -> Link tab -> 
in "Object/library modules" change wsock32.lib to 

With these changes, IP_HDRINCL exists in socket:

Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC 
v.1200 32 
bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
>>> import socket
>>> socket.IP_HDRINCL

And it works as it should, as do other obscure WinSock 2 
msg45441 - (view) Author: Jeff Connelly aka shellreef (jeffconnelly) Date: 2004-03-02 23:18
Logged In: YES 

P.S.: The original bug report is here:
msg45442 - (view) Author: Jeff Connelly aka shellreef (jeffconnelly) Date: 2004-03-02 23:20
Logged In: YES 

P.S.: The original bug report is here:
msg45443 - (view) Author: Jeff Connelly aka shellreef (jeffconnelly) Date: 2004-07-17 10:17
Logged In: YES 

Can this change be merged into the current source tree? I 
need WinSock 2 for my application and distributing a patched 
version of Python isn't very elegant.
msg45444 - (view) Author: Jeff Connelly aka shellreef (jeffconnelly) Date: 2004-08-25 04:51
Logged In: YES 

Python 2.4a2 fixes this issue somewhat, but not completely.
Since the Win32 release is compiled using Visual Studio 7.1,
the IP_HDRINCL and related symbols are defined.

However, socketmodule still links to wsock32.lib instead of
ws2_32.lib. This means that setsockopt(IP_HDRINCL) appears
to work, and even returns None, but it doesn't really work.
From :

> You're not doing anything wrong.  The problem is that,
> Micorosoft's WinSock 2 doesn't support the IP_HDRINCL
socket option.
> They don't support IPPROTO_RAW ("raw IP") either. They
will gladly
> give you a socket, but then they send your IP header as
data, and
> send a bogus IP datagram that has 255--the value of
> as the protocol ID.  If you look at the net traffic that
> from this (with a net analyzer), you'd see the receiver of
> bogus datagram respond with a "Protocol Unreachable" ICMP
> message.
I haven't even succesfully sent raw sockets with wsock32.lib. 

This is fixed in ws2_32.lib. So all that Python has to do to
pull in these fixes is to link to wsock32.lib instead of
>Client: Requires Windows XP, Windows 2000 Professional, 
>Windows NT Workstation, Windows Me, Windows 98, or 
>Windows 95.
>Library: Use Ws2_32.lib.
Therefore it leads me to believe that having Python link
with ws2_32.lib shouldn't cause any compatibility problems
on older systems, provided they have the Winsock2 updates.

If anyone is here, can we expect this patch to be merged soon?

msg45445 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2004-09-18 16:18
Logged In: YES 

I have changed _socket.vcproj 1.6 to link with ws2_32.lib
(and I wonder whether any library needs to be specified in
the project in the first place).

I'm rejecting this patch as out-of-date - the build
procedure for VC6 won't be changed, now that we have VC7.
Date User Action Args
2004-03-02 23:16:49jeffconnellycreate