1ad3d2d02a4e1cf2207b203a26ea231ae3448aeb
[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_PCAP_CHECK
299 #
300 AC_DEFUN([AC_WIRESHARK_PCAP_CHECK],
301 [
302         if test -z "$pcap_dir"
303         then
304           # Pcap header checks
305           # XXX need to set a var AC_CHECK_HEADER(pcap.h,,)
306
307           #
308           # The user didn't specify a directory in which libpcap resides;
309           # we assume that the current library search path will work,
310           # but we may have to look for the header in a "pcap"
311           # subdirectory of "/usr/include" or "/usr/local/include",
312           # as some systems apparently put "pcap.h" in a "pcap"
313           # subdirectory, and we also check "$prefix/include" - and
314           # "$prefix/include/pcap", in case $prefix is set to
315           # "/usr/include" or "/usr/local/include".
316           #
317           # XXX - should we just add "$prefix/include" to the include
318           # search path and "$prefix/lib" to the library search path?
319           #
320           AC_MSG_CHECKING(for extraneous pcap header directories)
321           found_pcap_dir=""
322           pcap_dir_list="/usr/include/pcap $prefix/include/pcap $prefix/include"
323           if test "x$ac_cv_enable_usr_local" = "xyes" ; then
324             pcap_dir_list="$pcap_dir_list /usr/local/include/pcap"
325           fi
326           for pcap_dir in $pcap_dir_list
327           do
328             if test -d $pcap_dir ; then
329                 if test x$pcap_dir != x/usr/include -a x$pcap_dir != x/usr/local/include ; then
330                     CFLAGS="$CFLAGS -I$pcap_dir"
331                     CPPFLAGS="$CPPFLAGS -I$pcap_dir"
332                 fi
333                 found_pcap_dir=" $found_pcap_dir -I$pcap_dir"
334                 break
335             fi
336           done
337
338           if test "$found_pcap_dir" != "" ; then
339             AC_MSG_RESULT(found --$found_pcap_dir added to CFLAGS)
340           else
341             AC_MSG_RESULT(not found)
342           fi
343         else
344           #
345           # The user specified a directory in which libpcap resides,
346           # so add the "include" subdirectory of that directory to
347           # the include file search path and the "lib" subdirectory
348           # of that directory to the library search path.
349           #
350           # XXX - if there's also a libpcap in a directory that's
351           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
352           # make us find the version in the specified directory,
353           # as the compiler and/or linker will search that other
354           # directory before it searches the specified directory.
355           #
356           CFLAGS="$CFLAGS -I$pcap_dir/include"
357           CPPFLAGS="$CPPFLAGS -I$pcap_dir/include"
358           AC_WIRESHARK_ADD_DASH_L(LDFLAGS, $pcap_dir/lib)
359         fi
360
361         # Pcap header check
362         AC_CHECK_HEADER(pcap.h,, 
363             AC_MSG_ERROR([[Header file pcap.h not found; if you installed libpcap
364 from source, did you also do \"make install-incl\", and if you installed a
365 binary package of libpcap, is there also a developer's package of libpcap,
366 and did you also install that package?]]))
367
368         #
369         # Check to see if we find "pcap_open_live" in "-lpcap".
370         # Also check for various additional libraries that libpcap might
371         # require.
372         #
373         AC_CHECK_LIB(pcap, pcap_open_live,
374           [
375             PCAP_LIBS=-lpcap
376             AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
377           ], [
378             ac_wireshark_extras_found=no
379             ac_save_LIBS="$LIBS"
380             for extras in "-lcfg -lodm" "-lpfring"
381             do
382                 AC_MSG_CHECKING([for pcap_open_live in -lpcap with $extras])
383                 LIBS="-lpcap $extras"
384                 #
385                 # XXX - can't we use AC_CHECK_LIB here?
386                 #
387                 AC_TRY_LINK(
388                     [
389 #       include <pcap.h>
390                     ],
391                     [
392         pcap_open_live(NULL, 0, 0, 0, NULL);
393                     ],
394                     [
395                         ac_wireshark_extras_found=yes
396                         AC_MSG_RESULT([yes])
397                         PCAP_LIBS="-lpcap $extras"
398                         AC_DEFINE(HAVE_LIBPCAP, 1, [Define to use libpcap library])
399                     ],
400                     [
401                         AC_MSG_RESULT([no])
402                     ])
403                 if test x$ac_wireshark_extras_found = xyes
404                 then
405                     break
406                 fi
407             done
408             if test x$ac_wireshark_extras_found = xno
409             then
410                 AC_MSG_ERROR([Can't link with library libpcap.])
411             fi
412             LIBS=$ac_save_LIBS
413           ], $SOCKET_LIBS $NSL_LIBS)
414         AC_SUBST(PCAP_LIBS)
415
416         #
417         # Check whether various variables and functions are defined by
418         # libpcap.
419         #
420         ac_save_LIBS="$LIBS"
421         AC_MSG_CHECKING(whether pcap_version is defined by libpcap)
422         LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
423         AC_TRY_LINK(
424            [
425 #       include <stdio.h>
426         extern char *pcap_version;
427            ],
428            [
429         printf ("%s\n", pcap_version);
430            ],
431            ac_cv_pcap_version_defined=yes,
432            ac_cv_pcap_version_defined=no,
433            [echo $ac_n "cross compiling; assumed OK... $ac_c"])
434         if test "$ac_cv_pcap_version_defined" = yes ; then
435                 AC_MSG_RESULT(yes)
436                 AC_DEFINE(HAVE_PCAP_VERSION, 1, [Define if libpcap version is known])
437         else
438                 AC_MSG_RESULT(no)
439         fi
440         AC_CHECK_FUNCS(pcap_open_dead pcap_freecode pcap_breakloop)
441         #
442         # Later versions of Mac OS X 10.3[.x] ship a pcap.h that
443         # doesn't define pcap_if_t but ship an 0.8[.x] libpcap,
444         # so the library has "pcap_findalldevs()", but pcap.h
445         # doesn't define "pcap_if_t" so you can't actually *use*
446         # "pcap_findalldevs()".
447         #
448         # That even appears to be true of systems shipped with
449         # 10.3.4, so it doesn't appear only to be a case of
450         # Software Update not updating header files.
451         #
452         # (You can work around this by installing the 0.8 header
453         # files.)
454         #
455         AC_CACHE_CHECK([whether pcap_findalldevs is present and usable],
456           [ac_cv_func_pcap_findalldevs],
457           [
458             AC_LINK_IFELSE(
459               [
460                 AC_LANG_SOURCE(
461                   [[
462                     #include <pcap.h>
463                     main()
464                     {
465                       pcap_if_t *devpointer;
466                       char errbuf[1];
467
468                       pcap_findalldevs(&devpointer, errbuf);
469                     }
470                   ]])
471               ],
472               [
473                 ac_cv_func_pcap_findalldevs=yes
474               ],
475               [
476                 ac_cv_func_pcap_findalldevs=no
477               ])
478           ])
479         #
480         # Don't check for other new routines that showed up after
481         # "pcap_findalldevs()" if we don't have a usable
482         # "pcap_findalldevs()", so we don't end up using them if the
483         # "pcap.h" is crufty and old and doesn't declare them.
484         #
485         if test $ac_cv_func_pcap_findalldevs = "yes" ; then
486           AC_DEFINE(HAVE_PCAP_FINDALLDEVS, 1,
487            [Define to 1 if you have the `pcap_findalldevs' function and a pcap.h that declares pcap_if_t.])
488           AC_CHECK_FUNCS(pcap_datalink_val_to_name pcap_datalink_name_to_val)
489           AC_CHECK_FUNCS(pcap_list_datalinks pcap_set_datalink pcap_lib_version)
490           AC_CHECK_FUNCS(pcap_get_selectable_fd)
491         fi
492         LIBS="$ac_save_LIBS"
493 ])
494
495 #
496 # AC_WIRESHARK_ZLIB_CHECK
497 #
498 AC_DEFUN([AC_WIRESHARK_ZLIB_CHECK],
499 [
500         if test "x$zlib_dir" != "x"
501         then
502           #
503           # The user specified a directory in which zlib resides,
504           # so add the "include" subdirectory of that directory to
505           # the include file search path and the "lib" subdirectory
506           # of that directory to the library search path.
507           #
508           # XXX - if there's also a zlib in a directory that's
509           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
510           # make us find the version in the specified directory,
511           # as the compiler and/or linker will search that other
512           # directory before it searches the specified directory.
513           #
514           wireshark_save_CFLAGS="$CFLAGS"
515           CFLAGS="$CFLAGS -I$zlib_dir/include"
516           wireshark_save_CPPFLAGS="$CPPFLAGS"
517           CPPFLAGS="$CPPFLAGS -I$zlib_dir/include"
518           wireshark_save_LIBS="$LIBS"
519           AC_WIRESHARK_ADD_DASH_L(LIBS, $zlib_dir/lib)
520         fi
521
522         #
523         # Make sure we have "zlib.h".  If we don't, it means we probably
524         # don't have zlib, so don't use it.
525         #
526         AC_CHECK_HEADER(zlib.h,,
527           [
528             if test "x$zlib_dir" != "x"
529             then
530               #
531               # The user used "--with-zlib=" to specify a directory
532               # containing zlib, but we didn't find the header file
533               # there; that either means they didn't specify the
534               # right directory or are confused about whether zlib
535               # is, in fact, installed.  Report the error and give up.
536               #
537               AC_MSG_ERROR([zlib header not found in directory specified in --with-zlib])
538             else
539               if test "x$want_zlib" = "xyes"
540               then
541                 #
542                 # The user tried to force us to use the library, but we
543                 # couldn't find the header file; report an error.
544                 #
545                 AC_MSG_ERROR(Header file zlib.h not found.)
546               else
547                 #
548                 # We couldn't find the header file; don't use the
549                 # library, as it's probably not present.
550                 #
551                 want_zlib=no
552               fi
553             fi
554           ])
555
556         if test "x$want_zlib" != "xno"
557         then
558                 #
559                 # Well, we at least have the zlib header file.
560                 #
561                 # Check for "gzgets()" in zlib, because we need it, but
562                 # some older versions of zlib don't have it.  It appears
563                 # from the zlib ChangeLog that any released version of zlib
564                 # with "gzgets()" should have the other routines we
565                 # depend on, such as "gzseek()", "gztell()", and "zError()".
566                 #
567                 # Another reason why we require "gzgets()" is that
568                 # some versions of zlib that didn't have it, such
569                 # as 1.0.8, had a bug in "gzseek()" that meant that it
570                 # doesn't work correctly on uncompressed files; this
571                 # means we cannot use version 1.0.8.  (Unfortunately,
572                 # that's the version that comes with recent X11 source,
573                 # and many people who install XFree86 on their Slackware
574                 # boxes don't realize that they should configure it to
575                 # use the native zlib rather than building and installing
576                 # the crappy old version that comes with XFree86.)
577                 #
578                 # I.e., we can't just avoid using "gzgets()", as
579                 # versions of zlib without "gzgets()" are likely to have
580                 # a broken "gzseek()".
581                 #
582                 AC_CHECK_LIB(z, gzgets,
583                 [
584                         if test "x$zlib_dir" != "x"
585                         then
586                                 #
587                                 # Put the "-I" and "-L" flags for zlib at
588                                 # the beginning of CFLAGS, CPPFLAGS, and
589                                 # LIBS.
590                                 #
591                                 LIBS=""
592                                 AC_WIRESHARK_ADD_DASH_L(LIBS, $zlib_dir/lib)
593                                 LIBS="$LIBS -lz $wireshark_save_LIBS"
594                         else
595                                 LIBS="-lz $LIBS"
596                         fi
597                         AC_DEFINE(HAVE_LIBZ, 1, [Define to use libz library])
598                 ],[
599                         if test "x$zlib_dir" != "x"
600                         then
601                                 #
602                                 # Restore the versions of CFLAGS, CPPFLAGS,
603                                 # and LIBS before we added the "-with-zlib="
604                                 # directory, as we didn't actually find
605                                 # zlib there, or didn't find a zlib that
606                                 # contains gzgets there.
607                                 #
608                                 CFLAGS="$wireshark_save_CFLAGS"
609                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
610                                 LIBS="$wireshark_save_LIBS"
611                         fi
612                         want_zlib=no
613                 ])
614         fi
615
616         if test "x$want_zlib" != "xno"
617         then
618                 #
619                 # Well, we at least have the zlib header file and a zlib
620                 # with "gzgets()".
621                 #
622                 # Now check for "gzgets()" in zlib when linking with the
623                 # linker flags for GTK+ applications; people often grab
624                 # XFree86 source and build and install it on their systems,
625                 # and they appear sometimes to misconfigure XFree86 so that,
626                 # even on systems with zlib, it assumes there is no zlib,
627                 # so the XFree86 build process builds and installs its
628                 # own zlib in the X11 library directory.
629                 #
630                 # The XFree86 zlib is an older version that lacks
631                 # "gzgets()", and that's the zlib with which Ethereal
632                 # gets linked, so the build of Ethereal fails.
633                 #
634                 ac_save_CFLAGS="$CFLAGS"
635                 ac_save_LIBS="$LIBS"
636                 CFLAGS="$CFLAGS $GTK_CFLAGS"
637                 LIBS="$GTK_LIBS -lz $LIBS"
638                 AC_MSG_CHECKING([for gzgets missing when linking with X11])
639                 AC_TRY_LINK_FUNC(gzgets, AC_MSG_RESULT(no),
640                   [
641                     AC_MSG_RESULT(yes)
642                     AC_MSG_ERROR(old zlib found when linking with X11 - get rid of old zlib.)
643                   ])
644                 CFLAGS="$ac_save_CFLAGS"
645                 LIBS="$ac_save_LIBS"
646         fi
647 ])
648
649 #
650 # AC_WIRESHARK_LIBPCRE_CHECK
651 #
652 AC_DEFUN([AC_WIRESHARK_LIBPCRE_CHECK],
653 [
654         if test "x$pcre_dir" != "x"
655         then
656           #
657           # The user specified a directory in which libpcre resides,
658           # so add the "include" subdirectory of that directory to
659           # the include file search path and the "lib" subdirectory
660           # of that directory to the library search path.
661           #
662           # XXX - if there's also a libpcre in a directory that's
663           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
664           # make us find the version in the specified directory,
665           # as the compiler and/or linker will search that other
666           # directory before it searches the specified directory.
667           #
668           wireshark_save_CFLAGS="$CFLAGS"
669           CFLAGS="$CFLAGS -I$pcre_dir/include"
670           wireshark_save_CPPFLAGS="$CPPFLAGS"
671           CPPFLAGS="$CPPFLAGS -I$pcre_dir/include"
672           wireshark_save_LIBS="$LIBS"
673           LIBS="$LIBS -lpcre"
674           wireshark_save_LDFLAGS="$LDFLAGS"
675           LDFLAGS="$LDFLAGS -L$pcre_dir/lib"
676         fi
677
678         #
679         # Make sure we have "pcre.h".  If we don't, it means we probably
680         # don't have libpcre, so don't use it.
681         #
682         AC_CHECK_HEADER(pcre.h,,
683           [
684             if test "x$pcre_dir" != "x"
685             then
686               #
687               # The user used "--with-pcre=" to specify a directory
688               # containing libpcre, but we didn't find the header file
689               # there; that either means they didn't specify the
690               # right directory or are confused about whether libpcre
691               # is, in fact, installed.  Report the error and give up.
692               #
693               AC_MSG_ERROR([libpcre header not found in directory specified in --with-pcre])
694             else
695               if test "x$want_pcre" = "xyes"
696               then
697                 #
698                 # The user tried to force us to use the library, but we
699                 # couldn't find the header file; report an error.
700                 #
701                 AC_MSG_ERROR(Header file pcre.h not found.)
702               else
703                 #
704                 # We couldn't find the header file; don't use the
705                 # library, as it's probably not present.
706                 #
707                 want_pcre=no
708               fi
709             fi
710           ])
711
712         if test "x$want_pcre" != "xno"
713         then
714                 #
715                 # Well, we at least have the pcre header file.
716                 #
717                 # We're only using standard functions from libpcre,
718                 # so we don't need to perform extra checks.
719                 #
720                 AC_CHECK_LIB(pcre, pcre_compile,
721                 [
722                         if test "x$pcre_dir" != "x"
723                         then
724                                 #
725                                 # Put the "-I" and "-L" flags for pcre at
726                                 # the beginning of CFLAGS, CPPFLAGS,
727                                 # LDFLAGS, and LIBS.
728                                 #
729                                 PCRE_LIBS="-L$pcre_dir/lib -lpcre $wireshark_save_LIBS"
730                         else
731                                 PCRE_LIBS="-lpcre"
732                         fi
733                         AC_DEFINE(HAVE_LIBPCRE, 1, [Define to use libpcre library])
734                 ],[
735                         if test "x$pcre_dir" != "x"
736                         then
737                                 #
738                                 # Restore the versions of CFLAGS, CPPFLAGS,
739                                 # LDFLAGS, and LIBS before we added the
740                                 # "--with-pcre=" directory, as we didn't
741                                 # actually find pcre there.
742                                 #
743                                 CFLAGS="$wireshark_save_CFLAGS"
744                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
745                                 LDFLAGS="$wireshark_save_LDFLAGS"
746                                 LIBS="$wireshark_save_LIBS"
747                                 PCRE_LIBS=""
748                         fi
749                         want_pcre=no
750                 ])
751                 AC_SUBST(PCRE_LIBS)
752         fi
753 ])
754
755 #
756 # AC_WIRESHARK_LIBLUA_CHECK
757 #
758 AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
759
760         if test "x$lua_dir" != "x"
761         then
762                 #
763                 # The user specified a directory in which liblua resides,
764                 # so add the "include" subdirectory of that directory to
765                 # the include file search path and the "lib" subdirectory
766                 # of that directory to the library search path.
767                 #
768                 # XXX - if there's also a liblua in a directory that's
769                 # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
770                 # make us find the version in the specified directory,
771                 # as the compiler and/or linker will search that other
772                 # directory before it searches the specified directory.
773                 #
774                 wireshark_save_CFLAGS="$CFLAGS"
775                 CFLAGS="$CFLAGS -I$lua_dir/include"
776                 wireshark_save_CPPFLAGS="$CPPFLAGS"
777                 CPPFLAGS="$CPPFLAGS -I$lua_dir/include"
778                 wireshark_save_LIBS="$LIBS"
779                 LIBS="$LIBS -L$lua_dir/lib -llua"
780                 wireshark_save_LDFLAGS="$LDFLAGS"
781                 LDFLAGS="$LDFLAGS -L$lua_dir/lib"
782         else 
783                 #
784                 # The user specified no directory in which liblua resides,
785                 # so just add "-llua -lliblua" to the used libs.
786                 #
787                 wireshark_save_CFLAGS="$CFLAGS"
788                 wireshark_save_CPPFLAGS="$CPPFLAGS"
789                 wireshark_save_LDFLAGS="$LDFLAGS"
790                 wireshark_save_LIBS="$LIBS"
791                 LIBS="$LIBS -llua"
792         fi
793
794         #
795         # Make sure we have "lua.h", "lualib.h" and "lauxlib.h".  If we don't, it means we probably
796         # don't have liblua, so don't use it.
797         #
798         AC_CHECK_HEADERS(lua.h lualib.h lauxlib.h,,
799         [
800                 AC_CHECK_HEADERS(lua5.1/lua.h lua5.1/lualib.h lua5.1/lauxlib.h,
801                 [
802                         if test "x$lua_dir" != "x"
803                         then
804                                 LUA_INCLUDES="-I$lua_dir/include/lua5.1"
805                         else
806                                 # we found lua5.1/lua.h, but we don't know which include dir contains it
807                                 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.)
808                         fi
809                         
810                 ],
811                 [
812                         if test "x$lua_dir" != "x"
813                         then
814                                 #
815                                 # The user used "--with-lua=" to specify a directory
816                                 # containing liblua, but we didn't find the header file
817                                 # there; that either means they didn't specify the
818                                 # right directory or are confused about whether liblua
819                                 # is, in fact, installed.  Report the error and give up.
820                                 #
821                                 AC_MSG_ERROR([liblua header not found in directory specified in --with-lua])
822                         else
823                                 if test "x$want_lua" = "xyes"
824                                 then
825                                         #
826                                         # The user tried to force us to use the library, but we
827                                         # couldn't find the header file; report an error.
828                                         #
829                                         AC_MSG_ERROR(Header file lua.h not found.)
830                                 else
831                                         #
832                                         # We couldn't find the header file; don't use the
833                                         # library, as it's probably not present.
834                                         #
835                                         want_lua=no
836                                 fi
837                         fi
838                 ])
839         ])
840
841         if test "x$want_lua" != "xno"
842         then
843                 #
844                 # Well, we at least have the lua header file.
845                 #
846                 # let's check if the libs are there
847                 #
848
849                 # At least on Suse 9.3 systems, liblualib needs linking
850                 # against libm.
851                 LIBS="$LIBS $LUA_LIBS -lm"
852
853                 AC_CHECK_LIB(lua, lua_call,
854                 [
855                         if test "x$lua_dir" != "x"
856                         then
857                                 #
858                                 # Put the "-I" and "-L" flags for lua at
859                                 # the beginning of CFLAGS, CPPFLAGS,
860                                 # LDFLAGS, and LIBS.
861                                 #
862                                 LUA_LIBS="-L$lua_dir/lib -llua"
863                                 LUA_INCLUDES="-I$lua_dir/include"
864                         else
865                                 LUA_LIBS="-llua"
866                                 LUA_INCLUDES=""
867                         fi
868
869                         #
870                         # we got lua, now look for lualib
871                         #
872                         AC_CHECK_LIB(lualib, luaL_openlib,
873                         [
874                                 #
875                                 # we have 5.0
876                                 #
877                                 LUA_LIBS="$LUA_LIBS -llualib"
878                         ],[
879                                 #
880                                 # no lualib, in 5.1 there's only liblua
881                                 # do we have 5.1?
882                                 #
883                                 
884                                 LIBS="$wireshark_save_LIBS $LUA_LIBS"
885
886                                 AC_CHECK_LIB(lua, luaL_register,
887                                 [
888                                     #
889                                     #  Lua 5.1 found
890                                     #
891                                     AC_DEFINE(HAVE_LUA_5_1, 1, [Define to use Lua 5.1])
892                                 ],[
893                                     #
894                                     # No, it is not 5.1
895                                     #
896                                     if test "x$lua_dir" != "x"
897                                     then
898                                         #
899                                         # Restore the versions of CFLAGS, CPPFLAGS,
900                                         # LDFLAGS, and LIBS before we added the
901                                         # "--with-lua=" directory, as we didn't
902                                         # actually find lua there.
903                                         #
904                                         CFLAGS="$wireshark_save_CFLAGS"
905                                         CPPFLAGS="$wireshark_save_CPPFLAGS"
906                                         LDFLAGS="$wireshark_save_LDFLAGS"
907                                         LIBS="$wireshark_save_LIBS"
908                                         LUA_LIBS=""
909                                     fi
910                                     # User requested --with-lua but it isn't available
911                                     if test "x$want_lua" = "xyes"
912                                     then
913                                         AC_MSG_ERROR(Linking with liblualib failed.)
914                                     fi
915                                     want_lua=no
916                                 ])
917                         ])
918                 ],[  
919                         #
920                         # We could not find the libs, maybe we have version number in the lib name
921                         #
922
923                         LIBS="$wireshark_save_LIBS -llua5.1 -lm"
924
925                         AC_CHECK_LIB(lua5.1, luaL_register,
926                         [
927                             #
928                             #  Lua 5.1 found
929                             #
930                             AC_DEFINE(HAVE_LUA_5_1, 1, [Define to use Lua 5.1])
931                             LUA_LIBS=" -llua5.1 -lm"
932                         ],[
933                                 #
934                                 # Restore the versions of CFLAGS, CPPFLAGS,
935                                 # LDFLAGS, and LIBS before we added the
936                                 # "--with-lua=" directory, as we didn't
937                                 # actually find lua there.
938                                 #
939                                 CFLAGS="$wireshark_save_CFLAGS"
940                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
941                                 LDFLAGS="$wireshark_save_LDFLAGS"
942                                 LIBS="$wireshark_save_LIBS"
943                                 LUA_LIBS=""
944                                 # User requested --with-lua but it isn't available
945                                 if test "x$want_lua" = "xyes"
946                                 then
947                                         AC_MSG_ERROR(Linking with liblua failed.)
948                                 fi
949                                 want_lua=no
950                         ])
951                 ])
952
953         CFLAGS="$wireshark_save_CFLAGS"
954         CPPFLAGS="$wireshark_save_CPPFLAGS"
955         LDFLAGS="$wireshark_save_LDFLAGS"
956         LIBS="$wireshark_save_LIBS"
957         AC_SUBST(LUA_LIBS)
958         AC_SUBST(LUA_INCLUDES)
959
960         fi
961 ])
962
963 #
964 # AC_WIRESHARK_LIBPORTAUDIO_CHECK
965 #
966 AC_DEFUN([AC_WIRESHARK_LIBPORTAUDIO_CHECK],[
967
968         if test "x$portaudio_dir" != "x"
969         then
970                 #
971                 # The user specified a directory in which libportaudio
972                 # resides, so add the "include" subdirectory of that directory to
973                 # the include file search path and the "lib" subdirectory
974                 # of that directory to the library search path.
975                 #
976                 # XXX - if there's also a libportaudio in a directory that's
977                 # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
978                 # make us find the version in the specified directory,
979                 # as the compiler and/or linker will search that other
980                 # directory before it searches the specified directory.
981                 #
982                 wireshark_save_CFLAGS="$CFLAGS"
983                 CFLAGS="$CFLAGS -I$portaudio_dir/include"
984                 wireshark_save_CPPFLAGS="$CPPFLAGS"
985                 CPPFLAGS="$CPPFLAGS -I$portaudio_dir/include"
986                 wireshark_save_LIBS="$LIBS"
987                 LIBS="$LIBS -L$portaudio_dir/lib -lportaudio"
988                 wireshark_save_LDFLAGS="$LDFLAGS"
989                 LDFLAGS="$LDFLAGS -L$portaudio_dir/lib"
990         else 
991                 #
992                 # The user specified no directory in which libportaudio resides,
993                 # so just add "-lportaudio" to the used libs.
994                 #
995                 wireshark_save_CFLAGS="$CFLAGS"
996                 wireshark_save_CPPFLAGS="$CPPFLAGS"
997                 wireshark_save_LDFLAGS="$LDFLAGS"
998                 wireshark_save_LIBS="$LIBS"
999                 LIBS="$LIBS -lportaudio"
1000         fi
1001
1002         #
1003         # Make sure we have "portaudio.h".  If we don't, it means we probably
1004         # don't have libportaudio, so don't use it.
1005         #
1006         AC_CHECK_HEADERS(portaudio.h,,
1007         [
1008                 if test "x$portaudio_dir" != "x"
1009                 then
1010                         #
1011                         # The user used "--with-portaudio=" to specify a directory
1012                         # containing libportaudio, but we didn't find the header file
1013                         # there; that either means they didn't specify the
1014                         # right directory or are confused about whether libportaudio
1015                         # is, in fact, installed.  Report the error and give up.
1016                         #
1017                         AC_MSG_ERROR([libportaudio header not found in directory specified in --with-portaudio])
1018                 else
1019                         CFLAGS="$wireshark_save_CFLAGS"
1020                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1021                         LDFLAGS="$wireshark_save_LDFLAGS"
1022                         LIBS="$wireshark_save_LIBS"
1023                         PORTAUDIO_LIBS=""
1024                         if test "x$want_portaudio" = "xyes"
1025                         then
1026                                 #
1027                                 # The user tried to force us to use the library, but we
1028                                 # couldn't find the header file; report an error.
1029                                 #
1030                                 AC_MSG_ERROR(Header file portaudio.h not found.)
1031                         else
1032                                 #
1033                                 # We couldn't find the header file; don't use the
1034                                 # library, as it's probably not present.
1035                                 #
1036                                 want_portaudio=no
1037                         fi
1038                 fi
1039         ])
1040
1041         #
1042         # Check whether we have the right version of portaudio
1043         #
1044         if test "x$want_portaudio" != "xno"
1045         then
1046                 AC_CHECK_TYPE(PortAudioStream,
1047                 AC_DEFINE(PORTAUDIO_API_1, 1, [Define if we are using version of of the Portaudio library API]),
1048                 ,
1049                 [#include <portaudio.h>])
1050         fi
1051
1052         if test "x$want_portaudio" != "xno"
1053         then
1054                 #
1055                 # Well, we at least have the portaudio header file.
1056                 #
1057                 # let's check if the libs are there
1058                 #
1059
1060                 AC_CHECK_LIB(portaudio, Pa_Initialize,
1061                 [
1062                         if test "x$portaudio_dir" != "x"
1063                         then
1064                                 #
1065                                 # Put the "-I" and "-L" flags for portaudio at
1066                                 # the beginning of CFLAGS, CPPFLAGS,
1067                                 # LDFLAGS, and LIBS.
1068                                 #
1069                                 PORTAUDIO_LIBS="-L$portaudio_dir/lib -lportaudio"
1070                                 PORTAUDIO_INCLUDES="-I$portaudio_dir/include"
1071                         else
1072                                 PORTAUDIO_LIBS="-lportaudio"
1073                                 PORTAUDIO_INCLUDES=""
1074                         fi
1075                         AC_DEFINE(HAVE_LIBPORTAUDIO, 1, [Define to use libportaudio library])
1076                         want_portaudio=yes
1077                 ],[  
1078                         #
1079                         # Restore the versions of CFLAGS, CPPFLAGS,
1080                         # LDFLAGS, and LIBS before we added the
1081                         # "--with-portaudio=" directory, as we didn't
1082                         # actually find portaudio there.
1083                         #
1084                         CFLAGS="$wireshark_save_CFLAGS"
1085                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1086                         LDFLAGS="$wireshark_save_LDFLAGS"
1087                         LIBS="$wireshark_save_LIBS"
1088                         PORTAUDIO_LIBS=""
1089                         # User requested --with-portaudio but it isn't available
1090                         if test "x$want_portaudio" = "xyes"
1091                         then
1092                                 AC_MSG_ERROR(Linking with libportaudio failed.)
1093                         fi
1094                         want_portaudio=no
1095                 ])
1096
1097         CFLAGS="$wireshark_save_CFLAGS"
1098         CPPFLAGS="$wireshark_save_CPPFLAGS"
1099         LDFLAGS="$wireshark_save_LDFLAGS"
1100         LIBS="$wireshark_save_LIBS"
1101         AC_SUBST(PORTAUDIO_LIBS)
1102         AC_SUBST(PORTAUDIO_INCLUDES)
1103
1104         fi
1105 ])
1106
1107 #
1108 # AC_WIRESHARK_NETSNMP_CHECK
1109 #
1110 AC_DEFUN([AC_WIRESHARK_NETSNMP_CHECK],
1111 [
1112         dnl get the net-snmp-config binary
1113         if test "x$netsnmpconfig" = "x" ; then
1114                 #
1115                 # The user didn't specify where net-snmp-config is
1116                 # located; search for it.
1117                 #
1118                 AC_PATH_PROG(NETSNMPCONFIG, net-snmp-config)
1119         else
1120                 NETSNMPCNFIG=$netsnmpconfig
1121                 if test ! -x $NETSNMPCONFIG -o ! -f $NETSNMPCONFIG ; then
1122                         NETSNMPCONFIG=$netsnmpconfig/bin/net-snmp-config
1123                         if test ! -x $NETSNMPCONFIG -o ! -f $NETSNMPCONFIG ; then
1124                                 AC_MSG_ERROR(Invalid net-snmp-config: $netsnmpconfig)
1125                         fi
1126                 fi
1127         fi
1128
1129         #
1130         # XXX - check whether $NETSNMPCONFIG is executable?
1131         # if test "x$NETSNMPCONFIG" != "xno" -a "x$NETSNMPCONFIG" != "x" -a -x "$NETSNMPCONFIG" ; then
1132         # We already did that if it was set; presumably AC_PATH_PROG
1133         # will fail if it doesn't find an executable version.
1134         #
1135         if test "x$NETSNMPCONFIG" != "x" ; then
1136                 dnl other choices for flags to use here: could also use
1137                 dnl --prefix or --exec-prefix if you don't want the full list.
1138
1139                 #
1140                 # Save the current settings of CFLAGS and CPPFLAGS, and add
1141                 # the output of "$NETSNMPCONFIG --cflags" to it, so that when
1142                 # searching for the Net-SNMP headers, we look in whatever
1143                 # directory that output specifies.
1144                 #
1145                 wireshark_save_CFLAGS="$CFLAGS"
1146                 wireshark_save_CPPFLAGS="$CPPFLAGS"
1147                 CFLAGS="$CFLAGS `$NETSNMPCONFIG --cflags`"
1148                 CPPFLAGS="$CPPFLAGS `$NETSNMPCONFIG --cflags`"
1149
1150                 AC_CHECK_HEADERS(net-snmp/net-snmp-config.h net-snmp/library/default_store.h)
1151                 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
1152                         SNMP_LIBS=`$NETSNMPCONFIG --libs`
1153                         if echo "$SNMP_LIBS" | grep crypto >/dev/null  && test "x$SSL_LIBS" = "x"; then
1154                                 if test "x$want_netsnmp" = "xyes" ; then
1155                                         AC_MSG_ERROR(Net-SNMP requires openssl but ssl not enabled)
1156                                 else
1157                                         AC_MSG_RESULT(Net-SNMP requires openssl but ssl not enabled - disabling Net-SNMP)
1158                                 fi
1159                                 CFLAGS="$wireshark_save_CFLAGS"
1160                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
1161                                 SNMP_LIBS=
1162                         else
1163                                 AC_DEFINE(HAVE_NET_SNMP, 1, [Define to enable support for Net-SNMP])
1164                                 have_net_snmp="yes"
1165                         fi
1166                 else
1167                         if test "x$want_netsnmp" = "xyes" ; then
1168                                 AC_MSG_ERROR(Net-SNMP not found)
1169                         else
1170                                 #
1171                                 # Restore the versions of CFLAGS and
1172                                 # CPPFLAGS before we added the output
1173                                 # of '$NETSNMPCONFIG --cflags", as we
1174                                 # didn't actually find Net-SNMP there.
1175                                 #
1176                                 CFLAGS="$wireshark_save_CFLAGS"
1177                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
1178                         fi
1179                 fi
1180         fi      
1181 ])
1182
1183 #
1184 # AC_WIRESHARK_UCDSNMP_CHECK
1185 #
1186 AC_DEFUN([AC_WIRESHARK_UCDSNMP_CHECK],
1187 [
1188         if test "x$ucdsnmp_dir" != "x"
1189         then
1190                 #
1191                 # The user specified a directory in which UCD SNMP resides,
1192                 # so add the "include" subdirectory of that directory to
1193                 # the include file search path and the "lib" subdirectory
1194                 # of that directory to the library search path.
1195                 #
1196                 # XXX - if there's also a libpcap in a directory that's
1197                 # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
1198                 # make us find the version in the specified directory,
1199                 # as the compiler and/or linker will search that other
1200                 # directory before it searches the specified directory.
1201                 #
1202                 CFLAGS="$CFLAGS -I$ucdsnmp_dir/include"
1203                 CPPFLAGS="$CPPFLAGS -I$ucdsnmp_dir/include"
1204                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, $ucdsnmp_dir/lib)
1205         fi
1206
1207         #
1208         # Check for one of the UCD SNMP header files we include,
1209         # to see whether we have UCD SNMP installed.
1210         #
1211         AC_CHECK_HEADER(ucd-snmp/ucd-snmp-config.h,
1212         [
1213                 #
1214                 # UCD SNMP or Net-SNMP might require various helper
1215                 # libraries on various platforms, such as "-ldes425"
1216                 # in "/usr/kerberos/lib" on some versions of Red
1217                 # Hat Linux, or "-lkstat" on Solaris.
1218                 #
1219                 # It might also require "-lcrypto" on some platforms;
1220                 # if the user didn't specify --with-ssl, we check
1221                 # whether it would have made a difference and, if so,
1222                 # we tell the user that they needed to request it.
1223                 # (There are annoying licensing issues with it and
1224                 # GPL'ed code, so we don't include it by default.)
1225                 #
1226                 # XXX - autoconf really needs a way to test for
1227                 # a given routine in a given library *and* to test
1228                 # whether additional "-L"/"-R"/whatever flags are
1229                 # needed *before* the "-l" flag for the library
1230                 # and to test whether additional libraries are
1231                 # needed after the library *and* to cache all that
1232                 # information.
1233                 #
1234                 wireshark_save_LIBS="$LIBS"
1235                 found_sprint_realloc_objid=no
1236                 for extras in "" "-L/usr/kerberos/lib -ldes425" "-lkstat"
1237                 do
1238                         LIBS="-lsnmp $extras $SOCKET_LIBS $NSL_LIBS $SSL_LIBS"
1239                         if test -z "$extras"
1240                         then
1241                                 AC_MSG_CHECKING([whether UCD SNMP includes sprint_realloc_objid])
1242                         else
1243                                 AC_MSG_CHECKING([whether UCD SNMP includes sprint_realloc_objid (linking with $extras)])
1244                         fi
1245                         AC_TRY_LINK(
1246                             [
1247                             ],
1248                             [
1249                                 sprint_realloc_objid();
1250                             ],
1251                             [
1252                                 #
1253                                 # We found "sprint_realloc_objid()",
1254                                 # and required the libraries in
1255                                 # extras as well.
1256                                 #
1257                                 AC_MSG_RESULT(yes)
1258                                 SNMP_LIBS="-lsnmp $extras"; break;
1259                                 found_sprint_realloc_objid=yes
1260                                 break
1261                             ],
1262                             [
1263                                 #
1264                                 # The link failed.  If they didn't ask
1265                                 # for SSL, try linking with -lcrypto
1266                                 # as well, and if *that* succeeds,
1267                                 # tell them they'll need to specify
1268                                 # --want-ssl.
1269                                 #
1270                                 AC_MSG_RESULT(no)
1271                                 if test "x$want_ssl" = "xno"
1272                                 then
1273                                         LIBS="$LIBS -lcrypto"
1274                                         AC_TRY_LINK(
1275                                             [
1276                                             ],
1277                                             [
1278                                                 sprint_realloc_objid();
1279                                             ],
1280                                             [
1281                                                 #
1282                                                 # It worked with -lcrypto; tell
1283                                                 # them they'll need to specify
1284                                                 # --with-ssl.
1285                                                 #
1286                                                 found_sprint_realloc_objid=yesnocrypto
1287                                                 AC_MSG_RESULT([UCD SNMP requires -lcrypto but --with-ssl was not specified - disabling UCD SNMP.])
1288                                             ])
1289                                 fi
1290                             ])
1291                 done
1292                 LIBS="$wireshark_save_LIBS"
1293
1294                 #
1295                 # If we didn't find "sprint_realloc_objid()", fail.
1296                 # Either the user needs a newer version of UCD SNMP
1297                 # with "sprint_realloc_objid()", or they may need to
1298                 # specify "--with-ssl".
1299                 #
1300                 if test "$found_snmp_sprint_realloc_objid" = no; then
1301                     AC_MSG_RESULT([UCD SNMP header files found, but sprint_realloc_objid not found in SNMP library - disabling UCD SNMP.])
1302                 elif test "$found_snmp_sprint_realloc_objid" != yes -a "x$want_ucdsnmp" = "xyes"; then
1303                         AC_MSG_ERROR(UCD SNMP requested but fails to build)
1304                 fi
1305
1306                 #
1307                 # We found it, so we have UCD SNMP.
1308                 #
1309                 AC_DEFINE(HAVE_UCD_SNMP, 1, [Define to enable support for UCD-SNMP])
1310                 have_ucd_snmp="yes"
1311         ],[
1312                 #
1313                 # No, we don't have it.
1314                 # If the user explicitly asked for UCD SNMP, fail,
1315                 # otherwise just don't use the UCD SNMP library.
1316                 #
1317                 if test "x$want_ucdsnmp" = "xyes" ; then
1318                         AC_MSG_ERROR(Header file ucd-snmp/snmp.h not found.)
1319                 fi
1320         ])
1321 ])
1322
1323 #
1324 # AC_WIRESHARK_RPM_CHECK
1325 # Looks for the rpm program, and checks to see if we can redefine "_topdir".
1326 #
1327 AC_DEFUN([AC_WIRESHARK_RPM_CHECK],
1328 [
1329         AC_CHECK_PROG(ac_cv_wireshark_have_rpm, rpm, "yes", "no")
1330         if test "x$ac_cv_wireshark_have_rpm" = "xyes"; then
1331                 rpm --define '_topdir /tmp' > /dev/null 2>&1
1332                 AC_MSG_CHECKING(to see if we can redefine _topdir)
1333                 if test $? -eq 0 ; then
1334                         AC_MSG_RESULT(yes)
1335                         HAVE_RPM=yes
1336                 else
1337                         AC_MSG_RESULT(no.  You'll have to build packages manually.)
1338                         HAVE_RPM=no
1339                 fi
1340         fi
1341 ])
1342
1343 #
1344 # AC_WIRESHARK_GNU_SED_CHECK
1345 # Checks if GNU sed is the first sed in PATH.
1346 #
1347 AC_DEFUN([AC_WIRESHARK_GNU_SED_CHECK],
1348 [
1349         AC_MSG_CHECKING(for GNU sed as first sed in PATH)
1350         if  ( sh -c "sed --version" </dev/null 2> /dev/null | grep "GNU sed" 2>&1 > /dev/null ) ;  then
1351                 AC_MSG_RESULT(yes)
1352                 HAVE_GNU_SED=yes
1353         else
1354                 AC_MSG_RESULT(no)
1355                 HAVE_GNU_SED=no
1356         fi
1357 ])
1358
1359 #
1360 # AC_WIRESHARK_ADNS_CHECK
1361 #
1362 AC_DEFUN([AC_WIRESHARK_ADNS_CHECK],
1363 [
1364         want_adns=defaultyes
1365
1366         if test "x$want_adns" = "xdefaultyes"; then
1367                 want_adns=yes
1368                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1369                         withval=/usr/local
1370                         if test -d "$withval"; then
1371                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1372                         fi
1373                 fi
1374         fi
1375
1376         if test "x$want_adns" = "xyes"; then
1377                 AC_CHECK_LIB(adns, adns_init,
1378                   [
1379                     ADNS_LIBS=-ladns
1380                 AC_DEFINE(HAVE_GNU_ADNS, 1, [Define to use GNU ADNS library])
1381                 have_good_adns=yes
1382                   ],, $SOCKET_LIBS $NSL_LIBS
1383                 )
1384         else
1385                 AC_MSG_RESULT(not required)
1386         fi
1387 ])
1388
1389
1390 #
1391 # AC_WIRESHARK_KRB5_CHECK
1392 #
1393 AC_DEFUN([AC_WIRESHARK_KRB5_CHECK],
1394 [
1395         wireshark_save_CFLAGS="$CFLAGS"
1396         wireshark_save_CPPFLAGS="$CPPFLAGS"
1397         if test "x$krb5_dir" != "x"
1398         then
1399           #
1400           # The user specified a directory in which kerberos resides,
1401           # so add the "include" subdirectory of that directory to
1402           # the include file search path and the "lib" subdirectory
1403           # of that directory to the library search path.
1404           #
1405           # XXX - if there's also a kerberos in a directory that's
1406           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
1407           # make us find the version in the specified directory,
1408           # as the compiler and/or linker will search that other
1409           # directory before it searches the specified directory.
1410           #
1411           CFLAGS="$CFLAGS -I$krb5_dir/include"
1412           CPPFLAGS="$CPPFLAGS -I$krb5_dir/include"
1413           ac_heimdal_version=`grep heimdal $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*heimdal.*$/HEIMDAL/'`
1414           ac_mit_version=`grep 'Massachusetts Institute of Technology' $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*Massachusetts Institute of Technology.*$/MIT/'`
1415           ac_krb5_version="$ac_heimdal_version$ac_mit_version"
1416           if test "x$ac_krb5_version" = "xHEIMDAL"
1417               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lasn1 $SSL_LIBS -lroken -lcrypt"
1418           then
1419               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lk5crypto -lcom_err"
1420           fi
1421           if test "x$ac_krb5_version" = "xMIT"
1422           then
1423             AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
1424           fi
1425         else
1426           AC_PATH_PROG(KRB5_CONFIG, krb5-config) 
1427           if test -x "$KRB5_CONFIG"
1428           then
1429             KRB5_FLAGS=`"$KRB5_CONFIG" --cflags`
1430             KRB5_LIBS=`"$KRB5_CONFIG" --libs`
1431             CFLAGS="$CFLAGS $KRB5_FLAGS"
1432             CPPFLAGS="$CPPFLAGS $KRB5_FLAGS"
1433             #
1434             # If -lcrypto is in KRB5_FLAGS, we require it to build
1435             # with Heimdal/MIT.  We don't want to built with it by
1436             # default, due to annoying license incompatibilities
1437             # between the OpenSSL license and the GPL, so:
1438             #
1439             #   if SSL_LIBS is set to a non-empty string, we
1440             #   remove -lcrypto from KRB5_LIBS and replace
1441             #   it with SSL_LIBS;
1442             #
1443             #   if SSL_LIBS is not set to a non-empty string
1444             #   we fail with an appropriate error message.
1445             #
1446             case "$KRB5_LIBS" in
1447             *-lcrypto*)
1448                 if test ! -z "$SSL_LIBS"
1449                 then
1450                     KRB5_LIBS=`echo $KRB5_LIBS | sed 's/-lcrypto//'`
1451                     KRB5_LIBS="$KRB5_LIBS $SSL_LIBS"
1452                 else
1453                     AC_MSG_ERROR([Kerberos library requires -lcrypto but --with-ssl not specified])
1454                 fi
1455                 ;;
1456             esac
1457             ac_krb5_version=`"$KRB5_CONFIG" --version | head -n 1 | sed -e 's/^.*heimdal.*$/HEIMDAL/' -e 's/^Kerberos .*$/MIT/'`
1458           fi
1459         fi
1460
1461         #
1462         # Make sure we have "krb5.h".  If we don't, it means we probably
1463         # don't have kerberos, so don't use it.
1464         #
1465         AC_CHECK_HEADER(krb5.h,,
1466           [
1467             if test "x$krb5_dir" != "x"
1468             then
1469               #
1470               # The user used "--with-krb5=" to specify a directory
1471               # containing kerberos, but we didn't find the header file
1472               # there; that either means they didn't specify the
1473               # right directory or are confused about whether kerberos
1474               # is, in fact, installed.  Report the error and give up.
1475               #
1476               AC_MSG_ERROR([kerberos header not found in directory specified in --with-krb5])
1477             else
1478               if test "x$want_krb5" = "xyes"
1479               then
1480                 #
1481                 # The user tried to force us to use the library, but we
1482                 # couldn't find the header file; report an error.
1483                 #
1484                 AC_MSG_ERROR(Header file krb5.h not found.)
1485               else
1486                 #
1487                 # We couldn't find the header file; don't use the
1488                 # library, as it's probably not present.
1489                 #
1490                 want_krb5=no
1491                 AC_MSG_RESULT(No Heimdal or MIT header found - disabling dissection for some kerberos data in packet decoding)
1492               fi
1493             fi
1494           ])
1495
1496         if test "x$want_krb5" != "xno"
1497         then
1498             #
1499             # Well, we at least have the krb5 header file.
1500             # Check whether this is Heimdal or MIT.
1501             #
1502             AC_MSG_CHECKING(whether the Kerberos library is Heimdal or MIT)
1503             if test "x$ac_krb5_version" = "xHEIMDAL" -o "x$ac_krb5_version" = "xMIT"
1504             then
1505                 #
1506                 # Yes.
1507                 # Check whether we have krb5_kt_resolve - and whether
1508                 # we need to link with -lresolv when linking with
1509                 # the Kerberos library.
1510                 #
1511                 AC_MSG_RESULT($ac_krb5_version)
1512                 wireshark_save_LIBS="$LIBS"
1513                 found_krb5_kt_resolve=no
1514                 for extras in "" "-lresolv"
1515                 do
1516                     LIBS="$KRB5_LIBS $extras"
1517                     if test -z "$extras"
1518                     then
1519                         AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve])
1520                     else
1521                         AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve (linking with $extras)])
1522                     fi
1523                     AC_TRY_LINK(
1524                         [
1525                         ],
1526                         [
1527                             krb5_kt_resolve();
1528                         ],
1529                         [
1530                             #
1531                             # We found "krb5_kt_resolve()", and required
1532                             # the libraries in extras as well.
1533                             #
1534                             AC_MSG_RESULT(yes)
1535                             KRB5_LIBS="$LIBS"
1536                             AC_DEFINE(HAVE_KERBEROS, 1, [Define to use kerberos])
1537                             if test "x$ac_krb5_version" = "xHEIMDAL"
1538                             then
1539                                 AC_DEFINE(HAVE_HEIMDAL_KERBEROS, 1, [Define to use heimdal kerberos])
1540                             elif test "x$ac_krb5_version" = "xMIT"
1541                             then
1542                                 AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
1543                             fi
1544                             found_krb5_kt_resolve=yes
1545                             break
1546                         ],
1547                         [
1548                             AC_MSG_RESULT(no)
1549                         ])
1550                 done
1551                 if test "$found_krb5_kt_resolve" = no
1552                 then
1553                     #
1554                     # We didn't find "krb5_kt_resolve()" in the
1555                     # Kerberos library, even when we tried linking
1556                     # with -lresolv; we can't link with kerberos.
1557                     #
1558                     if test "x$want_krb5" = "xyes"
1559                     then
1560                         #
1561                         # The user tried to force us to use the library,
1562                         # but we can't do so; report an error.
1563                         #
1564                         AC_MSG_ERROR(Usable $ac_krb5_version not found)
1565                     else
1566                         #
1567                         # Restore the versions of CFLAGS and CPPFLAGS
1568                         # from before we added the flags for Kerberos.
1569                         #
1570                         AC_MSG_RESULT(Usable $ac_krb5_version not found - disabling dissection for some kerberos data in packet decoding)
1571                         CFLAGS="$wireshark_save_CFLAGS"
1572                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1573                         KRB5_LIBS=""
1574                         want_krb5=no
1575                     fi
1576                 else
1577                     #
1578                     # We can link with Kerberos; see whether krb5.h
1579                     # defines KEYTYPE_ARCFOUR_56 (where "defines" means
1580                     # "as a #define or as an enum member).
1581                     #
1582                     AC_MSG_CHECKING([whether krb5.h defines KEYTYPE_ARCFOUR_56])
1583                     AC_COMPILE_IFELSE(
1584                       [
1585                         AC_LANG_SOURCE(
1586                           [[
1587                             #include <krb5.h>
1588                             #include <stdio.h>
1589
1590                             main()
1591                             {
1592                               printf("%u\n", KEYTYPE_ARCFOUR_56);
1593                             }
1594                           ]])
1595                       ],
1596                       [
1597                         AC_MSG_RESULT(yes)
1598                         AC_DEFINE(HAVE_KEYTYPE_ARCFOUR_56, 1, [Define if krb5.h defines KEYTYPE_ARCFOUR_56])
1599                       ],
1600                       [
1601                         AC_MSG_RESULT(no)
1602                       ])
1603                 fi
1604                 LIBS="$wireshark_save_LIBS"
1605             else
1606                 #
1607                 # It's not Heimdal or MIT.
1608                 #
1609                 AC_MSG_RESULT(no)
1610                 if test "x$want_krb5" = "xyes"
1611                 then
1612                     #
1613                     # The user tried to force us to use the library,
1614                     # but we can't do so; report an error.
1615                     #
1616                     AC_MSG_ERROR(Kerberos not found)
1617                 else
1618                     #
1619                     # Restore the versions of CFLAGS and CPPFLAGS
1620                     # from before we added the flags for Kerberos.
1621                     #
1622                     AC_MSG_RESULT(Kerberos not found - disabling dissection for some kerberos data in packet decoding)
1623                     CFLAGS="$wireshark_save_CFLAGS"
1624                     CPPFLAGS="$wireshark_save_CPPFLAGS"
1625                     KRB5_LIBS=""
1626                     want_krb5=no
1627                 fi
1628             fi
1629         else
1630             #
1631             # The user asked us not to use Kerberos, or they didn't
1632             # say whether they wanted us to use it but we found
1633             # that we couldn't.
1634             #
1635             # Restore the versions of CFLAGS and CPPFLAGS
1636             # from before we added the flags for Kerberos.
1637             #
1638             CFLAGS="$wireshark_save_CFLAGS"
1639             CPPFLAGS="$wireshark_save_CPPFLAGS"
1640             KRB5_LIBS=""
1641             want_krb5=no
1642         fi
1643         AC_SUBST(KRB5_LIBS)
1644 ])
1645