@@ -6269,7 +6269,7 @@ Return the true host name, a list of aliases, and a list of IP addresses,\n\
6269
6269
for a host. The host argument is a string giving a host name or IP number." );
6270
6270
#endif
6271
6271
6272
- #ifdef HAVE_GETSERVBYNAME
6272
+ #if defined( HAVE_GETSERVBYNAME_R ) || defined ( HAVE_GETSERVBYNAME )
6273
6273
/* Python interface to getservbyname(name).
6274
6274
This only returns the port number, since the other info is already
6275
6275
known or not useful (like the list of aliases). */
@@ -6279,6 +6279,12 @@ static PyObject *
6279
6279
socket_getservbyname (PyObject * self , PyObject * args )
6280
6280
{
6281
6281
const char * name , * proto = NULL ;
6282
+ #ifdef HAVE_GETSERVBYNAME_R
6283
+ struct servent entry ;
6284
+ /* TODO: The man page says 1024 is usually enough, start with that and
6285
+ retry if insufficient? */
6286
+ char buf [16384 ];
6287
+ #endif
6282
6288
struct servent * sp ;
6283
6289
if (!PyArg_ParseTuple (args , "s|s:getservbyname" , & name , & proto ))
6284
6290
return NULL ;
@@ -6288,7 +6294,11 @@ socket_getservbyname(PyObject *self, PyObject *args)
6288
6294
}
6289
6295
6290
6296
Py_BEGIN_ALLOW_THREADS
6297
+ #ifdef HAVE_GETSERVBYNAME_R
6298
+ getservbyname_r (name , proto , & entry , buf , sizeof (buf ), & sp );
6299
+ #else
6291
6300
sp = getservbyname (name , proto );
6301
+ #endif
6292
6302
Py_END_ALLOW_THREADS
6293
6303
if (sp == NULL) {
6294
6304
PyErr_SetString (PyExc_OSError , "service/proto not found" );
@@ -6305,7 +6315,7 @@ The optional protocol name, if given, should be 'tcp' or 'udp',\n\
6305
6315
otherwise any protocol will match." );
6306
6316
#endif
6307
6317
6308
- #ifdef HAVE_GETSERVBYPORT
6318
+ #if defined( HAVE_GETSERVBYPORT_R ) || defined ( HAVE_GETSERVBYPORT )
6309
6319
/* Python interface to getservbyport(port).
6310
6320
This only returns the service name, since the other info is already
6311
6321
known or not useful (like the list of aliases). */
@@ -6316,6 +6326,12 @@ socket_getservbyport(PyObject *self, PyObject *args)
6316
6326
{
6317
6327
int port ;
6318
6328
const char * proto = NULL ;
6329
+ #ifdef HAVE_GETSERVBYPORT_R
6330
+ struct servent entry ;
6331
+ /* TODO: The man page says 1024 is usually enough, start with that and
6332
+ retry if insufficient? */
6333
+ char buf [16384 ];
6334
+ #endif
6319
6335
struct servent * sp ;
6320
6336
if (!PyArg_ParseTuple (args , "i|s:getservbyport" , & port , & proto ))
6321
6337
return NULL ;
@@ -6331,7 +6347,11 @@ socket_getservbyport(PyObject *self, PyObject *args)
6331
6347
}
6332
6348
6333
6349
Py_BEGIN_ALLOW_THREADS
6350
+ #ifdef HAVE_GETSERVBYPORT_R
6351
+ getservbyport_r (htons ((short )port ), proto , & entry , buf , sizeof (buf ), & sp );
6352
+ #else
6334
6353
sp = getservbyport (htons ((short )port ), proto );
6354
+ #endif
6335
6355
Py_END_ALLOW_THREADS
6336
6356
if (sp == NULL) {
6337
6357
PyErr_SetString (PyExc_OSError , "port/proto not found" );
@@ -6348,7 +6368,7 @@ The optional protocol name, if given, should be 'tcp' or 'udp',\n\
6348
6368
otherwise any protocol will match." );
6349
6369
#endif
6350
6370
6351
- #ifdef HAVE_GETPROTOBYNAME
6371
+ #if defined( HAVE_GETPROTOBYNAME_R ) || defined ( HAVE_GETPROTOBYNAME )
6352
6372
/* Python interface to getprotobyname(name).
6353
6373
This only returns the protocol number, since the other info is
6354
6374
already known or not useful (like the list of aliases). */
@@ -6358,11 +6378,21 @@ static PyObject *
6358
6378
socket_getprotobyname (PyObject * self , PyObject * args )
6359
6379
{
6360
6380
const char * name ;
6381
+ #ifdef HAVE_GETPROTOBYNAME_R
6382
+ struct protoent entry ;
6383
+ /* TODO: The man page says 1024 is usually enough, start with that and
6384
+ retry if insufficient? */
6385
+ char buf [16384 ];
6386
+ #endif
6361
6387
struct protoent * sp ;
6362
6388
if (!PyArg_ParseTuple (args , "s:getprotobyname" , & name ))
6363
6389
return NULL ;
6364
6390
Py_BEGIN_ALLOW_THREADS
6391
+ #ifdef HAVE_GETPROTOBYNAME_R
6392
+ getprotobyname_r (name , & entry , buf , sizeof (buf ), & sp );
6393
+ #else
6365
6394
sp = getprotobyname (name );
6395
+ #endif
6366
6396
Py_END_ALLOW_THREADS
6367
6397
if (sp == NULL) {
6368
6398
PyErr_SetString (PyExc_OSError , "protocol not found" );
@@ -7415,15 +7445,15 @@ static PyMethodDef socket_methods[] = {
7415
7445
{"sethostname" , socket_sethostname ,
7416
7446
METH_VARARGS , sethostname_doc },
7417
7447
#endif
7418
- #ifdef HAVE_GETSERVBYNAME
7448
+ #if defined( HAVE_GETSERVBYNAME_R ) || defined ( HAVE_GETSERVBYNAME )
7419
7449
{"getservbyname" , socket_getservbyname ,
7420
7450
METH_VARARGS , getservbyname_doc },
7421
7451
#endif
7422
- #ifdef HAVE_GETSERVBYPORT
7452
+ #if defined( HAVE_GETSERVBYPORT_R ) || defined ( HAVE_GETSERVBYPORT )
7423
7453
{"getservbyport" , socket_getservbyport ,
7424
7454
METH_VARARGS , getservbyport_doc },
7425
7455
#endif
7426
- #ifdef HAVE_GETPROTOBYNAME
7456
+ #if defined ( HAVE_GETPROTOBYNAME_R ) || defined ( HAVE_GETPROTOBYNAME )
7427
7457
{"getprotobyname" , socket_getprotobyname ,
7428
7458
METH_VARARGS , getprotobyname_doc },
7429
7459
#endif
0 commit comments