]> granicus.if.org Git - python/commitdiff
Patch #874083: Bluetooth support for socket module.
authorMartin v. Löwis <martin@v.loewis.de>
Sat, 31 Jan 2004 12:34:17 +0000 (12:34 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sat, 31 Jan 2004 12:34:17 +0000 (12:34 +0000)
Misc/ACKS
Misc/NEWS
Modules/socketmodule.c
Modules/socketmodule.h
configure
configure.in
pyconfig.h.in

index eea665aced2ee4f1cc514c0e789b1ffbd8eba7d8..77c798074bc7d4622716aa340284b3ffbe80653e 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -177,6 +177,7 @@ Sebastian Fernandez
 Vincent Fiack
 Russell Finn
 Nils Fischbeck
+Frederik Fix
 Hernán Martínez Foffani
 Doug Fort
 Martin Franklin
index 71a549e5912ecd85d137919a345fb1ad54e9e56f..e4332d8b0bfeb8e396223e4c054eec2692723465 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -121,6 +121,9 @@ Core and builtins
 Extension modules
 -----------------
 
+- The socket module now supports Bluetooth sockets, if the
+  system has <bluetooth/bluetooth.h>
+
 - Added a collections module containing a new datatype, deque(),
   offering high-performance, thread-safe, memory friendly appends
   and pops on either side of the deque.
index c7777fd3928ae0de978e52edf04cb99f1ed9059d..28e9877ea23f6e9ffe7e8f33fd5d7dc81a8028b5 100644 (file)
@@ -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);
index 167d50711a2f0dfbf92280b4605f5e6080315f88..9756a47ede273a1ead724d3d5d6280c8fa586afc 100644 (file)
 # 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
index f1a46c79c7ba518e1d1dcee2f8ce25ce69447ea1..0f8d4fb06301c053bd24f615b248e6866bf56322 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 1.445 .
+# From configure.in Revision: 1.447 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.57 for python 2.4.
 #
@@ -3008,7 +3008,7 @@ rm -f conftest*
 
 # Check for unsupported systems
 case $ac_sys_system/$ac_sys_release in
-SunOS/4*|Linux*/1*)
+Linux*/1*)
    echo This system \($ac_sys_system/$ac_sys_release\) is no longer supported.
    echo See README for details.
    exit 1;;
@@ -4347,6 +4347,7 @@ done
 
 
 
+
 
 
 for ac_header in dlfcn.h fcntl.h grp.h limits.h langinfo.h \
@@ -4356,7 +4357,7 @@ unistd.h utime.h \
 sys/audioio.h sys/bsdtty.h sys/file.h sys/lock.h sys/mkdev.h sys/modem.h \
 sys/param.h sys/poll.h sys/select.h sys/socket.h sys/time.h sys/times.h \
 sys/un.h sys/utsname.h sys/wait.h pty.h term.h libutil.h \
-sys/resource.h netpacket/packet.h sysexits.h
+sys/resource.h netpacket/packet.h sysexits.h bluetooth/bluetooth.h
 do
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
 if eval "test \"\${$as_ac_Header+set}\" = set"; then
@@ -9362,7 +9363,7 @@ fi
 echo "$as_me:$LINENO: result: $SO" >&5
 echo "${ECHO_T}$SO" >&6
 # LDSHARED is the ld *command* used to create shared library
-# -- "ld" on SunOS 4.x.x, "cc -G" on SunOS 5.x, "ld -shared" on IRIX 5
+# -- "cc -G" on SunOS 5.x, "ld -shared" on IRIX 5
 # (Shared libraries in this instance are shared modules to be loaded into
 # Python, as opposed to building Python itself as a shared library.)
 echo "$as_me:$LINENO: checking LDSHARED" >&5
@@ -9380,7 +9381,6 @@ then
                ;;
        IRIX/5*) LDSHARED="ld -shared";;
        IRIX*/6*) LDSHARED="ld ${SGI_ABI} -shared -all";;
-       SunOS/4*) LDSHARED="ld";;
        SunOS/5*)
                if test "$GCC" = "yes"
                then LDSHARED='$(CC) -shared'
@@ -15518,56 +15518,6 @@ rm -f conftest.$ac_objext conftest.$ac_ext
 echo "$as_me:$LINENO: result: $works" >&5
 echo "${ECHO_T}$works" >&6
 
-if test "$have_prototypes" = yes; then
-bad_prototypes=no
-echo "$as_me:$LINENO: checking for bad exec* prototypes" >&5
-echo $ECHO_N "checking for bad exec* prototypes... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-#line $LINENO "configure"
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <unistd.h>
-int
-main ()
-{
-char **t;execve("@",t,t);
-  ;
-  return 0;
-}
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
-  (eval $ac_compile) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } &&
-         { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); }; }; then
-  :
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-
-cat >>confdefs.h <<\_ACEOF
-#define BAD_EXEC_PROTOTYPES 1
-_ACEOF
-
-    bad_prototypes=yes
-
-fi
-rm -f conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $bad_prototypes" >&5
-echo "${ECHO_T}$bad_prototypes" >&6
-fi
-
 # check if sockaddr has sa_len member
 echo "$as_me:$LINENO: checking if sockaddr has sa_len member" >&5
 echo $ECHO_N "checking if sockaddr has sa_len member... $ECHO_C" >&6
index c4b60f789df62eaa14a5ed4373ec5a330c446d39..0f7ebdf46177621b338fdc459bb196c4e2ae6252 100644 (file)
@@ -918,7 +918,7 @@ unistd.h utime.h \
 sys/audioio.h sys/bsdtty.h sys/file.h sys/lock.h sys/mkdev.h sys/modem.h \
 sys/param.h sys/poll.h sys/select.h sys/socket.h sys/time.h sys/times.h \
 sys/un.h sys/utsname.h sys/wait.h pty.h term.h libutil.h \
-sys/resource.h netpacket/packet.h sysexits.h)
+sys/resource.h netpacket/packet.h sysexits.h bluetooth/bluetooth.h)
 AC_HEADER_DIRENT
 AC_HEADER_MAJOR
 
index e1c432fb5e7c532c6b633076c560ad6ac066d68e..f4ba0fcc149f40e6668b0fdb92d637ee7891c985 100644 (file)
@@ -37,6 +37,9 @@
 /* Define this if your time.h defines altzone. */
 #undef HAVE_ALTZONE
 
+/* Define to 1 if you have the <bluetooth/bluetooth.h> header file. */
+#undef HAVE_BLUETOOTH_BLUETOOTH_H
+
 /* Define if nice() returns success/failure instead of the new priority. */
 #undef HAVE_BROKEN_NICE
 
 /* 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