@@ -339,13 +339,6 @@ if_indextoname(index) -- return the corresponding interface name\n\
339
339
# include "addrinfo.h"
340
340
#endif
341
341
342
- #ifndef HAVE_INET_PTON
343
- #if !defined(NTDDI_VERSION ) || (NTDDI_VERSION < NTDDI_LONGHORN )
344
- int inet_pton (int af , const char * src , void * dst );
345
- const char * inet_ntop (int af , const void * src , char * dst , socklen_t size );
346
- #endif
347
- #endif
348
-
349
342
#ifdef __APPLE__
350
343
/* On OS X, getaddrinfo returns no error indication of lookup
351
344
failure, so we must use the emulation instead of the libinfo
@@ -514,11 +507,13 @@ select_error(void)
514
507
# define SET_SOCK_ERROR (err ) WSASetLastError(err)
515
508
# define SOCK_TIMEOUT_ERR WSAEWOULDBLOCK
516
509
# define SOCK_INPROGRESS_ERR WSAEWOULDBLOCK
510
+ # define SUPPRESS_DEPRECATED_CALL __pragma(warning(suppress: 4996))
517
511
#else
518
512
# define GET_SOCK_ERROR errno
519
513
# define SET_SOCK_ERROR (err ) do { errno = err; } while (0)
520
514
# define SOCK_TIMEOUT_ERR EWOULDBLOCK
521
515
# define SOCK_INPROGRESS_ERR EINPROGRESS
516
+ # define SUPPRESS_DEPRECATED_CALL
522
517
#endif
523
518
524
519
@@ -4397,15 +4392,15 @@ SIO_LOOPBACK_FAST_PATH: 'option' is a boolean value, and is disabled by default"
4397
4392
static PyObject *
4398
4393
sock_share (PySocketSockObject * s , PyObject * arg )
4399
4394
{
4400
- WSAPROTOCOL_INFO info ;
4395
+ WSAPROTOCOL_INFOW info ;
4401
4396
DWORD processId ;
4402
4397
int result ;
4403
4398
4404
4399
if (!PyArg_ParseTuple (arg , "I" , & processId ))
4405
4400
return NULL ;
4406
4401
4407
4402
Py_BEGIN_ALLOW_THREADS
4408
- result = WSADuplicateSocket (s -> sock_fd , processId , & info );
4403
+ result = WSADuplicateSocketW (s -> sock_fd , processId , & info );
4409
4404
Py_END_ALLOW_THREADS
4410
4405
if (result == SOCKET_ERROR )
4411
4406
return set_error ();
@@ -4636,7 +4631,7 @@ sock_initobj(PyObject *self, PyObject *args, PyObject *kwds)
4636
4631
#ifdef MS_WINDOWS
4637
4632
/* recreate a socket that was duplicated */
4638
4633
if (PyBytes_Check (fdobj )) {
4639
- WSAPROTOCOL_INFO info ;
4634
+ WSAPROTOCOL_INFOW info ;
4640
4635
if (PyBytes_GET_SIZE (fdobj ) != sizeof (info )) {
4641
4636
PyErr_Format (PyExc_ValueError ,
4642
4637
"socket descriptor string has wrong size, "
@@ -4645,7 +4640,7 @@ sock_initobj(PyObject *self, PyObject *args, PyObject *kwds)
4645
4640
}
4646
4641
memcpy (& info , PyBytes_AS_STRING (fdobj ), sizeof (info ));
4647
4642
Py_BEGIN_ALLOW_THREADS
4648
- fd = WSASocket (FROM_PROTOCOL_INFO , FROM_PROTOCOL_INFO ,
4643
+ fd = WSASocketW (FROM_PROTOCOL_INFO , FROM_PROTOCOL_INFO ,
4649
4644
FROM_PROTOCOL_INFO , & info , 0 , WSA_FLAG_OVERLAPPED );
4650
4645
Py_END_ALLOW_THREADS
4651
4646
if (fd == INVALID_SOCKET ) {
@@ -4678,7 +4673,7 @@ sock_initobj(PyObject *self, PyObject *args, PyObject *kwds)
4678
4673
4679
4674
Py_BEGIN_ALLOW_THREADS
4680
4675
if (support_wsa_no_inherit ) {
4681
- fd = WSASocket (family , type , proto ,
4676
+ fd = WSASocketW (family , type , proto ,
4682
4677
NULL , 0 ,
4683
4678
WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT );
4684
4679
if (fd == INVALID_SOCKET ) {
@@ -5116,6 +5111,7 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args)
5116
5111
#ifdef USE_GETHOSTBYNAME_LOCK
5117
5112
PyThread_acquire_lock (netdb_lock , 1 );
5118
5113
#endif
5114
+ SUPPRESS_DEPRECATED_CALL
5119
5115
h = gethostbyname (name );
5120
5116
#endif /* HAVE_GETHOSTBYNAME_R */
5121
5117
Py_END_ALLOW_THREADS
@@ -5214,6 +5210,7 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
5214
5210
#ifdef USE_GETHOSTBYNAME_LOCK
5215
5211
PyThread_acquire_lock (netdb_lock , 1 );
5216
5212
#endif
5213
+ SUPPRESS_DEPRECATED_CALL
5217
5214
h = gethostbyaddr (ap , al , af );
5218
5215
#endif /* HAVE_GETHOSTBYNAME_R */
5219
5216
Py_END_ALLOW_THREADS
@@ -5336,18 +5333,18 @@ socket_dup(PyObject *self, PyObject *fdobj)
5336
5333
SOCKET_T fd , newfd ;
5337
5334
PyObject * newfdobj ;
5338
5335
#ifdef MS_WINDOWS
5339
- WSAPROTOCOL_INFO info ;
5336
+ WSAPROTOCOL_INFOW info ;
5340
5337
#endif
5341
5338
5342
5339
fd = PyLong_AsSocket_t (fdobj );
5343
5340
if (fd == (SOCKET_T )(-1 ) && PyErr_Occurred ())
5344
5341
return NULL ;
5345
5342
5346
5343
#ifdef MS_WINDOWS
5347
- if (WSADuplicateSocket (fd , GetCurrentProcessId (), & info ))
5344
+ if (WSADuplicateSocketW (fd , GetCurrentProcessId (), & info ))
5348
5345
return set_error ();
5349
5346
5350
- newfd = WSASocket (FROM_PROTOCOL_INFO , FROM_PROTOCOL_INFO ,
5347
+ newfd = WSASocketW (FROM_PROTOCOL_INFO , FROM_PROTOCOL_INFO ,
5351
5348
FROM_PROTOCOL_INFO ,
5352
5349
& info , 0 , WSA_FLAG_OVERLAPPED );
5353
5350
if (newfd == INVALID_SOCKET )
@@ -5666,6 +5663,7 @@ socket_inet_aton(PyObject *self, PyObject *args)
5666
5663
packed_addr = INADDR_BROADCAST ;
5667
5664
} else {
5668
5665
5666
+ SUPPRESS_DEPRECATED_CALL
5669
5667
packed_addr = inet_addr (ip_addr );
5670
5668
5671
5669
if (packed_addr == INADDR_NONE ) { /* invalid address */
@@ -5709,21 +5707,18 @@ socket_inet_ntoa(PyObject *self, PyObject *args)
5709
5707
memcpy (& packed_addr , packed_ip .buf , packed_ip .len );
5710
5708
PyBuffer_Release (& packed_ip );
5711
5709
5710
+ SUPPRESS_DEPRECATED_CALL
5712
5711
return PyUnicode_FromString (inet_ntoa (packed_addr ));
5713
5712
}
5714
5713
5715
- #if defined( HAVE_INET_PTON ) || defined( MS_WINDOWS )
5714
+ #ifdef HAVE_INET_PTON
5716
5715
5717
5716
PyDoc_STRVAR (inet_pton_doc ,
5718
5717
"inet_pton(af, ip) -> packed IP address string\n\
5719
5718
\n\
5720
5719
Convert an IP address from string format to a packed string suitable\n\
5721
5720
for use with low-level network functions." );
5722
5721
5723
- #endif
5724
-
5725
- #ifdef HAVE_INET_PTON
5726
-
5727
5722
static PyObject *
5728
5723
socket_inet_pton (PyObject * self , PyObject * args )
5729
5724
{
@@ -5768,52 +5763,12 @@ socket_inet_pton(PyObject *self, PyObject *args)
5768
5763
return NULL ;
5769
5764
}
5770
5765
}
5771
- #elif defined(MS_WINDOWS )
5772
-
5773
- static PyObject *
5774
- socket_inet_pton (PyObject * self , PyObject * args )
5775
- {
5776
- int af ;
5777
- char * ip ;
5778
- struct sockaddr_in6 addr ;
5779
- INT ret , size ;
5780
-
5781
- if (!PyArg_ParseTuple (args , "is:inet_pton" , & af , & ip )) {
5782
- return NULL ;
5783
- }
5784
-
5785
- size = sizeof (addr );
5786
- ret = WSAStringToAddressA (ip , af , NULL , (LPSOCKADDR )& addr , & size );
5787
-
5788
- if (ret ) {
5789
- PyErr_SetExcFromWindowsErr (PyExc_OSError , WSAGetLastError ());
5790
- return NULL ;
5791
- } else if (af == AF_INET ) {
5792
- struct sockaddr_in * addr4 = (struct sockaddr_in * )& addr ;
5793
- return PyBytes_FromStringAndSize ((const char * )& (addr4 -> sin_addr ),
5794
- sizeof (addr4 -> sin_addr ));
5795
- } else if (af == AF_INET6 ) {
5796
- return PyBytes_FromStringAndSize ((const char * )& (addr .sin6_addr ),
5797
- sizeof (addr .sin6_addr ));
5798
- } else {
5799
- PyErr_SetString (PyExc_OSError , "unknown address family" );
5800
- return NULL ;
5801
- }
5802
- }
5803
-
5804
- #endif
5805
-
5806
- #if defined(HAVE_INET_PTON ) || defined(MS_WINDOWS )
5807
5766
5808
5767
PyDoc_STRVAR (inet_ntop_doc ,
5809
5768
"inet_ntop(af, packed_ip) -> string formatted IP address\n\
5810
5769
\n\
5811
5770
Convert a packed IP address of the given family to string format." );
5812
5771
5813
- #endif
5814
-
5815
-
5816
- #ifdef HAVE_INET_PTON
5817
5772
static PyObject *
5818
5773
socket_inet_ntop (PyObject * self , PyObject * args )
5819
5774
{
@@ -5866,73 +5821,6 @@ socket_inet_ntop(PyObject *self, PyObject *args)
5866
5821
}
5867
5822
}
5868
5823
5869
- #elif defined(MS_WINDOWS )
5870
-
5871
- static PyObject *
5872
- socket_inet_ntop (PyObject * self , PyObject * args )
5873
- {
5874
- int af ;
5875
- Py_buffer packed_ip ;
5876
- struct sockaddr_in6 addr ;
5877
- DWORD addrlen , ret , retlen ;
5878
- #ifdef ENABLE_IPV6
5879
- char ip [Py_MAX (INET_ADDRSTRLEN , INET6_ADDRSTRLEN ) + 1 ];
5880
- #else
5881
- char ip [INET_ADDRSTRLEN + 1 ];
5882
- #endif
5883
-
5884
- /* Guarantee NUL-termination for PyUnicode_FromString() below */
5885
- memset ((void * ) & ip [0 ], '\0' , sizeof (ip ));
5886
-
5887
- if (!PyArg_ParseTuple (args , "iy*:inet_ntop" , & af , & packed_ip )) {
5888
- return NULL ;
5889
- }
5890
-
5891
- if (af == AF_INET ) {
5892
- struct sockaddr_in * addr4 = (struct sockaddr_in * )& addr ;
5893
-
5894
- if (packed_ip .len != sizeof (struct in_addr )) {
5895
- PyErr_SetString (PyExc_ValueError ,
5896
- "invalid length of packed IP address string" );
5897
- PyBuffer_Release (& packed_ip );
5898
- return NULL ;
5899
- }
5900
- memset (addr4 , 0 , sizeof (struct sockaddr_in ));
5901
- addr4 -> sin_family = AF_INET ;
5902
- memcpy (& (addr4 -> sin_addr ), packed_ip .buf , sizeof (addr4 -> sin_addr ));
5903
- addrlen = sizeof (struct sockaddr_in );
5904
- } else if (af == AF_INET6 ) {
5905
- if (packed_ip .len != sizeof (struct in6_addr )) {
5906
- PyErr_SetString (PyExc_ValueError ,
5907
- "invalid length of packed IP address string" );
5908
- PyBuffer_Release (& packed_ip );
5909
- return NULL ;
5910
- }
5911
-
5912
- memset (& addr , 0 , sizeof (addr ));
5913
- addr .sin6_family = AF_INET6 ;
5914
- memcpy (& (addr .sin6_addr ), packed_ip .buf , sizeof (addr .sin6_addr ));
5915
- addrlen = sizeof (addr );
5916
- } else {
5917
- PyErr_Format (PyExc_ValueError ,
5918
- "unknown address family %d" , af );
5919
- PyBuffer_Release (& packed_ip );
5920
- return NULL ;
5921
- }
5922
- PyBuffer_Release (& packed_ip );
5923
-
5924
- retlen = sizeof (ip );
5925
- ret = WSAAddressToStringA ((struct sockaddr * )& addr , addrlen , NULL ,
5926
- ip , & retlen );
5927
-
5928
- if (ret ) {
5929
- PyErr_SetExcFromWindowsErr (PyExc_OSError , WSAGetLastError ());
5930
- return NULL ;
5931
- } else {
5932
- return PyUnicode_FromString (ip );
5933
- }
5934
- }
5935
-
5936
5824
#endif /* HAVE_INET_PTON */
5937
5825
5938
5826
/* Python interface to getaddrinfo(host, port). */
@@ -6394,7 +6282,7 @@ static PyMethodDef socket_methods[] = {
6394
6282
METH_VARARGS , inet_aton_doc },
6395
6283
{"inet_ntoa" , socket_inet_ntoa ,
6396
6284
METH_VARARGS , inet_ntoa_doc },
6397
- #if defined( HAVE_INET_PTON ) || defined ( MS_WINDOWS )
6285
+ #ifdef HAVE_INET_PTON
6398
6286
{"inet_pton" , socket_inet_pton ,
6399
6287
METH_VARARGS , inet_pton_doc },
6400
6288
{"inet_ntop" , socket_inet_ntop ,
@@ -7713,46 +7601,3 @@ PyInit__socket(void)
7713
7601
#endif
7714
7602
return m ;
7715
7603
}
7716
-
7717
-
7718
- #ifndef HAVE_INET_PTON
7719
- #if !defined(NTDDI_VERSION ) || (NTDDI_VERSION < NTDDI_LONGHORN )
7720
-
7721
- /* Simplistic emulation code for inet_pton that only works for IPv4 */
7722
- /* These are not exposed because they do not set errno properly */
7723
-
7724
- int
7725
- inet_pton (int af , const char * src , void * dst )
7726
- {
7727
- if (af == AF_INET ) {
7728
- #if (SIZEOF_INT != 4 )
7729
- #error "Not sure if in_addr_t exists and int is not 32-bits."
7730
- #endif
7731
- unsigned int packed_addr ;
7732
- packed_addr = inet_addr (src );
7733
- if (packed_addr == INADDR_NONE )
7734
- return 0 ;
7735
- memcpy (dst , & packed_addr , 4 );
7736
- return 1 ;
7737
- }
7738
- /* Should set errno to EAFNOSUPPORT */
7739
- return -1 ;
7740
- }
7741
-
7742
- const char *
7743
- inet_ntop (int af , const void * src , char * dst , socklen_t size )
7744
- {
7745
- if (af == AF_INET ) {
7746
- struct in_addr packed_addr ;
7747
- if (size < 16 )
7748
- /* Should set errno to ENOSPC. */
7749
- return NULL ;
7750
- memcpy (& packed_addr , src , sizeof (packed_addr ));
7751
- return strncpy (dst , inet_ntoa (packed_addr ), size );
7752
- }
7753
- /* Should set errno to EAFNOSUPPORT */
7754
- return NULL ;
7755
- }
7756
-
7757
- #endif
7758
- #endif
0 commit comments