]> The Tcpdump Group git mirrors - libpcap/commitdiff
Cope with Bluetooth API breakage in some Linux 3.x(?) kernel.
authorGuy Harris <[email protected]>
Mon, 25 Mar 2013 12:18:35 +0000 (05:18 -0700)
committerGuy Harris <[email protected]>
Mon, 25 Mar 2013 12:18:35 +0000 (05:18 -0700)
In the 2.6.32.4 kernel, struct sockaddr_hci has no hci_channel member.

In the 3.0.4 kernel, struct sockaddr_hci has an hci_channel member, and
it has to get set in order for binds of AF_BLUETOOTH/BTPROTO_HCI sockets
to work.

Cope with this API breakage by checking whether struct sockaddr_hci has
an hci_channel member and, if it does, set it to HCI_CHANNEL_RAW.

config.h.in
configure
configure.in
pcap-bt-linux.c

index 05a1c9806b887d3731ae288b369cf5eb5f09bfcb..06dbf8200c9962b86e651b7f3b2d1e4ad69b9c19 100644 (file)
 /* include ACN support */
 #undef SITA
 
+/* if struct sockaddr_hci has hci_channel member */
+#undef SOCKADDR_HCI_HAS_HCI_CHANNEL
+
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
index 88577c4e91eea09afac75acf40d844259c44760d..f7291760c2e28e587ab359a80d04616d2e05d654 100755 (executable)
--- a/configure
+++ b/configure
@@ -11489,6 +11489,71 @@ _ACEOF
                  { echo "$as_me:$LINENO: Bluetooth sniffing is supported" >&5
 echo "$as_me: Bluetooth sniffing is supported" >&6;}
 
+                 #
+                 # OK, does struct sockaddr_hci have an hci_channel
+                 # member?
+                 #
+                 { echo "$as_me:$LINENO: checking if struct sockaddr_hci has hci_channel member" >&5
+echo $ECHO_N "checking if struct sockaddr_hci has hci_channel member... $ECHO_C" >&6; }
+                 if test "${ac_cv_lbl_sockaddr_hci_has_hci_channel+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+
+int
+main ()
+{
+u_int i = sizeof(((struct sockaddr_hci *)0)->hci_channel)
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_lbl_sockaddr_hci_has_hci_channel=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_cv_lbl_sockaddr_hci_has_hci_channel=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+
+                   { echo "$as_me:$LINENO: result: $ac_cv_lbl_sockaddr_hci_has_hci_channel" >&5
+echo "${ECHO_T}$ac_cv_lbl_sockaddr_hci_has_hci_channel" >&6; }
+                   if test $ac_cv_lbl_sockaddr_hci_has_hci_channel = yes ; then
+
+cat >>confdefs.h <<\_ACEOF
+#define SOCKADDR_HCI_HAS_HCI_CHANNEL
+_ACEOF
+
+                   fi
+
 else
   { echo "$as_me:$LINENO: Bluetooth sniffing is not supported; install bluez-lib devel to enable it" >&5
 echo "$as_me: Bluetooth sniffing is not supported; install bluez-lib devel to enable it" >&6;}
index bd478413fe5611423733487ba0c21062f0d4e0d5..b3a10abc488f05ee6afec94993379372725676d3 100644 (file)
@@ -1413,6 +1413,26 @@ if test "x$enable_bluetooth" != "xno" ; then
                  AC_DEFINE(PCAP_SUPPORT_BT, 1, [target host supports Bluetooth sniffing])
                  BT_SRC=pcap-bt-linux.c
                  AC_MSG_NOTICE(Bluetooth sniffing is supported)
+
+                 #
+                 # OK, does struct sockaddr_hci have an hci_channel
+                 # member?
+                 #
+                 AC_MSG_CHECKING(if struct sockaddr_hci has hci_channel member)
+                 AC_CACHE_VAL(ac_cv_lbl_sockaddr_hci_has_hci_channel,
+                   AC_TRY_COMPILE(
+[
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+],
+                     [u_int i = sizeof(((struct sockaddr_hci *)0)->hci_channel)],
+                     ac_cv_lbl_sockaddr_hci_has_hci_channel=yes,
+                     ac_cv_lbl_sockaddr_hci_has_hci_channel=no))
+                   AC_MSG_RESULT($ac_cv_lbl_sockaddr_hci_has_hci_channel)
+                   if test $ac_cv_lbl_sockaddr_hci_has_hci_channel = yes ; then
+                     AC_DEFINE(SOCKADDR_HCI_HAS_HCI_CHANNEL,,
+                       [if struct sockaddr_hci has hci_channel member])
+                   fi
                ],
                AC_MSG_NOTICE(Bluetooth sniffing is not supported; install bluez-lib devel to enable it)
                )
index c951a7e2d70e660684caa3d1447cc081fa9ce775..d4d7bb58a4bcc8eaa46c7467f9381bf54f5d7f48 100644 (file)
@@ -254,6 +254,9 @@ bt_activate(pcap_t* handle)
        /* Bind socket to the HCI device */
        addr.hci_family = AF_BLUETOOTH;
        addr.hci_dev = handle->md.ifindex;
+#ifdef SOCKADDR_HCI_HAS_HCI_CHANNEL
+       addr.hci_channel = HCI_CHANNEL_RAW;
+#endif
        if (bind(handle->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
                snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
                    "Can't attach to device %d: %s", handle->md.ifindex,