git » pytipc » commit 1bb1fa2

Add binding for getsockname()

author Peter Sabaini
2008-08-21 19:49:13 UTC
committer Alberto Bertogli
2008-09-07 01:46:41 UTC
parent 3b5cb20eacd198a94efdfc0ad4d5906324a88666

Add binding for getsockname()

tipc.py +3 -0
tipc_ll.c +15 -0

diff --git a/tipc.py b/tipc.py
index e43bc5d..b07c13d 100644
--- a/tipc.py
+++ b/tipc.py
@@ -95,6 +95,9 @@ class TIPCSocket:
 			self.closed = 1
 			return os.close(self.fd)
 
+	def getsockname(self):
+		return tipc_ll.getsockname(self.fd)
+
 
 	# Other useful functions, some of them based on socketmodule
 
diff --git a/tipc_ll.c b/tipc_ll.c
index fb623fe..089724f 100644
--- a/tipc_ll.c
+++ b/tipc_ll.c
@@ -234,6 +234,20 @@ static PyObject *tipc_recvfrom(PyObject *self, PyObject *args)
 	return Py_BuildValue("NN", str, sa_to_tuple(&sa));
 }
 
+static PyObject *tipc_getsockname(PyObject *self, PyObject *args)
+{
+	int fd, rv;
+	struct sockaddr_tipc sa;
+	socklen_t salen = sizeof(sa);
+
+	if (!PyArg_ParseTuple(args, "i:tipc_getsockname", &fd))
+		return NULL;
+
+	rv = getsockname(fd, (struct sockaddr *) &sa, &salen);
+
+	return Py_BuildValue("N", sa_to_tuple(&sa));
+}
+
 static PyObject *tipc_build_subscr(PyObject *self, PyObject *args)
 {
 	int stype, lower, upper;
@@ -295,6 +309,7 @@ static PyMethodDef pytipc_functions[] = {
 	{ "recvfrom", (PyCFunction) tipc_recvfrom, METH_VARARGS, NULL },
 	{ "build_subscr", (PyCFunction) tipc_build_subscr, METH_VARARGS, NULL },
 	{ "parse_event", (PyCFunction) tipc_parse_event, METH_VARARGS, NULL },
+	{ "getsockname", (PyCFunction) tipc_getsockname, METH_VARARGS, NULL },
 	{ NULL }
 };