This patch is based on the work referenced here: http://bugs.python.org/issue10141 It is tested with ptxdist >= 2010.08.0 and toolchain kernel >= 2.6.27 on powerpc architectures
Signed-off-by: Daniel Kriesten <[email protected]> --- ...-for-socketcan-to-the-python-socket-modul.patch | 491 +++++++++++++------- 1 files changed, 322 insertions(+), 169 deletions(-) diff --git a/patches/Python-2.6.6/0001-Add-support-for-socketcan-to-the-python-socket-modul.patch b/patches/Python-2.6.6/0001-Add-support-for-socketcan-to-the-python-socket-modul.patch index 899d509..280b7ec 100644 --- a/patches/Python-2.6.6/0001-Add-support-for-socketcan-to-the-python-socket-modul.patch +++ b/patches/Python-2.6.6/0001-Add-support-for-socketcan-to-the-python-socket-modul.patch @@ -1,227 +1,380 @@ -From: Michael Olbrich <[email protected]> -Date: Tue, 5 May 2009 15:17:20 +0200 +From 5caecb284e410d04db7bf40347101f0e240a6828 Mon Sep 17 00:00:00 2001 +From: Daniel Kriesten <[email protected]> +Date: Fri, 25 Feb 2011 15:18:22 +0100 Subject: [PATCH] Add support for socketcan to the python socket module -This patch add support for the protocol family AF_CAN. It contains all the -necessary code to use the python socket module for socketcan. +This patch add support for the protocol family AF_CAN. It contains all the necessary code to use the python socket module for socketcan. +By now it is tested against kernel 2.6.27, but should work with kernels up to 2.6.37. -Signed-off-by: Michael Olbrich <[email protected]> -Signed-off-by: Marc Kleine-Budde <[email protected]> +Signed-off-by: Daniel Kriesten <[email protected]> --- - Lib/plat-linux2/IN.py | 2 + - Modules/socketmodule.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ - Modules/socketmodule.h | 11 ++++++ - configure.in | 13 +++++++ - 4 files changed, 115 insertions(+), 0 deletions(-) + Modules/socketmodule.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ + Modules/socketmodule.h | 17 ++++++++ + configure.in | 7 +++ + pyconfig.h.in | 83 ++++++++++++++++++++++++++++++++--------- + 4 files changed, 184 insertions(+), 19 deletions(-) -diff --git a/Lib/plat-linux2/IN.py b/Lib/plat-linux2/IN.py -index ad307f6..f72ae88 100644 ---- a/Lib/plat-linux2/IN.py -+++ b/Lib/plat-linux2/IN.py -@@ -384,6 +384,7 @@ PF_SNA = 22 - PF_IRDA = 23 - PF_PPPOX = 24 - PF_WANPIPE = 25 -+PF_CAN = 29 - PF_BLUETOOTH = 31 - PF_MAX = 32 - AF_UNSPEC = PF_UNSPEC -@@ -414,6 +415,7 @@ AF_SNA = PF_SNA - AF_IRDA = PF_IRDA - AF_PPPOX = PF_PPPOX - AF_WANPIPE = PF_WANPIPE -+AF_CAN = PF_CAN - AF_BLUETOOTH = PF_BLUETOOTH - AF_MAX = PF_MAX - SOL_RAW = 255 diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c -index a28116c..8b3625d 100644 +index a28116c..99ae1e8 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c -@@ -417,6 +417,10 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); - - #define SAS2SA(x) ((struct sockaddr *)(x)) - -+#ifdef ENABLE_CAN -+#include <linux/can/raw.h> -+#endif -+ - /* - * Constants for getnameinfo() - */ -@@ -1041,6 +1045,22 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto) +@@ -1151,6 +1151,25 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto) } #endif -+#ifdef ENABLE_CAN -+ case AF_CAN: -+ { -+ struct sockaddr_can *a = (struct sockaddr_can *)addr; -+ char *ifname = ""; -+ struct ifreq ifr; -+ /* need to look up interface name give index */ -+ if (a->can_ifindex) { -+ ifr.ifr_ifindex = a->can_ifindex; -+ if (ioctl(sockfd, SIOCGIFNAME, &ifr) == 0) -+ ifname = ifr.ifr_name; -+ } -+ return Py_BuildValue("s", ifname); -+ } ++#ifdef HAVE_LINUX_CAN_H ++ case AF_CAN: ++ { ++ struct sockaddr_can *a = (struct sockaddr_can *)addr; ++ char *ifname = ""; ++ struct ifreq ifr; ++ /* need to look up interface name give index */ ++ if (a->can_ifindex) { ++ ifr.ifr_ifindex = a->can_ifindex; ++ if (ioctl(sockfd, SIOCGIFNAME, &ifr) == 0) ++ ifname = ifr.ifr_name; ++ } ++ ++ return Py_BuildValue("sh", ++ ifname, ++ a->can_family); ++ } +#endif + - #ifdef USE_BLUETOOTH - case AF_BLUETOOTH: - switch (proto) { -@@ -1304,6 +1324,28 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, + /* More cases here... */ + + default: +@@ -1487,6 +1506,43 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, } #endif -+#ifdef ENABLE_CAN -+ case AF_CAN: -+ { -+ struct sockaddr_can* addr; -+ struct ifreq ifr; -+ char *interfaceName; -+ addr = (struct sockaddr_can*)addr_ret; -+ if (!PyArg_Parse(args, "s", &interfaceName)) -+ return 0; -+ strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name)); -+ ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0'; -+ if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) { -+ s->errorhandler(); -+ return 0; ++#ifdef HAVE_LINUX_CAN_H ++ case AF_CAN: ++ switch (s->sock_proto) { ++ case CAN_RAW: ++ { ++ struct sockaddr_can* addr; ++ char *interfaceName; ++ struct ifreq ifr; ++ addr = (struct sockaddr_can *)addr_ret; ++ ++ if (!PyArg_ParseTuple(args, "s", &interfaceName)) ++ return 0; ++ ++ if (!strcmp(interfaceName, "any")) { ++ ifr.ifr_ifindex = 0; ++ } else { ++ strncpy(ifr.ifr_name, interfaceName, ++ sizeof(ifr.ifr_name)); ++ ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0'; ++ if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) { ++ s->errorhandler(); ++ return 0; ++ } ++ } ++ ++ addr->can_family = AF_CAN; ++ addr->can_ifindex = ifr.ifr_ifindex; ++ ++ *len_ret = sizeof(*addr); ++ return 1; ++ } ++ default: ++ PyErr_SetString(socket_error, "getsockaddrarg: unsupported CAN protocol"); ++ return 0; + } -+ addr->can_family = AF_CAN; -+ addr->can_ifindex = ifr.ifr_ifindex; -+ *len_ret = sizeof *addr; -+ return 1; -+ } +#endif + - #ifdef USE_BLUETOOTH - case AF_BLUETOOTH: - { -@@ -1535,6 +1577,14 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret) + /* More cases here... */ + + default: +@@ -1580,6 +1636,14 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret) } #endif -+#ifdef ENABLE_CAN -+ case AF_CAN: -+ { -+ *len_ret = sizeof (struct sockaddr_can); -+ return 1; -+ } ++#ifdef HAVE_LINUX_CAN_H ++ case AF_CAN: ++ { ++ *len_ret = sizeof (struct sockaddr_can); ++ return 1; ++ } +#endif + - #ifdef USE_BLUETOOTH - case AF_BLUETOOTH: - { -@@ -4583,6 +4633,10 @@ init_socket(void) - PyModule_AddIntConstant(m, "AF_LLC", AF_LLC); - #endif + /* More cases here... */ -+#ifdef ENABLE_CAN -+ PyModule_AddIntConstant(m, "AF_CAN", AF_CAN); -+#endif -+ - #ifdef USE_BLUETOOTH - PyModule_AddIntConstant(m, "AF_BLUETOOTH", AF_BLUETOOTH); - PyModule_AddIntConstant(m, "BTPROTO_L2CAP", BTPROTO_L2CAP); -@@ -4916,6 +4970,41 @@ init_socket(void) - PyModule_AddIntConstant(m, "IPPROTO_MAX", IPPROTO_MAX); + default: +@@ -4599,6 +4663,15 @@ init_socket(void) + PyModule_AddStringConstant(m, "BDADDR_LOCAL", "00:00:00:FF:FF:FF"); #endif -+#ifdef CAN_RAW -+ PyModule_AddIntConstant(m, "CAN_RAW", CAN_RAW); -+#endif -+#ifdef CAN_BCM -+ PyModule_AddIntConstant(m, "CAN_BCM", CAN_BCM); ++#ifdef AF_CAN ++ /* Controller Area Network */ ++ PyModule_AddIntConstant(m, "AF_CAN", AF_CAN); +#endif -+#ifdef CAN_TP16 -+ PyModule_AddIntConstant(m, "CAN_TP16", CAN_TP16); ++#ifdef PF_CAN ++ /* Controller Area Network */ ++ PyModule_AddIntConstant(m, "PF_CAN", PF_CAN); +#endif -+#ifdef CAN_TP20 -+ PyModule_AddIntConstant(m, "CAN_TP20", CAN_TP20); -+#endif -+#ifdef CAN_MCNET -+ PyModule_AddIntConstant(m, "CAN_MCNET", CAN_MCNET); -+#endif -+#ifdef CAN_ISOTP -+ PyModule_AddIntConstant(m, "CAN_ISOTP", CAN_ISOTP); ++ + #ifdef HAVE_NETPACKET_PACKET_H + PyModule_AddIntConstant(m, "AF_PACKET", AF_PACKET); + PyModule_AddIntConstant(m, "PF_PACKET", PF_PACKET); +@@ -4799,6 +4872,29 @@ init_socket(void) + #else + PyModule_AddIntConstant(m, "SOL_UDP", 17); + #endif ++#ifdef SOL_CAN_BASE ++ PyModule_AddIntConstant(m, "SOL_CAN_BASE", SOL_CAN_BASE); +#endif -+#ifdef CAN_NPROTO -+ PyModule_AddIntConstant(m, "CAN_NPROTO", CAN_NPROTO); ++#ifdef SOL_CAN_RAW ++ PyModule_AddIntConstant(m, "SOL_CAN_RAW", SOL_CAN_RAW); ++ PyModule_AddIntConstant(m, "CAN_RAW", CAN_RAW); +#endif ++#ifdef HAVE_LINUX_CAN_H ++ PyModule_AddIntConstant(m, "CAN_EFF_FLAG", CAN_EFF_FLAG); ++ PyModule_AddIntConstant(m, "CAN_RTR_FLAG", CAN_RTR_FLAG); ++ PyModule_AddIntConstant(m, "CAN_ERR_FLAG", CAN_ERR_FLAG); + -+#ifdef SOL_CAN_BASE -+ PyModule_AddIntConstant(m, "SOL_CAN_BASE", SOL_CAN_BASE); ++ PyModule_AddIntConstant(m, "CAN_SFF_MASK", CAN_SFF_MASK); ++ PyModule_AddIntConstant(m, "CAN_EFF_MASK", CAN_EFF_MASK); ++ PyModule_AddIntConstant(m, "CAN_ERR_MASK", CAN_ERR_MASK); +#endif -+#ifdef SOL_CAN_RAW -+ PyModule_AddIntConstant(m, "SOL_CAN_RAW", SOL_CAN_RAW); -+#endif -+#ifdef ENABLE_CAN -+ PyModule_AddIntConstant(m, "CAN_RAW_FILTER", CAN_RAW_FILTER); -+ PyModule_AddIntConstant(m, "CAN_RAW_ERR_FILTER", CAN_RAW_ERR_FILTER); -+ PyModule_AddIntConstant(m, "CAN_RAW_LOOPBACK", CAN_RAW_LOOPBACK); -+ PyModule_AddIntConstant(m, "CAN_RAW_RECV_OWN_MSGS", CAN_RAW_RECV_OWN_MSGS); ++#ifdef HAVE_LINUX_CAN_RAW_H ++ PyModule_AddIntConstant(m, "CAN_RAW_FILTER", CAN_RAW_FILTER); ++ PyModule_AddIntConstant(m, "CAN_RAW_ERR_FILTER", CAN_RAW_ERR_FILTER); ++ PyModule_AddIntConstant(m, "CAN_RAW_LOOPBACK", CAN_RAW_LOOPBACK); ++ PyModule_AddIntConstant(m, "CAN_RAW_RECV_OWN_MSGS", CAN_RAW_RECV_OWN_MSGS); +#endif + - /* Some port configuration */ - #ifdef IPPORT_RESERVED - PyModule_AddIntConstant(m, "IPPORT_RESERVED", IPPORT_RESERVED); + #ifdef IPPROTO_IP + PyModule_AddIntConstant(m, "IPPROTO_IP", IPPROTO_IP); + #else diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h -index 9b85773..f0d8265 100644 +index 9b85773..2b6b219 100644 --- a/Modules/socketmodule.h +++ b/Modules/socketmodule.h -@@ -55,6 +55,14 @@ typedef int socklen_t; - #include <bluetooth/hci.h> +@@ -69,6 +69,20 @@ typedef int socklen_t; + # include <linux/tipc.h> #endif -+#define AF_CAN 29 -+#define PF_CAN AF_CAN -+ +#ifdef HAVE_LINUX_CAN_H -+#define ENABLE_CAN 1 +#include <linux/can.h> ++#ifndef PF_CAN ++# define PF_CAN 29 ++#endif ++#ifndef AF_CAN ++# define AF_CAN PF_CAN ++#endif +#endif + - #ifdef HAVE_BLUETOOTH_H - #include <bluetooth.h> - #endif -@@ -105,6 +113,9 @@ typedef union sock_addr { - struct sockaddr_in6 in6; - struct sockaddr_storage storage; ++#ifdef HAVE_LINUX_CAN_RAW_H ++#include <linux/can/raw.h> ++#endif ++ + #ifndef Py__SOCKET_H + #define Py__SOCKET_H + #ifdef __cplusplus +@@ -114,6 +128,9 @@ typedef union sock_addr { + #ifdef HAVE_NETPACKET_PACKET_H + struct sockaddr_ll ll; #endif -+#ifdef ENABLE_CAN -+ struct sockaddr_can can; ++#ifdef HAVE_LINUX_CAN_H ++ struct sockaddr_can* can; +#endif - #ifdef HAVE_BLUETOOTH_BLUETOOTH_H - struct sockaddr_l2 bt_l2; - struct sockaddr_rc bt_rc; + } sock_addr_t; + + /* The object holding a socket. It holds some extra information, diff --git a/configure.in b/configure.in -index a3b96ae..e9b5cf0 100644 +index 7bfd6c2..aadba8b 100644 --- a/configure.in +++ b/configure.in -@@ -1350,6 +1350,19 @@ AC_CHECK_HEADERS(linux/netlink.h,,,[ +@@ -1349,6 +1349,13 @@ AC_CHECK_HEADERS(linux/netlink.h,,,[ #endif ]) -+AC_CHECK_HEADERS(linux/can.h,[],[],[#include <sys/socket.h>]) -+# check for AF_CAN -+AC_TRY_COMPILE( -+ [[#include <sys/socket.h> -+ int domain = AF_CAN;]], -+ [[socket(domain, 0, 0);]], -+ [], -+ [ -+ AC_DEFINE(AF_CAN, 29, [Define AF_CAN if not defined by sys/socket.h]) -+ AC_DEFINE(PF_CAN, 29, [Define PF_CAN if not defined by sys/socket.h]) -+ ] -+) ++# On Linux, can.h and can/raw.h require sys/socket.h ++AC_CHECK_HEADERS(linux/can.h linux/can/raw.h,,,[ ++#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) +diff --git a/pyconfig.h.in b/pyconfig.h.in +index e05ab4a..4a30858 100644 +--- a/pyconfig.h.in ++++ b/pyconfig.h.in +@@ -5,6 +5,12 @@ + #define Py_PYCONFIG_H + + ++/* Define if building universal (internal helper macro) */ ++#undef AC_APPLE_UNIVERSAL_BUILD ++ ++#undef HAVE_LINUX_CAN_H ++#undef HAVE_LINUX_CAN_RAW_H ++ + /* Define for AIX if your compiler is a genuine IBM xlC/xlC_r and you want + support for AIX C++ shared extension modules. */ + #undef AIX_GENUINE_CPLUSPLUS +@@ -387,12 +393,15 @@ + /* Define to 1 if you have the `log1p' function. */ + #undef HAVE_LOG1P + +-/* Define this if you have the type long double. */ ++/* Define to 1 if the system has the type `long double'. */ + #undef HAVE_LONG_DOUBLE + + /* Define this if you have the type long long. */ + #undef HAVE_LONG_LONG + ++/* Define to 1 if the system has the type `long long int'. */ ++#undef HAVE_LONG_LONG_INT ++ + /* Define to 1 if you have the `lstat' function. */ + #undef HAVE_LSTAT + +@@ -610,25 +619,25 @@ + /* Define to 1 if you have the <stropts.h> header file. */ + #undef HAVE_STROPTS_H + +-/* Define to 1 if `st_birthtime' is member of `struct stat'. */ ++/* Define to 1 if `st_birthtime' is a member of `struct stat'. */ + #undef HAVE_STRUCT_STAT_ST_BIRTHTIME + +-/* Define to 1 if `st_blksize' is member of `struct stat'. */ ++/* Define to 1 if `st_blksize' is a member of `struct stat'. */ + #undef HAVE_STRUCT_STAT_ST_BLKSIZE + +-/* Define to 1 if `st_blocks' is member of `struct stat'. */ ++/* Define to 1 if `st_blocks' is a member of `struct stat'. */ + #undef HAVE_STRUCT_STAT_ST_BLOCKS + +-/* Define to 1 if `st_flags' is member of `struct stat'. */ ++/* Define to 1 if `st_flags' is a member of `struct stat'. */ + #undef HAVE_STRUCT_STAT_ST_FLAGS + +-/* Define to 1 if `st_gen' is member of `struct stat'. */ ++/* Define to 1 if `st_gen' is a member of `struct stat'. */ + #undef HAVE_STRUCT_STAT_ST_GEN + +-/* Define to 1 if `st_rdev' is member of `struct stat'. */ ++/* Define to 1 if `st_rdev' is a member of `struct stat'. */ + #undef HAVE_STRUCT_STAT_ST_RDEV + +-/* Define to 1 if `tm_zone' is member of `struct tm'. */ ++/* Define to 1 if `tm_zone' is a member of `struct tm'. */ + #undef HAVE_STRUCT_TM_TM_ZONE + + /* Define to 1 if your `struct stat' has `st_blocks'. Deprecated, use +@@ -845,6 +854,9 @@ + /* Define to the one symbol short name of this package. */ + #undef PACKAGE_TARNAME + ++/* Define to the home page for this package. */ ++#undef PACKAGE_URL ++ + /* Define to the version of this package. */ + #undef PACKAGE_VERSION + +@@ -908,7 +920,7 @@ + /* The size of `pid_t', as computed by sizeof. */ + #undef SIZEOF_PID_T + +-/* The number of bytes in a pthread_t. */ ++/* The size of `pthread_t', as computed by sizeof. */ + #undef SIZEOF_PTHREAD_T + + /* The size of `short', as computed by sizeof. */ +@@ -948,6 +960,28 @@ + /* Define to 1 if your <sys/time.h> declares `struct tm'. */ + #undef TM_IN_SYS_TIME + ++/* Enable extensions on AIX 3, Interix. */ ++#ifndef _ALL_SOURCE ++# undef _ALL_SOURCE ++#endif ++/* Enable GNU extensions on systems that have them. */ ++#ifndef _GNU_SOURCE ++# undef _GNU_SOURCE ++#endif ++/* Enable threading extensions on Solaris. */ ++#ifndef _POSIX_PTHREAD_SEMANTICS ++# undef _POSIX_PTHREAD_SEMANTICS ++#endif ++/* Enable extensions on HP NonStop. */ ++#ifndef _TANDEM_SOURCE ++# undef _TANDEM_SOURCE ++#endif ++/* Enable general extensions on Solaris. */ ++#ifndef __EXTENSIONS__ ++# undef __EXTENSIONS__ ++#endif ++ ++ + /* Define if you want to use MacPython modules on MacOSX in unix-Python. */ + #undef USE_TOOLBOX_OBJECT_GLUE + +@@ -988,20 +1022,21 @@ + /* Define to profile with the Pentium timestamp counter */ + #undef WITH_TSC + +-/* Define to 1 if your processor stores words with the most significant byte +- first (like Motorola and SPARC, unlike Intel and VAX). */ +-#undef WORDS_BIGENDIAN ++/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most ++ significant byte first (like Motorola and SPARC, unlike Intel). */ ++#if defined AC_APPLE_UNIVERSAL_BUILD ++# if defined __BIG_ENDIAN__ ++# define WORDS_BIGENDIAN 1 ++# endif ++#else ++# ifndef WORDS_BIGENDIAN ++# undef WORDS_BIGENDIAN ++# endif ++#endif + + /* Define if arithmetic is subject to x87-style double rounding issue */ + #undef X87_DOUBLE_ROUNDING + +-/* Define to 1 if on AIX 3. +- System headers sometimes define this. +- We just want to avoid a redefinition error message. */ +-#ifndef _ALL_SOURCE +-# undef _ALL_SOURCE +-#endif +- + /* Define on OpenBSD to activate all library features */ + #undef _BSD_SOURCE + +@@ -1020,15 +1055,25 @@ + /* This must be defined on some systems to enable large file support. */ + #undef _LARGEFILE_SOURCE + ++/* Define to 1 if on MINIX. */ ++#undef _MINIX ++ + /* Define on NetBSD to activate all library features */ + #undef _NETBSD_SOURCE + + /* Define _OSF_SOURCE to get the makedev macro. */ + #undef _OSF_SOURCE + ++/* Define to 2 if the system does not provide POSIX.1 features except with ++ this defined. */ ++#undef _POSIX_1_SOURCE ++ + /* Define to activate features from IEEE Stds 1003.1-2001 */ + #undef _POSIX_C_SOURCE + ++/* Define to 1 if you need to in order for `stat' and other things to work. */ ++#undef _POSIX_SOURCE ++ + /* Define if you have POSIX threads, and your system does not define that. */ + #undef _POSIX_THREADS + -- -1.7.2.3 +1.7.3.4 -- 1.7.3.4 -- ptxdist mailing list [email protected]
