Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cope with Bluetooth API breakage in some Linux 3.x(?) kernel.

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.
  • Loading branch information...
commit b6aa2bd0b3975e4349bb56d5c11eca329385510d 1 parent 574199b
@guyharris guyharris authored
Showing with 91 additions and 0 deletions.
  1. +3 −0  config.h.in
  2. +65 −0 configure
  3. +20 −0 configure.in
  4. +3 −0  pcap-bt-linux.c
View
3  config.h.in
@@ -268,6 +268,9 @@
/* 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
View
65 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;}
View
20 configure.in
@@ -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)
)
View
3  pcap-bt-linux.c
@@ -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,
Please sign in to comment.
Something went wrong with that request. Please try again.