diff -dur Python-2.4.3/Modules/socketmodule.h Python-2.4.3-AF_NETLINK/Modules/socketmodule.h --- Python-2.4.3/Modules/socketmodule.h 2005-09-15 04:15:03.000000000 +1000 +++ Python-2.4.3-AF_NETLINK/Modules/socketmodule.h 2006-06-05 18:02:31.790847412 +1000 @@ -49,6 +49,10 @@ # include #endif +#ifdef AF_NETLINK +# include +#endif + #ifndef Py__SOCKET_H #define Py__SOCKET_H #ifdef __cplusplus @@ -90,6 +94,9 @@ #ifdef HAVE_NETPACKET_PACKET_H struct sockaddr_ll ll; #endif +#ifdef AF_NETLINK + struct sockaddr_nl nl; +#endif } sock_addr_t; /* The object holding a socket. It holds some extra information, diff -dur Python-2.4.3/Modules/socketmodule.c Python-2.4.3-AF_NETLINK/Modules/socketmodule.c --- Python-2.4.3/Modules/socketmodule.c 2006-02-20 20:42:37.000000000 +1100 +++ Python-2.4.3-AF_NETLINK/Modules/socketmodule.c 2006-06-05 18:02:13.121884612 +1000 @@ -1049,6 +1049,14 @@ } #endif +#ifdef AF_NETLINK + case AF_NETLINK: + { + struct sockaddr_nl *a = (struct sockaddr_nl *)addr; + return Py_BuildValue("II", a->nl_pid, a->nl_groups); + } +#endif + /* More cases here... */ default: @@ -1271,6 +1279,24 @@ } #endif +#ifdef AF_NETLINK + case AF_NETLINK: + { + struct sockaddr_nl* addr; + unsigned pid, groups; + if (!PyArg_ParseTuple(args, "II:getsockaddrarg", &pid, &groups)) + return 0; + addr = &(s->sock_addr).nl; + addr->nl_family = AF_NETLINK; + addr->nl_pad = 0; + addr->nl_pid = pid; + addr->nl_groups = groups; + *addr_ret = (struct sockaddr *) addr; + *len_ret = sizeof *addr; + return 1; + } +#endif + /* More cases here... */ default: @@ -1346,6 +1372,14 @@ } #endif +#ifdef AF_NETLINK + case AF_NETLINK: + { + *len_ret = sizeof (struct sockaddr_nl); + return 1; + } +#endif + /* More cases here... */ default: @@ -3975,9 +4009,75 @@ PyModule_AddIntConstant(m, "AF_KEY", AF_KEY); #endif #ifdef AF_NETLINK - /* */ + /* Linux netlink sockets, used for kernel<->user communication */ + /* see netlink(7) manpage for details */ PyModule_AddIntConstant(m, "AF_NETLINK", AF_NETLINK); -#endif + /* Netlink message flags */ + PyModule_AddIntConstant(m, "NLM_F_REQUEST", NLM_F_REQUEST); + PyModule_AddIntConstant(m, "NLM_F_MULTI", NLM_F_MULTI); + PyModule_AddIntConstant(m, "NLM_F_ACK", NLM_F_ACK); + PyModule_AddIntConstant(m, "NLM_F_ECHO", NLM_F_ECHO); + PyModule_AddIntConstant(m, "NLM_F_ROOT", NLM_F_ROOT); + PyModule_AddIntConstant(m, "NLM_F_MATCH", NLM_F_MATCH); + PyModule_AddIntConstant(m, "NLM_F_ATOMIC", NLM_F_ATOMIC); + PyModule_AddIntConstant(m, "NLM_F_DUMP", NLM_F_DUMP); + PyModule_AddIntConstant(m, "NLM_F_REPLACE", NLM_F_REPLACE); + PyModule_AddIntConstant(m, "NLM_F_EXCL", NLM_F_EXCL); + PyModule_AddIntConstant(m, "NLM_F_CREATE", NLM_F_CREATE); + PyModule_AddIntConstant(m, "NLM_F_APPEND", NLM_F_APPEND); + /* Netlink message types */ + PyModule_AddIntConstant(m, "NLMSG_NOOP", NLMSG_NOOP); + PyModule_AddIntConstant(m, "NLMSG_ERROR", NLMSG_ERROR); + PyModule_AddIntConstant(m, "NLMSG_DONE", NLMSG_DONE); + PyModule_AddIntConstant(m, "NLMSG_OVERRUN", NLMSG_OVERRUN); + /* Netlink protocol constants, used for 3rd arg to socket */ +# ifdef NETLINK_ROUTE + PyModule_AddIntConstant(m, "NETLINK_ROUTE", NETLINK_ROUTE); +# endif +# ifdef NETLINK_SKIP + PyModule_AddIntConstant(m, "NETLINK_SKIP", NETLINK_SKIP); +# endif +# ifdef NETLINK_USERSOCK + PyModule_AddIntConstant(m, "NETLINK_USERSOCK", NETLINK_USERSOCK); +# endif +# ifdef NETLINK_FIREWALL + PyModule_AddIntConstant(m, "NETLINK_FIREWALL", NETLINK_FIREWALL); +# endif +# ifdef NETLINK_TCPDIAG + PyModule_AddIntConstant(m, "NETLINK_TCPDIAG", NETLINK_TCPDIAG); +# endif +# ifdef NETLINK_NFLOG + PyModule_AddIntConstant(m, "NETLINK_NFLOG", NETLINK_NFLOG); +# endif +# ifdef NETLINK_XFRM + PyModule_AddIntConstant(m, "NETLINK_XFRM", NETLINK_XFRM); +# endif +# ifdef NETLINK_SELINUX + PyModule_AddIntConstant(m, "NETLINK_SELINUX", NETLINK_SELINUX); +# endif +# ifdef NETLINK_ARPD + PyModule_AddIntConstant(m, "NETLINK_ARPD", NETLINK_ARPD); +# endif +# ifdef NETLINK_AUDIT + PyModule_AddIntConstant(m, "NETLINK_AUDIT", NETLINK_AUDIT); +# endif +# ifdef NETLINK_ROUTE6 + PyModule_AddIntConstant(m, "NETLINK_ROUTE6", NETLINK_ROUTE6); +# endif +# ifdef NETLINK_IP6_FW + PyModule_AddIntConstant(m, "NETLINK_IP6_FW", NETLINK_IP6_FW); +# endif +# ifdef NETLINK_DNRTMSG + PyModule_AddIntConstant(m, "NETLINK_DNRTMSG", NETLINK_DNRTMSG); +# endif +# ifdef NETLINK_KOBJECT_UEVENT + PyModule_AddIntConstant(m, "NETLINK_KOBJECT_UEVENT", + NETLINK_KOBJECT_UEVENT); +# endif +# ifdef NETLINK_TAPBASE + PyModule_AddIntConstant(m, "NETLINK_TAPBASE", NETLINK_TAPBASE); +# endif +#endif /* AF_NETLINK */ #ifdef AF_ROUTE /* Alias to emulate 4.4BSD */ PyModule_AddIntConstant(m, "AF_ROUTE", AF_ROUTE);