Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
On Linux, handle all CAN captures with pcap-linux.c, in cooked mode.
There's no need to support capturing on PF_CAN sockets; CAN interfaces
show up as regular interfaces on which you can capture with PF_PACKET
sockets, so just let pcap-linux.c handle them, and get rid of
pcap-can-linux.c.

Capture on them in cooked mode, so we get the protocol field and can
distinguish between "classic" CAN and CAN FD.

The hardware for which pcap-canusb-linux.c was intended never reached
production:

    axos88/libpcap@f3edbb5#commitcomment-18716617

so we don't need pcap-canusb-linux.c, either.

This all removes the need for the "host-endian" link-layer header type;
it never made it into a libpcap release, so we just remove it.  The
"big-endian" link-layer header type is kept for the benefit of packets
captured with the old pcap-can-linux.c code; we revert it to its old
name.
  • Loading branch information
guyharris committed Aug 25, 2016
1 parent 4c9aed0 commit 93ca5ff
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 1,243 deletions.
6 changes: 1 addition & 5 deletions Makefile.in
Expand Up @@ -79,7 +79,7 @@ YACC = @YACC@
@rm -f $@
$(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c

PSRC = pcap-@V_PCAP@.c @USB_SRC@ @BT_SRC@ @BT_MONITOR_SRC@ @CAN_SRC@ @NETFILTER_SRC@ @CANUSB_SRC@ @DBUS_SRC@
PSRC = pcap-@V_PCAP@.c @USB_SRC@ @BT_SRC@ @BT_MONITOR_SRC@ @NETFILTER_SRC@ @DBUS_SRC@
FSRC = @V_FINDALLDEVS@
SSRC = @SSRC@
CSRC = pcap.c inet.c fad-helpers.c gencode.c optimize.c nametoaddr.c \
Expand Down Expand Up @@ -307,10 +307,6 @@ EXTRA_DIST = \
pcap-bt-linux.h \
pcap-bt-monitor-linux.c \
pcap-bt-monitor-linux.h \
pcap-can-linux.c \
pcap-can-linux.h \
pcap-canusb-linux.c \
pcap-canusb-linux.h \
pcap-config.in \
pcap-dag.c \
pcap-dag.h \
Expand Down
6 changes: 0 additions & 6 deletions cmakeconfig.h.in
Expand Up @@ -265,12 +265,6 @@
/* target host supports Bluetooth Monitor */
#cmakedefine PCAP_SUPPORT_BT_MONITOR 1

/* target host supports CAN sniffing */
#cmakedefine PCAP_SUPPORT_CAN 1

/* target host supports canusb */
#cmakedefine PCAP_SUPPORT_CANUSB 1

/* support D-Bus sniffing */
#cmakedefine PCAP_SUPPORT_DBUS 1

Expand Down
6 changes: 0 additions & 6 deletions config.h.in
Expand Up @@ -265,12 +265,6 @@
/* target host supports Bluetooth Monitor */
#undef PCAP_SUPPORT_BT_MONITOR

/* target host supports CAN sniffing */
#undef PCAP_SUPPORT_CAN

/* target host supports canusb */
#undef PCAP_SUPPORT_CANUSB

/* support D-Bus sniffing */
#undef PCAP_SUPPORT_DBUS

Expand Down
167 changes: 0 additions & 167 deletions configure
Expand Up @@ -627,10 +627,6 @@ PCAP_SUPPORT_PACKET_RING
DBUS_SRC
PCAP_SUPPORT_DBUS
PKGCONFIG
CAN_SRC
PCAP_SUPPORT_CAN
CANUSB_SRC
PCAP_SUPPORT_CANUSB
BT_MONITOR_SRC
BT_SRC
PCAP_SUPPORT_BT
Expand Down Expand Up @@ -753,8 +749,6 @@ enable_universal
enable_shared
enable_usb
enable_bluetooth
enable_canusb
enable_can
enable_dbus
enable_packet_ring
'
Expand Down Expand Up @@ -1394,10 +1388,6 @@ Optional Features:
available]
--enable-bluetooth enable Bluetooth support [default=yes, if support
available]
--enable-canusb enable canusb support [default=yes, if support
available]
--enable-can enable CAN support [default=yes, if support
available]
--enable-dbus enable D-Bus capture support [default=yes, if
support available]
--enable-packet-ring enable Linux packet ring support [default=yes]
Expand Down Expand Up @@ -8762,163 +8752,6 @@ $as_echo "$as_me: no Bluetooth sniffing support implemented for $host_os" >&6;}



