From 3932978feb80273f87b4bace789541890a9dce0f Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Tue, 5 Mar 2019 07:48:58 -0800 Subject: [PATCH 1/6] add constants --- Lib/test/test_socket.py | 20 +++++++++++++ Modules/socketmodule.c | 62 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 571f45c2b030ca..110ed347679d41 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -875,6 +875,26 @@ def testCrucialConstants(self): socket.SOCK_SEQPACKET socket.SOL_SOCKET socket.SO_REUSEADDR + if socket.has_ipv6: + socket.AF_INET6 + + def testCrucialIpProtoConstants(self): + socket.IPPROTO_TCP + socket.IPPROTO_UDP + socket.IPPROTO_IPV4 + if socket.has_ipv6: + socket.IPPROTO_IPV6 + + @unittest.skipUnless(os.name == "nt", "Windows specific") + def testWindowsSpecificConstants(self): + socket.IPPROTO_ICLFXBM + socket.IPPROTO_ST + socket.IPPROTO_CBT + socket.IPPROTO_IGP + socket.IPPROTO_RDP + socket.IPPROTO_PGM + socket.IPPROTO_L2TP + socket.IPPROTO_SCTP def testHostnameRes(self): # Testing hostname resolution mechanisms diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 8c3c2faddb9d21..07976341e5e974 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -308,6 +308,40 @@ if_indextoname(index) -- return the corresponding interface name\n\ # include # endif +/* Macros based on the IPPROTO enum, see: https://bugs.python.org/issue29515 */ +#ifdef MS_WINDOWS +#define IPPROTO_ICMP IPPROTO_ICMP +#define IPPROTO_IGMP IPPROTO_IGMP +#define IPPROTO_GGP IPPROTO_GGP +#define IPPROTO_TCP IPPROTO_TCP +#define IPPROTO_PUP IPPROTO_PUP +#define IPPROTO_UDP IPPROTO_UDP +#define IPPROTO_IDP IPPROTO_IDP +#define IPPROTO_ND IPPROTO_ND +#define IPPROTO_RAW IPPROTO_RAW +#define IPPROTO_MAX IPPROTO_MAX +#define IPPROTO_HOPOPTS IPPROTO_HOPOPTS +#define IPPROTO_IPV4 IPPROTO_IPV4 +#define IPPROTO_IPV6 IPPROTO_IPV6 +#define IPPROTO_ROUTING IPPROTO_ROUTING +#define IPPROTO_FRAGMENT IPPROTO_FRAGMENT +#define IPPROTO_ESP IPPROTO_ESP +#define IPPROTO_AH IPPROTO_AH +#define IPPROTO_ICMPV6 IPPROTO_ICMPV6 +#define IPPROTO_NONE IPPROTO_NONE +#define IPPROTO_DSTOPTS IPPROTO_DSTOPTS +#define IPPROTO_EGP IPPROTO_EGP +#define IPPROTO_PIM IPPROTO_PIM +#define IPPROTO_ICLFXBM IPPROTO_ICLFXBM // Windows only +#define IPPROTO_ST IPPROTO_ST // Windows only +#define IPPROTO_CBT IPPROTO_CBT // Windows only +#define IPPROTO_IGP IPPROTO_IGP // Windows only +#define IPPROTO_RDP IPPROTO_RDP // Windows only +#define IPPROTO_PGM IPPROTO_PGM // Windows only +#define IPPROTO_L2TP IPPROTO_L2TP // Windows only +#define IPPROTO_SCTP IPPROTO_SCTP // Windows only +#endif /* MS_WINDOWS */ + /* Provides the IsWindows7SP1OrGreater() function */ #include @@ -355,7 +389,7 @@ remove_unusable_flags(PyObject *m) for (int i=0; i Date: Tue, 5 Mar 2019 18:11:18 +0100 Subject: [PATCH 2/6] add back space --- .../next/Windows/2019-03-05-18-09-43.bpo-29515.vwUTv0.rst | 1 + Modules/socketmodule.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Windows/2019-03-05-18-09-43.bpo-29515.vwUTv0.rst diff --git a/Misc/NEWS.d/next/Windows/2019-03-05-18-09-43.bpo-29515.vwUTv0.rst b/Misc/NEWS.d/next/Windows/2019-03-05-18-09-43.bpo-29515.vwUTv0.rst new file mode 100644 index 00000000000000..6117eaba26b6c6 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2019-03-05-18-09-43.bpo-29515.vwUTv0.rst @@ -0,0 +1 @@ +socket module is missing many IPPROTO_* constants on Windows diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 07976341e5e974..7b501027d44307 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -389,7 +389,7 @@ remove_unusable_flags(PyObject *m) for (int i=0; i Date: Tue, 5 Mar 2019 19:55:31 +0100 Subject: [PATCH 3/6] do not check for IPPROTO_IPV4 --- Lib/test/test_socket.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 9391b0ab333265..8bff1fb44c701b 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -880,7 +880,6 @@ def testCrucialConstants(self): def testCrucialIpProtoConstants(self): socket.IPPROTO_TCP socket.IPPROTO_UDP - socket.IPPROTO_IPV4 if socket.has_ipv6: socket.IPPROTO_IPV6 From fe190eb281005f37a5e70173d5b260e0126dcba1 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Tue, 5 Mar 2019 20:48:04 +0100 Subject: [PATCH 4/6] use more broad #ifdef --- Modules/socketmodule.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 7b501027d44307..80b706a7f57cd7 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -332,14 +332,14 @@ if_indextoname(index) -- return the corresponding interface name\n\ #define IPPROTO_DSTOPTS IPPROTO_DSTOPTS #define IPPROTO_EGP IPPROTO_EGP #define IPPROTO_PIM IPPROTO_PIM -#define IPPROTO_ICLFXBM IPPROTO_ICLFXBM // Windows only -#define IPPROTO_ST IPPROTO_ST // Windows only -#define IPPROTO_CBT IPPROTO_CBT // Windows only -#define IPPROTO_IGP IPPROTO_IGP // Windows only -#define IPPROTO_RDP IPPROTO_RDP // Windows only -#define IPPROTO_PGM IPPROTO_PGM // Windows only -#define IPPROTO_L2TP IPPROTO_L2TP // Windows only -#define IPPROTO_SCTP IPPROTO_SCTP // Windows only +#define IPPROTO_ICLFXBM IPPROTO_ICLFXBM // WinSock2 only +#define IPPROTO_ST IPPROTO_ST // WinSock2 only +#define IPPROTO_CBT IPPROTO_CBT // WinSock2 only +#define IPPROTO_IGP IPPROTO_IGP // WinSock2 only +#define IPPROTO_RDP IPPROTO_RDP // WinSock2 only +#define IPPROTO_PGM IPPROTO_PGM // WinSock2 only +#define IPPROTO_L2TP IPPROTO_L2TP // WinSock2 only +#define IPPROTO_SCTP IPPROTO_SCTP // WinSock2 only #endif /* MS_WINDOWS */ /* Provides the IsWindows7SP1OrGreater() function */ @@ -389,7 +389,7 @@ remove_unusable_flags(PyObject *m) for (int i=0; i Date: Tue, 5 Mar 2019 21:33:24 +0100 Subject: [PATCH 5/6] minor style change --- Lib/test/test_socket.py | 4 ++-- Modules/socketmodule.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 8bff1fb44c701b..8a990ea3141073 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -867,6 +867,8 @@ def testSendtoErrors(self): def testCrucialConstants(self): # Testing for mission critical constants socket.AF_INET + if socket.has_ipv6: + socket.AF_INET6 socket.SOCK_STREAM socket.SOCK_DGRAM socket.SOCK_RAW @@ -874,8 +876,6 @@ def testCrucialConstants(self): socket.SOCK_SEQPACKET socket.SOL_SOCKET socket.SO_REUSEADDR - if socket.has_ipv6: - socket.AF_INET6 def testCrucialIpProtoConstants(self): socket.IPPROTO_TCP diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 80b706a7f57cd7..7947882dc957a5 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -7692,7 +7692,7 @@ PyInit__socket(void) PyModule_AddIntMacro(m, IPPROTO_MAX); #endif -#ifdef MS_WINDOWS +#ifdef MS_WINDOWS PyModule_AddIntMacro(m, IPPROTO_ICLFXBM); PyModule_AddIntMacro(m, IPPROTO_ST); PyModule_AddIntMacro(m, IPPROTO_CBT); From 3c6dec766237f325d16983cbd8aeba113c72b62f Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Tue, 5 Mar 2019 21:54:40 +0100 Subject: [PATCH 6/6] update NEWS entry --- .../2019-03-05-18-09-43.bpo-29515.vwUTv0.rst | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Windows/2019-03-05-18-09-43.bpo-29515.vwUTv0.rst b/Misc/NEWS.d/next/Windows/2019-03-05-18-09-43.bpo-29515.vwUTv0.rst index 6117eaba26b6c6..2f3f0991d9a283 100644 --- a/Misc/NEWS.d/next/Windows/2019-03-05-18-09-43.bpo-29515.vwUTv0.rst +++ b/Misc/NEWS.d/next/Windows/2019-03-05-18-09-43.bpo-29515.vwUTv0.rst @@ -1 +1,27 @@ -socket module is missing many IPPROTO_* constants on Windows +Add the following socket module constants on Windows: +IPPROTO_AH +IPPROTO_CBT +IPPROTO_DSTOPTS +IPPROTO_EGP +IPPROTO_ESP +IPPROTO_FRAGMENT +IPPROTO_GGP +IPPROTO_HOPOPTS +IPPROTO_ICLFXBM +IPPROTO_ICMPV6 +IPPROTO_IDP +IPPROTO_IGMP +IPPROTO_IGP +IPPROTO_IPV4 +IPPROTO_IPV6 +IPPROTO_L2TP +IPPROTO_MAX +IPPROTO_ND +IPPROTO_NONE +IPPROTO_PGM +IPPROTO_PIM +IPPROTO_PUP +IPPROTO_RDP +IPPROTO_ROUTING +IPPROTO_SCTP +IPPROTO_ST