summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-12-19 16:35:04 (GMT)
committerGuido van Rossum <guido@python.org>1996-12-19 16:35:04 (GMT)
commit3901d85277588bd368eb7a360f6bc3ede2c1227e (patch)
tree1102e2c34e71976efdce9ee61750d2542f9b1c03 /Modules/socketmodule.c
parentae0cd0b9b3c003c15c68a95911c8a62577ce1103 (diff)
downloadcpython-3901d85277588bd368eb7a360f6bc3ede2c1227e.zip
cpython-3901d85277588bd368eb7a360f6bc3ede2c1227e.tar.gz
cpython-3901d85277588bd368eb7a360f6bc3ede2c1227e.tar.bz2
Added getprotobyname() interface.
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 6c72539..6d4da23 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1117,6 +1117,29 @@ BUILD_FUNC_DEF_2(PySocket_getservbyname,PyObject *,self, PyObject *,args)
}
+/* Python interface to getprotobyname(name).
+ This only returns the protocol number, since the other info is
+ already known or not useful (like the list of aliases). */
+
+/*ARGSUSED*/
+static PyObject *
+BUILD_FUNC_DEF_2(PySocket_getprotobyname,PyObject *,self, PyObject *,args)
+{
+ char *name;
+ struct protoent *sp;
+ if (!PyArg_Parse(args, "s", &name))
+ return NULL;
+ Py_BEGIN_ALLOW_THREADS
+ sp = getprotobyname(name);
+ Py_END_ALLOW_THREADS
+ if (sp == NULL) {
+ PyErr_SetString(PySocket_Error, "protocol not found");
+ return NULL;
+ }
+ return PyInt_FromLong((long) sp->p_proto);
+}
+
+
/* Python interface to socket(family, type, proto).
The third (protocol) argument is optional.
Return a new socket object. */
@@ -1238,6 +1261,7 @@ static PyMethodDef PySocket_methods[] = {
{"gethostbyaddr", PySocket_gethostbyaddr},
{"gethostname", PySocket_gethostname},
{"getservbyname", PySocket_getservbyname},
+ {"getprotobyname", PySocket_getprotobyname},
{"socket", PySocket_socket, 1},
#ifndef NO_DUP
{"fromfd", PySocket_fromfd, 1},