netsniff-ng: Remove unnecessary initialization of struct ctx members
[netsniff-ng.git] / configure
blob68291d2266092c9baba51360a47559a2f3884611
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 void 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 void 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 tools_remove "netsniff-ng"
210 else
211 echo "[YES]"
212 HAVE_TPACKET3=1
216 check_tpacket_v2()
218 echo -n "[*] Checking tpacket_v2 ... "
220 cat > $TMPDIR/tpacketv2test.c << EOF
221 #include <stdio.h>
222 #include <linux/if_packet.h>
224 void main(void)
226 struct tpacket2_hdr *hdr;
227 int foo[] = {
228 TP_STATUS_AVAILABLE,
229 TP_STATUS_SEND_REQUEST,
230 TP_STATUS_SENDING,
231 TP_STATUS_KERNEL,
232 TP_STATUS_USER,
235 printf("%d\n", hdr->tp_status);
239 $CC -o $TMPDIR/tpacketv2test $TMPDIR/tpacketv2test.c >> config.log 2>&1
240 if [ ! -x $TMPDIR/tpacketv2test ] ; then
241 echo "[NO]"
242 MISSING_DEFS=1
243 tools_remove "netsniff-ng"
244 tools_remove "trafgen"
245 else
246 echo "[YES]"
251 check_ncurses()
253 echo -n "[*] Checking ncurses ... "
255 cat > $TMPDIR/ncursestest.c << EOF
256 #include <curses.h>
258 void main(void)
260 WINDOW *screen = initscr();
264 $CC \
265 $(pkg-config --cflags ncurses 2>> config.log) \
266 -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c \
267 $(pkg-config --libs ncurses 2>> config.log \
268 || echo '-lncurses' ) \
269 >> config.log 2>&1
270 if [ ! -x $TMPDIR/ncursestest ] ; then
271 echo "[NO]"
272 MISSING_DEFS=1
273 tools_remove "flowtop"
274 tools_remove "ifpps"
275 else
276 echo "[YES]"
280 check_libgeoip()
282 echo -n "[*] Checking libGeoIP ... "
284 cat > $TMPDIR/geoiptest.c << EOF
285 #include <GeoIP.h>
286 #include <GeoIPCity.h>
288 void main(void)
290 int dbs[] = {
291 GEOIP_CITY_EDITION_REV1,
292 GEOIP_CITY_EDITION_REV1_V6,
293 GEOIP_COUNTRY_EDITION,
294 GEOIP_COUNTRY_EDITION_V6,
295 GEOIP_ASNUM_EDITION,
296 GEOIP_ASNUM_EDITION_V6,
298 GeoIP *geoip = GeoIP_new(0);
302 $CC -o $TMPDIR/geoiptest $TMPDIR/geoiptest.c -lGeoIP >> config.log 2>&1
303 if [ ! -x $TMPDIR/geoiptest ] ; then
304 echo "[NO]"
305 echo "CONFIG_LIBGEOIP=0" >> Config
306 MISSING_DEFS=1
307 tools_remove "astraceroute"
308 tools_remove "flowtop"
309 else
310 echo "[YES]"
311 echo "CONFIG_LIBGEOIP=1" >> Config
312 HAVE_LIBGEOIP=1
316 check_libnf_ct()
318 echo -n "[*] Checking libnetfilter-conntrack ... "
320 cat > $TMPDIR/nfcttest.c << EOF
321 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
322 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
323 #include <libnetfilter_conntrack/libnetfilter_conntrack_dccp.h>
324 #include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>
326 void main(void)
328 struct nf_conntrack *ct;
329 const uint32_t id = nfct_get_attr_u32(ct, ATTR_ID);
333 $CC -o $TMPDIR/nfcttest $TMPDIR/nfcttest.c -lnetfilter_conntrack >> config.log 2>&1
334 if [ ! -x $TMPDIR/nfcttest ] ; then
335 echo "[NO]"
336 MISSING_DEFS=1
337 tools_remove "flowtop"
338 else
339 echo "[YES]"
343 check_zlib()
345 echo -n "[*] Checking libz ... "
347 cat > $TMPDIR/ztest.c << EOF
348 #include "zlib.h"
350 void main(void)
352 gzFile fp = gzopen("foo.gz", "rb");
356 $CC -o $TMPDIR/ztest $TMPDIR/ztest.c -lz >> config.log 2>&1
357 if [ ! -x $TMPDIR/ztest ] ; then
358 echo "[NO]"
359 echo "CONFIG_LIBZ=0" >> Config
360 MISSING_DEFS=1
361 tools_remove "astraceroute"
362 tools_remove "flowtop"
363 else
364 echo "[YES]"
365 echo "CONFIG_LIBZ=1" >> Config
366 HAVE_LIBZ=1
370 check_urcu()
372 echo -n "[*] Checking liburcu ... "
374 cat > $TMPDIR/urcutest.c << EOF
375 #include <urcu.h>
377 void main(void)
379 rcu_init();
380 synchronize_rcu();
384 $CC -o $TMPDIR/urcutest $TMPDIR/urcutest.c -lurcu >> config.log 2>&1
385 if [ ! -x $TMPDIR/urcutest ] ; then
386 echo "[NO]"
387 MISSING_DEFS=1
388 tools_remove "flowtop"
389 else
390 echo "[YES]"
394 check_libpcap()
396 echo -n "[*] Checking libpcap ... "
398 cat > $TMPDIR/pcaptest.c << EOF
399 #include <pcap.h>
401 void main(void)
403 struct bpf_program bpf;
404 int ret = pcap_compile_nopcap(65535, 1, &bpf, "foo.bpf", 1, 0xffffffff);
408 $CC -o $TMPDIR/pcaptest $TMPDIR/pcaptest.c -lpcap >> config.log 2>&1
409 if [ ! -x $TMPDIR/pcaptest ] ; then
410 echo "[NO]"
411 echo "CONFIG_LIBPCAP=0" >> Config
412 MISSING_DEFS=1
413 tools_remove "mausezahn"
414 else
415 echo "[YES]"
416 echo "CONFIG_LIBPCAP=1" >> Config
417 HAVE_LIBPCAP=1
421 check_hwtstamp()
423 echo -n "[*] Checking hw timestamping ... "
425 cat > $TMPDIR/hwtstest.c << EOF
426 #include <string.h>
427 #include <arpa/inet.h>
428 #include <sys/ioctl.h>
429 #include <sys/types.h>
430 #include <sys/socket.h>
431 #include <linux/sockios.h>
432 #include <linux/net_tstamp.h>
433 #include <linux/if_packet.h>
434 #include <linux/if_ether.h>
435 #include <linux/if.h>
437 void main(void)
439 int timesource = SOF_TIMESTAMPING_RAW_HARDWARE, ret;
440 int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
441 struct hwtstamp_config hwconfig;
442 struct ifreq ifr;
444 memset(&hwconfig, 0, sizeof(hwconfig));
445 hwconfig.tx_type = HWTSTAMP_TX_OFF;
446 hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
448 memset(&ifr, 0, sizeof(ifr));
449 strncpy(ifr.ifr_name, "lo", sizeof(ifr.ifr_name));
450 ifr.ifr_data = &hwconfig;
452 ioctl(sock, SIOCSHWTSTAMP, &ifr);
453 setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
454 sizeof(timesource));
458 $CC -o $TMPDIR/hwtstest $TMPDIR/hwtstest.c >> config.log 2>&1
459 if [ ! -x $TMPDIR/hwtstest ] ; then
460 echo "[NO]"
461 echo "CONFIG_HWTSTAMP=0" >> Config
462 else
463 echo "[YES]"
464 echo "CONFIG_HWTSTAMP=1" >> Config
465 HAVE_HWTSTAMP=1
469 check_libcli()
471 echo -n "[*] Checking libcli ... "
473 cat > $TMPDIR/clitest.c << EOF
474 #include <sys/time.h>
475 #include <libcli.h>
477 void main(void)
479 struct cli_def *cli = cli_init();
483 $CC -o $TMPDIR/clitest $TMPDIR/clitest.c -lcli >> config.log 2>&1
484 if [ ! -x $TMPDIR/clitest ] ; then
485 echo "[NO]"
486 MISSING_DEFS=1
487 tools_remove "mausezahn"
488 else
489 echo "[YES]"
493 check_libnet()
495 echo -n "[*] Checking libnet ... "
497 cat > $TMPDIR/nettest.c << EOF
498 #include <libnet.h>
500 void main(void)
502 char err_buf[LIBNET_ERRBUF_SIZE];
503 libnet_t *l = libnet_init(LIBNET_LINK_ADV, "ethX", err_buf);
507 $CC -o $TMPDIR/nettest $TMPDIR/nettest.c -lnet >> config.log 2>&1
508 if [ ! -x $TMPDIR/nettest ] ; then
509 echo "[NO]"
510 MISSING_DEFS=1
511 tools_remove "mausezahn"
512 else
513 echo "[YES]"
517 gen_version_appendix()
519 local _appendix=""
521 git rev-parse > /dev/null 2>&1
522 if [ "$?" == "0" ] ; then
523 if [ ! "`git describe --always`" == \
524 "`git describe --abbrev=0 --tags`" ] ; then
525 _appendix="+"
529 echo "CONFIG_RC=\"$_appendix\"" >> Config
532 gen_config_hdr()
534 local _version=""
535 local _have_libpcap=""
536 local _have_libgeoip=""
537 local _have_libz=""
538 local _have_hwts=""
539 local _have_tp3=""
541 echo "[*] Generating config.h ..."
543 git rev-parse > /dev/null 2>&1
544 if [ "$?" == "0" ] ; then
545 _version="`git describe --always`"
546 else
547 _version="(none)"
550 if [ "$HAVE_LIBPCAP" == "1" ] ; then
551 _have_libpcap="#define HAVE_TCPDUMP_LIKE_FILTER 1"
554 if [ "$HAVE_HWTSTAMP" == "1" ] ; then
555 _have_hwts="#define HAVE_HARDWARE_TIMESTAMPING 1"
558 if [ "$HAVE_LIBGEOIP" == "1" ] ; then
559 _have_libgeoip="#define HAVE_GEOIP 1"
562 if [ "$HAVE_LIBZ" == "1" ] ; then
563 _have_libz="#define HAVE_LIBZ 1"
566 if [ "$HAVE_TPACKET3" == "1" ] ; then
567 _have_tp3="#define HAVE_TPACKET3 1"
570 cat > config.h << EOF
571 #ifndef CONFIG_H
572 #define CONFIG_H
573 #define FILE_CLIENTS ".curvetun/clients"
574 #define FILE_SERVERS ".curvetun/servers"
575 #define FILE_PRIVKEY ".curvetun/priv.key"
576 #define FILE_PUBKEY ".curvetun/pub.key"
577 #define FILE_USERNAM ".curvetun/username"
578 #define GITVERSION "$_version"
579 $_have_libpcap
580 $_have_libgeoip
581 $_have_libz
582 $_have_hwts
583 $_have_tp3
584 #endif /* CONFIG_H */
588 rm -f config.log
590 echo "# This file is autogenerated by the configure script" > Config
591 check_pkg_config
593 if [ "$MISSING_PKG_CONFIG" == "1" ] ; then
594 echo "[!] pkg-config is not installed on your system or not in the PATH"
595 exit 1
598 check_ccache
599 check_flex
600 check_bison
601 check_nacl
602 check_libnl
603 check_tpacket_v2
604 check_tpacket_v3
605 check_libnf_ct
606 check_ncurses
607 check_libgeoip
608 check_zlib
609 check_urcu
610 check_libpcap
611 check_hwtstamp
612 check_libcli
613 check_libnet
615 gen_config_hdr
616 gen_version_appendix
618 if [ "$MISSING_DEFS" == "1" ] ; then
619 echo "[!] Some libraries or header definitions are missing or too old. Thus"
620 echo " certain tools will not be built (see below). Please refer to the"
621 echo " INSTALL file for the libraries needed to build the complete"
622 echo " netsniff-ng toolkit."
625 if [ "$MISSING_NACL" == "1" ] ; then
626 echo "[!] The NaCl crypto library is currently not present on your system or"
627 echo " could not be found. Either install it from your distro or build it"
628 echo " manually using 'make nacl' and make sure that the NACL_INC_DIR and"
629 echo " NACL_LIB_DIR environment variables are set appropriately."
632 if [ "x$TOOLS_NOBUILD" != "x" ] ; then
633 echo "[!] The following tools will *not* be built: $TOOLS_NOBUILD"
634 echo "[*] The following tools will be built: $TOOLS"
635 else
636 echo "[*] Looks good! All tools will be built!"
639 if [ -s config.log ] ; then
640 echo "[!] There were errors in the configure script. Please check the file"
641 echo " config.log for details."
644 if [ "$HAVE_LIBGEOIP" == "1" -a "$HAVE_LIBZ" == "1" ] ; then
645 echo "CONFIG_GEOIP=1" >> Config
646 else
647 echo "CONFIG_GEOIP=0" >> Config
650 echo "CONFIG_TOOLS=$TOOLS" >> Config
651 echo "CONFIG_OK=1" >> Config
653 exit 0