netsniff-ng 0.5.8-rc4
[netsniff-ng.git] / configure
blob07bffb2d42cdde0bec96436d2fe144578e48f680
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 LDFLAGS="-L $NACL_LIB_DIR"
123 CFLAGS="-I $NACL_INC_DIR"
125 $CC $CFLAGS $LDFLAGS -o $TMPDIR/nacltest $TMPDIR/nacltest.c >> config.log 2>&1
126 if [ ! -x $TMPDIR/nacltest ] ; then
127 echo "[NO]"
128 MISSING_NACL=1
129 tools_remove "curvetun"
130 else
131 echo "[YES]"
132 echo "CONFIG_NACL_INC_DIR:=$NACL_INC_DIR" >> Config
133 echo "CONFIG_NACL_LIB_DIR:=$NACL_LIB_DIR" >> Config
137 check_libnl()
139 echo -n "[*] Checking libnl ... "
141 cat > $TMPDIR/libnltest.c << EOF
142 #include <libnl3/netlink/genl/genl.h>
143 #include <libnl3/netlink/genl/family.h>
144 #include <libnl3/netlink/genl/ctrl.h>
145 #include <libnl3/netlink/msg.h>
146 #include <libnl3/netlink/attr.h>
147 #include <libnl3/netlink/version.h>
149 #if LIBNL_VER_NUM < LIBNL_VER(3,0)
150 # error incompatible libnl version
151 #endif
153 void main(void)
155 struct nl_sock *sock = nl_socket_alloc();
156 struct nl_cache *nl_cache;
157 int ret = genl_connect(sock);
159 ret = genl_ctrl_alloc_cache(sock, &nl_cache);
163 $CC \
164 $(pkg-config --cflags libnl-3.0 2>> config.log) \
165 $(pkg-config --cflags libnl-genl-3.0 2>> config.log) \
166 -o $TMPDIR/libnltest \
167 $TMPDIR/libnltest.c \
168 $(pkg-config --libs libnl-3.0 2>> config.log) \
169 $(pkg-config --libs libnl-genl-3.0 2>> config.log) \
170 >> config.log 2>&1
171 if [ ! -x $TMPDIR/libnltest ] ; then
172 echo "[NO]"
173 MISSING_DEFS=1
174 tools_remove "trafgen"
175 tools_remove "netsniff-ng"
176 else
177 echo "[YES]"
181 check_tpacket_v3()
183 echo -n "[*] Checking tpacket_v3 ... "
185 cat > $TMPDIR/tpacketv3test.c << EOF
186 #include <stdio.h>
187 #include <linux/if_packet.h>
189 void main(void)
191 struct tpacket3_hdr *hdr;
192 int foo[] = {
193 TP_STATUS_BLK_TMO,
196 printf("%d\n", hdr->tp_status);
200 $CC -o $TMPDIR/tpacketv3test $TMPDIR/tpacketv3test.c >> config.log 2>&1
201 if [ ! -x $TMPDIR/tpacketv3test ] ; then
202 echo "[NO]"
203 MISSING_DEFS=1
204 tools_remove "netsniff-ng"
205 else
206 echo "[YES]"
207 HAVE_TPACKET3=1
211 check_tpacket_v2()
213 echo -n "[*] Checking tpacket_v2 ... "
215 cat > $TMPDIR/tpacketv2test.c << EOF
216 #include <stdio.h>
217 #include <linux/if_packet.h>
219 void main(void)
221 struct tpacket2_hdr *hdr;
222 int foo[] = {
223 TP_STATUS_AVAILABLE,
224 TP_STATUS_SEND_REQUEST,
225 TP_STATUS_SENDING,
226 TP_STATUS_KERNEL,
227 TP_STATUS_USER,
230 printf("%d\n", hdr->tp_status);
234 $CC -o $TMPDIR/tpacketv2test $TMPDIR/tpacketv2test.c >> config.log 2>&1
235 if [ ! -x $TMPDIR/tpacketv2test ] ; then
236 echo "[NO]"
237 MISSING_DEFS=1
238 tools_remove "netsniff-ng"
239 tools_remove "trafgen"
240 else
241 echo "[YES]"
246 check_ncurses()
248 echo -n "[*] Checking ncurses ... "
250 cat > $TMPDIR/ncursestest.c << EOF
251 #include <curses.h>
253 void main(void)
255 WINDOW *screen = initscr();
259 $CC \
260 $(pkg-config --cflags ncurses 2>> config.log) \
261 -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c \
262 $(pkg-config --libs ncurses 2>> config.log) \
263 >> config.log 2>&1
264 if [ ! -x $TMPDIR/ncursestest ] ; then
265 echo "[NO]"
266 MISSING_DEFS=1
267 tools_remove "flowtop"
268 tools_remove "ifpps"
269 else
270 echo "[YES]"
274 check_libgeoip()
276 echo -n "[*] Checking libGeoIP ... "
278 cat > $TMPDIR/geoiptest.c << EOF
279 #include <GeoIP.h>
280 #include <GeoIPCity.h>
282 void main(void)
284 int dbs[] = {
285 GEOIP_CITY_EDITION_REV1,
286 GEOIP_CITY_EDITION_REV1_V6,
287 GEOIP_COUNTRY_EDITION,
288 GEOIP_COUNTRY_EDITION_V6,
289 GEOIP_ASNUM_EDITION,
290 GEOIP_ASNUM_EDITION_V6,
292 GeoIP *geoip = GeoIP_new(0);
296 $CC -o $TMPDIR/geoiptest $TMPDIR/geoiptest.c -lGeoIP >> config.log 2>&1
297 if [ ! -x $TMPDIR/geoiptest ] ; then
298 echo "[NO]"
299 echo "CONFIG_LIBGEOIP=0" >> Config
300 MISSING_DEFS=1
301 tools_remove "astraceroute"
302 tools_remove "flowtop"
303 else
304 echo "[YES]"
305 echo "CONFIG_LIBGEOIP=1" >> Config
306 HAVE_LIBGEOIP=1
310 check_libnf_ct()
312 echo -n "[*] Checking libnetfilter-conntrack ... "
314 cat > $TMPDIR/nfcttest.c << EOF
315 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
316 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
317 #include <libnetfilter_conntrack/libnetfilter_conntrack_dccp.h>
318 #include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>
320 void main(void)
322 struct nf_conntrack *ct;
323 const uint32_t id = nfct_get_attr_u32(ct, ATTR_ID);
327 $CC -o $TMPDIR/nfcttest $TMPDIR/nfcttest.c -lnetfilter_conntrack >> config.log 2>&1
328 if [ ! -x $TMPDIR/nfcttest ] ; then
329 echo "[NO]"
330 MISSING_DEFS=1
331 tools_remove "flowtop"
332 else
333 echo "[YES]"
337 check_zlib()
339 echo -n "[*] Checking libz ... "
341 cat > $TMPDIR/ztest.c << EOF
342 #include "zlib.h"
344 void main(void)
346 gzFile fp = gzopen("foo.gz", "rb");
350 $CC -o $TMPDIR/ztest $TMPDIR/ztest.c -lz >> config.log 2>&1
351 if [ ! -x $TMPDIR/ztest ] ; then
352 echo "[NO]"
353 echo "CONFIG_LIBZ=0" >> Config
354 MISSING_DEFS=1
355 tools_remove "astraceroute"
356 tools_remove "flowtop"
357 else
358 echo "[YES]"
359 echo "CONFIG_LIBZ=1" >> Config
360 HAVE_LIBZ=1
364 check_urcu()
366 echo -n "[*] Checking liburcu ... "
368 cat > $TMPDIR/urcutest.c << EOF
369 #include <urcu.h>
371 void main(void)
373 rcu_init();
374 synchronize_rcu();
378 $CC -o $TMPDIR/urcutest $TMPDIR/urcutest.c -lurcu >> config.log 2>&1
379 if [ ! -x $TMPDIR/urcutest ] ; then
380 echo "[NO]"
381 MISSING_DEFS=1
382 tools_remove "flowtop"
383 else
384 echo "[YES]"
388 check_libpcap()
390 echo -n "[*] Checking libpcap ... "
392 cat > $TMPDIR/pcaptest.c << EOF
393 #include <pcap.h>
395 void main(void)
397 struct bpf_program bpf;
398 int ret = pcap_compile_nopcap(65535, 1, &bpf, "foo.bpf", 1, 0xffffffff);
402 $CC -o $TMPDIR/pcaptest $TMPDIR/pcaptest.c -lpcap >> config.log 2>&1
403 if [ ! -x $TMPDIR/pcaptest ] ; then
404 echo "[NO]"
405 echo "CONFIG_LIBPCAP=0" >> Config
406 MISSING_DEFS=1
407 tools_remove "mausezahn"
408 else
409 echo "[YES]"
410 echo "CONFIG_LIBPCAP=1" >> Config
411 HAVE_LIBPCAP=1
415 check_hwtstamp()
417 echo -n "[*] Checking hw timestamping ... "
419 cat > $TMPDIR/hwtstest.c << EOF
420 #include <string.h>
421 #include <arpa/inet.h>
422 #include <sys/ioctl.h>
423 #include <sys/types.h>
424 #include <sys/socket.h>
425 #include <linux/sockios.h>
426 #include <linux/net_tstamp.h>
427 #include <linux/if_packet.h>
428 #include <linux/if_ether.h>
429 #include <linux/if.h>
431 void main(void)
433 int timesource = SOF_TIMESTAMPING_RAW_HARDWARE, ret;
434 int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
435 struct hwtstamp_config hwconfig;
436 struct ifreq ifr;
438 memset(&hwconfig, 0, sizeof(hwconfig));
439 hwconfig.tx_type = HWTSTAMP_TX_OFF;
440 hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
442 memset(&ifr, 0, sizeof(ifr));
443 strncpy(ifr.ifr_name, "lo", sizeof(ifr.ifr_name));
444 ifr.ifr_data = &hwconfig;
446 ioctl(sock, SIOCSHWTSTAMP, &ifr);
447 setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
448 sizeof(timesource));
452 $CC -o $TMPDIR/hwtstest $TMPDIR/hwtstest.c >> config.log 2>&1
453 if [ ! -x $TMPDIR/hwtstest ] ; then
454 echo "[NO]"
455 echo "CONFIG_HWTSTAMP=0" >> Config
456 else
457 echo "[YES]"
458 echo "CONFIG_HWTSTAMP=1" >> Config
459 HAVE_HWTSTAMP=1
463 check_libcli()
465 echo -n "[*] Checking libcli ... "
467 cat > $TMPDIR/clitest.c << EOF
468 #include <sys/time.h>
469 #include <libcli.h>
471 void main(void)
473 struct cli_def *cli = cli_init();
477 $CC -o $TMPDIR/clitest $TMPDIR/clitest.c -lcli >> config.log 2>&1
478 if [ ! -x $TMPDIR/clitest ] ; then
479 echo "[NO]"
480 MISSING_DEFS=1
481 tools_remove "mausezahn"
482 else
483 echo "[YES]"
487 check_libnet()
489 echo -n "[*] Checking libnet ... "
491 cat > $TMPDIR/nettest.c << EOF
492 #include <libnet.h>
494 void main(void)
496 char err_buf[LIBNET_ERRBUF_SIZE];
497 libnet_t *l = libnet_init(LIBNET_LINK_ADV, "ethX", err_buf);
501 $CC -o $TMPDIR/nettest $TMPDIR/nettest.c -lnet >> config.log 2>&1
502 if [ ! -x $TMPDIR/nettest ] ; then
503 echo "[NO]"
504 MISSING_DEFS=1
505 tools_remove "mausezahn"
506 else
507 echo "[YES]"
511 gen_version_appendix()
513 local _appendix=""
515 git rev-parse > /dev/null 2>&1
516 if [ "$?" == "0" ] ; then
517 if [ ! "`git describe --always`" == \
518 "`git describe --abbrev=0 --tags`" ] ; then
519 _appendix="+"
523 echo "CONFIG_RC=\"$_appendix\"" >> Config
526 gen_config_hdr()
528 local _version=""
529 local _have_libpcap=""
530 local _have_libgeoip=""
531 local _have_libz=""
532 local _have_hwts=""
533 local _have_tp3=""
535 echo "[*] Generating config.h ..."
537 git rev-parse > /dev/null 2>&1
538 if [ "$?" == "0" ] ; then
539 _version="`git describe --always`"
540 else
541 _version="(none)"
544 if [ "$HAVE_LIBPCAP" == "1" ] ; then
545 _have_libpcap="#define HAVE_TCPDUMP_LIKE_FILTER 1"
548 if [ "$HAVE_HWTSTAMP" == "1" ] ; then
549 _have_hwts="#define HAVE_HARDWARE_TIMESTAMPING 1"
552 if [ "$HAVE_LIBGEOIP" == "1" ] ; then
553 _have_libgeoip="#define HAVE_GEOIP 1"
556 if [ "$HAVE_LIBZ" == "1" ] ; then
557 _have_libz="#define HAVE_LIBZ 1"
560 if [ "$HAVE_TPACKET3" == "1" ] ; then
561 _have_tp3="#define HAVE_TPACKET3 1"
564 cat > config.h << EOF
565 #ifndef CONFIG_H
566 #define CONFIG_H
567 #define FILE_CLIENTS ".curvetun/clients"
568 #define FILE_SERVERS ".curvetun/servers"
569 #define FILE_PRIVKEY ".curvetun/priv.key"
570 #define FILE_PUBKEY ".curvetun/pub.key"
571 #define FILE_USERNAM ".curvetun/username"
572 #define GITVERSION "$_version"
573 $_have_libpcap
574 $_have_libgeoip
575 $_have_libz
576 $_have_hwts
577 $_have_tp3
578 #endif /* CONFIG_H */
582 rm -f config.log
584 echo "# This file is autogenerated by the configure script" > Config
585 check_pkg_config
587 if [ "$MISSING_PKG_CONFIG" == "1" ] ; then
588 echo "[!] pkg-config is not installed on your system or not in the PATH"
589 exit 1
592 check_ccache
593 check_flex
594 check_bison
595 check_nacl
596 check_libnl
597 check_tpacket_v2
598 check_tpacket_v3
599 check_libnf_ct
600 check_ncurses
601 check_libgeoip
602 check_zlib
603 check_urcu
604 check_libpcap
605 check_hwtstamp
606 check_libcli
607 check_libnet
609 gen_config_hdr
610 gen_version_appendix
612 if [ "$MISSING_DEFS" == "1" ] ; then
613 echo "[!] Some libraries or header definitions are missing or too old. Thus"
614 echo " certain tools will not be built (see below). Please refer to the"
615 echo " INSTALL file for the libraries needed to build the complete"
616 echo " netsniff-ng toolkit."
619 if [ "$MISSING_NACL" == "1" ] ; then
620 echo "[!] The NaCl crypto library is currently not present on your system or"
621 echo " could not be found. Either install it from your distro or build it"
622 echo " manually using 'make nacl' and make sure that the NACL_INC_DIR and"
623 echo " NACL_LIB_DIR environment variables are set appropriately."
626 if [ "x$TOOLS_NOBUILD" != "x" ] ; then
627 echo "[!] The following tools will *not* be built: $TOOLS_NOBUILD"
628 echo "[*] The following tools will be built: $TOOLS"
629 else
630 echo "[*] Looks good! All tools will be built!"
633 if [ -s config.log ] ; then
634 echo "[!] There were errors in the configure script. Please check the file"
635 echo " config.log for details."
638 if [ "$HAVE_LIBGEOIP" == "1" -a "$HAVE_LIBZ" == "1" ] ; then
639 echo "CONFIG_GEOIP=1" >> Config
640 else
641 echo "CONFIG_GEOIP=0" >> Config
644 echo "CONFIG_TOOLS=$TOOLS" >> Config
645 echo "CONFIG_OK=1" >> Config
647 exit 0