ongrep

A cleaned up fork of ngrep for OpenBSD
git clone git://git.sgregoratto.me/ongrep
Log | Files | Refs | README | LICENSE

commit cfeb2eb46b2a0bfae96096a9f986eb3d72ad561b
parent ce64df46ddbc4d059b7c59a958f4a65da543b303
Author: Jordan Ritter <jpr5@darkridge.com>
Date:   Wed,  6 Sep 2017 14:28:23 -0700

Add support for Solaris IPnet

Credit to @sjthomason for #8 , which turned out to be a combination of
IPnet support as well as a solution for a nasty VLAN header frame
calculation bug.  Many thanks!

Diffstat:
Mconfig.h.in | 1+
Mconfigure | 43++++++++++++++++++++++++++++++++++++++++++-
Mconfigure.in | 13+++++++++++++
Mngrep.c | 7+++++++
Mngrep.h | 1+
5 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/config.h.in b/config.h.in @@ -15,6 +15,7 @@ #define HAVE_DLT_LINUX_SLL @HAVE_DLT_LINUX_SLL@ #define HAVE_DLT_IEEE802_11 @HAVE_DLT_IEEE802_11@ #define HAVE_DLT_IEEE802_11_RADIO @HAVE_DLT_IEEE802_11_RADIO@ +#define HAVE_DLT_IPNET @HAVE_DLT_IPNET@ #define USE_PCAP_RESTART @USE_PCAP_RESTART@ #if USE_PCAP_RESTART diff --git a/configure b/configure @@ -637,6 +637,7 @@ infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -714,6 +715,7 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE}' @@ -966,6 +968,15 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1103,7 +1114,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1256,6 +1267,7 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -3999,6 +4011,30 @@ rm -f conftest* +present="" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DLT_IPNET in $BPF" >&5 +$as_echo_n "checking for DLT_IPNET in $BPF... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include <$BPF> +#ifdef DLT_IPNET +yes +#endif + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "yes" >/dev/null 2>&1; then : + HAVE_DLT_IPNET="1" && { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + HAVE_DLT_IPNET="0" && { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +rm -f conftest* + + + cat >>confdefs.h <<_ACEOF @@ -4069,6 +4105,11 @@ cat >>confdefs.h <<_ACEOF _ACEOF +cat >>confdefs.h <<_ACEOF +#define HAVE_DLT_IPNET $HAVE_DLT_IPNET +_ACEOF + + diff --git a/configure.in b/configure.in @@ -432,6 +432,18 @@ yes [HAVE_DLT_PFLOG="1" && AC_MSG_RESULT(yes)], [HAVE_DLT_PFLOG="0" && AC_MSG_RESULT(no)]) +present="" +AC_MSG_CHECKING(for DLT_IPNET in $BPF) +AC_EGREP_CPP(yes, +[ +#include <$BPF> +#ifdef DLT_IPNET +yes +#endif +], +[HAVE_DLT_IPNET="1" && AC_MSG_RESULT(yes)], [HAVE_DLT_IPNET="0" && AC_MSG_RESULT(no)]) + + dnl dnl Now that we're past the OS-specific stuff, which could have dnl modified our USE_* and other defines, define them all now. @@ -453,6 +465,7 @@ AC_DEFINE_UNQUOTED(HAVE_DLT_IEEE802_11, $HAVE_DLT_IEEE802_11, [prese AC_DEFINE_UNQUOTED(HAVE_DLT_IEEE802_11_RADIO, $HAVE_DLT_IEEE802_11_RADIO, [presence of DLT_IEEE802_11_RADIO in bpf.h]) AC_DEFINE_UNQUOTED(HAVE_DLT_LOOP, $HAVE_DLT_LOOP, [presence of DLT_LOOP in bpf.h]) AC_DEFINE_UNQUOTED(HAVE_DLT_LINUX_SLL, $HAVE_DLT_LINUX_SLL, [presence of DLT_LINUX_SLL in bpf.h]) +AC_DEFINE_UNQUOTED(HAVE_DLT_IPNET, $HAVE_DLT_IPNET, [presence of DLT_IPNET in bpf.h]) dnl dnl Merge our global tack-ons with autoconf's. diff --git a/ngrep.c b/ngrep.c @@ -471,6 +471,13 @@ int main(int argc, char **argv) { break; #endif +#if HAVE_DLT_IPNET + case DLT_IPNET: + link_offset = IPNETHDR_SIZE; + include_vlan = 0; + break; +#endif + default: fprintf(stderr, "fatal: unsupported interface type %u\n", pcap_datalink(pd)); clean_exit(-1); diff --git a/ngrep.h b/ngrep.h @@ -23,6 +23,7 @@ #define IEEE80211HDR_SIZE 32 #define PFLOGHDR_SIZE 48 #define VLANHDR_SIZE 4 +#define IPNETHDR_SIZE 24 #ifndef ETHERTYPE_IP #define ETHERTYPE_IP 0x0800