[Python-checkins] r42046 - in python/trunk: Doc/lib/libsocket.tex Misc/ACKS Misc/NEWS Modules/socketmodule.c Modules/socketmodule.h configure configure.in pyconfig.h.in

martin.v.loewis python-checkins at python.org
Sat Jan 14 19:13:03 CET 2006


Author: martin.v.loewis
Date: Sat Jan 14 19:12:57 2006
New Revision: 42046

Modified:
   python/trunk/Doc/lib/libsocket.tex
   python/trunk/Misc/ACKS
   python/trunk/Misc/NEWS
   python/trunk/Modules/socketmodule.c
   python/trunk/Modules/socketmodule.h
   python/trunk/configure
   python/trunk/configure.in
   python/trunk/pyconfig.h.in
Log:
Patch #1103116: AF_NETLINK sockets basic support.


Modified: python/trunk/Doc/lib/libsocket.tex
==============================================================================
--- python/trunk/Doc/lib/libsocket.tex	(original)
+++ python/trunk/Doc/lib/libsocket.tex	Sat Jan 14 19:12:57 2006
@@ -68,6 +68,9 @@
 configuration.  For deterministic behavior use a numeric address in
 \var{host} portion.
 
+\versionadded[2.5]{AF_NETLINK sockets are represented as 
+pairs \code{\var{pid}, \var{groups}}.}
+
 All errors raise exceptions.  The normal exceptions for invalid
 argument types and out-of-memory conditions can be raised; errors
 related to socket or address semantics raise the error

Modified: python/trunk/Misc/ACKS
==============================================================================
--- python/trunk/Misc/ACKS	(original)
+++ python/trunk/Misc/ACKS	Sat Jan 14 19:12:57 2006
@@ -58,6 +58,7 @@
 Stephen Bevan
 Ron Bickers
 Dominic Binks
+Philippe Biondi
 Stuart Bishop
 Roy Bixler
 Martin Bless

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sat Jan 14 19:12:57 2006
@@ -216,6 +216,8 @@
 Extension Modules
 -----------------
 
+- Patch #1103116: Basic AF_NETLINK support.
+
 - Bug #1402308, (possible) segfault when using mmap.mmap(-1, ...)
 
 - Bug #1400822, _curses over{lay,write} doesn't work when passing 6 ints.

Modified: python/trunk/Modules/socketmodule.c
==============================================================================
--- python/trunk/Modules/socketmodule.c	(original)
+++ python/trunk/Modules/socketmodule.c	Sat Jan 14 19:12:57 2006
@@ -7,7 +7,7 @@
 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 @@
 	}
 #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 @@
 	}
 #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 @@
 		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 @@
 #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 */

Modified: python/trunk/Modules/socketmodule.h
==============================================================================
--- python/trunk/Modules/socketmodule.h	(original)
+++ python/trunk/Modules/socketmodule.h	Sat Jan 14 19:12:57 2006
@@ -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 @@
 #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;

Modified: python/trunk/configure
==============================================================================
--- python/trunk/configure	(original)
+++ python/trunk/configure	Sat Jan 14 19:12:57 2006
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 41975 .
+# From configure.in Revision: 41984 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.59 for python 2.5.
 #
@@ -4609,8 +4609,9 @@
 
 
 
-for ac_header in curses.h dlfcn.h fcntl.h grp.h shadow.h langinfo.h \
-libintl.h ncurses.h poll.h pthread.h \
+
+for ac_header in asm/types.h curses.h dlfcn.h fcntl.h grp.h \
+shadow.h langinfo.h libintl.h ncurses.h poll.h pthread.h \
 stropts.h termios.h thread.h \
 unistd.h utime.h \
 sys/audioio.h sys/bsdtty.h sys/file.h sys/loadavg.h sys/lock.h sys/mkdev.h \
@@ -5519,6 +5520,76 @@
 done
 
 
+# On Linux, netlink.h requires asm/types.h
+
+for ac_header in linux/netlink.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+#ifdef HAVE_ASM_TYPES_H
+#include <asm/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_Header=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_Header=no"
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
 # checks for typedefs
 was_it_defined=no
 echo "$as_me:$LINENO: checking for clock_t in time.h" >&5

Modified: python/trunk/configure.in
==============================================================================
--- python/trunk/configure.in	(original)
+++ python/trunk/configure.in	Sat Jan 14 19:12:57 2006
@@ -994,8 +994,8 @@
 
 # checks for header files
 AC_HEADER_STDC
-AC_CHECK_HEADERS(curses.h dlfcn.h fcntl.h grp.h shadow.h langinfo.h \
-libintl.h ncurses.h poll.h pthread.h \
+AC_CHECK_HEADERS(asm/types.h curses.h dlfcn.h fcntl.h grp.h \
+shadow.h langinfo.h libintl.h ncurses.h poll.h pthread.h \
 stropts.h termios.h thread.h \
 unistd.h utime.h \
 sys/audioio.h sys/bsdtty.h sys/file.h sys/loadavg.h sys/lock.h sys/mkdev.h \
@@ -1014,6 +1014,16 @@
 #endif
 ])
 
+# On Linux, netlink.h requires asm/types.h
+AC_CHECK_HEADERS(linux/netlink.h,,,[
+#ifdef HAVE_ASM_TYPES_H
+#include <asm/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+])
+
 # checks for typedefs
 was_it_defined=no
 AC_MSG_CHECKING(for clock_t in time.h)

Modified: python/trunk/pyconfig.h.in
==============================================================================
--- python/trunk/pyconfig.h.in	(original)
+++ python/trunk/pyconfig.h.in	Sat Jan 14 19:12:57 2006
@@ -37,6 +37,9 @@
 /* Define this if your time.h defines altzone. */
 #undef HAVE_ALTZONE
 
+/* Define to 1 if you have the <asm/types.h> header file. */
+#undef HAVE_ASM_TYPES_H
+
 /* Define to 1 if you have the `bind_textdomain_codeset' function. */
 #undef HAVE_BIND_TEXTDOMAIN_CODESET
 
@@ -290,6 +293,9 @@
 /* Define if you have the 'link' function. */
 #undef HAVE_LINK
 
+/* Define to 1 if you have the <linux/netlink.h> header file. */
+#undef HAVE_LINUX_NETLINK_H
+
 /* Define this if you have the type long long. */
 #undef HAVE_LONG_LONG
 


More information about the Python-checkins mailing list