fi

# Check whether --enable-canusb was given.
if test "${enable_canusb+set}" = set; then :
enableval=$enable_canusb;
else
enable_canusb=ifsupportavailable
fi


if test "xxx_only" = yes; then
# User requested something-else-only pcap, so they don't
# want canusb support.
enable_canusb=no
fi

if test "x$enable_canusb" != "xno" ; then
case "$host_os" in
linux*|uclinux*)
ac_fn_c_check_header_mongrel "$LINENO" "libusb-1.0/libusb.h" "ac_cv_header_libusb_1_0_libusb_h" "$ac_includes_default"
if test "x$ac_cv_header_libusb_1_0_libusb_h" = xyes; then :

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libusb_init in -lusb-1.0" >&5
$as_echo_n "checking for libusb_init in -lusb-1.0... " >&6; }
if ${ac_cv_lib_usb_1_0_libusb_init+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lusb-1.0 -lpthread
$LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char libusb_init ();
int
main ()
{
return libusb_init ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_usb_1_0_libusb_init=yes
else
ac_cv_lib_usb_1_0_libusb_init=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_usb_1_0_libusb_init" >&5
$as_echo "$ac_cv_lib_usb_1_0_libusb_init" >&6; }
if test "x$ac_cv_lib_usb_1_0_libusb_init" = xyes; then :


$as_echo "#define PCAP_SUPPORT_CANUSB 1" >>confdefs.h

CANUSB_SRC=pcap-canusb-linux.c
LIBS="-lusb-1.0 -lpthread $LIBS"
ac_lbl_has_libusb=yes

else
ac_lbl_has_libusb=no
fi


else
ac_lbl_has_libusb=no

fi


if test "x$ac_lbl_has_libusb" = "xyes" ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: canusb sniffing is supported" >&5
$as_echo "$as_me: canusb sniffing is supported" >&6;}
else
if test "x$enable_canusb" = "xyes" ; then
as_fn_error $? "canusb sniffing is not supported; install libusb1.0 lib devel to enable it" "$LINENO" 5
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: canusb sniffing is not supported; install libusb1.0 lib devel to enable it" >&5
$as_echo "$as_me: canusb sniffing is not supported; install libusb1.0 lib devel to enable it" >&6;}
fi
fi
;;
*)
if test "x$enable_canusb" = "xyes" ; then
as_fn_error $? "no canusb support implemented for $host_os" "$LINENO" 5
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: no canusb support implemented for $host_os" >&5
$as_echo "$as_me: no canusb support implemented for $host_os" >&6;}
fi
;;
esac


fi

# Check whether --enable-can was given.
if test "${enable_can+set}" = set; then :
enableval=$enable_can;
else
enable_can=ifsupportavailable
fi


if test "xxx_only" = yes; then
# User requested something-else-only pcap, so they don't
# want CAN support.
enable_can=no
fi

if test "x$enable_can" != "xno" ; then
case "$host_os" in
linux*)
ac_fn_c_check_header_compile "$LINENO" "linux/can.h" "ac_cv_header_linux_can_h" "#include <sys/socket.h>
"
if test "x$ac_cv_header_linux_can_h" = xyes; then :


$as_echo "#define PCAP_SUPPORT_CAN 1" >>confdefs.h

CAN_SRC=pcap-can-linux.c
{ $as_echo "$as_me:${as_lineno-$LINENO}: CAN sniffing is supported" >&5
$as_echo "$as_me: CAN sniffing is supported" >&6;}

else

if test "x$enable_can" = "xyes" ; then
as_fn_error $? "CAN sniffing is not supported" "$LINENO" 5
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: CAN sniffing is not supported" >&5
$as_echo "$as_me: CAN sniffing is not supported" >&6;}
fi

fi


;;
*)
if test "x$enable_can" = "xyes" ; then
as_fn_error $? "no CAN sniffing support implemented for $host_os" "$LINENO" 5
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: no CAN sniffing support implemented for $host_os" >&5
$as_echo "$as_me: no CAN sniffing support implemented for $host_os" >&6;}
fi
;;
esac


