Move the routine to get a list of the network interfaces on the system
[obnox/wireshark/wip.git] / acinclude.m4
1 dnl Macros that test for specific features.
2 dnl This file is part of the Autoconf packaging for Ethereal.
3 dnl Copyright (C) 1998-2000 by Gerald Combs.
4 dnl
5 dnl $Id: acinclude.m4,v 1.19 2000/01/15 21:01:04 guy Exp $
6 dnl
7 dnl This program is free software; you can redistribute it and/or modify
8 dnl it under the terms of the GNU General Public License as published by
9 dnl the Free Software Foundation; either version 2, or (at your option)
10 dnl any later version.
11 dnl
12 dnl This program is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 dnl GNU General Public License for more details.
16 dnl
17 dnl You should have received a copy of the GNU General Public License
18 dnl along with this program; if not, write to the Free Software
19 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 dnl 02111-1307, USA.
21 dnl
22 dnl As a special exception, the Free Software Foundation gives unlimited
23 dnl permission to copy, distribute and modify the configure scripts that
24 dnl are the output of Autoconf.  You need not follow the terms of the GNU
25 dnl General Public License when using or distributing such scripts, even
26 dnl though portions of the text of Autoconf appear in them.  The GNU
27 dnl General Public License (GPL) does govern all other use of the material
28 dnl that constitutes the Autoconf program.
29 dnl
30 dnl Certain portions of the Autoconf source text are designed to be copied
31 dnl (in certain cases, depending on the input) into the output of
32 dnl Autoconf.  We call these the "data" portions.  The rest of the Autoconf
33 dnl source text consists of comments plus executable code that decides which
34 dnl of the data portions to output in any given case.  We call these
35 dnl comments and executable code the "non-data" portions.  Autoconf never
36 dnl copies any of the non-data portions into its output.
37 dnl
38 dnl This special exception to the GPL applies to versions of Autoconf
39 dnl released by the Free Software Foundation.  When you make and
40 dnl distribute a modified version of Autoconf, you may extend this special
41 dnl exception to the GPL to apply to your modified version as well, *unless*
42 dnl your modified version has the potential to copy into its output some
43 dnl of the text that was the non-data portion of the version that you started
44 dnl with.  (In other words, unless your change moves or copies text from
45 dnl the non-data portions to the data portions.)  If your modification has
46 dnl such potential, you must delete any notice of this special exception
47 dnl to the GPL from your modified version.
48 dnl
49 dnl Written by David MacKenzie, with help from
50 dnl Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
51 dnl Roland McGrath, Noah Friedman, david d zuhn, and many others.
52
53 #
54 # AC_ETHEREAL_ADD_DASH_L
55 #
56 # Add to the variable specified as the first argument a "-L" flag for the
57 # directory specified as the second argument, and, on Solaris, add a
58 # "-R" flag for it as well.
59 #
60 # XXX - IRIX, and other OSes, may require some flag equivalent to
61 # "-R" here.
62 #
63 AC_DEFUN(AC_ETHEREAL_ADD_DASH_L,
64 [$1="$$1 -L$2"
65 case "$host_os" in
66   solaris*)
67     $1="$$1 -R$2"
68   ;;
69 esac
70 ])
71
72
73 #
74 # AC_ETHEREAL_STRUCT_SA_LEN
75 #
76 dnl AC_STRUCT_ST_BLKSIZE extracted from the file in question,
77 dnl "acspecific.m4" in GNU Autoconf 2.12, and turned into
78 dnl AC_ETHEREAL_STRUCT_SA_LEN, which checks if "struct sockaddr"
79 dnl has the 4.4BSD "sa_len" member, and defines HAVE_SA_LEN; that's
80 dnl what's in this file.
81 dnl Done by Guy Harris <guy@alum.mit.edu> on 1998-11-14. 
82
83 dnl ### Checks for structure members
84
85 AC_DEFUN(AC_ETHEREAL_STRUCT_SA_LEN,
86 [AC_CACHE_CHECK([for sa_len in struct sockaddr], ac_cv_ethereal_struct_sa_len,
87 [AC_TRY_COMPILE([#include <sys/types.h>
88 #include <sys/socket.h>], [struct sockaddr s; s.sa_len;],
89 ac_cv_ethereal_struct_sa_len=yes, ac_cv_ethereal_struct_sa_len=no)])
90 if test $ac_cv_ethereal_struct_sa_len = yes; then
91   AC_DEFINE(HAVE_SA_LEN)
92 fi
93 ])
94
95 #
96 # AC_ETHEREAL_IPV6_STACK
97 #
98 # By Jun-ichiro "itojun" Hagino, <itojun@iijlab.net>
99 #
100 AC_DEFUN(AC_ETHEREAL_IPV6_STACK,
101 [
102         v6type=unknown
103         v6lib=none
104
105         AC_MSG_CHECKING([ipv6 stack type])
106         for i in v6d toshiba kame inria zeta linux; do
107                 case $i in
108                 v6d)
109                         AC_EGREP_CPP(yes, [dnl
110 #include </usr/local/v6/include/sys/types.h>
111 #ifdef __V6D__
112 yes
113 #endif],
114                                 [v6type=$i; v6lib=v6;
115                                 v6libdir=/usr/local/v6/lib;
116                                 CFLAGS="-I/usr/local/v6/include $CFLAGS"])
117                         ;;
118                 toshiba)
119                         AC_EGREP_CPP(yes, [dnl
120 #include <sys/param.h>
121 #ifdef _TOSHIBA_INET6
122 yes
123 #endif],
124                                 [v6type=$i; v6lib=inet6;
125                                 v6libdir=/usr/local/v6/lib;
126                                 CFLAGS="-DINET6 $CFLAGS"])
127                         ;;
128                 kame)
129                         AC_EGREP_CPP(yes, [dnl
130 #include <netinet/in.h>
131 #ifdef __KAME__
132 yes
133 #endif],
134                                 [v6type=$i; v6lib=inet6;
135                                 v6libdir=/usr/local/v6/lib;
136                                 CFLAGS="-DINET6 $CFLAGS"])
137                         ;;
138                 inria)
139                         AC_EGREP_CPP(yes, [dnl
140 #include <netinet/in.h>
141 #ifdef IPV6_INRIA_VERSION
142 yes
143 #endif],
144                                 [v6type=$i; CFLAGS="-DINET6 $CFLAGS"])
145                         ;;
146                 zeta)
147                         AC_EGREP_CPP(yes, [dnl
148 #include <sys/param.h>
149 #ifdef _ZETA_MINAMI_INET6
150 yes
151 #endif],
152                                 [v6type=$i; v6lib=inet6;
153                                 v6libdir=/usr/local/v6/lib;
154                                 CFLAGS="-DINET6 $CFLAGS"])
155                         ;;
156                 linux)
157                         if test -d /usr/inet6; then
158                                 v6type=$i
159                                 v6lib=inet6
160                                 v6libdir=/usr/inet6
161                                 CFLAGS="-DINET6 $CFLAGS"
162                         fi
163                         ;;
164                 esac
165                 if test "$v6type" != "unknown"; then
166                         break
167                 fi
168         done
169
170         if test "$v6lib" != "none"; then
171                 for dir in $v6libdir /usr/local/v6/lib /usr/local/lib; do
172                         if test -d $dir -a -f $dir/lib$v6lib.a; then
173                                 LIBS="-L$dir $LIBS -l$v6lib"
174                                 break
175                         fi
176                 done
177                 enable_ipv6="yes"
178         else
179                 enable_ipv6="no"
180         fi
181         AC_MSG_RESULT(["$v6type, $v6lib"])
182 ])
183
184 #
185 # AC_ETHEREAL_GETHOSTBY_LIB_CHECK
186 #
187 # Checks whether we need "-lnsl" to get "gethostby*()", which we use
188 # in "resolv.c".
189 #
190 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
191 # GNU Autoconf 2.13; the comment came from there.
192 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14. 
193 #
194 AC_DEFUN(AC_ETHEREAL_GETHOSTBY_LIB_CHECK,
195 [
196     # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
197     # to get the SysV transport functions.
198     # chad@anasazi.com says the Pyramid MIS-ES running DC/OSx (SVR4)
199     # needs -lnsl.
200     # The nsl library prevents programs from opening the X display
201     # on Irix 5.2, according to dickey@clark.net.
202     AC_CHECK_FUNC(gethostbyname)
203     if test $ac_cv_func_gethostbyname = no; then
204       AC_CHECK_LIB(nsl, gethostbyname, NSL_LIBS="-lnsl")
205     fi
206     AC_SUBST(NSL_LIBS)
207 ])
208
209 #
210 # AC_ETHEREAL_SOCKET_LIB_CHECK
211 #
212 # Checks whether we need "-lsocket" to get "socket()", which is used
213 # by libpcap on some platforms - and, in effect, "gethostby*()" on
214 # most if not all platforms (so that it can use NIS or DNS or...
215 # to look up host names).
216 #
217 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
218 # GNU Autoconf 2.13; the comment came from there.
219 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14. 
220 #
221 # We use "connect" because that's what AC_PATH_XTRA did.
222 #
223 AC_DEFUN(AC_ETHEREAL_SOCKET_LIB_CHECK,
224 [
225     # lieder@skyler.mavd.honeywell.com says without -lsocket,
226     # socket/setsockopt and other routines are undefined under SCO ODT
227     # 2.0.  But -lsocket is broken on IRIX 5.2 (and is not necessary
228     # on later versions), says simon@lia.di.epfl.ch: it contains
229     # gethostby* variants that don't use the nameserver (or something).
230     # -lsocket must be given before -lnsl if both are needed.
231     # We assume that if connect needs -lnsl, so does gethostbyname.
232     AC_CHECK_FUNC(connect)
233     if test $ac_cv_func_connect = no; then
234       AC_CHECK_LIB(socket, connect, SOCKET_LIBS="-lsocket",
235                 AC_MSG_ERROR(Function 'socket' not found.), $NSL_LIBS)
236     fi
237     AC_SUBST(SOCKET_LIBS)
238 ])
239
240 #
241 # AC_ETHEREAL_PCAP_CHECK
242 #
243 AC_DEFUN(AC_ETHEREAL_PCAP_CHECK,
244 [
245         # Evidently, some systems have pcap.h, etc. in */include/pcap
246         AC_MSG_CHECKING(for extraneous pcap header directories)
247         found_pcap_dir=""
248         for pcap_dir in /usr/include/pcap /usr/local/include/pcap $prefix/include
249         do
250           if test -d $pcap_dir ; then
251             CFLAGS="$CFLAGS -I$pcap_dir"
252             CPPFLAGS="$CPPFLAGS -I$pcap_dir"
253             found_pcap_dir=" $found_pcap_dir -I$pcap_dir"
254           fi
255         done
256
257         if test "$found_pcap_dir" != "" ; then
258           AC_MSG_RESULT(found --$found_pcap_dir added to CFLAGS)
259         else
260           AC_MSG_RESULT(not found)
261         fi
262
263         # Pcap header checks
264         AC_CHECK_HEADER(net/bpf.h,,
265             AC_MSG_ERROR([[Header file net/bpf.h not found; if you installed libpcap from source, did you also do \"make install-incl\"?]]))
266         AC_CHECK_HEADER(pcap.h,, AC_MSG_ERROR(Header file pcap.h not found.))
267
268         #
269         # Try various directories to find libpcap
270         #
271         AC_CHECK_LIB(pcap, pcap_open_live,
272           [
273             PCAP_LIBS=-lpcap
274             AC_DEFINE(HAVE_LIBPCAP)
275           ],
276           [
277             #
278             # Throw away the cached "we didn't find it"
279             # answer, and see if it's in "/usr/local/lib".
280             #
281             unset ac_cv_lib_pcap_pcap_open_live
282             ethereal_save_LIBS="$LIBS"
283             AC_ETHEREAL_ADD_DASH_L(LIBS, /usr/local/lib)
284             AC_CHECK_LIB(pcap, pcap_open_live,
285               [
286                 #
287                 # Throw away the cached "we found it" answer, so that if
288                 # we rerun "configure", we don't just blow off the above
289                 # checks and blithely assume that we don't need to search
290                 # "/usr/local/lib".
291                 #
292                 # XXX - autoconf really needs a way to test for a given
293                 # routine in a given library *and* to test whether additional
294                 # "-L"/"-R"/whatever flags are needed *before* the "-l"
295                 # flag for the library and to test whether additional libraries
296                 # are needed after the library *and* to cache all that
297                 # information.
298                 #
299                 unset ac_cv_lib_pcap_pcap_open_live
300                 AC_ETHEREAL_ADD_DASH_L(PCAP_LIBS, /usr/local/lib)
301                 PCAP_LIBS="$PCAP_LIBS -lpcap"
302                 AC_DEFINE(HAVE_LIBPCAP)
303                 LIBS="$ethereal_save_LIBS"
304               ],
305               [
306                 #
307                 # Throw away the cached "we didn't find it"
308                 # answer, and see if it's in "$prefix/lib".
309                 #
310                 unset ac_cv_lib_pcap_pcap_open_live
311                 LIBS="$ethereal_save_LIBS -L$prefix/lib"
312                 AC_CHECK_LIB(pcap, pcap_open_live,
313                   [
314                     #
315                     # Throw away the cached "we found it" answer, so that if
316                     # we rerun "configure", we don't just blow off the above
317                     # checks and blithely assume that we don't need to search
318                     # "$prefix/lib".
319                     #
320                     unset ac_cv_lib_pcap_pcap_open_live
321                     AC_ETHEREAL_ADD_DASH_L(PCAP_LIBS, $prefix/lib)
322                     PCAP_LIBS="$PCAP_LIBS -lpcap"
323                     AC_DEFINE(HAVE_LIBPCAP)
324                     LIBS="$ethereal_save_LIBS"
325                   ],
326                   AC_MSG_ERROR(Library libpcap not found.),
327                   $SOCKET_LIBS $NSL_LIBS)
328               ], $SOCKET_LIBS $NSL_LIBS)
329           ], $SOCKET_LIBS $NSL_LIBS)
330         AC_SUBST(PCAP_LIBS)
331 ])
332
333 #
334 # AC_ETHEREAL_ZLIB_CHECK
335 #
336 AC_DEFUN(AC_ETHEREAL_ZLIB_CHECK,
337 [
338         AC_CHECK_HEADER(zlib.h,,enable_zlib=no)
339
340         dnl
341         dnl Check for "gzgets()" in zlib, because we need it, but
342         dnl some older versions of zlib don't have it.  It appears
343         dnl from the ChangeLog that any released version of zlib
344         dnl with "gzgets()" should have the other routines we
345         dnl depend on, such as "gzseek()", "gztell()", and "zError()".
346         dnl
347         AC_CHECK_LIB(z, gzgets,,enable_zlib=no)
348 ])
349
350 #
351 # AC_ETHEREAL_UCDSNMP_CHECK
352 #
353 AC_DEFUN(AC_ETHEREAL_UCDSNMP_CHECK,
354 [
355         want_ucdsnmp=yes
356
357         AC_ARG_WITH(ucdsnmp,
358         [  --with-ucdsnmp=DIR      use UCD SNMP client library, located in directory DIR.], [
359         if test $withval = no
360         then
361                 want_ucdsnmp=no
362         else
363                 want_ucdsnmp=yes
364                 ucdsnmp_user_dir=$withval
365         fi
366         ])
367
368         if test $want_ucdsnmp = yes
369         then
370                 ucdsnmpdir=""
371
372                 for d in $ucdsnmp_user_dir $prefix
373                 do
374                         if test x$d != xNONE 
375                         then
376                                 AC_MSG_CHECKING($d for ucd-snmp)
377
378                                 if test x$d != x/usr/local && test -f $d/include/ucd-snmp/snmp.h
379                                 then
380                                         AC_MSG_RESULT(found)
381                                         ucdsnmpdir=$d
382                                         break
383                                 else
384                                         AC_MSG_RESULT(not found)
385                                 fi
386                         fi
387                 done
388
389                 if test x$ucdsnmpdir != x
390                 then
391                         AC_MSG_RESULT(added $d to paths)
392                         CFLAGS="$CFLAGS -I${ucdsnmpdir}/include"
393                         CPPFLAGS="$CPPFLAGS -I${ucdsnmpdir}/include"
394                         LIBS="$LIBS -L${ucdsnmpdir}/lib"
395                 fi
396         fi
397 ])