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