setting svn:exports
[jnettop.git] / jnettop / acinclude.m4
blobd29fb38983b3867069fc596e7624702bdef9bd71
2 # $Header$
4 AH_TEMPLATE([HAVE_GETHOSTBYADDR_R_5], [Set to 1 if gethostbyaddr_r takes 5 arguments])
5 AH_TEMPLATE([HAVE_GETHOSTBYADDR_R_7], [Set to 1 if gethostbyaddr_r takes 7 arguments])
6 AH_TEMPLATE([HAVE_GETHOSTBYADDR_R_8], [Set to 1 if gethostbyaddr_r takes 8 arguments])
7 AH_TEMPLATE([HAVE_PCAP_FREECODE_2], [Set to 1 if pcap_freecode takes 2 arguments])
8 AH_TEMPLATE([HAVE_PCAP_FREECODE_1], [Set to 1 if pcap_freecode takes 1 argument])
9 AH_TEMPLATE([HAVE_IP6_S6_ADDR32], [Set to 1 if struct in6_addr contains s6_addr32 member])
10 AH_TEMPLATE([HAVE_IP6__S6_UN__S6_U32], [Set to 1 if struct in6_addr contains _S6_un._S6_u32 member])
11 AH_TEMPLATE([HAVE_IP6___U6_ADDR___U6_ADDR32], [Set to 1 if struct in6_addr contains __u6_addr.__u6_addr32 member])
12 AH_TEMPLATE([NEED_REENTRANT], [Set to 1 if gethostbyaddr_r requires _REENTRANT symbol to be defined])
14 AC_DEFUN(AC_NETTOP_GCC_FLAGS,
16 if test "$GCC" = "yes"; then
17   CFLAGS="$CFLAGS -Wall"
23 # AC_NETTOP_GETHOSTBY_LIB_CHECK
25 # Checks whether we need "-lnsl" to get "gethostby*()", which we use
26 # in "resolv.c".
28 # Copied from EtherReal package ;
29 # Done by Jakub Skopal <j@kubs.cz> on 2002-08-22.
31 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
32 # GNU Autoconf 2.13; the comment came from there.
33 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14. 
35 AC_DEFUN(AC_NETTOP_GETHOSTBY_LIB_CHECK,
37     # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
38     # to get the SysV transport functions.
39     # chad@anasazi.com says the Pyramid MIS-ES running DC/OSx (SVR4)
40     # needs -lnsl.
41     # The nsl library prevents programs from opening the X display
42     # on Irix 5.2, according to dickey@clark.net.
43     AC_CHECK_FUNC(gethostbyname, ,
44         AC_CHECK_LIB(nsl, gethostbyname, NSL_LIBS="-lnsl"))
45     AC_SUBST(NSL_LIBS)
50 # AC_NETTOP_SOCKET_LIB_CHECK
52 # Checks whether we need "-lsocket" to get "socket()", which is used
53 # by libpcap on some platforms - and, in effect, "gethostby*()" on
54 # most if not all platforms (so that it can use NIS or DNS or...
55 # to look up host names).
57 # Copied from EtherReal package ;
58 # Done by Jakub Skopal <j@kubs.cz> on 2002-08-22.
60 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
61 # GNU Autoconf 2.13; the comment came from there.
62 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14. 
64 # We use "connect" because that's what AC_PATH_XTRA did.
66 AC_DEFUN(AC_NETTOP_SOCKET_LIB_CHECK,
68     # lieder@skyler.mavd.honeywell.com says without -lsocket,
69     # socket/setsockopt and other routines are undefined under SCO ODT
70     # 2.0.  But -lsocket is broken on IRIX 5.2 (and is not necessary
71     # on later versions), says simon@lia.di.epfl.ch: it contains
72     # gethostby* variants that don't use the nameserver (or something).
73     # -lsocket must be given before -lnsl if both are needed.
74     # We assume that if connect needs -lnsl, so does gethostbyname.
75     AC_CHECK_FUNC(connect, ,
76       AC_CHECK_LIB(socket, connect, SOCKET_LIBS="-lsocket",
77                 AC_MSG_ERROR(Function 'socket' not found.), $NSL_LIBS))
78     AC_SUBST(SOCKET_LIBS)
82 # AC_NETTOP_PCAP_CHECK
84 AC_DEFUN(AC_NETTOP_PCAP_CHECK,
86         if test -z "$pcap_dir"
87         then
88           #
89           # The user didn't specify a directory in which libpcap resides;
90           # we assume that the current library search path will work,
91           # but we may have to look for the header in a "pcap"
92           # subdirectory of "/usr/include" or "/usr/local/include",
93           # as some systems apparently put "pcap.h" in a "pcap"
94           # subdirectory, and we also check "$prefix/include".
95           #
96           # XXX - should we just add "$prefix/include" to the include
97           # search path and "$prefix/lib" to the library search path?
98           #
99           AC_MSG_CHECKING(for extraneous pcap header directories)
100           found_pcap_dir=""
101           for pcap_dir in /usr/include/pcap /usr/local/include/pcap $prefix/include
102           do
103             if test -d $pcap_dir ; then
104                 if test x$pcap_dir != x/usr/include; then
105                     CFLAGS="$CFLAGS -I$pcap_dir"
106                     CPPFLAGS="$CPPFLAGS -I$pcap_dir"
107                 fi
108                 found_pcap_dir=" $found_pcap_dir -I$pcap_dir"
109             fi
110           done
112           if test "$found_pcap_dir" != "" ; then
113             AC_MSG_RESULT(found --$found_pcap_dir added to CFLAGS)
114           else
115             AC_MSG_RESULT(not found)
116           fi
117         else
118           #
119           # The user specified a directory in which libpcap resides,
120           # so add the "include" subdirectory of that directory to
121           # the include file search path and the "lib" subdirectory
122           # of that directory to the library search path.
123           #
124           # XXX - if there's also a libpcap in a directory that's
125           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
126           # make us find the version in the specified directory,
127           # as the compiler and/or linker will search that other
128           # directory before it searches the specified directory.
129           #
130           CFLAGS="$CFLAGS -I$pcap_dir/include"
131           CPPFLAGS="$CPPFLAGS -I$pcap_dir/include"
132           LDFLAGS="$LDFLAGS -L$pcap_dir/lib"
133         fi
135         # Pcap header checks
136         AC_CHECK_HEADER(pcap.h,, AC_MSG_ERROR(Header file pcap.h not found.))
138         AC_CHECK_LIB(pcap, pcap_open_live,, AC_MSG_ERROR(Library libpcap not found.),
139           $SOCKET_LIBS $NSL_LIBS)
142 dnl ************************************************************
143 dnl check for "localhost", if it doesn't exist, we can't do the
144 dnl gethostbyname_r tests!
145 dnl 
146 dnl Copied from cURL package ;
147 dnl Done by Jakub Skopal <j@kubs.cz> on 2002-08-28.
150 AC_DEFUN(AC_NETTOP_CHECK_WORKING_RESOLVER,[
151 AC_MSG_CHECKING([if "localhost" resolves])
152 AC_TRY_RUN([
153 #include <string.h>
154 #include <sys/types.h>
155 #include <netdb.h>
158 main () {
159 struct hostent *h;
160 h = gethostbyname("localhost");
161 exit (h == NULL ? 1 : 0); }],[
162       AC_MSG_RESULT(yes)],[
163       AC_MSG_RESULT(no)
164       AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
166       ]
171 dnl Try to discover struct in6_addr members
173 AC_DEFUN(AC_NETTOP_CHECK_IN6_ADDR,
175   AC_MSG_CHECKING([if struct in6_addr contains s6_addr32 member])
176   AC_TRY_COMPILE([
177 #include <sys/types.h>
178 #include <netinet/in.h>],[
179 struct in6_addr adr;
180 adr.s6_addr32[0]=0;
182     AC_MSG_RESULT(yes)
183     AC_DEFINE(HAVE_IP6_S6_ADDR32)],[
184       AC_MSG_RESULT(no)
185       AC_MSG_CHECKING([if struct in6_addr contains _S6_un._S6_u32 member])
186       AC_TRY_COMPILE([
187 #include <sys/types.h>
188 #include <netinet/in.h>],[
189 struct in6_addr adr;
190 adr._S6_un._S6_u32[0]=0;
192         AC_MSG_RESULT(yes)
193         AC_DEFINE(HAVE_IP6__S6_UN__S6_U32)],[
194           AC_MSG_RESULT(no)
195           AC_MSG_CHECKING([if struct in6_addr contains __u6_addr.__u6_addr32 member])
196           AC_TRY_COMPILE([
197 #include <sys/types.h>
198 #include <netinet/in.h>],[
199 struct in6_addr adr;
200 adr.__u6_addr.__u6_addr32[0]=0;
202             AC_MSG_RESULT(yes)
203             AC_DEFINE(HAVE_IP6___U6_ADDR___U6_ADDR32)],[
204               AC_MSG_RESULT(no)
205               AC_MSG_ERROR([can't figure out members of struct in6_addr])
206             ]
207           )
208         ]
209       )
210     ]
211   )
215 dnl Find number of arguments of pcap_freecode
217 AC_DEFUN(AC_NETTOP_CHECK_PCAP_FREECODE,
219   dnl check for number of arguments to pcap_freecode. it might take
220   dnl either 1 or 2.
221     AC_MSG_CHECKING(if pcap_freecode takes 2 arguments)
222     AC_TRY_COMPILE([
223 #include <pcap.h>],[
224 struct bpf_program *program;
225 pcap_t *pcap;
226 pcap_freecode(pcap, program);],[
227       AC_MSG_RESULT(yes)
228       AC_DEFINE(HAVE_PCAP_FREECODE_2)
229       ac_cv_pcap_freecode_args=2],[
230       AC_MSG_RESULT(no)
231       AC_MSG_CHECKING(if pcap_freecode takes 1 argument)
232       AC_TRY_COMPILE([
233 #include <pcap.h>],[
234 struct bpf_program *program;
235 pcap_freecode(program);],[
236         AC_MSG_RESULT(yes)
237         AC_DEFINE(HAVE_PCAP_FREECODE_1)
238         ac_cv_pcap_freecode_args=1],[
239           AC_MSG_RESULT(no)
240           AC_MSG_ERROR([cannot discover number of arguments of pcap_freecode])
241         ]
242       )]
243     )]
247 dnl 
248 dnl Copied from cURL package ;
249 dnl Done by Jakub Skopal <j@kubs.cz> on 2002-08-28.
251 AC_DEFUN(AC_NETTOP_CHECK_GETHOSTBYADDR_R,
253   AC_ARG_ENABLE(multithreaded-resolver, AC_HELP_STRING([--disable-multithreaded-resolver],[do not try to use multithreaded resolver !!FreeBSD!!]), disable_multithreaded_resolver=yes)
255   if test "x$disable_multithreaded_resolver" != "xyes"; then
257   if uname -a | grep "FreeBSD" > /dev/null 2>&1; then
258     echo "**********************************************************************"
259     echo "**  configure script detected, that you're using FreeBSD.           **"
260     echo "**  5.1-RELEASE and maybe others have been found to contain         **"
261     echo "**  bogus implementation of gethostbyaddr_r function.               **"
262     echo "**                                                                  **"
263     echo "**  IN CASE YOU ENCOUNTER ANY Bus Error OR SegFault PROBLEMS WITH   **"
264     echo "**  jnettop, PLEASE SPECIFY --disable-multithreaded-resolver        **"
265     echo "**  OPTION TO CONFIGURE SCRIPT!!                                    **"
266     echo "**********************************************************************"
267   fi
269   dnl check for number of arguments to gethostbyaddr_r. it might take
270   dnl either 5, 7, or 8 arguments.
271   AC_CHECK_FUNCS(gethostbyaddr_r,[
272     AC_MSG_CHECKING(if gethostbyaddr_r takes 5 arguments)
273     AC_TRY_COMPILE([
274 #include <sys/types.h>
275 #include <netdb.h>],[
276 char * address;
277 int length;
278 int type;
279 struct hostent h;
280 struct hostent_data hdata;
281 int rc;
282 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
283       AC_MSG_RESULT(yes)
284       AC_DEFINE(HAVE_GETHOSTBYADDR_R_5)
285       ac_cv_gethostbyaddr_args=5],[
286       AC_MSG_RESULT(no)
287       AC_MSG_CHECKING(if gethostbyaddr_r with -D_REENTRANT takes 5 arguments)
288       AC_TRY_COMPILE([
289 #define _REENTRANT
290 #include <sys/types.h>
291 #include <netdb.h>],[
292 char * address;
293 int length;
294 int type;
295 struct hostent h;
296 struct hostent_data hdata;
297 int rc;
298 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
299         AC_MSG_RESULT(yes)
300         AC_DEFINE(HAVE_GETHOSTBYADDR_R_5)
301         AC_DEFINE(NEED_REENTRANT)
302         ac_cv_gethostbyaddr_args=5],[
303           AC_MSG_RESULT(no)
304           AC_MSG_CHECKING(if gethostbyaddr_r takes 8 arguments)
305           AC_TRY_COMPILE([
306 #include <sys/types.h>
307 #include <netdb.h>],[
308 char * address;
309 int length;
310 int type;
311 struct hostent h;
312 char buffer[8192];
313 int h_errnop;
314 struct hostent * hp;
315 int rc;
317 rc = gethostbyaddr_r(address, length, type, &h,
318                      buffer, 8192, &hp, &h_errnop);],[
319             AC_MSG_RESULT(yes)
320             AC_DEFINE(HAVE_GETHOSTBYADDR_R_8)
321             ac_cv_gethostbyaddr_args=8],[
322             AC_MSG_RESULT(no)
323             have_missing_r_funcs="$have_missing_r_funcs gethostbyaddr_r"])])])])
325         fi