"Fossies" - the Fresh Open Source Software Archive

Member "ngrep-1_47/configure.in" (7 Sep 2017, 14259 Bytes) of package /linux/misc/ngrep-1_47.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes reports for "configure.in": 1_45_vs_1_47 or 1_46_1_vs_1_47.

    1 dnl
    2 dnl Copyright (c) 2017  Jordan Ritter <jpr5@darkridge.com>
    3 dnl
    4 dnl Please refer to the LICENSE file for more information.
    5 dnl
    6 dnl NOTE: configure.in requires autoconf 2.57 or more recent.
    7 
    8 AC_INIT(ngrep.c)
    9 
   10 AC_MSG_RESULT
   11 AC_MSG_RESULT(Configuring System ...)
   12 AC_MSG_RESULT
   13 
   14 AC_CANONICAL_SYSTEM
   15 AC_PROG_CC
   16 AC_HEADER_STDC
   17 
   18 AC_PREFIX_DEFAULT(/usr/local)
   19 if test -n "`which tcpdump 2> /dev/null`"; then
   20    AC_PREFIX_PROGRAM(tcpdump)
   21 fi
   22 
   23 EXTRA_DEFINES=""
   24 EXTRA_INCLUDES=""
   25 EXTRA_LDFLAGS=""
   26 EXTRA_OBJS=""
   27 EXTRA_LIBS=""
   28 
   29 dnl
   30 dnl Define the arguments that we accept.  Parse them first.
   31 dnl
   32 
   33 dnl
   34 dnl Allow user to specify alternate ``nobody'' user.
   35 dnl
   36 
   37 AC_ARG_WITH(dropprivs-user,
   38 [  --with-dropprivs-user[=user]     use different user for dropprivs],
   39 [
   40   DROPPRIVS_USER="$withval"
   41 ],
   42 [
   43   DROPPRIVS_USER="nobody"
   44 ])
   45 
   46 dnl
   47 dnl Enable or disable the drop privileges logic.
   48 dnl
   49 
   50 AC_ARG_ENABLE(dropprivs,
   51 [  --disable-dropprivs     disable privilege dropping logic],
   52 [
   53   use_dropprivs="$enableval"
   54 ],
   55 [
   56   use_dropprivs="yes"
   57 ])
   58 
   59 if test $use_dropprivs = yes; then
   60    USE_DROPPRIVS="1"
   61 else
   62    USE_DROPPRIVS="0"
   63 fi
   64 
   65 dnl
   66 dnl IPv6 (and ICMPv6) support
   67 dnl
   68 
   69 AC_ARG_ENABLE(ipv6,
   70 [  --enable-ipv6           enable IPv6 (and ICMPv6) support],
   71 [
   72   use_ipv6="$enableval"
   73 ],
   74 [
   75   use_ipv6="no"
   76 ])
   77 
   78 if test $use_ipv6 = yes; then
   79    USE_IPv6="1"
   80 else
   81    USE_IPv6="0"
   82 fi
   83 
   84 dnl
   85 dnl PCAP BPF filter expression lexer bugfix
   86 dnl
   87 dnl Typically ngrep is invoked with a (optional) search string plus a BPF
   88 dnl filter. However, ngrep doesn't semantically understand BPF filter terms
   89 dnl itself, so it assumes the first non-option parameter is the search string,
   90 dnl and attempts to compile the remainder as the BPF filter expression. If the
   91 dnl compilation fails, it probably means that no search string was specified, so
   92 dnl it restarts the BPF filter expression lexer and attempts to compile the
   93 dnl entire non-option parameter string as the expression. If that fails, then
   94 dnl the specified BPF filter expression is definitely bogus and ngrep errors
   95 dnl out.
   96 dnl
   97 dnl I favored this approach because it made invocation simpler & more fluid. In
   98 dnl order to make it work however, I had to solve for a bug in older versions of
   99 dnl libpcap where the library would segfault if the BPF filter compilation
  100 dnl function was invoked more than once. The workaround turned out to be a
  101 dnl simple invocation of the lexer's restart function in between compilation
  102 dnl invocations, however that function wasn't normally exposed in the header
  103 dnl since it was an internal built-in of whatever grammar lexer libpcap had
  104 dnl compiled with (bison/yacc/etc).
  105 dnl
  106 dnl The default behavior has long been to restart the lexer (keeping invocation
  107 dnl simpler) and provide a compile-time option to disable the mechanism, if
  108 dnl anyone cared to.  Based on a more recent bug report however[1], it seems
  109 dnl that the newer libpcap breaks when the lexer restart function is called.
  110 dnl So, given the choice between old platforms working by default (always call
  111 dnl restart/allow disablement at compile-time) vs. newer platforms working by
  112 dnl default (never call restart/allow enablement at compile-time), the default
  113 dnl behavior now is to do the latter.
  114 dnl
  115 dnl For versions of libpcap that require restart function invocation in between
  116 dnl multiple lexer passes, allow them to enable it here.
  117 dnl
  118 dnl [1] https://github.com/jpr5/ngrep/issues/2
  119 dnl
  120 
  121 AC_ARG_ENABLE(pcap-restart,
  122 [  --enable-pcap-restart   enable BPF lexer restart bugfix for older versions of PCAP (default off)],
  123 [
  124   use_pcap_restart="$enableval"
  125 ],
  126 [
  127   use_pcap_restart="no"
  128 ])
  129 
  130 if test $use_pcap_restart = yes; then
  131     USE_PCAP_RESTART="1"
  132 else
  133     USE_PCAP_RESTART="0"
  134 fi
  135 
  136 
  137 dnl
  138 dnl Configure the regular expression library.
  139 dnl
  140 
  141 REGEX_DIR=''
  142 REGEX_OBJS=''
  143 
  144 AC_ARG_ENABLE(pcre,
  145 [  --enable-pcre           use PCRE instead of GNU regex (default GNU)],
  146 [ use_pcre="$enableval" ],
  147 [ use_pcre="no" ])
  148 
  149 if test use_pcre = yes; then
  150   USE_PCRE="1"
  151   EXTRA_LIBS="$EXTRA_LIBS -lpcre"
  152 else
  153   USE_PCRE="0"
  154 
  155   AC_MSG_RESULT
  156   AC_MSG_RESULT(Configuring GNU Regular Expression library ...)
  157   AC_MSG_RESULT
  158 
  159   REGEX_DIR='regex-0.12'
  160   REGEX_OBJS="$REGEX_DIR/regex.o"
  161 
  162   ( cd $REGEX_DIR && ./configure )
  163 
  164   EXTRA_INCLUDES="$EXTRA_INCLUDES -I$REGEX_DIR"
  165 fi
  166 
  167 AC_SUBST(REGEX_DIR)
  168 AC_SUBST(REGEX_OBJS)
  169 
  170 dnl
  171 dnl tcpkill/libnet support (from Debian patch)
  172 dnl
  173 
  174 AC_ARG_ENABLE(tcpkill,
  175 [  --enable-tcpkill        enable connection killing support (default off)],
  176 [
  177   AC_CHECK_LIB(net, libnet_init_packet,,echo !!! error: tcpkill feature enabled but no libnet found; exit)
  178   use_tcpkill="$enableval"
  179 ],
  180 [ use_tcpkill="no" ])
  181 
  182 if test $use_tcpkill = yes; then
  183   USE_TCPKILL="1"
  184   EXTRA_OBJS="$EXTRA_OBJS tcpkill.o"
  185   EXTRA_DEFINES="$EXTRA_DEFINES $(libnet-config --defines)"
  186   EXTRA_LIBS="$EXTRA_LIBS $(libnet-config --libs)"
  187 else
  188   USE_TCPKILL="0"
  189 fi
  190 
  191 
  192 AC_ARG_ENABLE(vlan-hack,
  193 [  --disable-vlan-hack     disable automatic inclusion of VLAN frames (default on)],
  194 [use_vlan_hack="$enableval"],
  195 [use_vlan_hack="yes"])
  196 
  197 if test $use_vlan_hack = yes; then
  198   USE_VLAN_HACK="1"
  199 else
  200   USE_VLAN_HACK="0"
  201 fi
  202 
  203 
  204 AC_ARG_WITH(pcap-includes,
  205 [  --with-pcap-includes=dir       specify the pcap include directory],
  206 [PCAP_DIR=$withval],
  207 [
  208   PCAP_DIR="`eval echo -n ${includedir}` \
  209             /usr/include /usr/include/pcap \
  210             /usr/local/include /usr/local/include/pcap \
  211             /opt/local/include /opt/local/include/pcap \
  212             /usr/share/include /usr/share/include/pcap"
  213 ])
  214 
  215 
  216 AC_MSG_RESULT
  217 AC_MSG_RESULT(Configuring Network Grep ...)
  218 AC_MSG_RESULT
  219 
  220 dnl
  221 dnl OS-specific options
  222 dnl
  223 
  224 STRIPFLAG="-s"
  225 
  226 case "$target_os" in
  227 
  228 *linux*)
  229     AC_SUBST(OS, LINUX)
  230 
  231     ;;
  232 
  233 *bsd*)
  234     AC_SUBST(OS, BSD)
  235 
  236     ;;
  237 
  238 *solaris*)
  239     AC_SUBST(OS, SOLARIS)
  240 
  241     AC_CHECK_LIB(socket, socket,,
  242                  [AC_MSG_ERROR(no socket in -lsocket)])
  243     AC_CHECK_LIB(nsl, gethostbyname,,
  244                  [AC_MSG_ERROR(no gethostbyname in -lnsl)])
  245 
  246     EXTRA_LIBS="$EXTRA_LIBS -lnsl -lsocket"
  247 
  248     ;;
  249 
  250 *osf*)
  251     AC_SUBST(OS, OSF1)
  252 
  253     EXTRA_DEFINES="$EXTRA_DEFINES -D__STDC__=2"
  254 
  255     ;;
  256 
  257 *hpux11*)
  258     AC_SUBST(OS, BSD)
  259 
  260     ;;
  261 
  262 *aix*)
  263     AC_SUBST(OS, AIX)
  264 
  265     ;;
  266 
  267 *darwin*)
  268     AC_SUBST(OS, MACOSX)
  269 
  270     STRIPFLAG=""
  271 
  272     ;;
  273 
  274 *)
  275     AC_SUBST(OS, UNKNOWN_OS)
  276     AC_MSG_WARN(
  277 Your OS ($target_os) is not supported yet.
  278 Try playing with the build host and target options.
  279 )
  280     sleep 3
  281 
  282     ;;
  283 
  284 esac
  285 
  286 AC_SUBST(STRIPFLAG)
  287 
  288 EXTRA_DEFINES="$EXTRA_DEFINES -D_BSD_SOURCE=1 -D__FAVOR_BSD=1"
  289 
  290 dnl
  291 dnl Quick Background:
  292 dnl
  293 dnl A long time ago, the libpcap team decided to change the functionality split
  294 dnl and installation location of their header files.  Consequently, installing
  295 dnl the prior version's headers, followed by the newer version's, would result
  296 dnl in two sets of different but similarly-named headers.  This broke a lot of
  297 dnl packages, since most developers just included <pcap.h> in their programs.
  298 dnl Many (including ngrep) addressed the problem by detecting this condition and
  299 dnl alerting the user to fix it manually.  Eventually the libpcap team decided
  300 dnl to add back in the top-level pcap.h, presumably to rectify the hassle.
  301 dnl
  302 dnl On modern Linux distros, checking for this condition likely doesn't matter
  303 dnl anymore.  However, ngrep targets a much broader range of (older) OSes, so
  304 dnl it's still a possibility.  The re-addition of a top-level pcap.h confounds
  305 dnl the old header presence check, so I've updated it to search for the version,
  306 dnl PCAP_VERSION_MAJOR.  Maybe I'll delete it in another 5 years.  ;-)
  307 dnl
  308 
  309 AC_MSG_CHECKING(for a complete set of pcap headers)
  310 
  311 pcap_base=""
  312 for dir in $PCAP_DIR ; do
  313     if test -d $dir -a -r "$dir/pcap.h"; then
  314 
  315        AC_EGREP_HEADER([PCAP_VERSION_MAJOR], [$dir/pcap.h], [found=$dir], [found=""])
  316 
  317        if test -n "$found" -a "$found" != "$pcap_base"; then
  318           AC_MSG_RESULT
  319           AC_MSG_RESULT
  320           AC_MSG_RESULT(more than one set found in:)
  321           AC_MSG_RESULT(  $pcap_base)
  322           AC_MSG_RESULT(  $found)
  323           AC_MSG_RESULT
  324           AC_MSG_ERROR(please wipe out all unused pcap installations)
  325        else
  326           pcap_base="$dir"
  327        fi
  328 
  329     fi
  330 done
  331 
  332 if test -z "$pcap_base" ; then
  333    AC_MSG_RESULT(no)
  334    AC_MSG_ERROR(could not find a complete set of pcap headers)
  335 else
  336    AC_MSG_RESULT(found $pcap_base)
  337 
  338    EXTRA_INCLUDES="$EXTRA_INCLUDES -I$pcap_base"
  339 
  340    dnl Best-effort; newer ld warns on missing dirs.
  341    DIR="`dirname $pcap_base`/lib"
  342    if test -d $DIR; then
  343        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$DIR"
  344    fi
  345 fi
  346 
  347 
  348 dnl
  349 dnl Check for a working PCAP library we can link against..
  350 dnl
  351 
  352 AC_CHECK_LIB(pcap, pcap_open_live,,[AC_MSG_ERROR(a viable pcap lib is required)])
  353 
  354 dnl
  355 dnl And the PCAP restart function.
  356 dnl
  357 
  358 if test "$USE_PCAP_RESTART" = "1"; then
  359     PCAP_RESTART_FUNC="unused"
  360 
  361     for func in pcap_restart pcap_yyrestart yyrestart; do
  362         AC_CHECK_LIB(pcap, $func, found="$func")
  363         if test -n "$found"; then
  364             USE_PCAP_RESTART="1"
  365             PCAP_RESTART_FUNC="$found"
  366             break
  367         fi
  368     done
  369 
  370     if test "$PCAP_RESTART_FUNC" = "unused"; then
  371         AC_MSG_ERROR(BPF lexer restart fix requested, but no restart function found)
  372     fi
  373 fi
  374 
  375 
  376 dnl
  377 dnl Next figure out which bpf header file to look at.
  378 dnl
  379 
  380 AC_MSG_CHECKING(for BPF include path)
  381 BPF=`/usr/bin/perl -ne '/include\s+<(.*bpf\.h)>/ && print "$1\n"' $pcap_base/pcap.h`
  382 AC_MSG_RESULT($BPF)
  383 
  384 dnl
  385 dnl Check for DLT_* types that might not have existed in older
  386 dnl libpcap's
  387 dnl
  388 
  389 present=""
  390 AC_MSG_CHECKING(for DLT_LINUX_SLL in $BPF)
  391 AC_EGREP_CPP(yes,
  392 [
  393 #include <$BPF>
  394 #ifdef DLT_LINUX_SLL
  395 yes
  396 #endif
  397 ],
  398 [HAVE_DLT_LINUX_SLL="1" && AC_MSG_RESULT(yes)], [HAVE_DLT_LINUX_SLL="0" && AC_MSG_RESULT(no)])
  399 
  400 present=""
  401 AC_MSG_CHECKING(for DLT_LOOP in $BPF)
  402 AC_EGREP_CPP(yes,
  403 [
  404 #include <$BPF>
  405 #ifdef DLT_LOOP
  406 yes
  407 #endif
  408 ],
  409 [HAVE_DLT_LOOP="1" && AC_MSG_RESULT(yes)], [HAVE_DLT_LOOP="0" && AC_MSG_RESULT(no)])
  410 
  411 present=""
  412 AC_MSG_CHECKING(for DLT_IEEE802_11 in $BPF)
  413 AC_EGREP_CPP(yes,
  414 [
  415 #include <$BPF>
  416 #ifdef DLT_IEEE802_11
  417 yes
  418 #endif
  419 ],
  420 [HAVE_DLT_IEEE802_11="1" && AC_MSG_RESULT(yes)], [HAVE_DLT_IEEE802_11="0" && AC_MSG_RESULT(no)])
  421 
  422 
  423 present=""
  424 AC_MSG_CHECKING(for DLT_IEEE802_11_RADIO in $BPF)
  425 AC_EGREP_CPP(yes,
  426 [
  427 #include <$BPF>
  428 #ifdef DLT_IEEE802_11_RADIO
  429 yes
  430 #endif
  431 ],
  432 [HAVE_DLT_IEEE802_11_RADIO="1" && AC_MSG_RESULT(yes)], [HAVE_DLT_IEEE802_11_RADIO="0" && AC_MSG_RESULT(no)])
  433 
  434 
  435 present=""
  436 AC_MSG_CHECKING(for DLT_RAW in $BPF)
  437 AC_EGREP_CPP(yes,
  438 [
  439 #include <$BPF>
  440 #ifdef DLT_RAW
  441 yes
  442 #endif
  443 ],
  444 [HAVE_DLT_RAW="1" && AC_MSG_RESULT(yes)], [HAVE_DLT_RAW="0" && AC_MSG_RESULT(no)])
  445 
  446 
  447 present=""
  448 AC_MSG_CHECKING(for DLT_PFLOG in $BPF)
  449 AC_EGREP_CPP(yes,
  450 [
  451 #include <$BPF>
  452 #ifdef DLT_PFLOG
  453 yes
  454 #endif
  455 ],
  456 [HAVE_DLT_PFLOG="1" && AC_MSG_RESULT(yes)], [HAVE_DLT_PFLOG="0" && AC_MSG_RESULT(no)])
  457 
  458 
  459 present=""
  460 AC_MSG_CHECKING(for DLT_IPNET in $BPF)
  461 AC_EGREP_CPP(yes,
  462 [
  463 #include <$BPF>
  464 #ifdef DLT_IPNET
  465 yes
  466 #endif
  467 ],
  468 [HAVE_DLT_IPNET="1" && AC_MSG_RESULT(yes)], [HAVE_DLT_IPNET="0" && AC_MSG_RESULT(no)])
  469 
  470 
  471 dnl
  472 dnl Now that we're past the OS-specific stuff, which could have
  473 dnl modified our USE_* and other defines, define them all now.
  474 dnl
  475 
  476 AC_DEFINE_UNQUOTED(USE_PCAP_RESTART,          $USE_PCAP_RESTART,          [whether to call the BPF lexer restart function between multiple BPF filter compilation attempts (default no)])
  477 AC_DEFINE_UNQUOTED(PCAP_RESTART_FUNC,         $PCAP_RESTART_FUNC,         [routine used for restarting the BPF lexer])
  478 
  479 AC_DEFINE_UNQUOTED(USE_PCRE,                  $USE_PCRE,                  [whether to use PCRE (default GNU Regex)])
  480 AC_DEFINE_UNQUOTED(USE_IPv6,                  $USE_IPv6,                  [whether to use IPv6 (default off)])
  481 AC_DEFINE_UNQUOTED(USE_TCPKILL,               $USE_TCPKILL,               [whether to enable tcpkill functionality (default off)])
  482 AC_DEFINE_UNQUOTED(USE_VLAN_HACK,             $USE_VLAN_HACK,             [whether to automatically include VLAN frames (default on)])
  483 
  484 AC_DEFINE_UNQUOTED(USE_DROPPRIVS,             $USE_DROPPRIVS,             [whether to use privileges dropping (default yes)])
  485 AC_DEFINE_UNQUOTED(DROPPRIVS_USER,           "$DROPPRIVS_USER",           [pseudo-user for running ngrep (default "nobody")])
  486 
  487 AC_DEFINE_UNQUOTED(HAVE_DLT_RAW,              $HAVE_DLT_RAW,              [presence of DLT_RAW in bpf.h])
  488 AC_DEFINE_UNQUOTED(HAVE_DLT_PFLOG,            $HAVE_DLT_PFLOG,            [presence of DLT_PFLOG in $BPF])
  489 AC_DEFINE_UNQUOTED(HAVE_DLT_IEEE802_11,       $HAVE_DLT_IEEE802_11,       [presence of DLT_IEEE802_11 in bpf.h])
  490 AC_DEFINE_UNQUOTED(HAVE_DLT_IEEE802_11_RADIO, $HAVE_DLT_IEEE802_11_RADIO, [presence of DLT_IEEE802_11_RADIO in bpf.h])
  491 AC_DEFINE_UNQUOTED(HAVE_DLT_LOOP,             $HAVE_DLT_LOOP,             [presence of DLT_LOOP in bpf.h])
  492 AC_DEFINE_UNQUOTED(HAVE_DLT_LINUX_SLL,        $HAVE_DLT_LINUX_SLL,        [presence of DLT_LINUX_SLL in bpf.h])
  493 AC_DEFINE_UNQUOTED(HAVE_DLT_IPNET,            $HAVE_DLT_IPNET,            [presence of DLT_IPNET in bpf.h])
  494 
  495 dnl
  496 dnl Merge our global tack-ons with autoconf's.
  497 dnl
  498 
  499 AC_SUBST(EXTRA_DEFINES)
  500 AC_SUBST(EXTRA_INCLUDES)
  501 AC_SUBST(EXTRA_LDFLAGS)
  502 AC_SUBST(EXTRA_OBJS)
  503 AC_SUBST(EXTRA_LIBS)
  504 
  505 dnl
  506 dnl Emit configuration messages about any flags specified.
  507 dnl
  508 
  509 AC_MSG_RESULT
  510 
  511 if test "$USE_PCAP_RESTART" = "1"; then
  512     AC_MSG_RESULT([CONFIG: BPF filter lexer restart enabled (using $PCAP_RESTART_FUNC)])
  513 fi
  514 
  515 if test "$USE_IPv6" = "1"; then
  516     AC_MSG_RESULT(CONFIG: IPv6 support enabled)
  517 else
  518     AC_MSG_RESULT(CONFIG: IPv6 support disabled)
  519 fi
  520 
  521 if test "$USE_DROPPRIVS" = "1"; then
  522     AC_MSG_RESULT([CONFIG: privilege dropping enabled (using $DROPPRIVS_USER)])
  523 else
  524     AC_MSG_RESULT(CONFIG: privilege dropping DISABLED)
  525 fi
  526 
  527 if test "$USE_PCRE" = "1"; then
  528     AC_MSG_RESULT(CONFIG: using PCRE regex library)
  529 else
  530     AC_MSG_RESULT(CONFIG: using GNU regex library)
  531 fi
  532 
  533 if test "$USE_TCPKILL" = "1"; then
  534     AC_MSG_RESULT(CONFIG: tcpkill feature enabled)
  535 else
  536     AC_MSG_RESULT(CONFIG: tcpkill feature disabled)
  537 fi
  538 
  539 if test "$USE_VLAN_HACK" = "1"; then
  540     AC_MSG_RESULT(CONFIG: automatically including VLAN frames)
  541 else
  542     AC_MSG_RESULT(CONFIG: NOT automatically including VLAN frames)
  543 fi
  544 
  545 dnl
  546 dnl And we're done.  ALL YOUR BASE.  Don't forget.
  547 dnl
  548 
  549 AC_MSG_RESULT
  550 
  551 AC_CONFIG_HEADERS(config.h)
  552 AC_CONFIG_FILES(Makefile)
  553 AC_OUTPUT