diff -r ba264b26d8d9 Modules/socketmodule.c --- a/Modules/socketmodule.c Sun Jul 15 19:10:39 2012 +1000 +++ b/Modules/socketmodule.c Mon Jul 16 00:52:14 2012 +1200 @@ -1694,6 +1694,44 @@ Py_DECREF(interfaceName); return 1; } + case CAN_BCM: + { + struct sockaddr_can *addr; + PyObject *interfaceName; + struct ifreq ifr; + addr = (struct sockaddr_can *)addr_ret; + Py_ssize_t len; + + if (!PyArg_ParseTuple(args, "O&", PyUnicode_FSConverter, + &interfaceName)) + return 0; + + len = PyBytes_GET_SIZE(interfaceName); + + if (len == 0) { + ifr.ifr_ifindex = 0; + } else if (len < sizeof(ifr.ifr_name)) { + strcpy(ifr.ifr_name, PyBytes_AS_STRING(interfaceName)); + if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) { + s->errorhandler(); + Py_DECREF(interfaceName); + return 0; + } + } else { + PyErr_SetString(PyExc_OSError, + "AF_CAN interface name too long"); + Py_DECREF(interfaceName); + return 0; + } + + addr->can_family = PF_CAN; + addr->can_ifindex = ifr.ifr_ifindex; + s->sock_type = SOCK_DGRAM; + + *len_ret = sizeof(*addr); + Py_DECREF(interfaceName); + return 1; + } default: PyErr_SetString(PyExc_OSError, "getsockaddrarg: unsupported CAN protocol"); @@ -6118,6 +6156,14 @@ PyModule_AddIntConstant(m, "CAN_RAW_LOOPBACK", CAN_RAW_LOOPBACK); PyModule_AddIntConstant(m, "CAN_RAW_RECV_OWN_MSGS", CAN_RAW_RECV_OWN_MSGS); #endif +#ifdef HAVE_LINUX_CAN_BCM_H + PyModule_AddIntConstant(m, "CAN_BCM", CAN_BCM); + PyModule_AddIntConstant(m, "CAN_BCM_TX_SETUP", TX_SETUP); + PyModule_AddIntConstant(m, "CAN_BCM_TX_DELETE", TX_DELETE); + PyModule_AddIntConstant(m, "CAN_BCM_TX_READ", TX_READ); + PyModule_AddIntConstant(m, "CAN_BCM_TX_SEND", TX_SEND); + +#endif #ifdef SOL_RDS PyModule_AddIntConstant(m, "SOL_RDS", SOL_RDS); #endif diff -r ba264b26d8d9 Modules/socketmodule.h --- a/Modules/socketmodule.h Sun Jul 15 19:10:39 2012 +1000 +++ b/Modules/socketmodule.h Mon Jul 16 00:52:14 2012 +1200 @@ -80,6 +80,10 @@ #include #endif +#ifdef HAVE_LINUX_CAN_BCM_H +#include +#endif + #ifdef HAVE_SYS_SYS_DOMAIN_H #include #endif diff -r ba264b26d8d9 configure --- a/configure Sun Jul 15 19:10:39 2012 +1000 +++ b/configure Mon Jul 16 00:52:14 2012 +1200 @@ -7159,7 +7159,7 @@ # On Linux, can.h and can/raw.h require sys/socket.h -for ac_header in linux/can.h linux/can/raw.h +for ac_header in linux/can.h linux/can/raw.h linux/can/bcm.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" " diff -r ba264b26d8d9 configure.ac --- a/configure.ac Sun Jul 15 19:10:39 2012 +1000 +++ b/configure.ac Mon Jul 16 00:52:14 2012 +1200 @@ -1539,7 +1539,7 @@ ]) # On Linux, can.h and can/raw.h require sys/socket.h -AC_CHECK_HEADERS(linux/can.h linux/can/raw.h,,,[ +AC_CHECK_HEADERS(linux/can.h linux/can/raw.h linux/can/bcm.h,,,[ #ifdef HAVE_SYS_SOCKET_H #include #endif diff -r ba264b26d8d9 pyconfig.h.in --- a/pyconfig.h.in Sun Jul 15 19:10:39 2012 +1000 +++ b/pyconfig.h.in Mon Jul 16 00:52:14 2012 +1200 @@ -495,6 +495,9 @@ /* Define to 1 if you have the `linkat' function. */ #undef HAVE_LINKAT +/* Define to 1 if you have the header file. */ +#undef HAVE_LINUX_CAN_BCM_H + /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_CAN_H