1dnl 2dnl $Id: configure.in,v 1.36 2006/11/15 03:43:56 jpr5 Exp $ 3dnl 4dnl Copyright (c) 2001 Jordan Ritter <jpr5@darkridge.com> 5dnl 6dnl Please refer to the LICENSE file for more information. 7dnl 8dnl NOTE: configure.in requires autoconf 2.57 or more recent. 9 10AC_INIT(ngrep.c) 11 12echo 13echo 'Configuring System ...' 14echo 15 16AC_CANONICAL_SYSTEM 17AC_PROG_CC 18AC_HEADER_STDC 19 20AC_PREFIX_DEFAULT(/usr/local) 21if test -n "`which tcpdump 2> /dev/null`"; then 22 AC_PREFIX_PROGRAM(tcpdump) 23fi 24 25dnl 26dnl The following are globals that we tack on to the associated 27dnl variables in the makefile. They get AC_SUBST'd at the end. 28dnl 29 30EXTRA_DEFINES="" 31EXTRA_INCLUDES="" 32EXTRA_LIBS="" 33 34 35dnl 36dnl Define the arguments that we accept. 37dnl 38 39dnl 40dnl For libpcap's that don't need the restart function called for 41dnl multiple lexer passes, allow them to turn it off here. This option 42dnl exists solely to address a very rude email from the maintainer 43dnl indicating that it shouldn't be called directly (and of course he 44dnl was wrong because this is still needed). 45dnl 46 47AC_ARG_ENABLE(pcap-restart, 48[ --disable-pcap-restart disable libpcap restart in parser], 49[ 50 use_pcap_restart="$enableval" 51], 52[ 53 use_pcap_restart="yes" 54]) 55 56if test $use_pcap_restart = yes; then 57 USE_PCAP_RESTART="1" 58else 59 USE_PCAP_RESTART="0" 60fi 61 62dnl 63dnl Allow user to specify alternate ``nobody'' user. 64dnl 65 66AC_ARG_WITH(dropprivs-user, 67[ --with-dropprivs-user[=user] use different user for dropprivs], 68[ 69 DROPPRIVS_USER="$withval" 70], 71[ 72 DROPPRIVS_USER="nobody" 73]) 74 75dnl 76dnl Enable or disable the drop privileges logic. 77dnl 78 79AC_ARG_ENABLE(dropprivs, 80[ --disable-dropprivs disable privilege dropping logic], 81[ 82 use_dropprivs="$enableval" 83], 84[ 85 use_dropprivs="yes" 86]) 87 88if test $use_dropprivs = yes; then 89 USE_DROPPRIVS="1" 90else 91 USE_DROPPRIVS="0" 92fi 93 94dnl 95dnl IPv6 (and ICMPv6) support 96dnl 97 98AC_ARG_ENABLE(ipv6, 99[ --enable-ipv6 enable IPv6 (and ICMPv6) support], 100[ 101 use_ipv6="$enableval" 102], 103[ 104 use_ipv6="no" 105]) 106 107if test $use_ipv6 = yes; then 108 USE_IPv6="1" 109else 110 USE_IPv6="0" 111fi 112 113AC_ARG_ENABLE(capsicum, 114[ --enable-capsicum enable capsicum support], 115[ 116 use_capsicum="$enableval" 117], 118[ 119 use_capsicum="no" 120]) 121 122# 123# Check whether various functions are available. If any are, set 124# ac_lbl_capsicum_function_seen to yes; if any are not, set 125# ac_lbl_capsicum_function_not_seen to yes. 126# 127# All of them must be available in order to enable capsicum sandboxing. 128# 129if test $use_capsicum = yes && test $use_capsicum != no ; then 130 AC_CHECK_FUNCS(cap_enter cap_rights_limit cap_ioctls_limit openat, 131 ac_lbl_capsicum_function_seen=yes, 132 ac_lbl_capsicum_function_not_seen=yes) 133fi 134AC_MSG_CHECKING([whether to sandbox using capsicum]) 135if test "x$ac_lbl_capsicum_function_seen" = "xyes" -a "x$ac_lbl_capsicum_function_not_seen" != "xyes"; then 136 HAVE_CAPSICUM="1" 137 AC_MSG_RESULT(yes) 138else 139 AC_MSG_RESULT(no) 140fi 141 142dnl 143dnl Configure the regular expression library. 144dnl 145 146AC_ARG_ENABLE(pcre, 147[ --enable-pcre use PCRE instead of GNU regex], 148[ 149 use_pcre="$enableval" 150], 151[ 152 use_pcre="no" 153]) 154 155if test $use_pcre = yes; then 156 157 echo 158 echo 'Configuring Perl-Compatible Regular Expression (PCRE) library ...' 159 echo 160 161 REGEX_DIR='pcre-5.0' 162 REGEX_OBJS="$REGEX_DIR/pcre.o $REGEX_DIR/study.o" 163 USE_PCRE="1" 164 165else 166 167 echo 168 echo 'Configuring GNU Regular Expression library ...' 169 echo 170 171 REGEX_DIR='regex-0.12' 172 REGEX_OBJS="$REGEX_DIR/regex.o" 173 USE_PCRE="0" 174 175fi 176 177( cd $REGEX_DIR && ./configure ) 178 179AC_SUBST(REGEX_DIR) 180AC_SUBST(REGEX_OBJS) 181 182 183echo 184echo 'Configuring Network Grep (ngrep) ...' 185echo 186 187 188dnl 189dnl OS-specific options 190dnl 191 192STRIPFLAG="-s" 193HAVE_DUMB_UDPHDR="0" 194 195case "$target_os" in 196 197*linux*) 198 AC_SUBST(OS, LINUX) 199 200 AC_MSG_CHECKING(for a broken redhat glibc udphdr declaration) 201 AC_TRY_COMPILE([ 202#ifndef __FAVOR_BSD 203#define __FAVOR_BSD 204#endif 205 206#ifndef _BSD_SOURCE 207#define _BSD_SOURCE 1 208#endif 209 210#undef _GNU_SOURCE 211 212#include <netinet/udp.h> 213],[ 214struct udphdr foo; 215unsigned short bar = foo.source; 216], 217 HAVE_DUMB_UDPHDR="1" && echo "yes", 218 HAVE_DUMB_UDPHDR="0" && echo "no") 219 220 ;; 221 222*bsd*) 223 AC_SUBST(OS, BSD) 224 225 if test "$USE_PCAP_RESTART" = "0"; then 226 227 AC_MSG_WARN( 228Your OS ($target_os) may have an old libpcap installation. 229If the resulting ngrep binary segfaults when a BPF filter is specified 230without an ngrep match string then you should reconfigure ngrep with 231the option ``--disable-pcap-restart''. 232) 233 sleep 3 234 235 fi 236 237 ;; 238 239*solaris*) 240 AC_SUBST(OS, SOLARIS) 241 242 AC_CHECK_LIB(socket, socket,, 243 echo no socket in -lsocket\?; exit) 244 AC_CHECK_LIB(nsl, gethostbyname,, 245 echo no gethostbyname in -lnsl\?; exit) 246 247 EXTRA_LIBS="$EXTRA_LIBS -lnsl -lsocket" 248 249 ;; 250 251*osf*) 252 AC_SUBST(OS, OSF1) 253 254 EXTRA_DEFINES="$EXTRA_DEFINES -D__STDC__=2" 255 256 ;; 257 258*hpux11*) 259 AC_SUBST(OS, BSD) 260 261 ;; 262 263*aix*) 264 AC_SUBST(OS, AIX) 265 266 ;; 267 268*darwin*) 269 AC_SUBST(OS, MACOSX) 270 271 STRIPFLAG="" 272 273 ;; 274 275*) 276 AC_SUBST(OS, UNKNOWN_OS) 277 AC_MSG_WARN( 278Your OS ($target_os) is not supported yet. 279Try playing with the build host and target options. 280) 281 sleep 3 282 283 ;; 284 285esac 286 287AC_SUBST(STRIPFLAG) 288 289EXTRA_DEFINES="$EXTRA_DEFINES -D_BSD_SOURCE=1 -D__FAVOR_BSD=1" 290 291 292dnl 293dnl First find some usable PCAP headers. 294dnl 295 296AC_MSG_CHECKING(for a complete set of pcap headers) 297 298possible_dirs="`eval echo -n ${includedir}` \ 299 /usr/include /usr/include/pcap \ 300 /usr/local/include /usr/local/include/pcap \ 301 /usr/share/include /usr/share/include/pcap" 302 303AC_ARG_WITH(pcap-includes, 304[ --with-pcap-includes specify the pcap include directory], 305[PCAP_DIR=$withval], 306[PCAP_DIR=$possible_dirs]) 307 308pcap_dir="" 309for dir in $PCAP_DIR ; do 310 if test -d $dir -a -r "$dir/pcap.h" ; then 311 if test -n "$pcap_dir" -a "$pcap_dir" != "$dir"; then 312 echo 313 echo; echo more than one set found in: 314 echo $pcap_dir 315 echo $dir 316 echo; echo please wipe out all unused pcap installations 317 exit 318 else 319 pcap_dir="$dir" 320 fi 321 fi 322done 323 324if test -z "$pcap_dir" ; then 325 echo no; echo !!! couldn\'t find a complete set of pcap headers 326 exit 327else 328 echo found $pcap_dir 329 330 PCAP_INCLUDE="-I$pcap_dir" 331 PCAP_LINK="-L`dirname $pcap_dir`/lib" 332 333 AC_SUBST(PCAP_INCLUDE) 334 AC_SUBST(PCAP_LINK) 335 336fi 337 338 339dnl 340dnl Next figure out which bpf header file to look at. 341dnl 342 343AC_MSG_CHECKING(for BPF include path) 344BPF=`/usr/bin/perl -ne '/include\s+<(.*bpf\.h)>/ && print "$1\n"' $pcap_dir/pcap.h` 345echo $BPF 346 347dnl 348dnl Check for DLT_* types that might not have existed in older 349dnl libpcap's 350dnl 351 352present="" 353AC_MSG_CHECKING(for DLT_LINUX_SLL in bpf.h) 354AC_EGREP_CPP(yes, 355[ 356#include <$BPF> 357#ifdef DLT_LINUX_SLL 358yes 359#endif 360], 361[HAVE_DLT_LINUX_SLL="1" && echo yes], [HAVE_DLT_LINUX_SLL="0" && echo no]) 362 363 364present="" 365AC_MSG_CHECKING(for DLT_LOOP in bpf.h) 366AC_EGREP_CPP(yes, 367[ 368#include <$BPF> 369#ifdef DLT_LOOP 370yes 371#endif 372], 373[HAVE_DLT_LOOP="1" && echo yes], [HAVE_DLT_LOOP="0" && echo no]) 374 375 376present="" 377AC_MSG_CHECKING(for DLT_IEEE802_11 in bpf.h) 378AC_EGREP_CPP(yes, 379[ 380#include <$BPF> 381#ifdef DLT_IEEE802_11 382yes 383#endif 384], 385[HAVE_DLT_IEEE802_11="1" && echo yes], [HAVE_DLT_IEEE802_11="0" && echo no]) 386 387 388present="" 389AC_MSG_CHECKING(for DLT_IEEE802_11_RADIO in bpf.h) 390AC_EGREP_CPP(yes, 391[ 392#include <$BPF> 393#ifdef DLT_IEEE802_11_RADIO 394yes 395#endif 396], 397[HAVE_DLT_IEEE802_11_RADIO="1" && echo yes], [HAVE_DLT_IEEE802_11_RADIO="0" && echo no]) 398 399 400present="" 401AC_MSG_CHECKING(for DLT_RAW in bpf.h) 402AC_EGREP_CPP(yes, 403[ 404#include <$BPF> 405#ifdef DLT_RAW 406yes 407#endif 408], 409[HAVE_DLT_RAW="1" && echo yes], [HAVE_DLT_RAW="0" && echo no]) 410 411 412dnl 413dnl Now that we're past the OS-specific stuff, which could have 414dnl modified our USE_* and other defines, define them all now. 415dnl 416 417AC_DEFINE_UNQUOTED(USE_PCAP_RESTART, $USE_PCAP_RESTART, [whether to call pcap_restart() before subsequent invocations of pcap_compile() (default yes)]) 418 419AC_DEFINE_UNQUOTED(USE_PCRE, $USE_PCRE, [whether to use PCRE (default GNU Regex)]) 420AC_DEFINE_UNQUOTED(USE_IPv6, $USE_IPv6, [whether to use IPv6 (default off)]) 421AC_DEFINE_UNQUOTED(HAVE_CAPSICUM, $HAVE_CAPSICUM, [whether to use capsicum]) 422 423AC_DEFINE_UNQUOTED(USE_DROPPRIVS, $USE_DROPPRIVS, [whether to use privileges dropping (default yes)]) 424AC_DEFINE_UNQUOTED(DROPPRIVS_USER, "$DROPPRIVS_USER", [pseudo-user for running ngrep (default "nobody")]) 425 426AC_DEFINE_UNQUOTED(HAVE_DUMB_UDPHDR, $HAVE_DUMB_UDPHDR, [whether to accommodate broken redhat-glibc udphdr declaration (default no)]) 427 428AC_DEFINE_UNQUOTED(HAVE_DLT_RAW, $HAVE_DLT_RAW, [presence of DLT_RAW in bpf.h]) 429AC_DEFINE_UNQUOTED(HAVE_DLT_IEEE802_11, $HAVE_DLT_IEEE802_11, [presence of DLT_IEEE802_11 in bpf.h]) 430AC_DEFINE_UNQUOTED(HAVE_DLT_IEEE802_11_RADIO, $HAVE_DLT_IEEE802_11_RADIO, [presence of DLT_IEEE802_11_RADIO in bpf.h]) 431AC_DEFINE_UNQUOTED(HAVE_DLT_LOOP, $HAVE_DLT_LOOP, [presence of DLT_LOOP in bpf.h]) 432AC_DEFINE_UNQUOTED(HAVE_DLT_LINUX_SLL, $HAVE_DLT_LINUX_SLL, [presence of DLT_LINUX_SLL in bpf.h]) 433 434 435dnl 436dnl And the PCAP library.. 437dnl 438 439AC_CHECK_LIB(pcap, pcap_open_live,,echo need pcap lib; exit) 440 441dnl 442dnl And the PCAP restart function.. 443dnl 444 445pcap_restart_func="" 446if test "$use_pcap_restart" = "yes" ; then 447 AC_CHECK_LIB(pcap, pcap_restart, pcap_restart_func="pcap_restart", 448 AC_CHECK_LIB(pcap, pcap_yyrestart, pcap_restart_func="pcap_yyrestart", 449 AC_CHECK_LIB(pcap, yyrestart, pcap_restart_func="yyrestart", 450 echo no yacc restart func found 451 echo perhaps libpcap wasn\'t compiled with bison/flex\? 452 exit))) 453fi 454 455if test -z "$pcap_restart_func"; then 456 pcap_restart_func="unused" 457fi 458 459AC_DEFINE_UNQUOTED(PCAP_RESTART_FUNC, $pcap_restart_func, [routine used for restarting the PCAP lexer]) 460 461dnl 462dnl AC_SUBST in the tack-on globals.. 463dnl 464 465AC_SUBST(EXTRA_DEFINES) 466AC_SUBST(EXTRA_INCLUDES) 467AC_SUBST(EXTRA_LIBS) 468 469 470dnl 471dnl Emit configuration messages about any flags specified. 472dnl 473 474echo 475 476if test "$HAVE_DUMB_UDPHDR" = "1"; then 477 echo "CONFIG: support for broken redhat glibc udphdr enabled" 478fi 479 480if test "$USE_PCAP_RESTART" = "0"; then 481 echo "CONFIG: pcap restart logic disabled" 482fi 483 484if test "$USE_IPv6" = "1"; then 485 echo "CONFIG: ipv6 support enabled" 486else 487 echo "CONFIG: ipv6 support disabled" 488fi 489 490if test "$USE_DROPPRIVS" = "1"; then 491 echo "CONFIG: privilege dropping enabled, using \"$DROPPRIVS_USER\"" 492else 493 echo "CONFIG: privilege dropping disabled" 494fi 495 496if test "$USE_PCRE" = "1"; then 497 echo "CONFIG: using PCRE regex library" 498else 499 echo "CONFIG: using GNU regex library" 500fi 501 502 503dnl 504dnl And we're done. 505dnl 506 507echo 508 509AC_CONFIG_HEADERS(config.h) 510AC_CONFIG_FILES(Makefile) 511AC_OUTPUT 512