summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-01-14 18:12:57 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2006-01-14 18:12:57 (GMT)
commit11017b172dc2525079fe8a6f17650b2fc048c9e6 (patch)
treeca1c91cb4a3752fdff3c277f8e85958024bc84e0 /Modules
parent015f72b254019027c73a2f13925c77d0dbcdb028 (diff)
downloadcpython-11017b172dc2525079fe8a6f17650b2fc048c9e6.zip
cpython-11017b172dc2525079fe8a6f17650b2fc048c9e6.tar.gz
cpython-11017b172dc2525079fe8a6f17650b2fc048c9e6.tar.bz2
Patch #1103116: AF_NETLINK sockets basic support.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/socketmodule.c54
-rw-r--r--Modules/socketmodule.h9
2 files changed, 62 insertions, 1 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 038bd1f..7259432 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -7,7 +7,7 @@ This module provides an interface to Berkeley socket IPC.
Limitations:
- Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a
- portable manner, though AF_PACKET is supported under Linux.
+ portable manner, though AF_PACKET and AF_NETLINK are supported under Linux.
- No read/write operations (use sendall/recv or makefile instead).
- Additional restrictions apply on some non-Unix platforms (compensated
for by socket.py).
@@ -954,6 +954,14 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
}
#endif /* AF_UNIX */
+#if defined(AF_NETLINK)
+ case AF_NETLINK:
+ {
+ struct sockaddr_nl *a = (struct sockaddr_nl *) addr;
+ return Py_BuildValue("ii", a->nl_pid, a->nl_groups);
+ }
+#endif /* AF_NETLINK */
+
#ifdef ENABLE_IPV6
case AF_INET6:
{
@@ -1090,6 +1098,31 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
}
#endif /* AF_UNIX */
+#if defined(AF_NETLINK)
+ case AF_NETLINK:
+ {
+ struct sockaddr_nl* addr;
+ int pid, groups;
+ addr = (struct sockaddr_nl *)&(s->sock_addr).nl;
+ if (!PyTuple_Check(args)) {
+ PyErr_Format(
+ PyExc_TypeError,
+ "getsockaddrarg: "
+ "AF_NETLINK address must be tuple, not %.500s",
+ args->ob_type->tp_name);
+ return 0;
+ }
+ if (!PyArg_ParseTuple(args, "II:getsockaddrarg", &pid, &groups))
+ return 0;
+ addr->nl_family = AF_NETLINK;
+ addr->nl_pid = pid;
+ addr->nl_groups = groups;
+ *addr_ret = (struct sockaddr *) addr;
+ *len_ret = sizeof(*addr);
+ return 1;
+ }
+#endif
+
case AF_INET:
{
struct sockaddr_in* addr;
@@ -1286,6 +1319,13 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
return 1;
}
#endif /* AF_UNIX */
+#if defined(AF_NETLINK)
+ case AF_NETLINK:
+ {
+ *len_ret = sizeof (struct sockaddr_nl);
+ return 1;
+ }
+#endif
case AF_INET:
{
@@ -3947,6 +3987,18 @@ init_socket(void)
#ifdef AF_NETLINK
/* */
PyModule_AddIntConstant(m, "AF_NETLINK", AF_NETLINK);
+ PyModule_AddIntConstant(m, "NETLINK_ROUTE", NETLINK_ROUTE);
+ PyModule_AddIntConstant(m, "NETLINK_SKIP", NETLINK_SKIP);
+ PyModule_AddIntConstant(m, "NETLINK_USERSOCK", NETLINK_USERSOCK);
+ PyModule_AddIntConstant(m, "NETLINK_FIREWALL", NETLINK_FIREWALL);
+ PyModule_AddIntConstant(m, "NETLINK_TCPDIAG", NETLINK_TCPDIAG);
+ PyModule_AddIntConstant(m, "NETLINK_NFLOG", NETLINK_NFLOG);
+ PyModule_AddIntConstant(m, "NETLINK_XFRM", NETLINK_XFRM);
+ PyModule_AddIntConstant(m, "NETLINK_ARPD", NETLINK_ARPD);
+ PyModule_AddIntConstant(m, "NETLINK_ROUTE6", NETLINK_ROUTE6);
+ PyModule_AddIntConstant(m, "NETLINK_IP6_FW", NETLINK_IP6_FW);
+ PyModule_AddIntConstant(m, "NETLINK_DNRTMSG", NETLINK_DNRTMSG);
+ PyModule_AddIntConstant(m, "NETLINK_TAPBASE", NETLINK_TAPBASE);
#endif
#ifdef AF_ROUTE
/* Alias to emulate 4.4BSD */
diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h
index 384d595..0c5bfad 100644
--- a/Modules/socketmodule.h
+++ b/Modules/socketmodule.h
@@ -32,6 +32,12 @@
# undef AF_UNIX
#endif
+#ifdef HAVE_LINUX_NETLINK_H
+# include <linux/netlink.h>
+#else
+# undef AF_NETLINK
+#endif
+
#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
@@ -78,6 +84,9 @@ typedef union sock_addr {
#ifdef AF_UNIX
struct sockaddr_un un;
#endif
+#ifdef AF_NETLINK
+ struct sockaddr_nl nl;
+#endif
#ifdef ENABLE_IPV6
struct sockaddr_in6 in6;
struct sockaddr_storage storage;