1dnl Aircrack-ng
2dnl
3dnl Copyright (C) 2017 Joseph Benden <joe@benden.us>
4dnl
5dnl Autotool support was written by: Joseph Benden <joe@benden.us>
6dnl
7dnl This program is free software; you can redistribute it and/or modify
8dnl it under the terms of the GNU General Public License as published by
9dnl the Free Software Foundation; either version 2 of the License, or
10dnl (at your option) any later version.
11dnl
12dnl This program is distributed in the hope that it will be useful,
13dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15dnl GNU General Public License for more details.
16dnl
17dnl You should have received a copy of the GNU General Public License
18dnl along with this program; if not, write to the Free Software
19dnl Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20dnl
21dnl In addition, as a special exception, the copyright holders give
22dnl permission to link the code of portions of this program with the
23dnl OpenSSL library under certain conditions as described in each
24dnl individual source file, and distribute linked combinations
25dnl including the two.
26dnl
27dnl You must obey the GNU General Public License in all respects
28dnl for all of the code used other than OpenSSL.
29dnl
30dnl If you modify file(s) with this exception, you may extend this
31dnl exception to your dnl version of the file(s), but you are not obligated
32dnl to do so.
33dnl
34dnl If you dnl do not wish to do so, delete this exception statement from your
35dnl version.
36dnl
37dnl If you delete this exception statement from all source files in the
38dnl program, then also delete it here.
39
40AC_DEFUN([AIRCRACK_NG_PCAP], [
41AC_ARG_WITH(libpcap-include,
42    [AS_HELP_STRING([--with-libpcap-include=DIR],
43        [use PCAP includes in DIR, [default=auto]])
44    ],[
45    	if test -d "$withval" ; then
46    		CPPFLAGS="$CPPFLAGS -I$withval"
47    	fi
48    ])
49
50AC_ARG_WITH(libpcap-lib,
51    [AS_HELP_STRING([--with-libpcap-lib=DIR],
52        [use PCAP libraries in DIR, [default=auto]])
53    ],[
54    	if test -d "$withval" ; then
55    		LDFLAGS="$LDFLAGS -L$withval"
56    	fi
57    ])
58
59dnl
60dnl Search for headers
61dnl
62if test "${with_libpcap_include+set}" != set; then
63	AC_MSG_CHECKING(pcap header directories)
64
65	found_pcap_dir=""
66	for pcap_dir in /usr/include/pcap /usr/local/include/pcap \
67					$prefix/include ; do
68		if test -d "$pcap_dir" ; then
69			found_pcap_dir="$pcap_dir"
70			break
71		fi
72	done
73
74	if test "$found_pcap_dir" != "" ; then
75		PCAP_CFLAGS="-I$found_pcap_dir"
76		AC_SUBST([PCAP_CFLAGS])
77
78		AC_MSG_RESULT([$found_pcap_dir])
79	else
80		AC_MSG_RESULT([not found])
81	fi
82fi
83
84dnl
85dnl Verify that required headers are useable
86dnl
87saved_cflags="$CFLAGS"
88CFLAGS="$PCAP_INCLUDES $CFLAGS"
89AC_CHECK_HEADERS([pcap.h], [
90	PCAP_FOUND=yes
91], [
92	PCAP_FOUND=no
93])
94CFLAGS="$saved_cflags"
95
96AC_ARG_ENABLE(static-pcap,
97    AS_HELP_STRING([--enable-static-pcap],
98		[Enable statically linked PCAP libpcap.]),
99    [static_pcap=$enableval], [static_pcap=no])
100
101dnl
102dnl Locate the library
103dnl
104AS_IF([test "$PCAP_FOUND" = yes], [
105	if test "x$static_pcap" != "xno"; then
106		AC_REQUIRE([AX_EXT_HAVE_STATIC_LIB_DETECT])
107		AX_EXT_HAVE_STATIC_LIB(PCAP, ${DEFAULT_STATIC_LIB_SEARCH_PATHS}, pcap libpcap, pcap_open_live)
108		if test "x$PCAP_FOUND" = xyes; then
109			AC_DEFINE([HAVE_PCAP], [1])
110		fi
111	else
112		AC_CHECK_LIB([pcap], [pcap_open_live], [
113			PCAP_LIBS=-lpcap
114			AC_DEFINE([HAVE_PCAP], [1])
115			AC_SUBST(PCAP_LIBS)
116
117			PCAP_FOUND=yes
118		],[ PCAP_FOUND=no ])
119	fi
120])
121
122AM_CONDITIONAL([HAVE_PCAP], [test "$PCAP_FOUND" = yes])
123])
124