diff -r 341c18ae5cea usr/python/Lib/socket.py --- a/usr/python/Lib/socket.py Wed Aug 05 11:02:08 2015 -0600 +++ b/usr/python/Lib/socket.py Thu Aug 06 08:06:14 2015 -0600 @@ -18,6 +18,7 @@ gethostbyaddr() -- map an IP number or hostname to DNS info getservbyname() -- map a service name and a protocol name to a port number getprotobyname() -- map a protocol name (e.g. 'tcp') to a number +getprotobynumber() -- map a protocol number (e.g. '6') to a name ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order htons(), htonl() -- convert 16, 32 bit int from host to network byte order inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format diff -r 341c18ae5cea usr/python/Modules/socketmodule.c --- a/usr/python/Modules/socketmodule.c Wed Aug 05 11:02:08 2015 -0600 +++ b/usr/python/Modules/socketmodule.c Thu Aug 06 08:06:14 2015 -0600 @@ -24,6 +24,7 @@ - socket.gethostbyaddr(IP address) --> (hostname, [alias, ...], [IP addr, ...]) - socket.gethostname() --> host name (string: 'spam' or 'spam.domain.com') - socket.getprotobyname(protocolname) --> protocol number +- socket.getprotobynumber(protocolnumber) --> protocol name - socket.getservbyname(servicename[, protocolname]) --> port number - socket.getservbyport(portnumber[, protocolname]) --> service name - socket.socket([family[, type [, proto, fileno]]]) --> new socket object @@ -4569,6 +4570,34 @@ \n\ Return the protocol number for the named protocol. (Rarely used.)"); +/* Python interface to getprotobynumber(name). + This only returns the protocol name, since the other info is + already known or not useful (like the list of aliases). */ + +/*ARGSUSED*/ + +static PyObject * +socket_getprotobynumber(PyObject *self, PyObject *args) +{ + int proto; + struct protoent *sp; + if (!PyArg_ParseTuple(args, "i:getprotobynumber", &proto)) + return NULL; + Py_BEGIN_ALLOW_THREADS + sp = getprotobynumber(proto); + Py_END_ALLOW_THREADS + if (sp == NULL) { + PyErr_SetString(PyExc_OSError, "protocol not found"); + return NULL; + } + return PyUnicode_FromString(sp->p_name); +} + +PyDoc_STRVAR(getprotobynumber_doc, +"getprotobynumber(unsigned int) -> str\n\ +\n\ +Return the protocol string for the protocol number. (Rarely used.)"); + #ifndef NO_DUP /* dup() function for socket fds */ @@ -5431,6 +5460,8 @@ METH_VARARGS, getservbyport_doc}, {"getprotobyname", socket_getprotobyname, METH_VARARGS, getprotobyname_doc}, + {"getprotobynumber", socket_getprotobynumber, + METH_VARARGS, getprotobynumber_doc}, #ifndef NO_DUP {"dup", socket_dup, METH_O, dup_doc},