summaryrefslogtreecommitdiff
path: root/configure
blob: d977b376fc4e41d659cf52928b999c165d060e63 (plain)
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
#!/bin/bash
# This isn't a configure generated by autoconf!

MISSING_DEFS=0
MISSING_NACL=0

[ -z $CC ] && CC=cc

TMPDIR=$(mktemp -d config.XXXXXX)
trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM

check_nacl()
{
	echo -n "[*] Checking nacl ... "

	cat > $TMPDIR/nacltest.c << EOF
#include "crypto_hash_sha512.h"
#include "crypto_verify_32.h"
#include "crypto_hash_sha512.h"
#include "crypto_box_curve25519xsalsa20poly1305.h"
#include "crypto_scalarmult_curve25519.h"
#include "crypto_auth_hmacsha512256.h"

int main(void) { }
EOF

	if [ -z $NACL_INC_DIR ] ; then
		NACL_INC_DIR="/usr/include/nacl"
	fi

	if [ -z $NACL_LIB_DIR ] ; then
		NACL_LIB_DIR="/usr/lib"
	fi

	LDFLAGS="-L $NACL_LIB_DIR"
	CFLAGS="-I $NACL_INC_DIR"

	$CC $CFLAGS $LDFLAGS -o $TMPDIR/nacltest $TMPDIR/nacltest.c >> $TMPDIR/config.log 2>&1
	if [ ! -x $TMPDIR/nacltest ] ; then
		echo "[NO]"
		MISSING_NACL=1
	else
		echo "[YES]"
		echo "CONFIG_NACL_INC_DIR:=$NACL_INC_DIR" >> Config
		echo "CONFIG_NACL_LIB_DIR:=$NACL_LIB_DIR" >> Config
	fi

}

check_libnl()
{
	echo -n "[*] Checking libnl ... "

	cat > $TMPDIR/libnltest.c << EOF
#include <libnl3/netlink/genl/genl.h>
#include <libnl3/netlink/genl/family.h>
#include <libnl3/netlink/genl/ctrl.h>
#include <libnl3/netlink/msg.h>
#include <libnl3/netlink/attr.h>
#include <libnl3/netlink/version.h>

#if LIBNL_VER_NUM < LIBNL_VER(3,0)
# error incompatible libnl version
#endif

void main(void) { }
EOF

	$CC $(pkg-config --cflags libnl-3.0) -o $TMPDIR/libnltest $TMPDIR/libnltest.c >> $TMPDIR/config.log 2>&1
	if [ ! -x $TMPDIR/libnltest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
	else
		echo "[YES]"
	fi
}

check_tpacket()
{
	echo -n "[*] Checking tpacket ... "

	cat > $TMPDIR/tpackettest.c << EOF
#include <stdio.h>
#include <linux/if_packet.h>

struct tpacket3_hdr *hdr;

void main(void)
{
	printf("%d\n", hdr->tp_status);
}
EOF

	$CC -o $TMPDIR/tpackettest $TMPDIR/tpackettest.c >> $TMPDIR/config.log 2>&1
	if [ ! -x $TMPDIR/tpackettest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
	else
		echo "[YES]"
	fi
}

check_ncurses()
{
	echo -n "[*] Checking ncurses ... "

	cat > $TMPDIR/ncursestest.c << EOF
#include <curses.h>

void main(void)
{
	WINDOW *screen = initscr();
}
EOF

	$CC $(pkg-config --cflags --libs ncurses) -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c >> $TMPDIR/config.log 2>&1
	if [ ! -x $TMPDIR/ncursestest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
	else
		echo "[YES]"
	fi
}

check_libgeoip()
{
	echo -n "[*] Checking libGeoIP ... "

	cat > $TMPDIR/geoiptest.c << EOF
#include <GeoIP.h>
#include <GeoIPCity.h>

void main(void)
{
	GeoIP *geoip;
}
EOF

	$CC -o $TMPDIR/geoiptest $TMPDIR/geoiptest.c >> $TMPDIR/config.log 2>&1
	if [ ! -x $TMPDIR/geoiptest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
	else
		echo "[YES]"
	fi

}

check_libnf_ct()
{
	echo -n "[*] Checking libnetfilter-conntrack ... "

	cat > $TMPDIR/nfcttest.c << EOF
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_dccp.h>
#include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>

void main(void)
{
	struct nfconntrack *ct;
}
EOF

	$CC -o $TMPDIR/nfcttest $TMPDIR/nfcttest.c >> $TMPDIR/config.log 2>&1
	if [ ! -x $TMPDIR/nfcttest ] ; then
		echo "[NO]"
		MISSING_DEFS=1
	else
		echo "[YES]"
	fi

}
echo "# This file is autogenerated by the configure script" > Config
check_nacl
check_libnl
check_tpacket
check_ncurses
check_libgeoip

if [ "$MISSING_DEFS" == "1" ] ; then
	echo "[!] Some libraries or header definitions are missing or too old."
	echo "    Please refer to the INSTALL file for the libraries needed to"
	echo "    build netsniff-ng."
	exit 1
fi

if [ "$MISSING_NACL" == "1" ] ; then
	echo "[!] The NaCl crypto library is currently not present on your"
	echo "    system or could not be found. Either install it from your"
	echo "    distro or build it manually using 'make nacl' and make sure"
	echo "    that the NACL_INC_DIR and NACL_LIB_DIR variables are set"
	echo "    appropriately."
	exit 1
fi

exit 0