From 8dcc879ca0cb590e6840daf87231428ba36687b9 Mon Sep 17 00:00:00 2001 From: Hamish Coleman Date: Sat, 1 Jul 2023 13:39:02 +0100 Subject: [PATCH] Simplify config and build process for libpcap tool --- Makefile | 1 - config.mak.in | 1 - configure.ac | 15 +-------------- scripts/hack_fakeautoconf.sh | 4 ---- tools/Makefile | 7 ++----- tools/n2n-decode.c | 15 +++++++++++++++ 6 files changed, 18 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index efa9fc4..fb64d4d 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,6 @@ export AR export CFLAGS export LDFLAGS export LDLIBS -export TOOLS_ADDITIONAL -include config.mak diff --git a/config.mak.in b/config.mak.in index 92b833c..7db29d2 100644 --- a/config.mak.in +++ b/config.mak.in @@ -9,4 +9,3 @@ WINDRES=@WINDRES@ CFLAGS=@CFLAGS@ LDFLAGS=@LDFLAGS@ LDLIBS_EXTRA=@LIBS@ -TOOLS_ADDITIONAL=@TOOLS_ADDITIONAL@ diff --git a/configure.ac b/configure.ac index 8b1bae8..354eebe 100644 --- a/configure.ac +++ b/configure.ac @@ -66,19 +66,7 @@ AC_ARG_ENABLE([pcap], [AS_HELP_STRING([--enable-pcap], [support for pcap])], [], [enable_pcap=no]) AS_IF([test "x$enable_pcap" != xno], - [AC_CHECK_LIB([pcap], [pcap_open_live], - [ - AC_DEFINE([N2N_HAVE_PCAP], [1], [Have PCAP library]) - LIBS="-lpcap ${LIBS}" - TOOLS_ADDITIONAL="$TOOLS_ADDITIONAL n2n-decode" - - # TODO - # - pcap_set_immediate_mode has been available since libpcap 1.5 - # in 2013 - probably should remove this check - AC_CHECK_LIB([pcap], [pcap_set_immediate_mode], - AC_DEFINE([HAVE_PCAP_IMMEDIATE_MODE], [1], [Have pcap_immediate_mode]) - ) - ], + [AC_CHECK_LIB([pcap], [pcap_set_immediate_mode],, [AC_MSG_ERROR([pcap library not found])] )], ) @@ -104,7 +92,6 @@ AS_IF([test "x$enable_pthread" != xno], AC_SUBST(host) AC_SUBST(WINDRES) -AC_SUBST(TOOLS_ADDITIONAL) AC_CONFIG_HEADERS(include/config.h) AC_CONFIG_FILES(config.mak) diff --git a/scripts/hack_fakeautoconf.sh b/scripts/hack_fakeautoconf.sh index 3744a22..414c0c9 100755 --- a/scripts/hack_fakeautoconf.sh +++ b/scripts/hack_fakeautoconf.sh @@ -26,10 +26,6 @@ LDFLAGS=$LDFLAGS LDLIBS_EXTRA=$LDLIBS EOF -cat >tools/config.mak <include/config.h #define PACKAGE_VERSION "FIXME" #define PACKAGE_BUILDDATE "$(date)" diff --git a/tools/Makefile b/tools/Makefile index 8a49cdd..1de221c 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -15,8 +15,7 @@ LDFLAGS+=-L.. N2N_LIB=../libn2n.a -TOOLS=n2n-benchmark n2n-keygen n2n-route n2n-portfwd -TOOLS+=$(TOOLS_ADDITIONAL) +TOOLS=n2n-benchmark n2n-keygen n2n-route n2n-portfwd n2n-decode TESTS=tests-compress tests-elliptic tests-hashing tests-transform TESTS+=tests-wire @@ -29,9 +28,7 @@ n2n-benchmark.o: $(N2N_LIB) $(HEADERS) ../config.mak n2n-keygen.o: $(N2N_LIB) $(HEADERS) ../config.mak n2n-route.o: $(N2N_LIB) $(HEADERS) ../config.mak n2n-portfwd.o: $(N2N_LIB) $(HEADERS) ../config.mak - -n2n-decode: n2n-decode.c $(N2N_LIB) $(HEADERS) ../config.mak - $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDLIBS) -lpcap -o $@ +n2n-decode.o: $(N2N_LIB) $(HEADERS) ../config.mak # See comments in the topdir Makefile about how to generate coverage # data. diff --git a/tools/n2n-decode.c b/tools/n2n-decode.c index c11211c..a8c17dc 100644 --- a/tools/n2n-decode.c +++ b/tools/n2n-decode.c @@ -16,6 +16,10 @@ * */ +#include "config.h" + +#ifdef HAVE_LIBPCAP + #include // for errno #include #include // for signal, SIGINT, SIGTERM @@ -372,3 +376,14 @@ int main(int argc, char* argv[]) { return(rv); } + +#else + +#include + +int main() { + printf("n2n was compiled without libpcap support"); + return -1; +} + +#endif /* HAVE_LIBPCAP */