[Python-checkins] python/dist/src/Modules socketmodule.c, 1.291,
1.292
bwarsaw at users.sourceforge.net
bwarsaw at users.sourceforge.net
Sun Jun 27 20:50:46 EDT 2004
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13892/Modules
Modified Files:
socketmodule.c
Log Message:
Added socket.getservbyport(), and make its second argument and that of
getservbyname() optional. Update the tests and the docs.
Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.291
retrieving revision 1.292
diff -C2 -d -r1.291 -r1.292
*** socketmodule.c 3 Jun 2004 09:24:42 -0000 1.291
--- socketmodule.c 28 Jun 2004 00:50:43 -0000 1.292
***************
*** 26,30 ****
- socket.gethostname() --> host name (string: 'spam' or 'spam.domain.com')
- socket.getprotobyname(protocolname) --> protocol number
! - socket.getservbyname(servicename, protocolname) --> port number
- socket.socket([family[, type [, proto]]]) --> new socket object
- socket.ntohs(16 bit value) --> new int object
--- 26,31 ----
- socket.gethostname() --> host name (string: 'spam' or 'spam.domain.com')
- socket.getprotobyname(protocolname) --> protocol number
! - socket.getservbyname(servicename[, protocolname]) --> port number
! - socket.getservbyport(portnumber[, protocolname]) --> service name
- socket.socket([family[, type [, proto]]]) --> new socket object
- socket.ntohs(16 bit value) --> new int object
***************
*** 2885,2891 ****
socket_getservbyname(PyObject *self, PyObject *args)
{
! char *name, *proto;
struct servent *sp;
! if (!PyArg_ParseTuple(args, "ss:getservbyname", &name, &proto))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 2886,2892 ----
socket_getservbyname(PyObject *self, PyObject *args)
{
! char *name, *proto=NULL;
struct servent *sp;
! if (!PyArg_ParseTuple(args, "s|s:getservbyname", &name, &proto))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 2900,2908 ****
PyDoc_STRVAR(getservbyname_doc,
! "getservbyname(servicename, protocolname) -> integer\n\
\n\
Return a port number from a service name and protocol name.\n\
! The protocol name should be 'tcp' or 'udp'.");
/* Python interface to getprotobyname(name).
--- 2901,2940 ----
PyDoc_STRVAR(getservbyname_doc,
! "getservbyname(servicename[, protocolname]) -> integer\n\
\n\
Return a port number from a service name and protocol name.\n\
! The optional protocol name, if given, should be 'tcp' or 'udp',\n\
! otherwise any protocol will match.");
!
!
! /* Python interface to getservbyport(port).
! This only returns the service name, since the other info is already
! known or not useful (like the list of aliases). */
!
! /*ARGSUSED*/
! static PyObject *
! socket_getservbyport(PyObject *self, PyObject *args)
! {
! int port;
! char *proto=NULL;
! struct servent *sp;
! if (!PyArg_ParseTuple(args, "i|s:getservbyport", &port, &proto))
! return NULL;
! Py_BEGIN_ALLOW_THREADS
! sp = getservbyport(htons(port), proto);
! Py_END_ALLOW_THREADS
! if (sp == NULL) {
! PyErr_SetString(socket_error, "port/proto not found");
! return NULL;
! }
! return PyString_FromString(sp->s_name);
! }
+ PyDoc_STRVAR(getservbyport_doc,
+ "getservbyport(port[, protocolname]) -> string\n\
+ \n\
+ Return the service name from a port number and protocol name.\n\
+ The optional protocol name, if given, should be 'tcp' or 'udp',\n\
+ otherwise any protocol will match.");
/* Python interface to getprotobyname(name).
***************
*** 3531,3534 ****
--- 3563,3568 ----
{"getservbyname", socket_getservbyname,
METH_VARARGS, getservbyname_doc},
+ {"getservbyport", socket_getservbyport,
+ METH_VARARGS, getservbyport_doc},
{"getprotobyname", socket_getprotobyname,
METH_VARARGS,getprotobyname_doc},
More information about the Python-checkins
mailing list