From Anders: Fix wrong tag numbers.
[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 Wireshark.
3 dnl Copyright (C) 1998-2000 by Gerald Combs.
4 dnl
5 dnl $Id$
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_WIRESHARK_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_WIRESHARK_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_WIRESHARK_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_WIRESHARK_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_WIRESHARK_STRUCT_SA_LEN],
86 [AC_CACHE_CHECK([for sa_len in struct sockaddr], ac_cv_wireshark_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_wireshark_struct_sa_len=yes, ac_cv_wireshark_struct_sa_len=no)])
90 if test $ac_cv_wireshark_struct_sa_len = yes; then
91   AC_DEFINE(HAVE_SA_LEN, 1, [Define if sa_len field exists in struct sockaddr])
92 fi
93 ])
94
95
96 #
97 # AC_WIRESHARK_IPV6_STACK
98 #
99 # By Jun-ichiro "itojun" Hagino, <itojun@iijlab.net>
100 #
101 AC_DEFUN([AC_WIRESHARK_IPV6_STACK],
102 [
103         v6type=unknown
104         v6lib=none
105
106         AC_MSG_CHECKING([ipv6 stack type])
107         for i in v6d toshiba kame inria zeta linux linux-glibc solaris8; do
108                 case $i in
109                 v6d)
110                         AC_EGREP_CPP(yes, [
111 #include </usr/local/v6/include/sys/types.h>
112 #ifdef __V6D__
113 yes
114 #endif],
115                                 [v6type=$i; v6lib=v6;
116                                 v6libdir=/usr/local/v6/lib;
117                                 CFLAGS="-I/usr/local/v6/include $CFLAGS"])
118                         ;;
119                 toshiba)
120                         AC_EGREP_CPP(yes, [
121 #include <sys/param.h>
122 #ifdef _TOSHIBA_INET6
123 yes
124 #endif],
125                                 [v6type=$i; v6lib=inet6;
126                                 v6libdir=/usr/local/v6/lib;
127                                 CFLAGS="-DINET6 $CFLAGS"])
128                         ;;
129                 kame)
130                         AC_EGREP_CPP(yes, [
131 #include <netinet/in.h>
132 #ifdef __KAME__
133 yes
134 #endif],
135                                 [v6type=$i; v6lib=inet6;
136                                 v6libdir=/usr/local/v6/lib;
137                                 CFLAGS="-DINET6 $CFLAGS"])
138                         ;;
139                 inria)
140                         AC_EGREP_CPP(yes, [
141 #include <netinet/in.h>
142 #ifdef IPV6_INRIA_VERSION
143 yes
144 #endif],
145                                 [v6type=$i; CFLAGS="-DINET6 $CFLAGS"])
146                         ;;
147                 zeta)
148                         AC_EGREP_CPP(yes, [
149 #include <sys/param.h>
150 #ifdef _ZETA_MINAMI_INET6
151 yes
152 #endif],
153                                 [v6type=$i; v6lib=inet6;
154                                 v6libdir=/usr/local/v6/lib;
155                                 CFLAGS="-DINET6 $CFLAGS"])
156                         ;;
157                 linux)
158                         if test -d /usr/inet6; then
159                                 v6type=$i
160                                 v6lib=inet6
161                                 v6libdir=/usr/inet6
162                                 CFLAGS="-DINET6 $CFLAGS"
163                         fi
164                         ;;
165                 linux-glibc)
166                         AC_EGREP_CPP(yes, [
167 #include <features.h>
168 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
169 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || __GLIBC__ > 2
170 yes
171 #endif
172 #endif],
173                         [v6type=$i; v6lib=inet6; CFLAGS="-DINET6 $CFLAGS"])
174                         ;;
175                 solaris8)
176                         if test "`uname -s`" = "SunOS" && test "`uname -r`" = "5.8"; then
177                                 v6type=$i
178                                 v6lib=inet6
179                                 [CFLAGS="-DINET6 -DSOLARIS8_INET6 $CFLAGS"]
180                         fi
181                         ;;
182                 esac
183                 if test "$v6type" != "unknown"; then
184                         break
185                 fi
186         done
187
188         if test "$v6lib" != "none"; then
189                 for dir in $v6libdir /usr/local/v6/lib /usr/local/lib; do
190                         if test -d $dir -a -f $dir/lib$v6lib.a; then
191                                 LIBS="-L$dir $LIBS -l$v6lib"
192                                 break
193                         fi
194                 done
195                 enable_ipv6="yes"
196         else
197                 enable_ipv6="no"
198         fi
199         AC_MSG_RESULT(["$v6type, $v6lib"])
200 ])
201
202 #
203 # AC_WIRESHARK_GETHOSTBY_LIB_CHECK
204 #
205 # Checks whether we need "-lnsl" to get "gethostby*()", which we use
206 # in "resolv.c".
207 #
208 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
209 # GNU Autoconf 2.13; the comment came from there.
210 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14.
211 #
212 AC_DEFUN([AC_WIRESHARK_GETHOSTBY_LIB_CHECK],
213 [
214     # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
215     # to get the SysV transport functions.
216     # chad@anasazi.com says the Pyramid MIS-ES running DC/OSx (SVR4)
217     # needs -lnsl.
218     # The nsl library prevents programs from opening the X display
219     # on Irix 5.2, according to dickey@clark.net.
220     AC_CHECK_FUNC(gethostbyname, ,
221         AC_CHECK_LIB(nsl, gethostbyname, NSL_LIBS="-lnsl"))
222     AC_SUBST(NSL_LIBS)
223 ])
224
225 #
226 # AC_WIRESHARK_SOCKET_LIB_CHECK
227 #
228 # Checks whether we need "-lsocket" to get "socket()", which is used
229 # by libpcap on some platforms - and, in effect, "gethostby*()" on
230 # most if not all platforms (so that it can use NIS or DNS or...
231 # to look up host names).
232 #
233 # Adapted from stuff in the AC_PATH_XTRA macro in "acspecific.m4" in
234 # GNU Autoconf 2.13; the comment came from there.
235 # Done by Guy Harris <guy@alum.mit.edu> on 2000-01-14.
236 #
237 # We use "connect" because that's what AC_PATH_XTRA did.
238 #
239 AC_DEFUN([AC_WIRESHARK_SOCKET_LIB_CHECK],
240 [
241     # lieder@skyler.mavd.honeywell.com says without -lsocket,
242     # socket/setsockopt and other routines are undefined under SCO ODT
243     # 2.0.  But -lsocket is broken on IRIX 5.2 (and is not necessary
244     # on later versions), says simon@lia.di.epfl.ch: it contains
245     # gethostby* variants that don't use the nameserver (or something).
246     # -lsocket must be given before -lnsl if both are needed.
247     # We assume that if connect needs -lnsl, so does gethostbyname.
248     AC_CHECK_FUNC(connect, ,
249       AC_CHECK_LIB(socket, connect, SOCKET_LIBS="-lsocket",
250                 AC_MSG_ERROR(Function 'socket' not found.), $NSL_LIBS))
251     AC_SUBST(SOCKET_LIBS)
252 ])
253
254 #
255 # AC_WIRESHARK_BREAKLOOP_TRY_LINK
256 #
257 AC_DEFUN([AC_WIRESHARK_PCAP_BREAKLOOP_TRY_LINK],
258 [
259   AC_LINK_IFELSE(
260   [
261       AC_LANG_SOURCE(
262       [[
263 #       include <pcap.h>
264         int main(void)
265         {
266           pcap_t  *pct = NULL;
267           pcap_breakloop(pct);
268           return 0;
269         }
270       ]])
271   ],
272   [
273     ws_breakloop_compiled=yes
274   ],
275   [
276     ws_breakloop_compiled=no
277   ])
278 ])
279
280
281
282 #
283 # AC_WIRESHARK_PCAP_CHECK
284 #
285 AC_DEFUN([AC_WIRESHARK_PCAP_CHECK],
286 [
287         if test -z "$pcap_dir"
288         then
289           # Pcap header checks
290           # XXX need to set a var AC_CHECK_HEADER(pcap.h,,)
291
292           #
293           # The user didn't specify a directory in which libpcap resides.
294           # First, look for a pcap-config script.
295           #
296           AC_PATH_PROG(PCAP_CONFIG, pcap-config)
297
298           #
299           # Now check whether it's the libpcap 1.0 version, which
300           # put a space after "-L" - on some platforms, that doesn't
301           # work.
302           #
303           AC_MSG_CHECKING(for broken pcap-config)
304           if test -n "$PCAP_CONFIG" ; then
305             case "`\"$PCAP_CONFIG\" --libs`" in
306
307             "-L "*)
308               #
309               # Space after -L.  Pretend pcap-config doesn't exist.
310               #
311               AC_MSG_RESULT(yes)
312               PCAP_CONFIG=""
313               ;;
314
315             *)
316               #
317               # No space after -L.
318               #
319               AC_MSG_RESULT(no)
320               ;;
321             esac
322           fi
323           if test -n "$PCAP_CONFIG" ; then
324             #
325             # Found - use it to get the include flags for
326             # libpcap.
327             #
328             CFLAGS="$CFLAGS `\"$PCAP_CONFIG\" --cflags`"
329             CPPFLAGS="$CPPFLAGS `\"$PCAP_CONFIG\" --cflags`"
330           else  
331             #
332             # Didn't find it; we have to look for libpcap ourselves.
333             # We assume that the current library search path will work,
334             # but we may have to look for the header in a "pcap"
335             # subdirectory of "/usr/include" or "/usr/local/include",
336             # as some systems apparently put "pcap.h" in a "pcap"
337             # subdirectory, and we also check "$prefix/include" - and
338             # "$prefix/include/pcap", in case $prefix is set to
339             # "/usr/include" or "/usr/local/include".
340             #
341             # XXX - should we just add "$prefix/include" to the include
342             # search path and "$prefix/lib" to the library search path?
343             #
344             AC_MSG_CHECKING(for extraneous pcap header directories)
345             found_pcap_dir=""
346             pcap_dir_list="/usr/include/pcap $prefix/include/pcap $prefix/include"
347             if test "x$ac_cv_enable_usr_local" = "xyes" ; then
348               pcap_dir_list="$pcap_dir_list /usr/local/include/pcap"
349             fi
350             for pcap_dir in $pcap_dir_list
351             do
352               if test -d $pcap_dir ; then
353                 if test x$pcap_dir != x/usr/include -a x$pcap_dir != x/usr/local/include ; then
354                     CFLAGS="$CFLAGS -I$pcap_dir"
355                     CPPFLAGS="$CPPFLAGS -I$pcap_dir"
356                 fi
357                 found_pcap_dir=" $found_pcap_dir -I$pcap_dir"
358                 break
359               fi
360             done
361
362             if test "$found_pcap_dir" != "" ; then
363               AC_MSG_RESULT(found --$found_pcap_dir added to CFLAGS)
364             else
365               AC_MSG_RESULT(not found)
366             fi
367           fi
368         else
369           #
370           # The user specified a directory in which libpcap resides,
371           # so add the "include" subdirectory of that directory to
372           # the include file search path and the "lib" subdirectory
373           # of that directory to the library search path.
374           #
375           # XXX - if there's also a libpcap in a directory that's
376           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
377           # make us find the version in the specified directory,
378           # as the compiler and/or linker will search that other
379           # directory before it searches the specified directory.
380           #
381           CFLAGS="$CFLAGS -I$pcap_dir/include"
382           CPPFLAGS="$CPPFLAGS -I$pcap_dir/include"
383           AC_WIRESHARK_ADD_DASH_L(LDFLAGS, $pcap_dir/lib)
384         fi
385
386         # Pcap header check
387         AC_CHECK_HEADER(pcap.h,,
388             AC_MSG_ERROR([[Header file pcap.h not found; if you installed libpcap
389 from source, did you also do \"make install-incl\", and if you installed a
390 binary package of libpcap, is there also a developer's package of libpcap,
391 and did you also install that package?]]))
392
393         if test -n "$PCAP_CONFIG" ; then
394           #
395           # We have pcap-config; we assume that means we have libpcap
396           # installed and that pcap-config will tell us whatever
397           # libraries libpcap needs.
398           #
399           if test x$enable_static = xyes; then
400             PCAP_LIBS="`\"$PCAP_CONFIG\" --libs --static`"
401           else
402             PCAP_LIBS="`\"$PCAP_CONFIG\" --libs`"
403           fi
404           AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
405         else
406           #
407           # Check to see if we find "pcap_open_live" in "-lpcap".
408           # Also check for various additional libraries that libpcap might
409           # require.
410           #
411           AC_CHECK_LIB(pcap, pcap_open_live,
412             [
413               PCAP_LIBS=-lpcap
414               AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
415             ], [
416               ac_wireshark_extras_found=no
417               ac_save_LIBS="$LIBS"
418               for extras in "-lcfg -lodm" "-lpfring"
419               do
420                 AC_MSG_CHECKING([for pcap_open_live in -lpcap with $extras])
421                 LIBS="-lpcap $extras"
422                 #
423                 # XXX - can't we use AC_CHECK_LIB here?
424                 #
425                 AC_TRY_LINK(
426                     [
427 #       include <pcap.h>
428                     ],
429                     [
430         pcap_open_live(NULL, 0, 0, 0, NULL);
431                     ],
432                     [
433                         ac_wireshark_extras_found=yes
434                         AC_MSG_RESULT([yes])
435                         PCAP_LIBS="-lpcap $extras"
436                         AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
437                     ],
438                     [
439                         AC_MSG_RESULT([no])
440                     ])
441                 if test x$ac_wireshark_extras_found = xyes
442                 then
443                     break
444                 fi
445               done
446               if test x$ac_wireshark_extras_found = xno
447               then
448                 AC_MSG_ERROR([Can't link with library libpcap.])
449               fi
450               LIBS=$ac_save_LIBS
451             ], $SOCKET_LIBS $NSL_LIBS)
452         fi
453         AC_SUBST(PCAP_LIBS)
454
455         #
456         # Check whether various variables and functions are defined by
457         # libpcap.
458         #
459         ac_save_LIBS="$LIBS"
460         AC_MSG_CHECKING(whether pcap_version is defined by libpcap)
461         LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
462         AC_TRY_LINK(
463            [
464 #       include <stdio.h>
465         extern char *pcap_version;
466            ],
467            [
468         printf ("%s\n", pcap_version);
469            ],
470            ac_cv_pcap_version_defined=yes,
471            ac_cv_pcap_version_defined=no,
472            [echo $ac_n "cross compiling; assumed OK... $ac_c"])
473         if test "$ac_cv_pcap_version_defined" = yes ; then
474                 AC_MSG_RESULT(yes)
475                 AC_DEFINE(HAVE_PCAP_VERSION, 1, [Define if libpcap version is known])
476         else
477                 AC_MSG_RESULT(no)
478         fi
479         AC_CHECK_FUNCS(pcap_open_dead pcap_freecode)
480         #
481         # pcap_breakloop may be present in the library but not declared
482         # in the pcap.h header file.  If it's not declared in the header
483         # file, attempts to use it will get warnings, and, if we're
484         # building with warnings treated as errors, that warning will
485         # cause compilation to fail.
486         #
487         # We are therefore first testing whether the function is present
488         # and then, if we're compiling with warnings as errors, testing
489         # whether it is usable.  It is usable if it compiles without
490         # a -Wimplicit warning (the "compile with warnings as errors"
491         # option requires GCC). If it is not usable, we fail and tell
492         # the user that the pcap.h header needs to be updated.
493         #
494         # Ceteris paribus, this should only happen with Mac OS X 10.3[.x] which
495         # can have an up-to-date pcap library without the corresponding pcap
496         # header.
497         #
498         # However, it might also happen on some others OSes with some erroneous
499         # system manipulations where multiple versions of libcap might co-exist
500         # e.g. hand made symbolic link from libpcap.so -> libpcap.so.0.8 but
501         # having the pcap header version 0.7.
502         #
503         AC_MSG_CHECKING([whether pcap_breakloop is present])
504         ac_CFLAGS_saved="$CFLAGS"
505         AC_WIRESHARK_PCAP_BREAKLOOP_TRY_LINK
506         if test "x$ws_breakloop_compiled" = "xyes"; then
507           AC_MSG_RESULT(yes)
508           AC_DEFINE(HAVE_PCAP_BREAKLOOP, 1, [Define if pcap_breakloop is known])
509           if test "x$with_warnings_as_errors" = "xyes"; then
510             AC_MSG_CHECKING([whether pcap_breakloop is usable])
511             CFLAGS="$CFLAGS -Werror -Wimplicit"
512             AC_WIRESHARK_PCAP_BREAKLOOP_TRY_LINK
513             if test "x$ws_breakloop_compiled" = "xyes"; then
514               AC_MSG_RESULT(yes)
515             else
516               AC_MSG_RESULT(no)
517               AC_MSG_ERROR(
518 [Your pcap library is more recent than your pcap header.
519 As you are building with compiler warnings treated as errors, Wireshark
520 won't be able to use functions not declared in that header.
521 If you wish to build with compiler warnings treated as errors, You should
522 install a newer version of the header file.])
523             fi
524             CFLAGS="$ac_CFLAGS_saved"
525           fi
526         else
527           AC_MSG_RESULT(no)
528         fi
529
530         #
531         # Later versions of Mac OS X 10.3[.x] ship a pcap.h that
532         # doesn't define pcap_if_t but ship an 0.8[.x] libpcap,
533         # so the library has "pcap_findalldevs()", but pcap.h
534         # doesn't define "pcap_if_t" so you can't actually *use*
535         # "pcap_findalldevs()".
536         #
537         # That even appears to be true of systems shipped with
538         # 10.3.4, so it doesn't appear only to be a case of
539         # Software Update not updating header files.
540         #
541         # (You can work around this by installing the 0.8 header
542         # files.)
543         #
544         AC_CACHE_CHECK([whether pcap_findalldevs is present and usable],
545           [ac_cv_func_pcap_findalldevs],
546           [
547             AC_LINK_IFELSE(
548               [
549                 AC_LANG_SOURCE(
550                   [[
551                     #include <pcap.h>
552                     main()
553                     {
554                       pcap_if_t *devpointer;
555                       char errbuf[1];
556
557                       pcap_findalldevs(&devpointer, errbuf);
558                     }
559                   ]])
560               ],
561               [
562                 ac_cv_func_pcap_findalldevs=yes
563               ],
564               [
565                 ac_cv_func_pcap_findalldevs=no
566               ])
567           ])
568         #
569         # Don't check for other new routines that showed up after
570         # "pcap_findalldevs()" if we don't have a usable
571         # "pcap_findalldevs()", so we don't end up using them if the
572         # "pcap.h" is crufty and old and doesn't declare them.
573         #
574         if test $ac_cv_func_pcap_findalldevs = "yes" ; then
575           AC_DEFINE(HAVE_PCAP_FINDALLDEVS, 1,
576            [Define to 1 if you have the `pcap_findalldevs' function and a pcap.h that declares pcap_if_t.])
577           AC_CHECK_FUNCS(pcap_datalink_val_to_name pcap_datalink_name_to_val)
578           AC_CHECK_FUNCS(pcap_datalink_val_to_description)
579           AC_CHECK_FUNCS(pcap_list_datalinks pcap_set_datalink pcap_lib_version)
580           AC_CHECK_FUNCS(pcap_get_selectable_fd pcap_free_datalinks)
581         fi
582         LIBS="$ac_save_LIBS"
583 ])
584
585 AC_DEFUN([AC_WIRESHARK_PCAP_REMOTE_CHECK],
586 [
587     ac_save_LIBS="$LIBS"
588     LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
589     AC_DEFINE(HAVE_REMOTE, 1, [Define to 1 to enable remote
590               capturing feature in WinPcap library])
591     AC_CHECK_FUNCS(pcap_open pcap_findalldevs_ex pcap_createsrcstr)
592     if test $ac_cv_func_pcap_open = "yes" -a \
593             $ac_cv_func_pcap_findalldevs_ex = "yes" -a \
594             $ac_cv_func_pcap_createsrcstr = "yes" ; then
595         AC_DEFINE(HAVE_PCAP_REMOTE, 1,
596             [Define to 1 if you have WinPcap remote capturing support and prefer to use these new API features.])
597     fi
598     AC_CHECK_FUNCS(pcap_setsampling)
599     LIBS="$ac_save_LIBS"
600 ])
601
602 #
603 # AC_WIRESHARK_ZLIB_CHECK
604 #
605 AC_DEFUN([AC_WIRESHARK_ZLIB_CHECK],
606 [
607         if test "x$zlib_dir" != "x"
608         then
609           #
610           # The user specified a directory in which zlib resides,
611           # so add the "include" subdirectory of that directory to
612           # the include file search path and the "lib" subdirectory
613           # of that directory to the library search path.
614           #
615           # XXX - if there's also a zlib in a directory that's
616           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
617           # make us find the version in the specified directory,
618           # as the compiler and/or linker will search that other
619           # directory before it searches the specified directory.
620           #
621           wireshark_save_CFLAGS="$CFLAGS"
622           CFLAGS="$CFLAGS -I$zlib_dir/include"
623           wireshark_save_CPPFLAGS="$CPPFLAGS"
624           CPPFLAGS="$CPPFLAGS -I$zlib_dir/include"
625           wireshark_save_LIBS="$LIBS"
626           AC_WIRESHARK_ADD_DASH_L(LIBS, $zlib_dir/lib)
627         fi
628
629         #
630         # Make sure we have "zlib.h".  If we don't, it means we probably
631         # don't have zlib, so don't use it.
632         #
633         AC_CHECK_HEADER(zlib.h,,
634           [
635             if test "x$zlib_dir" != "x"
636             then
637               #
638               # The user used "--with-zlib=" to specify a directory
639               # containing zlib, but we didn't find the header file
640               # there; that either means they didn't specify the
641               # right directory or are confused about whether zlib
642               # is, in fact, installed.  Report the error and give up.
643               #
644               AC_MSG_ERROR([zlib header not found in directory specified in --with-zlib])
645             else
646               if test "x$want_zlib" = "xyes"
647               then
648                 #
649                 # The user tried to force us to use the library, but we
650                 # couldn't find the header file; report an error.
651                 #
652                 AC_MSG_ERROR(Header file zlib.h not found.)
653               else
654                 #
655                 # We couldn't find the header file; don't use the
656                 # library, as it's probably not present.
657                 #
658                 want_zlib=no
659               fi
660             fi
661           ])
662
663         if test "x$want_zlib" != "xno"
664         then
665                 #
666                 # Well, we at least have the zlib header file.
667                 #
668                 # Check for "gzgets()" in zlib, because we need it, but
669                 # some older versions of zlib don't have it.  It appears
670                 # from the zlib ChangeLog that any released version of zlib
671                 # with "gzgets()" should have the other routines we
672                 # depend on, such as "gzseek()", "gztell()", and "zError()".
673                 #
674                 # Another reason why we require "gzgets()" is that
675                 # some versions of zlib that didn't have it, such
676                 # as 1.0.8, had a bug in "gzseek()" that meant that it
677                 # doesn't work correctly on uncompressed files; this
678                 # means we cannot use version 1.0.8.  (Unfortunately,
679                 # that's the version that comes with recent X11 source,
680                 # and many people who install XFree86 on their Slackware
681                 # boxes don't realize that they should configure it to
682                 # use the native zlib rather than building and installing
683                 # the crappy old version that comes with XFree86.)
684                 #
685                 # I.e., we can't just avoid using "gzgets()", as
686                 # versions of zlib without "gzgets()" are likely to have
687                 # a broken "gzseek()".
688                 #
689                 AC_CHECK_LIB(z, gzgets,
690                 [
691                         if test "x$zlib_dir" != "x"
692                         then
693                                 #
694                                 # Put the "-I" and "-L" flags for zlib at
695                                 # the beginning of CFLAGS, CPPFLAGS, and
696                                 # LIBS.
697                                 #
698                                 LIBS=""
699                                 AC_WIRESHARK_ADD_DASH_L(LIBS, $zlib_dir/lib)
700                                 LIBS="$LIBS -lz $wireshark_save_LIBS"
701                         else
702                                 LIBS="-lz $LIBS"
703                         fi
704                         AC_DEFINE(HAVE_LIBZ, 1, [Define to use libz library])
705                 ],[
706                         if test "x$zlib_dir" != "x"
707                         then
708                                 #
709                                 # Restore the versions of CFLAGS, CPPFLAGS,
710                                 # and LIBS before we added the "-with-zlib="
711                                 # directory, as we didn't actually find
712                                 # zlib there, or didn't find a zlib that
713                                 # contains gzgets there.
714                                 #
715                                 CFLAGS="$wireshark_save_CFLAGS"
716                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
717                                 LIBS="$wireshark_save_LIBS"
718                         fi
719                         want_zlib=no
720                 ])
721         fi
722
723         if test "x$want_zlib" != "xno"
724         then
725                 #
726                 # Well, we at least have the zlib header file and a zlib
727                 # with "gzgets()".
728                 #
729                 # Now check for "gzgets()" in zlib when linking with the
730                 # linker flags for GTK+ applications; people often grab
731                 # XFree86 source and build and install it on their systems,
732                 # and they appear sometimes to misconfigure XFree86 so that,
733                 # even on systems with zlib, it assumes there is no zlib,
734                 # so the XFree86 build process builds and installs its
735                 # own zlib in the X11 library directory.
736                 #
737                 # The XFree86 zlib is an older version that lacks
738                 # "gzgets()", and that's the zlib with which Wireshark
739                 # gets linked, so the build of Wireshark fails.
740                 #
741                 ac_save_CFLAGS="$CFLAGS"
742                 ac_save_LIBS="$LIBS"
743                 CFLAGS="$CFLAGS $GTK_CFLAGS"
744                 LIBS="$GTK_LIBS -lz $LIBS"
745                 AC_MSG_CHECKING([for gzgets missing when linking with X11])
746                 AC_TRY_LINK_FUNC(gzgets, AC_MSG_RESULT(no),
747                   [
748                     AC_MSG_RESULT(yes)
749                     AC_MSG_ERROR(old zlib found when linking with X11 - get rid of old zlib.)
750                   ])
751                 CFLAGS="$ac_save_CFLAGS"
752                 LIBS="$ac_save_LIBS"
753         fi
754 ])
755
756 #
757 # AC_WIRESHARK_LIBPCRE_CHECK
758 #
759 AC_DEFUN([AC_WIRESHARK_LIBPCRE_CHECK],
760 [
761         if test "x$pcre_dir" != "x"
762         then
763           #
764           # The user specified a directory in which libpcre resides,
765           # so add the "include" subdirectory of that directory to
766           # the include file search path and the "lib" subdirectory
767           # of that directory to the library search path.
768           #
769           # XXX - if there's also a libpcre in a directory that's
770           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
771           # make us find the version in the specified directory,
772           # as the compiler and/or linker will search that other
773           # directory before it searches the specified directory.
774           #
775           wireshark_save_CFLAGS="$CFLAGS"
776           CFLAGS="$CFLAGS -I$pcre_dir/include"
777           wireshark_save_CPPFLAGS="$CPPFLAGS"
778           CPPFLAGS="$CPPFLAGS -I$pcre_dir/include"
779           wireshark_save_LIBS="$LIBS"
780           LIBS="$LIBS -lpcre"
781           wireshark_save_LDFLAGS="$LDFLAGS"
782           LDFLAGS="$LDFLAGS -L$pcre_dir/lib"
783         fi
784
785         #
786         # Make sure we have "pcre.h".  If we don't, it means we probably
787         # don't have libpcre, so don't use it.
788         #
789         AC_CHECK_HEADER(pcre.h,,
790           [
791             if test "x$pcre_dir" != "x"
792             then
793               #
794               # The user used "--with-pcre=" to specify a directory
795               # containing libpcre, but we didn't find the header file
796               # there; that either means they didn't specify the
797               # right directory or are confused about whether libpcre
798               # is, in fact, installed.  Report the error and give up.
799               #
800               AC_MSG_ERROR([libpcre header not found in directory specified in --with-pcre])
801             else
802               if test "x$want_pcre" = "xyes"
803               then
804                 #
805                 # The user tried to force us to use the library, but we
806                 # couldn't find the header file; report an error.
807                 #
808                 AC_MSG_ERROR(Header file pcre.h not found.)
809               else
810                 #
811                 # We couldn't find the header file; don't use the
812                 # library, as it's probably not present.
813                 #
814                 want_pcre=no
815               fi
816             fi
817           ])
818
819         if test "x$want_pcre" != "xno"
820         then
821                 #
822                 # Well, we at least have the pcre header file.
823                 #
824                 # We're only using standard functions from libpcre,
825                 # so we don't need to perform extra checks.
826                 #
827                 AC_CHECK_LIB(pcre, pcre_compile,
828                 [
829                         if test "x$pcre_dir" != "x"
830                         then
831                                 #
832                                 # Put the "-I" and "-L" flags for pcre at
833                                 # the beginning of CFLAGS, CPPFLAGS,
834                                 # LDFLAGS, and LIBS.
835                                 #
836                                 PCRE_LIBS="-L$pcre_dir/lib -lpcre $wireshark_save_LIBS"
837                         else
838                                 PCRE_LIBS="-lpcre"
839                         fi
840                         AC_DEFINE(HAVE_LIBPCRE, 1, [Define to use libpcre library])
841                 ],[
842                         if test "x$pcre_dir" != "x"
843                         then
844                                 #
845                                 # Restore the versions of CFLAGS, CPPFLAGS,
846                                 # LDFLAGS, and LIBS before we added the
847                                 # "--with-pcre=" directory, as we didn't
848                                 # actually find pcre there.
849                                 #
850                                 CFLAGS="$wireshark_save_CFLAGS"
851                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
852                                 LDFLAGS="$wireshark_save_LDFLAGS"
853                                 LIBS="$wireshark_save_LIBS"
854                                 PCRE_LIBS=""
855                         fi
856                         want_pcre=no
857                 ])
858                 AC_SUBST(PCRE_LIBS)
859         fi
860 ])
861
862 #
863 # AC_WIRESHARK_LIBLUA_CHECK
864 #
865 AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
866
867         if test "x$lua_dir" != "x"
868         then
869                 #
870                 # The user specified a directory in which liblua resides,
871                 # so add the "include" subdirectory of that directory to
872                 # the include file search path and the "lib" subdirectory
873                 # of that directory to the library search path.
874                 #
875                 # XXX - if there's also a liblua in a directory that's
876                 # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
877                 # make us find the version in the specified directory,
878                 # as the compiler and/or linker will search that other
879                 # directory before it searches the specified directory.
880                 #
881                 wireshark_save_CFLAGS="$CFLAGS"
882                 CFLAGS="$CFLAGS -I$lua_dir/include"
883                 wireshark_save_CPPFLAGS="$CPPFLAGS"
884                 CPPFLAGS="$CPPFLAGS -I$lua_dir/include"
885                 wireshark_save_LIBS="$LIBS"
886                 LIBS="$LIBS -L$lua_dir/lib -llua -lm"
887                 wireshark_save_LDFLAGS="$LDFLAGS"
888                 LDFLAGS="$LDFLAGS -L$lua_dir/lib"
889         else
890                 #
891                 # The user specified no directory in which liblua resides,
892                 # so just add "-llua -lliblua" to the used libs.
893                 #
894                 wireshark_save_CFLAGS="$CFLAGS"
895                 wireshark_save_CPPFLAGS="$CPPFLAGS"
896                 wireshark_save_LDFLAGS="$LDFLAGS"
897                 wireshark_save_LIBS="$LIBS"
898                 LIBS="$LIBS -llua -lm"
899         fi
900
901         #
902         # Make sure we have "lua.h", "lualib.h" and "lauxlib.h".  If we don't, it means we probably
903         # don't have liblua, so don't use it.
904         #
905         AC_CHECK_HEADERS(lua.h lualib.h lauxlib.h,,
906         [
907                 AC_CHECK_HEADERS(lua5.1/lua.h lua5.1/lualib.h lua5.1/lauxlib.h,
908                 [
909                         if test "x$lua_dir" != "x"
910                         then
911                                 LUA_INCLUDES="-I$lua_dir/include/lua5.1"
912                         else
913                                 #
914                                 # The user didn't specify a directory in which liblua resides;
915                                 # we must look for the headers in a "lua5.1" subdirectory of
916                                 # "/usr/include", "/usr/local/include", or "$prefix/include"
917                                 # as some systems apparently put the headers in a "lua5.1"
918                                 # subdirectory.
919                                 AC_MSG_CHECKING(for extraneous lua header directories)
920                                 found_lua_dir=""
921                                 lua_dir_list="/usr/include/lua5.1 $prefix/include/lua5.1"
922                                 if test "x$ac_cv_enable_usr_local" = "xyes"
923                                 then
924                                         lua_dir_list="$lua_dir_list /usr/local/include/lua5.1"
925                                 fi
926                                 for lua_dir_ent in $lua_dir_list
927                                 do
928                                         if test -d $lua_dir_ent
929                                         then
930                                                 LUA_INCLUDES="-I$lua_dir_ent"
931                                                 found_lua_dir="$lua_dir_ent"
932                                                 break
933                                         fi
934                                 done
935
936                                 if test "x$found_lua_dir" != "x"
937                                 then
938                                         AC_MSG_RESULT(found -- $found_lua_dir)
939                                 else
940                                         AC_MSG_RESULT(not found)
941                                         #
942                                         # Restore the versions of CFLAGS, CPPFLAGS,
943                                         # LDFLAGS, and LIBS before we added the
944                                         # "--with-lua=" directory, as we didn't
945                                         # actually find lua there.
946                                         #
947                                         CFLAGS="$wireshark_save_CFLAGS"
948                                         CPPFLAGS="$wireshark_save_CPPFLAGS"
949                                         LDFLAGS="$wireshark_save_LDFLAGS"
950                                         LIBS="$wireshark_save_LIBS"
951                                         LUA_LIBS=""
952                                         if test "x$want_lua" = "xyes"
953                                         then
954                                                 # we found lua5.1/lua.h, but we don't know which include dir contains it
955                                                 AC_MSG_ERROR(Header file lua.h was found as lua5.1/lua.h but we can't locate the include directory. Please set the DIR for the --with-lua configure parameter.)
956                                         else
957                                                 #
958                                                 # We couldn't find the header file; don't use the
959                                                 # library, as it's probably not present.
960                                                 #
961                                                 want_lua=no
962                                         fi
963                                 fi
964                         fi
965                 ],
966                 [
967                         #
968                         # Restore the versions of CFLAGS, CPPFLAGS,
969                         # LDFLAGS, and LIBS before we added the
970                         # "--with-lua=" directory, as we didn't
971                         # actually find lua there.
972                         #
973                         CFLAGS="$wireshark_save_CFLAGS"
974                         CPPFLAGS="$wireshark_save_CPPFLAGS"
975                         LDFLAGS="$wireshark_save_LDFLAGS"
976                         LIBS="$wireshark_save_LIBS"
977                         LUA_LIBS=""
978                         if test "x$lua_dir" != "x"
979                         then
980                                 #
981                                 # The user used "--with-lua=" to specify a directory
982                                 # containing liblua, but we didn't find the header file
983                                 # there; that either means they didn't specify the
984                                 # right directory or are confused about whether liblua
985                                 # is, in fact, installed.  Report the error and give up.
986                                 #
987                                 AC_MSG_ERROR([liblua header not found in directory specified in --with-lua])
988                         else
989                                 if test "x$want_lua" = "xyes"
990                                 then
991                                         #
992                                         # The user tried to force us to use the library, but we
993                                         # couldn't find the header file; report an error.
994                                         #
995                                         AC_MSG_ERROR(Header file lua.h not found.)
996                                 else
997                                         #
998                                         # We couldn't find the header file; don't use the
999                                         # library, as it's probably not present.
1000                                         #
1001                                         want_lua=no
1002                                 fi
1003                         fi
1004                 ])
1005         ])
1006
1007         if test "x$want_lua" != "xno"
1008         then
1009                 #
1010                 # Well, we at least have the lua header file.
1011                 #
1012                 # let's check if the libs are there
1013                 #
1014
1015                 # At least on Suse 9.3 systems, liblualib needs linking
1016                 # against libm.
1017                 LIBS="$LIBS $LUA_LIBS -lm"
1018
1019                 AC_CHECK_LIB(lua, luaL_register,
1020                 [
1021                     #
1022                     #  Lua 5.1 found
1023                     #
1024                         if test "x$lua_dir" != "x"
1025                         then
1026                                 #
1027                                 # Put the "-I" and "-L" flags for lua at
1028                                 # the beginning of CFLAGS, CPPFLAGS,
1029                                 # LDFLAGS, and LIBS.
1030                                 #
1031                                 LUA_LIBS="-L$lua_dir/lib -llua -lm"
1032                                 LUA_INCLUDES="-I$lua_dir/include"
1033                         else
1034                                 LUA_LIBS="-llua -lm"
1035                                 LUA_INCLUDES=""
1036                         fi
1037                         AC_DEFINE(HAVE_LUA_5_1, 1, [Define to use Lua 5.1])
1038                         want_lua=yes
1039
1040                 ],[
1041                         #
1042                         # We could not find the libs, maybe we have version number in the lib name
1043                         #
1044
1045                         LIBS="$wireshark_save_LIBS -llua5.1 -lm"
1046
1047                         AC_CHECK_LIB(lua5.1, luaL_register,
1048                         [
1049                             #
1050                             #  Lua 5.1 found
1051                             #
1052                             LUA_LIBS=" -llua5.1 -lm"
1053                             AC_DEFINE(HAVE_LUA_5_1, 1, [Define to use Lua 5.1])
1054                             want_lua=yes
1055                         ],[
1056                                 #
1057                                 # Restore the versions of CFLAGS, CPPFLAGS,
1058                                 # LDFLAGS, and LIBS before we added the
1059                                 # "--with-lua=" directory, as we didn't
1060                                 # actually find lua there.
1061                                 #
1062                                 CFLAGS="$wireshark_save_CFLAGS"
1063                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
1064                                 LDFLAGS="$wireshark_save_LDFLAGS"
1065                                 LIBS="$wireshark_save_LIBS"
1066                                 LUA_LIBS=""
1067                                 # User requested --with-lua but it isn't available
1068                                 if test "x$want_lua" = "xyes"
1069                                 then
1070                                         AC_MSG_ERROR(Linking with liblua failed.)
1071                                 fi
1072                                 want_lua=no
1073                         ])
1074                 ])
1075
1076         CFLAGS="$wireshark_save_CFLAGS"
1077         CPPFLAGS="$wireshark_save_CPPFLAGS"
1078         LDFLAGS="$wireshark_save_LDFLAGS"
1079         LIBS="$wireshark_save_LIBS"
1080         AC_SUBST(LUA_LIBS)
1081         AC_SUBST(LUA_INCLUDES)
1082
1083         fi
1084 ])
1085
1086 #
1087 # AC_WIRESHARK_LIBPORTAUDIO_CHECK
1088 #
1089 AC_DEFUN([AC_WIRESHARK_LIBPORTAUDIO_CHECK],[
1090
1091         if test "x$portaudio_dir" != "x"
1092         then
1093                 #
1094                 # The user specified a directory in which libportaudio
1095                 # resides, so add the "include" subdirectory of that directory to
1096                 # the include file search path and the "lib" subdirectory
1097                 # of that directory to the library search path.
1098                 #
1099                 # XXX - if there's also a libportaudio in a directory that's
1100                 # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
1101                 # make us find the version in the specified directory,
1102                 # as the compiler and/or linker will search that other
1103                 # directory before it searches the specified directory.
1104                 #
1105                 wireshark_save_CFLAGS="$CFLAGS"
1106                 CFLAGS="$CFLAGS -I$portaudio_dir/include"
1107                 wireshark_save_CPPFLAGS="$CPPFLAGS"
1108                 CPPFLAGS="$CPPFLAGS -I$portaudio_dir/include"
1109                 wireshark_save_LIBS="$LIBS"
1110                 LIBS="$LIBS -L$portaudio_dir/lib -lportaudio"
1111                 wireshark_save_LDFLAGS="$LDFLAGS"
1112                 LDFLAGS="$LDFLAGS -L$portaudio_dir/lib"
1113         else
1114                 #
1115                 # The user specified no directory in which libportaudio resides,
1116                 # so just add "-lportaudio" to the used libs.
1117                 #
1118                 wireshark_save_CFLAGS="$CFLAGS"
1119                 wireshark_save_CPPFLAGS="$CPPFLAGS"
1120                 wireshark_save_LDFLAGS="$LDFLAGS"
1121                 wireshark_save_LIBS="$LIBS"
1122                 LIBS="$LIBS -lportaudio"
1123         fi
1124
1125         #
1126         # Make sure we have "portaudio.h".  If we don't, it means we probably
1127         # don't have libportaudio, so don't use it.
1128         #
1129         AC_CHECK_HEADERS(portaudio.h,,
1130         [
1131                 if test "x$portaudio_dir" != "x"
1132                 then
1133                         #
1134                         # The user used "--with-portaudio=" to specify a directory
1135                         # containing libportaudio, but we didn't find the header file
1136                         # there; that either means they didn't specify the
1137                         # right directory or are confused about whether libportaudio
1138                         # is, in fact, installed.  Report the error and give up.
1139                         #
1140                         AC_MSG_ERROR([libportaudio header not found in directory specified in --with-portaudio])
1141                 else
1142                         CFLAGS="$wireshark_save_CFLAGS"
1143                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1144                         LDFLAGS="$wireshark_save_LDFLAGS"
1145                         LIBS="$wireshark_save_LIBS"
1146                         PORTAUDIO_LIBS=""
1147                         if test "x$want_portaudio" = "xyes"
1148                         then
1149                                 #
1150                                 # The user tried to force us to use the library, but we
1151                                 # couldn't find the header file; report an error.
1152                                 #
1153                                 AC_MSG_ERROR(Header file portaudio.h not found.)
1154                         else
1155                                 #
1156                                 # We couldn't find the header file; don't use the
1157                                 # library, as it's probably not present.
1158                                 #
1159                                 want_portaudio=no
1160                         fi
1161                 fi
1162         ])
1163
1164         #
1165         # Check whether we have the right version of portaudio
1166         #
1167         if test "x$want_portaudio" != "xno"
1168         then
1169                 AC_CHECK_TYPE(PortAudioStream,
1170                 AC_DEFINE(PORTAUDIO_API_1, 1, [Define if we are using version of of the Portaudio library API]),
1171                 ,
1172                 [#include <portaudio.h>])
1173         fi
1174
1175         if test "x$want_portaudio" != "xno"
1176         then
1177                 #
1178                 # Well, we at least have the portaudio header file.
1179                 #
1180                 # let's check if the libs are there
1181                 #
1182
1183                 AC_CHECK_LIB(portaudio, Pa_Initialize,
1184                 [
1185                         if test "x$portaudio_dir" != "x"
1186                         then
1187                                 #
1188                                 # Put the "-I" and "-L" flags for portaudio at
1189                                 # the beginning of CFLAGS, CPPFLAGS,
1190                                 # LDFLAGS, and LIBS.
1191                                 #
1192                                 PORTAUDIO_LIBS="-L$portaudio_dir/lib -lportaudio"
1193                                 PORTAUDIO_INCLUDES="-I$portaudio_dir/include"
1194                         else
1195                                 PORTAUDIO_LIBS="-lportaudio"
1196                                 PORTAUDIO_INCLUDES=""
1197                         fi
1198                         AC_DEFINE(HAVE_LIBPORTAUDIO, 1, [Define to use libportaudio library])
1199                         want_portaudio=yes
1200                 ],[
1201                         #
1202                         # Restore the versions of CFLAGS, CPPFLAGS,
1203                         # LDFLAGS, and LIBS before we added the
1204                         # "--with-portaudio=" directory, as we didn't
1205                         # actually find portaudio there.
1206                         #
1207                         CFLAGS="$wireshark_save_CFLAGS"
1208                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1209                         LDFLAGS="$wireshark_save_LDFLAGS"
1210                         LIBS="$wireshark_save_LIBS"
1211                         PORTAUDIO_LIBS=""
1212                         # User requested --with-portaudio but it isn't available
1213                         if test "x$want_portaudio" = "xyes"
1214                         then
1215                                 AC_MSG_ERROR(Linking with libportaudio failed.)
1216                         fi
1217                         want_portaudio=no
1218                 ])
1219
1220         CFLAGS="$wireshark_save_CFLAGS"
1221         CPPFLAGS="$wireshark_save_CPPFLAGS"
1222         LDFLAGS="$wireshark_save_LDFLAGS"
1223         LIBS="$wireshark_save_LIBS"
1224         AC_SUBST(PORTAUDIO_LIBS)
1225         AC_SUBST(PORTAUDIO_INCLUDES)
1226
1227         fi
1228 ])
1229
1230 #
1231 # AC_WIRESHARK_RPM_CHECK
1232 # Looks for the rpm program, and checks to see if we can redefine "_topdir".
1233 #
1234 AC_DEFUN([AC_WIRESHARK_RPM_CHECK],
1235 [
1236         AC_CHECK_PROG(ac_cv_wireshark_have_rpm, rpm, "yes", "no")
1237         if test "x$ac_cv_wireshark_have_rpm" = "xyes"; then
1238                 rpm --define '_topdir /tmp' > /dev/null 2>&1
1239                 AC_MSG_CHECKING(to see if we can redefine _topdir)
1240                 if test $? -eq 0 ; then
1241                         AC_MSG_RESULT(yes)
1242                         HAVE_RPM=yes
1243                 else
1244                         AC_MSG_RESULT(no.  You'll have to build packages manually.)
1245                         HAVE_RPM=no
1246                 fi
1247         fi
1248 ])
1249
1250 #
1251 # AC_WIRESHARK_GNU_SED_CHECK
1252 # Checks if GNU sed is the first sed in PATH.
1253 #
1254 AC_DEFUN([AC_WIRESHARK_GNU_SED_CHECK],
1255 [
1256         AC_MSG_CHECKING(for GNU sed as first sed in PATH)
1257         if  ( sh -c "sed --version" </dev/null 2> /dev/null | grep "GNU sed" 2>&1 > /dev/null ) ;  then
1258                 AC_MSG_RESULT(yes)
1259                 HAVE_GNU_SED=yes
1260         else
1261                 AC_MSG_RESULT(no)
1262                 HAVE_GNU_SED=no
1263         fi
1264 ])
1265
1266 #
1267 # AC_WIRESHARK_C_ARES_CHECK
1268 #
1269 AC_DEFUN([AC_WIRESHARK_C_ARES_CHECK],
1270 [
1271         want_c_ares=defaultyes
1272
1273         if test "x$want_c_ares" = "xdefaultyes"; then
1274                 want_c_ares=yes
1275                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1276                         withval=/usr/local
1277                         if test -d "$withval"; then
1278                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1279                         fi
1280                 fi
1281         fi
1282
1283         if test "x$want_c_ares" = "xyes"; then
1284                 AC_CHECK_LIB(cares, ares_init,
1285                   [
1286                     C_ARES_LIBS=-lcares
1287                 AC_DEFINE(HAVE_C_ARES, 1, [Define to use c-ares library])
1288                 have_good_c_ares=yes
1289                   ],, $SOCKET_LIBS $NSL_LIBS
1290                 )
1291         else
1292                 AC_MSG_RESULT(not required)
1293         fi
1294 ])
1295
1296
1297 #
1298 # AC_WIRESHARK_ADNS_CHECK
1299 #
1300 AC_DEFUN([AC_WIRESHARK_ADNS_CHECK],
1301 [
1302         want_adns=defaultyes
1303
1304         if test "x$want_adns" = "xdefaultyes"; then
1305                 want_adns=yes
1306                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1307                         withval=/usr/local
1308                         if test -d "$withval"; then
1309                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1310                         fi
1311                 fi
1312         fi
1313
1314         if test "x$want_adns" = "xyes"; then
1315                 AC_CHECK_LIB(adns, adns_init,
1316                   [
1317                     ADNS_LIBS=-ladns
1318                 AC_DEFINE(HAVE_GNU_ADNS, 1, [Define to use GNU ADNS library])
1319                 have_good_adns=yes
1320                   ],, $SOCKET_LIBS $NSL_LIBS
1321                 )
1322         else
1323                 AC_MSG_RESULT(not required)
1324         fi
1325 ])
1326
1327
1328 #
1329 # AC_WIRESHARK_LIBCAP_CHECK
1330 #
1331 AC_DEFUN([AC_WIRESHARK_LIBCAP_CHECK],
1332 [
1333         want_libcap=defaultyes
1334
1335         if test "x$want_libcap" = "xdefaultyes"; then
1336                 want_libcap=yes
1337                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1338                         withval=/usr/local
1339                         if test -d "$withval"; then
1340                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1341                         fi
1342                 fi
1343         fi
1344
1345         if test "x$want_libcap" = "xyes"; then
1346                 AC_CHECK_LIB(cap, cap_set_flag,
1347                   [
1348                     LIBCAP_LIBS=-lcap
1349                 AC_DEFINE(HAVE_LIBCAP, 1, [Define to use the libcap library])
1350                 have_good_libcap=yes
1351                   ],,
1352                 )
1353         else
1354                 AC_MSG_RESULT(not required)
1355         fi
1356 ])
1357
1358
1359 #
1360 # AC_WIRESHARK_KRB5_CHECK
1361 #
1362 AC_DEFUN([AC_WIRESHARK_KRB5_CHECK],
1363 [
1364         wireshark_save_CFLAGS="$CFLAGS"
1365         wireshark_save_CPPFLAGS="$CPPFLAGS"
1366         if test "x$krb5_dir" != "x"
1367         then
1368           #
1369           # The user specified a directory in which kerberos resides,
1370           # so add the "include" subdirectory of that directory to
1371           # the include file search path and the "lib" subdirectory
1372           # of that directory to the library search path.
1373           #
1374           # XXX - if there's also a kerberos in a directory that's
1375           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
1376           # make us find the version in the specified directory,
1377           # as the compiler and/or linker will search that other
1378           # directory before it searches the specified directory.
1379           #
1380           CFLAGS="$CFLAGS -I$krb5_dir/include"
1381           CPPFLAGS="$CPPFLAGS -I$krb5_dir/include"
1382           ac_heimdal_version=`grep heimdal $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*heimdal.*$/HEIMDAL/'`
1383           ac_mit_version=`grep 'Massachusetts Institute of Technology' $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*Massachusetts Institute of Technology.*$/MIT/'`
1384           ac_krb5_version="$ac_heimdal_version$ac_mit_version"
1385           if test "x$ac_krb5_version" = "xHEIMDAL"
1386               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lasn1 $SSL_LIBS -lroken -lcrypt"
1387           then
1388               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lk5crypto -lcom_err"
1389           fi
1390           if test "x$ac_krb5_version" = "xMIT"
1391           then
1392             AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
1393           fi
1394         else
1395           AC_PATH_PROG(KRB5_CONFIG, krb5-config)
1396           if test -x "$KRB5_CONFIG"
1397           then
1398             KRB5_FLAGS=`"$KRB5_CONFIG" --cflags`
1399             KRB5_LIBS=`"$KRB5_CONFIG" --libs`
1400             CFLAGS="$CFLAGS $KRB5_FLAGS"
1401             CPPFLAGS="$CPPFLAGS $KRB5_FLAGS"
1402             #
1403             # If -lcrypto is in KRB5_FLAGS, we require it to build
1404             # with Heimdal/MIT.  We don't want to built with it by
1405             # default, due to annoying license incompatibilities
1406             # between the OpenSSL license and the GPL, so:
1407             #
1408             #   if SSL_LIBS is set to a non-empty string, we
1409             #   remove -lcrypto from KRB5_LIBS and replace
1410             #   it with SSL_LIBS;
1411             #
1412             #   if SSL_LIBS is not set to a non-empty string
1413             #   we fail with an appropriate error message.
1414             #
1415             case "$KRB5_LIBS" in
1416             *-lcrypto*)
1417                 if test ! -z "$SSL_LIBS"
1418                 then
1419                     KRB5_LIBS=`echo $KRB5_LIBS | sed 's/-lcrypto//'`
1420                     KRB5_LIBS="$KRB5_LIBS $SSL_LIBS"
1421                 else
1422                     AC_MSG_ERROR([Kerberos library requires -lcrypto but --with-ssl not specified])
1423                 fi
1424                 ;;
1425             esac
1426             ac_krb5_version=`"$KRB5_CONFIG" --version | head -n 1 | sed -e 's/^.*heimdal.*$/HEIMDAL/' -e 's/^Kerberos .*$/MIT/' -e 's/^Solaris Kerberos .*$/MIT/'`
1427           fi
1428         fi
1429
1430         #
1431         # Make sure we have "krb5.h".  If we don't, it means we probably
1432         # don't have kerberos, so don't use it.
1433         #
1434         AC_CHECK_HEADER(krb5.h,,
1435           [
1436             if test "x$krb5_dir" != "x"
1437             then
1438               #
1439               # The user used "--with-krb5=" to specify a directory
1440               # containing kerberos, but we didn't find the header file
1441               # there; that either means they didn't specify the
1442               # right directory or are confused about whether kerberos
1443               # is, in fact, installed.  Report the error and give up.
1444               #
1445               AC_MSG_ERROR([kerberos header not found in directory specified in --with-krb5])
1446             else
1447               if test "x$want_krb5" = "xyes"
1448               then
1449                 #
1450                 # The user tried to force us to use the library, but we
1451                 # couldn't find the header file; report an error.
1452                 #
1453                 AC_MSG_ERROR(Header file krb5.h not found.)
1454               else
1455                 #
1456                 # We couldn't find the header file; don't use the
1457                 # library, as it's probably not present.
1458                 #
1459                 want_krb5=no
1460                 AC_MSG_RESULT(No Heimdal or MIT header found - disabling dissection for some kerberos data in packet decoding)
1461               fi
1462             fi
1463           ])
1464
1465         if test "x$want_krb5" != "xno"
1466         then
1467             #
1468             # Well, we at least have the krb5 header file.
1469             # Check whether this is Heimdal or MIT.
1470             #
1471             AC_MSG_CHECKING(whether the Kerberos library is Heimdal or MIT)
1472             if test "x$ac_krb5_version" = "xHEIMDAL" -o "x$ac_krb5_version" = "xMIT"
1473             then
1474                 #
1475                 # Yes.
1476                 # Check whether we have krb5_kt_resolve - and whether
1477                 # we need to link with -lresolv when linking with
1478                 # the Kerberos library.
1479                 #
1480                 AC_MSG_RESULT($ac_krb5_version)
1481                 wireshark_save_LIBS="$LIBS"
1482                 found_krb5_kt_resolve=no
1483                 for extras in "" "-lresolv"
1484                 do
1485                     LIBS="$KRB5_LIBS $extras"
1486                     if test -z "$extras"
1487                     then
1488                         AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve])
1489                     else
1490                         AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve (linking with $extras)])
1491                     fi
1492                     AC_TRY_LINK(
1493                         [
1494                         ],
1495                         [
1496                             krb5_kt_resolve();
1497                         ],
1498                         [
1499                             #
1500                             # We found "krb5_kt_resolve()", and required
1501                             # the libraries in extras as well.
1502                             #
1503                             AC_MSG_RESULT(yes)
1504                             KRB5_LIBS="$LIBS"
1505                             AC_DEFINE(HAVE_KERBEROS, 1, [Define to use kerberos])
1506                             if test "x$ac_krb5_version" = "xHEIMDAL"
1507                             then
1508                                 AC_DEFINE(HAVE_HEIMDAL_KERBEROS, 1, [Define to use heimdal kerberos])
1509                             elif test "x$ac_krb5_version" = "xMIT"
1510                             then
1511                                 AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
1512                             fi
1513                             found_krb5_kt_resolve=yes
1514                             break
1515                         ],
1516                         [
1517                             AC_MSG_RESULT(no)
1518                         ])
1519                 done
1520                 if test "$found_krb5_kt_resolve" = no
1521                 then
1522                     #
1523                     # We didn't find "krb5_kt_resolve()" in the
1524                     # Kerberos library, even when we tried linking
1525                     # with -lresolv; we can't link with kerberos.
1526                     #
1527                     if test "x$want_krb5" = "xyes"
1528                     then
1529                         #
1530                         # The user tried to force us to use the library,
1531                         # but we can't do so; report an error.
1532                         #
1533                         AC_MSG_ERROR(Usable $ac_krb5_version not found)
1534                     else
1535                         #
1536                         # Restore the versions of CFLAGS and CPPFLAGS
1537                         # from before we added the flags for Kerberos.
1538                         #
1539                         AC_MSG_RESULT(Usable $ac_krb5_version not found - disabling dissection for some kerberos data in packet decoding)
1540                         CFLAGS="$wireshark_save_CFLAGS"
1541                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1542                         KRB5_LIBS=""
1543                         want_krb5=no
1544                     fi
1545                 else
1546                     #
1547                     # We can link with Kerberos; see whether krb5.h
1548                     # defines KEYTYPE_ARCFOUR_56 (where "defines" means
1549                     # "as a #define or as an enum member).
1550                     #
1551                     AC_MSG_CHECKING([whether krb5.h defines KEYTYPE_ARCFOUR_56])
1552                     AC_COMPILE_IFELSE(
1553                       [
1554                         AC_LANG_SOURCE(
1555                           [[
1556                             #include <krb5.h>
1557                             #include <stdio.h>
1558
1559                             main()
1560                             {
1561                               printf("%u\n", KEYTYPE_ARCFOUR_56);
1562                             }
1563                           ]])
1564                       ],
1565                       [
1566                         AC_MSG_RESULT(yes)
1567                         AC_DEFINE(HAVE_KEYTYPE_ARCFOUR_56, 1, [Define if krb5.h defines KEYTYPE_ARCFOUR_56])
1568                       ],
1569                       [
1570                         AC_MSG_RESULT(no)
1571                       ])
1572                 fi
1573                 LIBS="$wireshark_save_LIBS"
1574             else
1575                 #
1576                 # It's not Heimdal or MIT.
1577                 #
1578                 AC_MSG_RESULT(no)
1579                 if test "x$want_krb5" = "xyes"
1580                 then
1581                     #
1582                     # The user tried to force us to use the library,
1583                     # but we can't do so; report an error.
1584                     #
1585                     AC_MSG_ERROR(Kerberos not found)
1586                 else
1587                     #
1588                     # Restore the versions of CFLAGS and CPPFLAGS
1589                     # from before we added the flags for Kerberos.
1590                     #
1591                     AC_MSG_RESULT(Kerberos not found - disabling dissection for some kerberos data in packet decoding)
1592                     CFLAGS="$wireshark_save_CFLAGS"
1593                     CPPFLAGS="$wireshark_save_CPPFLAGS"
1594                     KRB5_LIBS=""
1595                     want_krb5=no
1596                 fi
1597             fi
1598         else
1599             #
1600             # The user asked us not to use Kerberos, or they didn't
1601             # say whether they wanted us to use it but we found
1602             # that we couldn't.
1603             #
1604             # Restore the versions of CFLAGS and CPPFLAGS
1605             # from before we added the flags for Kerberos.
1606             #
1607             CFLAGS="$wireshark_save_CFLAGS"
1608             CPPFLAGS="$wireshark_save_CPPFLAGS"
1609             KRB5_LIBS=""
1610             want_krb5=no
1611         fi
1612         AC_SUBST(KRB5_LIBS)
1613 ])
1614
1615 #
1616 # AC_WIRESHARK_GEOIP_CHECK
1617 #
1618 AC_DEFUN([AC_WIRESHARK_GEOIP_CHECK],
1619 [
1620         want_geoip=defaultyes
1621
1622         if test "x$want_geoip" = "xdefaultyes"; then
1623                 want_geoip=yes
1624                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1625                         withval=/usr/local
1626                         if test -d "$withval"; then
1627                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1628                         fi
1629                 fi
1630         fi
1631
1632         if test "x$want_geoip" = "xyes"; then
1633                 AC_CHECK_LIB(GeoIP, GeoIP_new,
1634                   [
1635                     GEOIP_LIBS=-lGeoIP
1636                 AC_DEFINE(HAVE_GEOIP, 1, [Define to use GeoIP library])
1637                 have_good_geoip=yes
1638                   ],,
1639                 )
1640         else
1641                 AC_MSG_RESULT(not required)
1642         fi
1643 ])
1644
1645 #
1646 # AC_WIRESHARK_GCC_CFLAGS_CHECK
1647 #
1648 # $1 : cflags to test
1649 #
1650 # The macro first determines if the compiler is GCC. Then compile with the
1651 # defined cflags. The defined flags are added to CFLAGS only if the compilation
1652 # succeeds.
1653 #
1654 AC_DEFUN([AC_WIRESHARK_GCC_CFLAGS_CHECK],
1655 [GCC_OPTION="$1"
1656 AC_MSG_CHECKING(whether we can add $GCC_OPTION to CFLAGS)
1657 if test "x$GCC" != "x"; then
1658   CFLAGS_saved="$CFLAGS"
1659   CFLAGS="$CFLAGS $GCC_OPTION"
1660   AC_COMPILE_IFELSE([
1661     AC_LANG_SOURCE([[
1662                       int foo;
1663                   ]])],
1664                   [
1665                     AC_MSG_RESULT(yes)
1666                   ],
1667                   [
1668                     AC_MSG_RESULT(no)
1669                     CFLAGS="$CFLAGS_saved"
1670                   ])
1671 else
1672   AC_MSG_RESULT(no)
1673 fi
1674 ])
1675
1676 #
1677 # AC_WIRESHARK_IGE_MAC_INTEGRATION_CHECK
1678 #
1679 # Checks for the presence of OS X integration functions in the GTK+ framework
1680 # or as a separate library.
1681 #
1682 # http://developer.imendio.com/projects/gtk-macosx/integration
1683 #
1684 AC_DEFUN([AC_WIRESHARK_IGE_MAC_INTEGRATION_CHECK],
1685 [
1686         ac_save_CFLAGS="$CFLAGS"
1687         ac_save_LIBS="$LIBS"
1688         CFLAGS="$CFLAGS $GTK_CFLAGS"
1689         LIBS="$GTK_LIBS $LIBS"
1690         AC_CHECK_LIB(Gtk, ige_mac_menu_set_menu_bar,
1691         [
1692                 AC_DEFINE(HAVE_IGE_MAC_INTEGRATION, 1,
1693                         [Define to 1 if the the Gtk+ framework or a separate library inclues the Imendio IGE Mac OS X Integration functions.])
1694                 have_ige_mac=yes
1695                 # We don't want gtk stuff in LIBS (which is reset below) so
1696                 # manually set GTK_LIBS (which is more appropriate)
1697                 GTK_LIBS="$GTK_LIBS -lGtk"
1698         ])
1699
1700         if test x$have_ige_mac == x
1701         then
1702                 AC_CHECK_LIB(igemacintegration, ige_mac_menu_set_menu_bar,
1703                 [
1704                         AC_DEFINE(HAVE_IGE_MAC_INTEGRATION, 1,
1705                                 [Define to 1 if the the Gtk+ framework or a separate library inclues the Imendio IGE Mac OS X Integration functions.])
1706                         # We don't want gtk stuff in LIBS (which is reset below) so
1707                         # manually set GTK_LIBS (which is more appropriate)
1708                         GTK_LIBS="$GTK_LIBS -ligemacintegration"
1709                 ])
1710         fi
1711         CFLAGS="$ac_save_CFLAGS"
1712         LIBS="$ac_save_LIBS"
1713 ])
1714
1715 #
1716 # AC_WIRESHARK_PYTHON_CHECK
1717 #
1718 # Check whether python devel package is present
1719 #
1720 AC_DEFUN([AC_WIRESHARK_PYTHON_CHECK],
1721   [
1722     #
1723     # Checking whether we have a python devel environment available
1724     #
1725 #  AC_CACHE_CHECK([checking python devel package], ac_cv_wireshark_python_devel,
1726 #    [
1727     AC_CHECK_PROG([ac_ws_python_config], [python-config], "yes", "no")
1728     if test ac_ws_python_config = "no"; then
1729       ac_cv_wireshark_python_devel = "no"
1730     else
1731       AC_MSG_CHECKING([python devel])
1732       ac_save_ws_cflags=$CFLAGS
1733       ac_save_ws_libs=$LIBS
1734       CFLAGS=$(python-config --includes)
1735       LIBS=$(python-config --ldflags)
1736       AC_COMPILE_IFELSE(
1737         [
1738           AC_LANG_PROGRAM(
1739             [[#include <Python.h>]],
1740             [[Py_Initialiaze();]]
1741           )
1742         ],
1743         [
1744           #
1745           # Compilation successful, we have python devel available
1746           #
1747           ac_cv_wireshark_python_devel=yes
1748           PY_LIBS=$LIBS
1749           PY_CFLAGS=$CFLAGS
1750           AC_SUBST(PY_LIBS)
1751           AC_SUBST(PY_CFLAGS)
1752           CFLAGS="$ac_save_ws_cflags"
1753           LIBS="$ac_save_ws_libs"
1754           AC_DEFINE(HAVE_PYTHON, 1, [Define if python devel package available])
1755           AC_MSG_RESULT([yes])
1756         ],
1757         [
1758           #
1759           # Compilation unsuccessful, python devel not available
1760           #
1761           ac_cv_wireshark_python_devel=no
1762           CFLAGS=$ac_save_ws_cflags
1763           LIBS=$ac_save_ws_libs
1764           AC_MSG_RESULT([no])
1765         ])
1766     fi
1767 #    ])
1768 ])