diff options
Diffstat (limited to 'patches/Python-2.6.2/0001-Add-support-for-socketcan-to-the-python-socket-modul.patch')
-rw-r--r-- | patches/Python-2.6.2/0001-Add-support-for-socketcan-to-the-python-socket-modul.patch | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/patches/Python-2.6.2/0001-Add-support-for-socketcan-to-the-python-socket-modul.patch b/patches/Python-2.6.2/0001-Add-support-for-socketcan-to-the-python-socket-modul.patch new file mode 100644 index 000000000..a1a0c9dcf --- /dev/null +++ b/patches/Python-2.6.2/0001-Add-support-for-socketcan-to-the-python-socket-modul.patch @@ -0,0 +1,229 @@ +From 7f8972018c739fedf709f6d25405fa5505d226c7 Mon Sep 17 00:00:00 2001 +From: Michael Olbrich <m.olbrich@pengutronix.de> +Date: Tue, 5 May 2009 15:17:20 +0200 +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. + +Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> +Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> +--- + Lib/plat-linux2/IN.py | 2 + + Modules/socketmodule.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ + Modules/socketmodule.h | 11 ++++++ + configure.in | 13 +++++++ + 4 files changed, 116 insertions(+), 0 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 ca10fb5..02fe1e1 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) + } + #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); ++ } ++#endif ++ + #ifdef USE_BLUETOOTH + case AF_BLUETOOTH: + switch (proto) { +@@ -1300,6 +1320,29 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, + } + #endif + ++#ifdef ENABLE_CAN ++ case AF_CAN: ++ { ++ struct sockaddr_can* addr; ++ struct ifreq ifr; ++ char *interfaceName; ++ addr=&(s->sock_addr.can); ++ 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; ++ } ++ addr->can_family = AF_CAN; ++ addr->can_ifindex = ifr.ifr_ifindex; ++ *addr_ret = (struct sockaddr *) addr; ++ *len_ret = sizeof *addr; ++ return 1; ++ } ++#endif ++ + #ifdef USE_BLUETOOTH + case AF_BLUETOOTH: + { +@@ -1530,6 +1573,14 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret) + } + #endif + ++#ifdef ENABLE_CAN ++ case AF_CAN: ++ { ++ *len_ret = sizeof (struct sockaddr_can); ++ return 1; ++ } ++#endif ++ + #ifdef USE_BLUETOOTH + case AF_BLUETOOTH: + { +@@ -4559,6 +4610,10 @@ init_socket(void) + PyModule_AddIntConstant(m, "AF_LLC", AF_LLC); + #endif + ++#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); +@@ -4892,6 +4947,41 @@ init_socket(void) + PyModule_AddIntConstant(m, "IPPROTO_MAX", IPPROTO_MAX); + #endif + ++#ifdef CAN_RAW ++ PyModule_AddIntConstant(m, "CAN_RAW", CAN_RAW); ++#endif ++#ifdef CAN_BCM ++ PyModule_AddIntConstant(m, "CAN_BCM", CAN_BCM); ++#endif ++#ifdef CAN_TP16 ++ PyModule_AddIntConstant(m, "CAN_TP16", CAN_TP16); ++#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); ++#endif ++#ifdef CAN_NPROTO ++ PyModule_AddIntConstant(m, "CAN_NPROTO", CAN_NPROTO); ++#endif ++ ++#ifdef SOL_CAN_BASE ++ PyModule_AddIntConstant(m, "SOL_CAN_BASE", SOL_CAN_BASE); ++#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); ++#endif ++ + /* Some port configuration */ + #ifdef IPPORT_RESERVED + PyModule_AddIntConstant(m, "IPPORT_RESERVED", IPPORT_RESERVED); +diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h +index ef8d0fc..56c0cbc 100644 +--- a/Modules/socketmodule.h ++++ b/Modules/socketmodule.h +@@ -55,6 +55,14 @@ typedef int socklen_t; + #include <bluetooth/hci.h> + #endif + ++#define AF_CAN 29 ++#define PF_CAN AF_CAN ++ ++#ifdef HAVE_LINUX_CAN_H ++#define ENABLE_CAN 1 ++#include <linux/can.h> ++#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; + #endif ++#ifdef ENABLE_CAN ++ struct sockaddr_can can; ++#endif + #ifdef HAVE_BLUETOOTH_BLUETOOTH_H + struct sockaddr_l2 bt_l2; + struct sockaddr_rc bt_rc; +diff --git a/configure.in b/configure.in +index 106e6a7..311311b 100644 +--- a/configure.in ++++ b/configure.in +@@ -1261,6 +1261,19 @@ 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]) ++ ] ++) ++ + # checks for typedefs + was_it_defined=no + AC_MSG_CHECKING(for clock_t in time.h) +-- +1.5.6.3 + |