diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1262,6 +1262,16 @@ } #endif +#ifdef AF_IRDA + case AF_IRDA: + { + struct sockaddr_irda *a = (struct sockaddr_irda *)addr; + + return Py_BuildValue("iO&", a->sir_addr, + PyUnicode_DecodeFSDefault, a->sir_name); + } +#endif + /* More cases here... */ default: @@ -1759,6 +1769,47 @@ } #endif +#ifdef HAVE_IRDA_H + case AF_IRDA: + { + struct sockaddr_irda *addr; + int daddr; + PyObject *service; + addr = (struct sockaddr_irda *)addr_ret; + Py_ssize_t len; + + if (!PyArg_ParseTuple(args, "iO&", &daddr, + PyUnicode_FSConverter, &service)) + return 0; + + len = PyBytes_GET_SIZE(service); + + if (len <= 0 || len >= sizeof(addr->sir_name)) { + PyErr_SetString(PyExc_OSError, "AF_IRDA service name too long"); + Py_DECREF(service); + return 0; + } + +#ifdef HAVE_LINUX_IRDA_H + addr->sir_family = AF_IRDA; + addr->sir_lsap_sel = LSAP_ANY; + addr->sir_addr = daddr; + strcpy(addr->sir_name, PyBytes_AS_STRING(service)); +#else /* Windows */ + addr->irdaAddressFamily = AF_IRDA; + addr->irdaDeviceID[0] = (daddr >> 24) & Oxff; + addr->irdaDeviceID[1] = (daddr >> 16) & Oxff; + addr->irdaDeviceID[2] = (daddr >> 8) & Oxff; + addr->irdaDeviceID[3] = daddr & Oxff; + strcpy(addr->irdaServiceName, PyBytes_AS_STRING(service)); +#endif + + Py_DECREF(service); + *len_ret = sizeof(*addr); + return 1; + } +#endif + /* More cases here... */ default: @@ -1880,6 +1931,14 @@ } #endif +#ifdef AF_IRDA + case AF_IRDA: + { + *len_ret = sizeof (struct sockaddr_irda); + return 1; + } +#endif + /* More cases here... */ default: @@ -5823,6 +5882,14 @@ PyModule_AddIntConstant(m, "AF_SYSTEM", AF_SYSTEM); #endif +/* Infrared Data Association */ +#ifdef AF_IRDA + PyModule_AddIntConstant(m, "AF_IRDA", AF_IRDA); +#endif +#ifdef PF_IRDA + PyModule_AddIntConstant(m, "PF_IRDA", PF_IRDA); +#endif + #ifdef AF_PACKET PyModule_AddIntMacro(m, AF_PACKET); #endif @@ -5895,6 +5962,13 @@ PyModule_AddIntConstant(m, "TIPC_TOP_SRV", TIPC_TOP_SRV); #endif +#ifdef HAVE_IRDA_H + PyModule_AddIntConstant(m, "SOL_IRLMP", SOL_IRLMP); + PyModule_AddIntConstant(m, "IRLMP_ENUMDEVICES", IRLMP_ENUMDEVICES); + PyModule_AddIntConstant(m, "IRLMP_IAS_SET", IRLMP_IAS_SET); + PyModule_AddIntConstant(m, "IRLMP_IAS_QUERY", IRLMP_IAS_QUERY); +#endif + /* Socket types */ PyModule_AddIntConstant(m, "SOCK_STREAM", SOCK_STREAM); PyModule_AddIntConstant(m, "SOCK_DGRAM", SOCK_DGRAM); diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h --- a/Modules/socketmodule.h +++ b/Modules/socketmodule.h @@ -87,6 +87,17 @@ #include #endif +#if (defined(MS_WINDOWS) || defined(HAVE_LINUX_IRDA_H)) +#define HAVE_IRDA_H +#ifdef HAVE_LINUX_IRDA_H +#include +#include +#else +#include +#define sockaddr_irda _SOCKADDR_IRDA +#endif +#endif + #ifndef Py__SOCKET_H #define Py__SOCKET_H #ifdef __cplusplus @@ -148,6 +159,9 @@ #ifdef HAVE_SYS_KERN_CONTROL_H struct sockaddr_ctl ctl; #endif +#ifdef HAVE_IRDA_H + struct sockaddr_irda ir; +#endif } sock_addr_t; /* The object holding a socket. It holds some extra information, diff --git a/configure b/configure --- a/configure +++ b/configure @@ -6605,6 +6605,25 @@ done +# On Linux, irda.h requires sys/socket.h +for ac_header in linux/irda.h +do : + ac_fn_c_check_header_compile "$LINENO" "linux/irda.h" "ac_cv_header_linux_irda_h" " +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + +" +if test "x$ac_cv_header_linux_irda_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LINUX_IRDA_H 1 +_ACEOF + +fi + +done + + # checks for typedefs was_it_defined=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_t in time.h" >&5 diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1404,6 +1404,13 @@ #endif ]) +# On Linux, irda.h requires sys/socket.h +AC_CHECK_HEADERS(linux/irda.h,,,[ +#ifdef HAVE_SYS_SOCKET_H +#include +#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 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -501,6 +501,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_CAN_RAW_H +/* Define to 1 if you have the header file. */ +#undef HAVE_LINUX_IRDA_H + /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_NETLINK_H