fi

# Check whether --enable-dbus was given.
Expand Down
95 changes: 0 additions & 95 deletions configure.in
Expand Up @@ -1685,101 +1685,6 @@ if test "x$enable_bluetooth" != "xno" ; then
AC_SUBST(BT_MONITOR_SRC)
fi

AC_ARG_ENABLE([canusb],
[AC_HELP_STRING([--enable-canusb],[enable canusb support @<:@default=yes, if support available@:>@])],
[],
[enable_canusb=ifsupportavailable])

if test "xxx_only" = yes; then
# User requested something-else-only pcap, so they don't
# want canusb support.
enable_canusb=no
fi

if test "x$enable_canusb" != "xno" ; then
dnl check for canusb support
case "$host_os" in
linux*|uclinux*)
AC_CHECK_HEADER(libusb-1.0/libusb.h,
[
AC_CHECK_LIB(usb-1.0, libusb_init,
[
AC_DEFINE(PCAP_SUPPORT_CANUSB, 1, [target host supports canusb])
CANUSB_SRC=pcap-canusb-linux.c
LIBS="-lusb-1.0 -lpthread $LIBS"
ac_lbl_has_libusb=yes
],
ac_lbl_has_libusb=no,
-lpthread
)
],
ac_lbl_has_libusb=no
)
if test "x$ac_lbl_has_libusb" = "xyes" ; then
AC_MSG_NOTICE(canusb sniffing is supported)
else
if test "x$enable_canusb" = "xyes" ; then
AC_MSG_ERROR(canusb sniffing is not supported; install libusb1.0 lib devel to enable it)
else
AC_MSG_NOTICE(canusb sniffing is not supported; install libusb1.0 lib devel to enable it)
fi
fi
;;
*)
if test "x$enable_canusb" = "xyes" ; then
AC_MSG_ERROR(no canusb support implemented for $host_os)
else
AC_MSG_NOTICE(no canusb support implemented for $host_os)
fi
;;
esac
AC_SUBST(PCAP_SUPPORT_CANUSB)
AC_SUBST(CANUSB_SRC)
fi

AC_ARG_ENABLE([can],
[AC_HELP_STRING([--enable-can],[enable CAN support @<:@default=yes, if support available@:>@])],
[],
[enable_can=ifsupportavailable])

if test "xxx_only" = yes; then
# User requested something-else-only pcap, so they don't
# want CAN support.
enable_can=no
fi

if test "x$enable_can" != "xno" ; then
dnl check for CAN sniffing support
case "$host_os" in
linux*)
AC_CHECK_HEADER(linux/can.h,
[
AC_DEFINE(PCAP_SUPPORT_CAN, 1, [target host supports CAN sniffing])
CAN_SRC=pcap-can-linux.c
AC_MSG_NOTICE(CAN sniffing is supported)
],
[
if test "x$enable_can" = "xyes" ; then
AC_MSG_ERROR(CAN sniffing is not supported)
else
AC_MSG_NOTICE(CAN sniffing is not supported)
fi
],
[#include <sys/socket.h>]
)
;;
*)
if test "x$enable_can" = "xyes" ; then
AC_MSG_ERROR(no CAN sniffing support implemented for $host_os)
else
AC_MSG_NOTICE(no CAN sniffing support implemented for $host_os)
fi
;;
esac
AC_SUBST(PCAP_SUPPORT_CAN)
AC_SUBST(CAN_SRC)
fi

AC_ARG_ENABLE([dbus],
[AC_HELP_STRING([--enable-dbus],[enable D-Bus capture support @<:@default=yes, if support available@:>@])],
[],
Expand Down
3 changes: 1 addition & 2 deletions gencode.c
Expand Up @@ -3397,8 +3397,7 @@ gen_linktype(compiler_state_t *cstate, int proto)
bpf_error(cstate, "Bluetooth link-layer type filtering not implemented");

case DLT_CAN20B:
case DLT_CAN_SOCKETCAN_BIGENDIAN:
case DLT_CAN_SOCKETCAN_HOSTENDIAN:
case DLT_CAN_SOCKETCAN:
bpf_error(cstate, "CAN link-layer type filtering not implemented");

case DLT_IEEE802_15_4:
Expand Down

0 comments on commit 93ca5ff

Please sign in to comment.