Skip to content

Commit

Permalink
Simplify config and build process for libpcap tool
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishcoleman committed Jul 2, 2023
1 parent 433b14c commit 8dcc879
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 25 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export AR
export CFLAGS
export LDFLAGS
export LDLIBS
export TOOLS_ADDITIONAL

-include config.mak

Expand Down
1 change: 0 additions & 1 deletion config.mak.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ WINDRES=@WINDRES@
CFLAGS=@CFLAGS@
LDFLAGS=@LDFLAGS@
LDLIBS_EXTRA=@LIBS@
TOOLS_ADDITIONAL=@TOOLS_ADDITIONAL@
15 changes: 1 addition & 14 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])]
)],
)
Expand All @@ -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)

Expand Down
4 changes: 0 additions & 4 deletions scripts/hack_fakeautoconf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ LDFLAGS=$LDFLAGS
LDLIBS_EXTRA=$LDLIBS
EOF

cat >tools/config.mak <<EOF
TOOLS_ADDITIONAL=
EOF

cat <<EOF >include/config.h
#define PACKAGE_VERSION "FIXME"
#define PACKAGE_BUILDDATE "$(date)"
Expand Down
7 changes: 2 additions & 5 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions tools/n2n-decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*
*/

#include "config.h"

#ifdef HAVE_LIBPCAP

#include <errno.h> // for errno
#include <pcap.h>
#include <signal.h> // for signal, SIGINT, SIGTERM
Expand Down Expand Up @@ -372,3 +376,14 @@ int main(int argc, char* argv[]) {

return(rv);
}

#else

#include <stdio.h>

int main() {
printf("n2n was compiled without libpcap support");
return -1;
}

#endif /* HAVE_LIBPCAP */

0 comments on commit 8dcc879

Please sign in to comment.