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