diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2004-01-31 12:34:17 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2004-01-31 12:34:17 (GMT) |
commit | 12af0485f858c8eca9a8c9ed9894a8a60f975b4c (patch) | |
tree | 3126f0ddfe46bfc9d855254230ebaea2723451d2 /Modules | |
parent | 4d205e366cc48535f70c1fe939ce726658e46d98 (diff) | |
download | cpython-12af0485f858c8eca9a8c9ed9894a8a60f975b4c.zip cpython-12af0485f858c8eca9a8c9ed9894a8a60f975b4c.tar.gz cpython-12af0485f858c8eca9a8c9ed9894a8a60f975b4c.tar.bz2 |
Patch #874083: Bluetooth support for socket module.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/socketmodule.c | 101 | ||||
-rw-r--r-- | Modules/socketmodule.h | 12 |
2 files changed, 113 insertions, 0 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index c7777fd..28e9877 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1012,6 +1012,68 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, } #endif +#ifdef HAVE_BLUETOOTH_BLUETOOTH_H + case AF_BLUETOOTH: + { + switch( s->sock_proto ) + { + case BTPROTO_L2CAP: + { + struct sockaddr_l2* addr = (struct sockaddr_l2*) &(s->sock_addr).bt_l2; + bdaddr_t* bdaddr = &(addr->l2_bdaddr); + + addr->l2_family = AF_BLUETOOTH; + if( !PyArg_ParseTuple(args, "(iiiiii)i", &bdaddr->b[0], &bdaddr->b[1], &bdaddr->b[2], &bdaddr->b[3], &bdaddr->b[4], &bdaddr->b[5], &addr->l2_psm) ) + { + PyErr_SetString(socket_error, "getsockaddrarg: wrong format"); + return 0; + } + + *addr_ret = (struct sockaddr *) addr; + *len_ret = sizeof *addr; + return 1; + } + case BTPROTO_RFCOMM: + { + struct sockaddr_rc* addr = (struct sockaddr_rc*) &(s->sock_addr).bt_rc; + bdaddr_t* bdaddr = &(addr->rc_bdaddr); + + addr->rc_family = AF_BLUETOOTH; + if( !PyArg_ParseTuple(args, "(iiiiii)i", &bdaddr->b[0], &bdaddr->b[1], &bdaddr->b[2], &bdaddr->b[3], &bdaddr->b[4], &bdaddr->b[5], &addr->rc_channel) ) + { + PyErr_SetString(socket_error, "getsockaddrarg: wrong format"); + return 0; + } + + *addr_ret = (struct sockaddr *) addr; + *len_ret = sizeof *addr; + return 1; + } + case BTPROTO_SCO: + { + struct sockaddr_sco* addr = (struct sockaddr_sco*) &(s->sock_addr).bt_sco; + bdaddr_t* bdaddr = &(addr->sco_bdaddr); + + addr->sco_family = AF_BLUETOOTH; + if( !PyArg_ParseTuple(args, "iiiiii", &bdaddr->b[0], &bdaddr->b[1], &bdaddr->b[2], &bdaddr->b[3], &bdaddr->b[4], &bdaddr->b[5]) ) + { + PyErr_SetString(socket_error, "getsockaddrarg: wrong format"); + return 0; + } + + *addr_ret = (struct sockaddr *) addr; + *len_ret = sizeof *addr; + return 1; + } + default: + { + PyErr_SetString(socket_error, "getsockaddrarg: unknown Bluetooth protocol"); + return 0; + } + } + } +#endif + #ifdef HAVE_NETPACKET_PACKET_H case AF_PACKET: { @@ -1085,6 +1147,35 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret) } #endif +#ifdef HAVE_BLUETOOTH_BLUETOOTH_H + case AF_BLUETOOTH: + { + switch(s->sock_proto) + { + case BTPROTO_L2CAP: + { + *len_ret = sizeof (struct sockaddr_l2); + return 1; + } + case BTPROTO_RFCOMM: + { + *len_ret = sizeof (struct sockaddr_rc); + return 1; + } + case BTPROTO_SCO: + { + *len_ret = sizeof (struct sockaddr_sco); + return 1; + } + default: + { + PyErr_SetString(socket_error, "getsockaddrlen: unknown BT protocol"); + return 0; + } + } + } +#endif + #ifdef HAVE_NETPACKET_PACKET_H case AF_PACKET: { @@ -3573,6 +3664,16 @@ init_socket(void) /* Amateur Radio X.25 PLP */ PyModule_AddIntConstant(m, "AF_ROSE", AF_ROSE); #endif + +#ifdef HAVE_BLUETOOTH_BLUETOOTH_H + PyModule_AddIntConstant(m, "AF_BLUETOOTH", AF_BLUETOOTH); + PyModule_AddIntConstant(m, "BTPROTO_L2CAP", BTPROTO_L2CAP); + PyModule_AddIntConstant(m, "BTPROTO_SCO", BTPROTO_SCO); + PyModule_AddIntConstant(m, "BTPROTO_RFCOMM", BTPROTO_RFCOMM); + PyModule_AddObject(m, "BDADDR_ANY", Py_BuildValue( "iiiiii", 0,0,0,0,0,0 ) ); + PyModule_AddObject(m, "BDADDR_LOCAL", Py_BuildValue( "iiiiii", 0,0,0,0xff,0xff,0xff ) ); +#endif + #ifdef HAVE_NETPACKET_PACKET_H PyModule_AddIntConstant(m, "AF_PACKET", AF_PACKET); PyModule_AddIntConstant(m, "PF_PACKET", PF_PACKET); diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h index 167d507..9756a47 100644 --- a/Modules/socketmodule.h +++ b/Modules/socketmodule.h @@ -32,6 +32,13 @@ # undef AF_UNIX #endif +#ifdef HAVE_BLUETOOTH_BLUETOOTH_H +#include <bluetooth/bluetooth.h> +#include <bluetooth/rfcomm.h> +#include <bluetooth/l2cap.h> +#include <bluetooth/sco.h> +#endif + #ifdef HAVE_NETPACKET_PACKET_H # include <sys/ioctl.h> # include <net/if.h> @@ -80,6 +87,11 @@ typedef struct { struct sockaddr_in6 in6; struct sockaddr_storage storage; #endif +#ifdef HAVE_BLUETOOTH_BLUETOOTH_H + struct sockaddr_l2 bt_l2; + struct sockaddr_rc bt_rc; + struct sockaddr_sco bt_sco; +#endif #ifdef HAVE_NETPACKET_PACKET_H struct sockaddr_ll ll; #endif |