@@ -6332,14 +6332,18 @@ AF_UNIX if defined on the platform; otherwise, the default is AF_INET.");
6332
6332
#endif /* HAVE_SOCKETPAIR */
6333
6333
6334
6334
6335
+ /*[clinic input]
6336
+ _socket.socket.ntohs
6337
+ x: int
6338
+ /
6339
+
6340
+ Convert a 16-bit unsigned integer from network to host byte order.
6341
+ [clinic start generated code]*/
6342
+
6335
6343
static PyObject *
6336
- socket_ntohs (PyObject * self , PyObject * args )
6344
+ _socket_socket_ntohs_impl (PySocketSockObject * self , int x )
6345
+ /*[clinic end generated code: output=a828a61a9fb205b2 input=9a79cb3a71652147]*/
6337
6346
{
6338
- int x ;
6339
-
6340
- if (!PyArg_ParseTuple (args , "i:ntohs" , & x )) {
6341
- return NULL ;
6342
- }
6343
6347
if (x < 0 ) {
6344
6348
PyErr_SetString (PyExc_OverflowError ,
6345
6349
"ntohs: can't convert negative Python int to C "
@@ -6355,11 +6359,6 @@ socket_ntohs(PyObject *self, PyObject *args)
6355
6359
return PyLong_FromUnsignedLong (ntohs ((unsigned short )x ));
6356
6360
}
6357
6361
6358
- PyDoc_STRVAR (ntohs_doc ,
6359
- "ntohs(integer) -> integer\n\
6360
- \n\
6361
- Convert a 16-bit unsigned integer from network to host byte order." );
6362
-
6363
6362
6364
6363
static PyObject *
6365
6364
socket_ntohl (PyObject * self , PyObject * arg )
@@ -6395,14 +6394,18 @@ PyDoc_STRVAR(ntohl_doc,
6395
6394
Convert a 32-bit integer from network to host byte order." );
6396
6395
6397
6396
6397
+ /*[clinic input]
6398
+ _socket.socket.htons
6399
+ x: int
6400
+ /
6401
+
6402
+ Convert a 16-bit unsigned integer from host to network byte order.
6403
+ [clinic start generated code]*/
6404
+
6398
6405
static PyObject *
6399
- socket_htons (PyObject * self , PyObject * args )
6406
+ _socket_socket_htons_impl (PySocketSockObject * self , int x )
6407
+ /*[clinic end generated code: output=d785ee692312da47 input=053252d8416f4337]*/
6400
6408
{
6401
- int x ;
6402
-
6403
- if (!PyArg_ParseTuple (args , "i:htons" , & x )) {
6404
- return NULL ;
6405
- }
6406
6409
if (x < 0 ) {
6407
6410
PyErr_SetString (PyExc_OverflowError ,
6408
6411
"htons: can't convert negative Python int to C "
@@ -6418,11 +6421,6 @@ socket_htons(PyObject *self, PyObject *args)
6418
6421
return PyLong_FromUnsignedLong (htons ((unsigned short )x ));
6419
6422
}
6420
6423
6421
- PyDoc_STRVAR (htons_doc ,
6422
- "htons(integer) -> integer\n\
6423
- \n\
6424
- Convert a 16-bit unsigned integer from host to network byte order." );
6425
-
6426
6424
6427
6425
static PyObject *
6428
6426
socket_htonl (PyObject * self , PyObject * arg )
@@ -6459,14 +6457,17 @@ Convert a 32-bit integer from host to network byte order.");
6459
6457
6460
6458
/* socket.inet_aton() and socket.inet_ntoa() functions. */
6461
6459
6462
- PyDoc_STRVAR (inet_aton_doc ,
6463
- "inet_aton(string) -> bytes giving packed 32-bit IP representation\n\
6464
- \n\
6465
- Convert an IP address in string format (123.45.67.89) to the 32-bit packed\n\
6466
- binary format used in low-level network functions." );
6460
+ /*[clinic input]
6461
+ _socket.socket.inet_aton
6462
+ ip_addr: str
6463
+ /
6467
6464
6468
- static PyObject *
6469
- socket_inet_aton (PyObject * self , PyObject * args )
6465
+ Convert an IP address in string format (123.45.67.89) to the 32-bit packed binary format used in low-level network functions.
6466
+ [clinic start generated code]*/
6467
+
6468
+ static PyObject *
6469
+ _socket_socket_inet_aton_impl (PySocketSockObject * self , const char * ip_addr )
6470
+ /*[clinic end generated code: output=5bfe11a255423d8c input=a120e20cb52b9488]*/
6470
6471
{
6471
6472
#ifdef HAVE_INET_ATON
6472
6473
struct in_addr buf ;
@@ -6479,11 +6480,6 @@ socket_inet_aton(PyObject *self, PyObject *args)
6479
6480
/* Have to use inet_addr() instead */
6480
6481
unsigned int packed_addr ;
6481
6482
#endif
6482
- const char * ip_addr ;
6483
-
6484
- if (!PyArg_ParseTuple (args , "s:inet_aton" , & ip_addr ))
6485
- return NULL ;
6486
-
6487
6483
6488
6484
#ifdef HAVE_INET_ATON
6489
6485
@@ -6532,30 +6528,29 @@ socket_inet_aton(PyObject *self, PyObject *args)
6532
6528
}
6533
6529
6534
6530
#ifdef HAVE_INET_NTOA
6535
- PyDoc_STRVAR ( inet_ntoa_doc ,
6536
- " inet_ntoa(packed_ip) -> ip_address_string\n\
6537
- \n\
6538
- Convert an IP address from 32-bit packed binary format to string format" );
6531
+ /*[clinic input]
6532
+ _socket.socket. inet_ntoa
6533
+ packed_ip: Py_buffer
6534
+ /
6539
6535
6540
- static PyObject *
6541
- socket_inet_ntoa (PyObject * self , PyObject * args )
6536
+ Convert an IP address from 32-bit packed binary format to string format.
6537
+ [clinic start generated code]*/
6538
+
6539
+ static PyObject *
6540
+ _socket_socket_inet_ntoa_impl (PySocketSockObject * self , Py_buffer * packed_ip )
6541
+ /*[clinic end generated code: output=b671880a3f62461b input=95c2c4a1b2ee957c]*/
6542
6542
{
6543
- Py_buffer packed_ip ;
6544
6543
struct in_addr packed_addr ;
6545
6544
6546
- if (!PyArg_ParseTuple (args , "y*:inet_ntoa" , & packed_ip )) {
6547
- return NULL ;
6548
- }
6549
-
6550
- if (packed_ip .len != sizeof (packed_addr )) {
6545
+ if (packed_ip -> len != sizeof (packed_addr )) {
6551
6546
PyErr_SetString (PyExc_OSError ,
6552
6547
"packed IP wrong length for inet_ntoa" );
6553
- PyBuffer_Release (& packed_ip );
6548
+ PyBuffer_Release (packed_ip );
6554
6549
return NULL ;
6555
6550
}
6556
6551
6557
- memcpy (& packed_addr , packed_ip . buf , packed_ip . len );
6558
- PyBuffer_Release (& packed_ip );
6552
+ memcpy (& packed_addr , packed_ip -> buf , packed_ip -> len );
6553
+ PyBuffer_Release (packed_ip );
6559
6554
6560
6555
SUPPRESS_DEPRECATED_CALL
6561
6556
return PyUnicode_FromString (inet_ntoa (packed_addr ));
@@ -7049,18 +7044,23 @@ PyDoc_STRVAR(if_nameindex_doc,
7049
7044
\n\
7050
7045
Returns a list of network interface information (index, name) tuples." );
7051
7046
7047
+ /*[clinic input]
7048
+ _socket.socket.if_nametoindex
7049
+ oname: object(converter="PyUnicode_FSConverter")
7050
+ /
7051
+
7052
+ Returns the interface index corresponding to the interface name if_name.
7053
+ [clinic start generated code]*/
7054
+
7052
7055
static PyObject *
7053
- socket_if_nametoindex (PyObject * self , PyObject * args )
7056
+ _socket_socket_if_nametoindex_impl (PySocketSockObject * self , PyObject * oname )
7057
+ /*[clinic end generated code: output=f7fc00511a309a8e input=662688054482cd46]*/
7054
7058
{
7055
- PyObject * oname ;
7056
7059
#ifdef MS_WINDOWS
7057
7060
NET_IFINDEX index ;
7058
7061
#else
7059
7062
unsigned long index ;
7060
7063
#endif
7061
- if (!PyArg_ParseTuple (args , "O&:if_nametoindex" ,
7062
- PyUnicode_FSConverter , & oname ))
7063
- return NULL ;
7064
7064
7065
7065
index = if_nametoindex (PyBytes_AS_STRING (oname ));
7066
7066
Py_DECREF (oname );
@@ -7073,10 +7073,6 @@ socket_if_nametoindex(PyObject *self, PyObject *args)
7073
7073
return PyLong_FromUnsignedLong (index );
7074
7074
}
7075
7075
7076
- PyDoc_STRVAR (if_nametoindex_doc ,
7077
- "if_nametoindex(if_name)\n\
7078
- \n\
7079
- Returns the interface index corresponding to the interface name if_name." );
7080
7076
7081
7077
static PyObject *
7082
7078
socket_if_indextoname (PyObject * self , PyObject * arg )
@@ -7215,19 +7211,15 @@ static PyMethodDef socket_methods[] = {
7215
7211
{"socketpair" , socket_socketpair ,
7216
7212
METH_VARARGS , socketpair_doc },
7217
7213
#endif
7218
- {"ntohs" , socket_ntohs ,
7219
- METH_VARARGS , ntohs_doc },
7214
+ _SOCKET_SOCKET_NTOHS_METHODDEF
7220
7215
{"ntohl" , socket_ntohl ,
7221
7216
METH_O , ntohl_doc },
7222
- {"htons" , socket_htons ,
7223
- METH_VARARGS , htons_doc },
7217
+ _SOCKET_SOCKET_HTONS_METHODDEF
7224
7218
{"htonl" , socket_htonl ,
7225
7219
METH_O , htonl_doc },
7226
- {"inet_aton" , socket_inet_aton ,
7227
- METH_VARARGS , inet_aton_doc },
7220
+ _SOCKET_SOCKET_INET_ATON_METHODDEF
7228
7221
#ifdef HAVE_INET_NTOA
7229
- {"inet_ntoa" , socket_inet_ntoa ,
7230
- METH_VARARGS , inet_ntoa_doc },
7222
+ _SOCKET_SOCKET_INET_NTOA_METHODDEF
7231
7223
#endif
7232
7224
#ifdef HAVE_INET_PTON
7233
7225
{"inet_pton ", socket_inet_pton ,
@@ -7250,8 +7242,7 @@ static PyMethodDef socket_methods[] = {
7250
7242
#if defined(HAVE_IF_NAMEINDEX ) || defined(MS_WINDOWS )
7251
7243
{"if_nameindex ", socket_if_nameindex ,
7252
7244
METH_NOARGS , if_nameindex_doc },
7253
- {"if_nametoindex" , socket_if_nametoindex ,
7254
- METH_VARARGS , if_nametoindex_doc },
7245
+ _SOCKET_SOCKET_IF_NAMETOINDEX_METHODDEF
7255
7246
{"if_indextoname ", socket_if_indextoname ,
7256
7247
METH_O , if_indextoname_doc },
7257
7248
#endif
0 commit comments