netsniff-ng: Move variable definition
[netsniff-ng.git] / configure
blobfa607649ba2ec3c42eaf4a2a0559f7aff1085b55
1 #!/bin/bash
2 # This isn't a configure generated by autoconf!
3 # netsniff-ng build system
4 # Copyright 2013 Tobias Klauser <tklauser@distanz.ch>
5 # Copyright 2013 Daniel Borkmann <borkmann@gnumaniacs.org>
6 # Subject to the GNU GPL, version 2.
8 MISSING_PKG_CONFIG=0
9 MISSING_DEFS=0
10 MISSING_NACL=0
12 TOOLS="netsniff-ng trafgen astraceroute flowtop ifpps bpfc curvetun mausezahn"
13 TOOLS_NOBUILD=""
15 HAVE_LIBPCAP=0
16 HAVE_HWTSTAMP=0
17 HAVE_LIBGEOIP=0
18 HAVE_LIBZ=0
19 HAVE_TPACKET3=0
21 [ -z $CC ] && CC=cc
23 TMPDIR=$(mktemp -d config.XXXXXX)
24 trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
26 tools_remove()
28 local _tools=$TOOLS
29 local _todel=$1
30 TOOLS=""
31 for tool in $_tools ; do
32 case "$tool" in
33 $_todel)
34 case $_todel in
35 $TOOLS_NOBUILD) ;;
36 *) TOOLS_NOBUILD="$TOOLS_NOBUILD $tool" ;;
37 esac ;;
38 *) TOOLS="$TOOLS $tool" ;;
39 esac
40 done
42 TOOLS=${TOOLS# }
43 TOOLS_NOBUILD=${TOOLS_NOBUILD# }
46 check_pkg_config()
48 echo -n "[*] Checking pkg-config ... "
50 if [ "x$(which pkg-config 2>> config.log)" == "x" ] ; then
51 echo "[NO]"
52 MISSING_PKG_CONFIG=1
53 else
54 echo "[YES]"
58 check_ccache()
60 echo -n "[*] Checking ccache ... "
62 if [ "x$(which ccache 2>> config.log)" == "x" ] ; then
63 echo "[NO]"
64 echo "CONFIG_CCACHE=" >> Config
65 else
66 echo "[YES]"
67 echo "CONFIG_CCACHE=ccache" >> Config
71 check_flex()
73 echo -n "[*] Checking flex ... "
75 if [ "x$(which flex 2>> config.log)" == "x" ] ; then
76 echo "[NO]"
77 MISSING_DEFS=1
78 tools_remove "trafgen"
79 tools_remove "bpfc"
80 else
81 echo "[YES]"
85 check_bison()
87 echo -n "[*] Checking bison ... "
89 if [ "x$(which bison 2>> config.log)" == "x" ] ; then
90 echo "[NO]"
91 MISSING_DEFS=1
92 tools_remove "trafgen"
93 tools_remove "bpfc"
94 else
95 echo "[YES]"
99 check_nacl()
101 echo -n "[*] Checking nacl ... "
103 cat > $TMPDIR/nacltest.c << EOF
104 #include "crypto_hash_sha512.h"
105 #include "crypto_verify_32.h"
106 #include "crypto_hash_sha512.h"
107 #include "crypto_box_curve25519xsalsa20poly1305.h"
108 #include "crypto_scalarmult_curve25519.h"
109 #include "crypto_auth_hmacsha512256.h"
111 int main(void) { }
114 if [ -z $NACL_INC_DIR ] ; then
115 NACL_INC_DIR="/usr/include/nacl"
118 if [ -z $NACL_LIB_DIR ] ; then
119 NACL_LIB_DIR="/usr/lib"
122 if [ -z $NACL_LIB ] ; then
123 NACL_LIB="nacl"
126 LDFLAGS="-L $NACL_LIB_DIR"
127 CFLAGS="-I $NACL_INC_DIR"
129 $CC $CFLAGS $LDFLAGS -o $TMPDIR/nacltest $TMPDIR/nacltest.c >> config.log 2>&1
130 if [ ! -x $TMPDIR/nacltest ] ; then
131 echo "[NO]"
132 MISSING_NACL=1
133 tools_remove "curvetun"
134 else
135 echo "[YES]"
136 echo "CONFIG_NACL_INC_DIR:=$NACL_INC_DIR" >> Config
137 echo "CONFIG_NACL_LIB_DIR:=$NACL_LIB_DIR" >> Config
138 echo "CONFIG_NACL_LIB:=$NACL_LIB" >> Config
142 check_libnl()
144 echo -n "[*] Checking libnl ... "
146 cat > $TMPDIR/libnltest.c << EOF
147 #include <libnl3/netlink/genl/genl.h>
148 #include <libnl3/netlink/genl/family.h>
149 #include <libnl3/netlink/genl/ctrl.h>
150 #include <libnl3/netlink/msg.h>
151 #include <libnl3/netlink/attr.h>
152 #include <libnl3/netlink/version.h>
154 #if LIBNL_VER_NUM < LIBNL_VER(3,0)
155 # error incompatible libnl version
156 #endif
158 int main(void)
160 struct nl_sock *sock = nl_socket_alloc();
161 struct nl_cache *nl_cache;
162 int ret = genl_connect(sock);
164 ret = genl_ctrl_alloc_cache(sock, &nl_cache);
168 $CC \
169 $(pkg-config --cflags libnl-3.0 2>> config.log) \
170 $(pkg-config --cflags libnl-genl-3.0 2>> config.log) \
171 -o $TMPDIR/libnltest \
172 $TMPDIR/libnltest.c \
173 $(pkg-config --libs libnl-3.0 2>> config.log) \
174 $(pkg-config --libs libnl-genl-3.0 2>> config.log) \
175 >> config.log 2>&1
176 if [ ! -x $TMPDIR/libnltest ] ; then
177 echo "[NO]"
178 MISSING_DEFS=1
179 tools_remove "trafgen"
180 tools_remove "netsniff-ng"
181 else
182 echo "[YES]"
186 check_tpacket_v3()
188 echo -n "[*] Checking tpacket_v3 ... "
190 cat > $TMPDIR/tpacketv3test.c << EOF
191 #include <stdio.h>
192 #include <linux/if_packet.h>
194 int main(void)
196 struct tpacket3_hdr *hdr;
197 int foo[] = {
198 TP_STATUS_BLK_TMO,
201 printf("%d\n", hdr->tp_status);
205 $CC -o $TMPDIR/tpacketv3test $TMPDIR/tpacketv3test.c >> config.log 2>&1
206 if [ ! -x $TMPDIR/tpacketv3test ] ; then
207 echo "[NO]"
208 MISSING_DEFS=1
209 else
210 echo "[YES]"
211 HAVE_TPACKET3=1
215 check_tpacket_v2()
217 echo -n "[*] Checking tpacket_v2 ... "
219 cat > $TMPDIR/tpacketv2test.c << EOF
220 #include <stdio.h>
221 #include <linux/if_packet.h>
223 int main(void)
225 struct tpacket2_hdr *hdr;
226 int foo[] = {
227 TP_STATUS_AVAILABLE,
228 TP_STATUS_SEND_REQUEST,
229 TP_STATUS_SENDING,
230 TP_STATUS_KERNEL,
231 TP_STATUS_USER,
234 printf("%d\n", hdr->tp_status);
238 $CC -o $TMPDIR/tpacketv2test $TMPDIR/tpacketv2test.c >> config.log 2>&1
239 if [ ! -x $TMPDIR/tpacketv2test ] ; then
240 echo "[NO]"
241 MISSING_DEFS=1
242 tools_remove "netsniff-ng"
243 tools_remove "trafgen"
244 else
245 echo "[YES]"
250 check_ncurses()
252 echo -n "[*] Checking ncurses ... "
254 cat > $TMPDIR/ncursestest.c << EOF
255 #include <curses.h>
257 int main(void)
259 WINDOW *screen = initscr();
263 $CC \
264 $(pkg-config --cflags ncurses 2>> config.log) \
265 -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c \
266 $(pkg-config --libs ncurses 2>> config.log \
267 || echo '-lncurses' ) \
268 >> config.log 2>&1
269 if [ ! -x $TMPDIR/ncursestest ] ; then
270 echo "[NO]"
271 MISSING_DEFS=1
272 tools_remove "flowtop"
273 tools_remove "ifpps"
274 else
275 echo "[YES]"
279 check_libgeoip()
281 echo -n "[*] Checking libGeoIP ... "
283 cat > $TMPDIR/geoiptest.c << EOF
284 #include <GeoIP.h>
285 #include <GeoIPCity.h>
287 int main(void)
289 int dbs[] = {
290 GEOIP_CITY_EDITION_REV1,
291 GEOIP_CITY_EDITION_REV1_V6,
292 GEOIP_COUNTRY_EDITION,
293 GEOIP_COUNTRY_EDITION_V6,
294 GEOIP_ASNUM_EDITION,
295 GEOIP_ASNUM_EDITION_V6,
297 GeoIP *geoip = GeoIP_new(0);
301 $CC -o $TMPDIR/geoiptest $TMPDIR/geoiptest.c -lGeoIP >> config.log 2>&1
302 if [ ! -x $TMPDIR/geoiptest ] ; then
303 echo "[NO]"
304 MISSING_DEFS=1
305 else
306 echo "[YES]"
307 HAVE_LIBGEOIP=1
311 check_libnf_ct()
313 echo -n "[*] Checking libnetfilter-conntrack ... "
315 cat > $TMPDIR/nfcttest.c << EOF
316 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
317 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
318 #include <libnetfilter_conntrack/libnetfilter_conntrack_dccp.h>
319 #include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>
321 int main(void)
323 struct nf_conntrack *ct;
324 const uint32_t id = nfct_get_attr_u32(ct, ATTR_ID);
328 $CC -o $TMPDIR/nfcttest $TMPDIR/nfcttest.c -lnetfilter_conntrack >> config.log 2>&1
329 if [ ! -x $TMPDIR/nfcttest ] ; then
330 echo "[NO]"
331 MISSING_DEFS=1
332 tools_remove "flowtop"
333 else
334 echo "[YES]"
338 check_zlib()
340 echo -n "[*] Checking libz ... "
342 cat > $TMPDIR/ztest.c << EOF
343 #include "zlib.h"
345 int main(void)
347 gzFile fp = gzopen("foo.gz", "rb");
351 $CC -o $TMPDIR/ztest $TMPDIR/ztest.c -lz >> config.log 2>&1
352 if [ ! -x $TMPDIR/ztest ] ; then
353 echo "[NO]"
354 echo "CONFIG_LIBZ=0" >> Config
355 MISSING_DEFS=1
356 tools_remove "astraceroute"
357 tools_remove "flowtop"
358 else
359 echo "[YES]"
360 echo "CONFIG_LIBZ=1" >> Config
361 HAVE_LIBZ=1
365 check_urcu()
367 echo -n "[*] Checking liburcu ... "
369 cat > $TMPDIR/urcutest.c << EOF
370 #include <urcu.h>
372 int main(void)
374 rcu_init();
375 synchronize_rcu();
379 $CC -o $TMPDIR/urcutest $TMPDIR/urcutest.c -lurcu >> config.log 2>&1
380 if [ ! -x $TMPDIR/urcutest ] ; then
381 echo "[NO]"
382 MISSING_DEFS=1
383 tools_remove "flowtop"
384 else
385 echo "[YES]"
389 check_libpcap()
391 echo -n "[*] Checking libpcap ... "
393 cat > $TMPDIR/pcaptest.c << EOF
394 #include <pcap.h>
396 int main(void)
398 struct bpf_program bpf;
399 int ret = pcap_compile_nopcap(65535, 1, &bpf, "foo.bpf", 1, 0xffffffff);
403 $CC -o $TMPDIR/pcaptest $TMPDIR/pcaptest.c -lpcap >> config.log 2>&1
404 if [ ! -x $TMPDIR/pcaptest ] ; then
405 echo "[NO]"
406 echo "CONFIG_LIBPCAP=0" >> Config
407 MISSING_DEFS=1
408 tools_remove "mausezahn"
409 else
410 echo "[YES]"
411 echo "CONFIG_LIBPCAP=1" >> Config
412 HAVE_LIBPCAP=1
416 check_hwtstamp()
418 echo -n "[*] Checking hw timestamping ... "
420 cat > $TMPDIR/hwtstest.c << EOF
421 #include <string.h>
422 #include <arpa/inet.h>
423 #include <sys/ioctl.h>
424 #include <sys/types.h>
425 #include <sys/socket.h>
426 #include <linux/sockios.h>
427 #include <linux/net_tstamp.h>
428 #include <linux/if_packet.h>
429 #include <linux/if_ether.h>
430 #include <linux/if.h>
432 int main(void)
434 int timesource = SOF_TIMESTAMPING_RAW_HARDWARE, ret;
435 int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
436 struct hwtstamp_config hwconfig;
437 struct ifreq ifr;
439 memset(&hwconfig, 0, sizeof(hwconfig));
440 hwconfig.tx_type = HWTSTAMP_TX_OFF;
441 hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
443 memset(&ifr, 0, sizeof(ifr));
444 strncpy(ifr.ifr_name, "lo", sizeof(ifr.ifr_name));
445 ifr.ifr_data = &hwconfig;
447 ioctl(sock, SIOCSHWTSTAMP, &ifr);
448 setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
449 sizeof(timesource));
453 $CC -o $TMPDIR/hwtstest $TMPDIR/hwtstest.c >> config.log 2>&1
454 if [ ! -x $TMPDIR/hwtstest ] ; then
455 echo "[NO]"
456 echo "CONFIG_HWTSTAMP=0" >> Config
457 else
458 echo "[YES]"
459 echo "CONFIG_HWTSTAMP=1" >> Config
460 HAVE_HWTSTAMP=1
464 check_libcli()
466 echo -n "[*] Checking libcli ... "
468 cat > $TMPDIR/clitest.c << EOF
469 #include <sys/time.h>
470 #include <libcli.h>
472 int main(void)
474 struct cli_def *cli = cli_init();
478 $CC -o $TMPDIR/clitest $TMPDIR/clitest.c -lcli >> config.log 2>&1
479 if [ ! -x $TMPDIR/clitest ] ; then
480 echo "[NO]"
481 MISSING_DEFS=1
482 tools_remove "mausezahn"
483 else
484 echo "[YES]"
488 check_libnet()
490 echo -n "[*] Checking libnet ... "
492 cat > $TMPDIR/nettest.c << EOF
493 #include <libnet.h>
495 int main(void)
497 char err_buf[LIBNET_ERRBUF_SIZE];
498 libnet_t *l = libnet_init(LIBNET_LINK_ADV, "ethX", err_buf);
502 $CC -o $TMPDIR/nettest $TMPDIR/nettest.c -lnet >> config.log 2>&1
503 if [ ! -x $TMPDIR/nettest ] ; then
504 echo "[NO]"
505 MISSING_DEFS=1
506 tools_remove "mausezahn"
507 else
508 echo "[YES]"
512 gen_version_appendix()
514 local _appendix=""
516 git rev-parse > /dev/null 2>&1
517 if [ "$?" == "0" ] ; then
518 if [ ! "`git describe --always`" == \
519 "`git describe --abbrev=0 --tags`" ] ; then
520 _appendix="+"
524 echo "CONFIG_RC=\"$_appendix\"" >> Config
527 gen_config_hdr()
529 local _version=""
530 local _have_libpcap=""
531 local _have_libgeoip=""
532 local _have_libz=""
533 local _have_hwts=""
534 local _have_tp3=""
536 echo "[*] Generating config.h ..."
538 git rev-parse > /dev/null 2>&1
539 if [ "$?" == "0" ] ; then
540 _version="`git describe --always`"
541 else
542 _version="(none)"
545 if [ "$HAVE_LIBPCAP" == "1" ] ; then
546 _have_libpcap="#define HAVE_TCPDUMP_LIKE_FILTER 1"
549 if [ "$HAVE_HWTSTAMP" == "1" ] ; then
550 _have_hwts="#define HAVE_HARDWARE_TIMESTAMPING 1"
553 if [ "$HAVE_LIBGEOIP" == "1" ] ; then
554 _have_libgeoip="#define HAVE_GEOIP 1"
557 if [ "$HAVE_LIBZ" == "1" ] ; then
558 _have_libz="#define HAVE_LIBZ 1"
561 if [ "$HAVE_TPACKET3" == "1" ] ; then
562 _have_tp3="#define HAVE_TPACKET3 1"
565 cat > config.h << EOF
566 #ifndef CONFIG_H
567 #define CONFIG_H
568 #define FILE_CLIENTS ".curvetun/clients"
569 #define FILE_SERVERS ".curvetun/servers"
570 #define FILE_PRIVKEY ".curvetun/priv.key"
571 #define FILE_PUBKEY ".curvetun/pub.key"
572 #define FILE_USERNAM ".curvetun/username"
573 #define GITVERSION "$_version"
574 $_have_libpcap
575 $_have_libgeoip
576 $_have_libz
577 $_have_hwts
578 $_have_tp3
579 #endif /* CONFIG_H */
583 rm -f config.log
585 echo "# This file is autogenerated by the configure script" > Config
586 check_pkg_config
588 if [ "$MISSING_PKG_CONFIG" == "1" ] ; then
589 echo "[!] pkg-config is not installed on your system or not in the PATH"
590 exit 1
593 check_ccache
594 check_flex
595 check_bison
596 check_nacl
597 check_libnl
598 check_tpacket_v2
599 check_tpacket_v3
600 check_libnf_ct
601 check_ncurses
602 check_libgeoip
603 check_zlib
604 check_urcu
605 check_libpcap
606 check_hwtstamp
607 check_libcli
608 check_libnet
610 gen_config_hdr
611 gen_version_appendix
613 if [ "$MISSING_DEFS" == "1" ] ; then
614 echo "[!] Some libraries or header definitions are missing or too old. Thus"
615 echo " certain tools will not be built (see below). Please refer to the"
616 echo " INSTALL file for the libraries needed to build the complete"
617 echo " netsniff-ng toolkit."
620 if [ "$MISSING_NACL" == "1" ] ; then
621 echo "[!] The NaCl crypto library is currently not present on your system or"
622 echo " could not be found. Either install it from your distro or build it"
623 echo " manually using 'make nacl' and make sure that the NACL_INC_DIR and"
624 echo " NACL_LIB_DIR environment variables are set appropriately."
627 if [ "x$TOOLS_NOBUILD" != "x" ] ; then
628 echo "[!] The following tools will *not* be built: $TOOLS_NOBUILD"
629 echo "[*] The following tools will be built: $TOOLS"
630 else
631 echo "[*] Looks good! All tools will be built!"
634 if [ -s config.log ] ; then
635 echo "[!] There were errors in the configure script. Please check the file"
636 echo " config.log for details."
639 if [ "$HAVE_LIBGEOIP" == "1" -a "$HAVE_LIBZ" == "1" ] ; then
640 echo "CONFIG_GEOIP=1" >> Config
641 else
642 echo "CONFIG_GEOIP=0" >> Config
645 echo "CONFIG_TOOLS=$TOOLS" >> Config
646 echo "CONFIG_OK=1" >> Config
648 exit 0