set SVN properties
[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 but not declared
471         # in the pcap.h header file.  If it's not declared in the header
472         # file, attempts to use it will get warnings, and, if we're
473         # building with warnings treated as errors, that warning will
474         # cause compilation to fail.
475         #
476         # We are therefore first testing whether the function is present
477         # and then, if we're compiling with warnings as errors, testing
478         # whether it is usable.  It is usable if it compiles without
479         # a -Wimplicit warning (the "compile with warnings as errors"
480         # option requires GCC). If it is not usable, we fail and tell
481         # the user that the pcap.h header needs to be updated.
482         # 
483         # Ceteris paribus, this should only happen with Mac OS X 10.3[.x] which
484         # can have an up-to-date pcap library without the corresponding pcap
485         # header.
486         #
487         # However, it might also happen on some others OSes with some erroneous
488         # system manipulations where multiple versions of libcap might co-exist 
489         # e.g. hand made symbolic link from libpcap.so -> libpcap.so.0.8 but
490         # having the pcap header version 0.7.
491         #
492         AC_MSG_CHECKING([whether pcap_breakloop is present])
493         ac_CFLAGS_saved="$CFLAGS"
494         AC_WIRESHARK_PCAP_BREAKLOOP_TRY_LINK
495         if test "x$ws_breakloop_compiled" = "xyes"; then
496           AC_MSG_RESULT(yes)
497           AC_DEFINE(HAVE_PCAP_BREAKLOOP, 1, [Define if pcap_breakloop is known])
498           if test "x$with_warnings_as_errors" = "xyes"; then
499             AC_MSG_CHECKING([whether pcap_breakloop is usable])
500             CFLAGS="$CFLAGS -Werror -Wimplicit"
501             AC_WIRESHARK_PCAP_BREAKLOOP_TRY_LINK
502             if test "x$ws_breakloop_compiled" = "xyes"; then
503               AC_MSG_RESULT(yes)
504             else
505               AC_MSG_RESULT(no)
506               AC_MSG_ERROR(
507 [Your pcap library is more recent than your pcap header.
508 As you are building with compiler warnings treated as errors, Wireshark
509 won't be able to use functions not declared in that header.
510 If you wish to build with compiler warnings treated as errors, You should
511 install a newer version of the header file.])
512             fi
513             CFLAGS="$ac_CFLAGS_saved"
514           fi
515         else
516           AC_MSG_RESULT(no)
517         fi
518
519         #
520         # Later versions of Mac OS X 10.3[.x] ship a pcap.h that
521         # doesn't define pcap_if_t but ship an 0.8[.x] libpcap,
522         # so the library has "pcap_findalldevs()", but pcap.h
523         # doesn't define "pcap_if_t" so you can't actually *use*
524         # "pcap_findalldevs()".
525         #
526         # That even appears to be true of systems shipped with
527         # 10.3.4, so it doesn't appear only to be a case of
528         # Software Update not updating header files.
529         #
530         # (You can work around this by installing the 0.8 header
531         # files.)
532         #
533         AC_CACHE_CHECK([whether pcap_findalldevs is present and usable],
534           [ac_cv_func_pcap_findalldevs],
535           [
536             AC_LINK_IFELSE(
537               [
538                 AC_LANG_SOURCE(
539                   [[
540                     #include <pcap.h>
541                     main()
542                     {
543                       pcap_if_t *devpointer;
544                       char errbuf[1];
545
546                       pcap_findalldevs(&devpointer, errbuf);
547                     }
548                   ]])
549               ],
550               [
551                 ac_cv_func_pcap_findalldevs=yes
552               ],
553               [
554                 ac_cv_func_pcap_findalldevs=no
555               ])
556           ])
557         #
558         # Don't check for other new routines that showed up after
559         # "pcap_findalldevs()" if we don't have a usable
560         # "pcap_findalldevs()", so we don't end up using them if the
561         # "pcap.h" is crufty and old and doesn't declare them.
562         #
563         if test $ac_cv_func_pcap_findalldevs = "yes" ; then
564           AC_DEFINE(HAVE_PCAP_FINDALLDEVS, 1,
565            [Define to 1 if you have the `pcap_findalldevs' function and a pcap.h that declares pcap_if_t.])
566           AC_CHECK_FUNCS(pcap_datalink_val_to_name pcap_datalink_name_to_val)
567           AC_CHECK_FUNCS(pcap_list_datalinks pcap_set_datalink pcap_lib_version)
568           AC_CHECK_FUNCS(pcap_get_selectable_fd)
569         fi
570         LIBS="$ac_save_LIBS"
571 ])
572
573 AC_DEFUN([AC_WIRESHARK_PCAP_REMOTE_CHECK],
574 [
575     ac_save_LIBS="$LIBS"
576     LIBS="$PCAP_LIBS $SOCKET_LIBS $NSL_LIBS $LIBS"
577     AC_DEFINE(HAVE_REMOTE, 1, [Define to 1 to enable remote
578               capturing feature in WinPcap library])
579     AC_CHECK_FUNCS(pcap_open pcap_findalldevs_ex pcap_createsrcstr)
580     if test $ac_cv_func_pcap_open = "yes" -a \
581             $ac_cv_func_pcap_findalldevs_ex = "yes" -a \
582             $ac_cv_func_pcap_createsrcstr = "yes" ; then
583         AC_DEFINE(HAVE_PCAP_REMOTE, 1,
584             [Define to 1 if you have WinPcap remote capturing support and prefer to use these new API features.])
585     fi
586     AC_CHECK_FUNCS(pcap_setsampling)
587     LIBS="$ac_save_LIBS"
588 ])
589
590 #
591 # AC_WIRESHARK_ZLIB_CHECK
592 #
593 AC_DEFUN([AC_WIRESHARK_ZLIB_CHECK],
594 [
595         if test "x$zlib_dir" != "x"
596         then
597           #
598           # The user specified a directory in which zlib resides,
599           # so add the "include" subdirectory of that directory to
600           # the include file search path and the "lib" subdirectory
601           # of that directory to the library search path.
602           #
603           # XXX - if there's also a zlib in a directory that's
604           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
605           # make us find the version in the specified directory,
606           # as the compiler and/or linker will search that other
607           # directory before it searches the specified directory.
608           #
609           wireshark_save_CFLAGS="$CFLAGS"
610           CFLAGS="$CFLAGS -I$zlib_dir/include"
611           wireshark_save_CPPFLAGS="$CPPFLAGS"
612           CPPFLAGS="$CPPFLAGS -I$zlib_dir/include"
613           wireshark_save_LIBS="$LIBS"
614           AC_WIRESHARK_ADD_DASH_L(LIBS, $zlib_dir/lib)
615         fi
616
617         #
618         # Make sure we have "zlib.h".  If we don't, it means we probably
619         # don't have zlib, so don't use it.
620         #
621         AC_CHECK_HEADER(zlib.h,,
622           [
623             if test "x$zlib_dir" != "x"
624             then
625               #
626               # The user used "--with-zlib=" to specify a directory
627               # containing zlib, but we didn't find the header file
628               # there; that either means they didn't specify the
629               # right directory or are confused about whether zlib
630               # is, in fact, installed.  Report the error and give up.
631               #
632               AC_MSG_ERROR([zlib header not found in directory specified in --with-zlib])
633             else
634               if test "x$want_zlib" = "xyes"
635               then
636                 #
637                 # The user tried to force us to use the library, but we
638                 # couldn't find the header file; report an error.
639                 #
640                 AC_MSG_ERROR(Header file zlib.h not found.)
641               else
642                 #
643                 # We couldn't find the header file; don't use the
644                 # library, as it's probably not present.
645                 #
646                 want_zlib=no
647               fi
648             fi
649           ])
650
651         if test "x$want_zlib" != "xno"
652         then
653                 #
654                 # Well, we at least have the zlib header file.
655                 #
656                 # Check for "gzgets()" in zlib, because we need it, but
657                 # some older versions of zlib don't have it.  It appears
658                 # from the zlib ChangeLog that any released version of zlib
659                 # with "gzgets()" should have the other routines we
660                 # depend on, such as "gzseek()", "gztell()", and "zError()".
661                 #
662                 # Another reason why we require "gzgets()" is that
663                 # some versions of zlib that didn't have it, such
664                 # as 1.0.8, had a bug in "gzseek()" that meant that it
665                 # doesn't work correctly on uncompressed files; this
666                 # means we cannot use version 1.0.8.  (Unfortunately,
667                 # that's the version that comes with recent X11 source,
668                 # and many people who install XFree86 on their Slackware
669                 # boxes don't realize that they should configure it to
670                 # use the native zlib rather than building and installing
671                 # the crappy old version that comes with XFree86.)
672                 #
673                 # I.e., we can't just avoid using "gzgets()", as
674                 # versions of zlib without "gzgets()" are likely to have
675                 # a broken "gzseek()".
676                 #
677                 AC_CHECK_LIB(z, gzgets,
678                 [
679                         if test "x$zlib_dir" != "x"
680                         then
681                                 #
682                                 # Put the "-I" and "-L" flags for zlib at
683                                 # the beginning of CFLAGS, CPPFLAGS, and
684                                 # LIBS.
685                                 #
686                                 LIBS=""
687                                 AC_WIRESHARK_ADD_DASH_L(LIBS, $zlib_dir/lib)
688                                 LIBS="$LIBS -lz $wireshark_save_LIBS"
689                         else
690                                 LIBS="-lz $LIBS"
691                         fi
692                         AC_DEFINE(HAVE_LIBZ, 1, [Define to use libz library])
693                 ],[
694                         if test "x$zlib_dir" != "x"
695                         then
696                                 #
697                                 # Restore the versions of CFLAGS, CPPFLAGS,
698                                 # and LIBS before we added the "-with-zlib="
699                                 # directory, as we didn't actually find
700                                 # zlib there, or didn't find a zlib that
701                                 # contains gzgets there.
702                                 #
703                                 CFLAGS="$wireshark_save_CFLAGS"
704                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
705                                 LIBS="$wireshark_save_LIBS"
706                         fi
707                         want_zlib=no
708                 ])
709         fi
710
711         if test "x$want_zlib" != "xno"
712         then
713                 #
714                 # Well, we at least have the zlib header file and a zlib
715                 # with "gzgets()".
716                 #
717                 # Now check for "gzgets()" in zlib when linking with the
718                 # linker flags for GTK+ applications; people often grab
719                 # XFree86 source and build and install it on their systems,
720                 # and they appear sometimes to misconfigure XFree86 so that,
721                 # even on systems with zlib, it assumes there is no zlib,
722                 # so the XFree86 build process builds and installs its
723                 # own zlib in the X11 library directory.
724                 #
725                 # The XFree86 zlib is an older version that lacks
726                 # "gzgets()", and that's the zlib with which Wireshark
727                 # gets linked, so the build of Wireshark fails.
728                 #
729                 ac_save_CFLAGS="$CFLAGS"
730                 ac_save_LIBS="$LIBS"
731                 CFLAGS="$CFLAGS $GTK_CFLAGS"
732                 LIBS="$GTK_LIBS -lz $LIBS"
733                 AC_MSG_CHECKING([for gzgets missing when linking with X11])
734                 AC_TRY_LINK_FUNC(gzgets, AC_MSG_RESULT(no),
735                   [
736                     AC_MSG_RESULT(yes)
737                     AC_MSG_ERROR(old zlib found when linking with X11 - get rid of old zlib.)
738                   ])
739                 CFLAGS="$ac_save_CFLAGS"
740                 LIBS="$ac_save_LIBS"
741         fi
742 ])
743
744 #
745 # AC_WIRESHARK_LIBPCRE_CHECK
746 #
747 AC_DEFUN([AC_WIRESHARK_LIBPCRE_CHECK],
748 [
749         if test "x$pcre_dir" != "x"
750         then
751           #
752           # The user specified a directory in which libpcre resides,
753           # so add the "include" subdirectory of that directory to
754           # the include file search path and the "lib" subdirectory
755           # of that directory to the library search path.
756           #
757           # XXX - if there's also a libpcre in a directory that's
758           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
759           # make us find the version in the specified directory,
760           # as the compiler and/or linker will search that other
761           # directory before it searches the specified directory.
762           #
763           wireshark_save_CFLAGS="$CFLAGS"
764           CFLAGS="$CFLAGS -I$pcre_dir/include"
765           wireshark_save_CPPFLAGS="$CPPFLAGS"
766           CPPFLAGS="$CPPFLAGS -I$pcre_dir/include"
767           wireshark_save_LIBS="$LIBS"
768           LIBS="$LIBS -lpcre"
769           wireshark_save_LDFLAGS="$LDFLAGS"
770           LDFLAGS="$LDFLAGS -L$pcre_dir/lib"
771         fi
772
773         #
774         # Make sure we have "pcre.h".  If we don't, it means we probably
775         # don't have libpcre, so don't use it.
776         #
777         AC_CHECK_HEADER(pcre.h,,
778           [
779             if test "x$pcre_dir" != "x"
780             then
781               #
782               # The user used "--with-pcre=" to specify a directory
783               # containing libpcre, but we didn't find the header file
784               # there; that either means they didn't specify the
785               # right directory or are confused about whether libpcre
786               # is, in fact, installed.  Report the error and give up.
787               #
788               AC_MSG_ERROR([libpcre header not found in directory specified in --with-pcre])
789             else
790               if test "x$want_pcre" = "xyes"
791               then
792                 #
793                 # The user tried to force us to use the library, but we
794                 # couldn't find the header file; report an error.
795                 #
796                 AC_MSG_ERROR(Header file pcre.h not found.)
797               else
798                 #
799                 # We couldn't find the header file; don't use the
800                 # library, as it's probably not present.
801                 #
802                 want_pcre=no
803               fi
804             fi
805           ])
806
807         if test "x$want_pcre" != "xno"
808         then
809                 #
810                 # Well, we at least have the pcre header file.
811                 #
812                 # We're only using standard functions from libpcre,
813                 # so we don't need to perform extra checks.
814                 #
815                 AC_CHECK_LIB(pcre, pcre_compile,
816                 [
817                         if test "x$pcre_dir" != "x"
818                         then
819                                 #
820                                 # Put the "-I" and "-L" flags for pcre at
821                                 # the beginning of CFLAGS, CPPFLAGS,
822                                 # LDFLAGS, and LIBS.
823                                 #
824                                 PCRE_LIBS="-L$pcre_dir/lib -lpcre $wireshark_save_LIBS"
825                         else
826                                 PCRE_LIBS="-lpcre"
827                         fi
828                         AC_DEFINE(HAVE_LIBPCRE, 1, [Define to use libpcre library])
829                 ],[
830                         if test "x$pcre_dir" != "x"
831                         then
832                                 #
833                                 # Restore the versions of CFLAGS, CPPFLAGS,
834                                 # LDFLAGS, and LIBS before we added the
835                                 # "--with-pcre=" directory, as we didn't
836                                 # actually find pcre there.
837                                 #
838                                 CFLAGS="$wireshark_save_CFLAGS"
839                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
840                                 LDFLAGS="$wireshark_save_LDFLAGS"
841                                 LIBS="$wireshark_save_LIBS"
842                                 PCRE_LIBS=""
843                         fi
844                         want_pcre=no
845                 ])
846                 AC_SUBST(PCRE_LIBS)
847         fi
848 ])
849
850 #
851 # AC_WIRESHARK_LIBLUA_CHECK
852 #
853 AC_DEFUN([AC_WIRESHARK_LIBLUA_CHECK],[
854
855         if test "x$lua_dir" != "x"
856         then
857                 #
858                 # The user specified a directory in which liblua resides,
859                 # so add the "include" subdirectory of that directory to
860                 # the include file search path and the "lib" subdirectory
861                 # of that directory to the library search path.
862                 #
863                 # XXX - if there's also a liblua in a directory that's
864                 # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
865                 # make us find the version in the specified directory,
866                 # as the compiler and/or linker will search that other
867                 # directory before it searches the specified directory.
868                 #
869                 wireshark_save_CFLAGS="$CFLAGS"
870                 CFLAGS="$CFLAGS -I$lua_dir/include"
871                 wireshark_save_CPPFLAGS="$CPPFLAGS"
872                 CPPFLAGS="$CPPFLAGS -I$lua_dir/include"
873                 wireshark_save_LIBS="$LIBS"
874                 LIBS="$LIBS -L$lua_dir/lib -llua -lm"
875                 wireshark_save_LDFLAGS="$LDFLAGS"
876                 LDFLAGS="$LDFLAGS -L$lua_dir/lib"
877         else 
878                 #
879                 # The user specified no directory in which liblua resides,
880                 # so just add "-llua -lliblua" to the used libs.
881                 #
882                 wireshark_save_CFLAGS="$CFLAGS"
883                 wireshark_save_CPPFLAGS="$CPPFLAGS"
884                 wireshark_save_LDFLAGS="$LDFLAGS"
885                 wireshark_save_LIBS="$LIBS"
886                 LIBS="$LIBS -llua -lm"
887         fi
888
889         #
890         # Make sure we have "lua.h", "lualib.h" and "lauxlib.h".  If we don't, it means we probably
891         # don't have liblua, so don't use it.
892         #
893         AC_CHECK_HEADERS(lua.h lualib.h lauxlib.h,,
894         [
895                 AC_CHECK_HEADERS(lua5.1/lua.h lua5.1/lualib.h lua5.1/lauxlib.h,
896                 [
897                         if test "x$lua_dir" != "x"
898                         then
899                                 LUA_INCLUDES="-I$lua_dir/include/lua5.1"
900                         else
901                                 # we found lua5.1/lua.h, but we don't know which include dir contains it
902                                 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.)
903                         fi
904                         
905                 ],
906                 [
907                         if test "x$lua_dir" != "x"
908                         then
909                                 #
910                                 # The user used "--with-lua=" to specify a directory
911                                 # containing liblua, but we didn't find the header file
912                                 # there; that either means they didn't specify the
913                                 # right directory or are confused about whether liblua
914                                 # is, in fact, installed.  Report the error and give up.
915                                 #
916                                 AC_MSG_ERROR([liblua header not found in directory specified in --with-lua])
917                         else
918                                 if test "x$want_lua" = "xyes"
919                                 then
920                                         #
921                                         # The user tried to force us to use the library, but we
922                                         # couldn't find the header file; report an error.
923                                         #
924                                         AC_MSG_ERROR(Header file lua.h not found.)
925                                 else
926                                         #
927                                         # We couldn't find the header file; don't use the
928                                         # library, as it's probably not present.
929                                         #
930                                         want_lua=no
931                                 fi
932                         fi
933                 ])
934         ])
935
936         if test "x$want_lua" != "xno"
937         then
938                 #
939                 # Well, we at least have the lua header file.
940                 #
941                 # let's check if the libs are there
942                 #
943
944                 # At least on Suse 9.3 systems, liblualib needs linking
945                 # against libm.
946                 LIBS="$LIBS $LUA_LIBS -lm"
947
948                 AC_CHECK_LIB(lua, lua_call,
949                 [
950                         if test "x$lua_dir" != "x"
951                         then
952                                 #
953                                 # Put the "-I" and "-L" flags for lua at
954                                 # the beginning of CFLAGS, CPPFLAGS,
955                                 # LDFLAGS, and LIBS.
956                                 #
957                                 LUA_LIBS="-L$lua_dir/lib -llua -lm"
958                                 LUA_INCLUDES="-I$lua_dir/include"
959                         else
960                                 LUA_LIBS="-llua -lm"
961                                 LUA_INCLUDES=""
962                         fi
963
964                         #
965                         # we got lua, now look for lualib
966                         #
967                         AC_CHECK_LIB(lualib, luaL_openlib,
968                         [
969                                 #
970                                 # we have 5.0
971                                 #
972                                 LUA_LIBS="$LUA_LIBS -llualib"
973                         ],[
974                                 #
975                                 # no lualib, in 5.1 there's only liblua
976                                 # do we have 5.1?
977                                 #
978                                 
979                                 LIBS="$wireshark_save_LIBS $LUA_LIBS"
980
981                                 AC_CHECK_LIB(lua, luaL_register,
982                                 [
983                                     #
984                                     #  Lua 5.1 found
985                                     #
986                                     AC_DEFINE(HAVE_LUA_5_1, 1, [Define to use Lua 5.1])
987                                 ],[
988                                     #
989                                     # No, it is not 5.1
990                                     #
991                                     if test "x$lua_dir" != "x"
992                                     then
993                                         #
994                                         # Restore the versions of CFLAGS, CPPFLAGS,
995                                         # LDFLAGS, and LIBS before we added the
996                                         # "--with-lua=" directory, as we didn't
997                                         # actually find lua there.
998                                         #
999                                         CFLAGS="$wireshark_save_CFLAGS"
1000                                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1001                                         LDFLAGS="$wireshark_save_LDFLAGS"
1002                                         LIBS="$wireshark_save_LIBS"
1003                                         LUA_LIBS=""
1004                                     fi
1005                                     # User requested --with-lua but it isn't available
1006                                     if test "x$want_lua" = "xyes"
1007                                     then
1008                                         AC_MSG_ERROR(Linking with liblualib failed.)
1009                                     fi
1010                                     want_lua=no
1011                                 ])
1012                         ])
1013                 ],[  
1014                         #
1015                         # We could not find the libs, maybe we have version number in the lib name
1016                         #
1017
1018                         LIBS="$wireshark_save_LIBS -llua5.1 -lm"
1019
1020                         AC_CHECK_LIB(lua5.1, luaL_register,
1021                         [
1022                             #
1023                             #  Lua 5.1 found
1024                             #
1025                             AC_DEFINE(HAVE_LUA_5_1, 1, [Define to use Lua 5.1])
1026                             LUA_LIBS=" -llua5.1 -lm"
1027                         ],[
1028                                 #
1029                                 # Restore the versions of CFLAGS, CPPFLAGS,
1030                                 # LDFLAGS, and LIBS before we added the
1031                                 # "--with-lua=" directory, as we didn't
1032                                 # actually find lua there.
1033                                 #
1034                                 CFLAGS="$wireshark_save_CFLAGS"
1035                                 CPPFLAGS="$wireshark_save_CPPFLAGS"
1036                                 LDFLAGS="$wireshark_save_LDFLAGS"
1037                                 LIBS="$wireshark_save_LIBS"
1038                                 LUA_LIBS=""
1039                                 # User requested --with-lua but it isn't available
1040                                 if test "x$want_lua" = "xyes"
1041                                 then
1042                                         AC_MSG_ERROR(Linking with liblua failed.)
1043                                 fi
1044                                 want_lua=no
1045                         ])
1046                 ])
1047
1048         CFLAGS="$wireshark_save_CFLAGS"
1049         CPPFLAGS="$wireshark_save_CPPFLAGS"
1050         LDFLAGS="$wireshark_save_LDFLAGS"
1051         LIBS="$wireshark_save_LIBS"
1052         AC_SUBST(LUA_LIBS)
1053         AC_SUBST(LUA_INCLUDES)
1054
1055         fi
1056 ])
1057
1058 #
1059 # AC_WIRESHARK_LIBPORTAUDIO_CHECK
1060 #
1061 AC_DEFUN([AC_WIRESHARK_LIBPORTAUDIO_CHECK],[
1062
1063         if test "x$portaudio_dir" != "x"
1064         then
1065                 #
1066                 # The user specified a directory in which libportaudio
1067                 # resides, so add the "include" subdirectory of that directory to
1068                 # the include file search path and the "lib" subdirectory
1069                 # of that directory to the library search path.
1070                 #
1071                 # XXX - if there's also a libportaudio in a directory that's
1072                 # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
1073                 # make us find the version in the specified directory,
1074                 # as the compiler and/or linker will search that other
1075                 # directory before it searches the specified directory.
1076                 #
1077                 wireshark_save_CFLAGS="$CFLAGS"
1078                 CFLAGS="$CFLAGS -I$portaudio_dir/include"
1079                 wireshark_save_CPPFLAGS="$CPPFLAGS"
1080                 CPPFLAGS="$CPPFLAGS -I$portaudio_dir/include"
1081                 wireshark_save_LIBS="$LIBS"
1082                 LIBS="$LIBS -L$portaudio_dir/lib -lportaudio"
1083                 wireshark_save_LDFLAGS="$LDFLAGS"
1084                 LDFLAGS="$LDFLAGS -L$portaudio_dir/lib"
1085         else 
1086                 #
1087                 # The user specified no directory in which libportaudio resides,
1088                 # so just add "-lportaudio" to the used libs.
1089                 #
1090                 wireshark_save_CFLAGS="$CFLAGS"
1091                 wireshark_save_CPPFLAGS="$CPPFLAGS"
1092                 wireshark_save_LDFLAGS="$LDFLAGS"
1093                 wireshark_save_LIBS="$LIBS"
1094                 LIBS="$LIBS -lportaudio"
1095         fi
1096
1097         #
1098         # Make sure we have "portaudio.h".  If we don't, it means we probably
1099         # don't have libportaudio, so don't use it.
1100         #
1101         AC_CHECK_HEADERS(portaudio.h,,
1102         [
1103                 if test "x$portaudio_dir" != "x"
1104                 then
1105                         #
1106                         # The user used "--with-portaudio=" to specify a directory
1107                         # containing libportaudio, but we didn't find the header file
1108                         # there; that either means they didn't specify the
1109                         # right directory or are confused about whether libportaudio
1110                         # is, in fact, installed.  Report the error and give up.
1111                         #
1112                         AC_MSG_ERROR([libportaudio header not found in directory specified in --with-portaudio])
1113                 else
1114                         CFLAGS="$wireshark_save_CFLAGS"
1115                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1116                         LDFLAGS="$wireshark_save_LDFLAGS"
1117                         LIBS="$wireshark_save_LIBS"
1118                         PORTAUDIO_LIBS=""
1119                         if test "x$want_portaudio" = "xyes"
1120                         then
1121                                 #
1122                                 # The user tried to force us to use the library, but we
1123                                 # couldn't find the header file; report an error.
1124                                 #
1125                                 AC_MSG_ERROR(Header file portaudio.h not found.)
1126                         else
1127                                 #
1128                                 # We couldn't find the header file; don't use the
1129                                 # library, as it's probably not present.
1130                                 #
1131                                 want_portaudio=no
1132                         fi
1133                 fi
1134         ])
1135
1136         #
1137         # Check whether we have the right version of portaudio
1138         #
1139         if test "x$want_portaudio" != "xno"
1140         then
1141                 AC_CHECK_TYPE(PortAudioStream,
1142                 AC_DEFINE(PORTAUDIO_API_1, 1, [Define if we are using version of of the Portaudio library API]),
1143                 ,
1144                 [#include <portaudio.h>])
1145         fi
1146
1147         if test "x$want_portaudio" != "xno"
1148         then
1149                 #
1150                 # Well, we at least have the portaudio header file.
1151                 #
1152                 # let's check if the libs are there
1153                 #
1154
1155                 AC_CHECK_LIB(portaudio, Pa_Initialize,
1156                 [
1157                         if test "x$portaudio_dir" != "x"
1158                         then
1159                                 #
1160                                 # Put the "-I" and "-L" flags for portaudio at
1161                                 # the beginning of CFLAGS, CPPFLAGS,
1162                                 # LDFLAGS, and LIBS.
1163                                 #
1164                                 PORTAUDIO_LIBS="-L$portaudio_dir/lib -lportaudio"
1165                                 PORTAUDIO_INCLUDES="-I$portaudio_dir/include"
1166                         else
1167                                 PORTAUDIO_LIBS="-lportaudio"
1168                                 PORTAUDIO_INCLUDES=""
1169                         fi
1170                         AC_DEFINE(HAVE_LIBPORTAUDIO, 1, [Define to use libportaudio library])
1171                         want_portaudio=yes
1172                 ],[  
1173                         #
1174                         # Restore the versions of CFLAGS, CPPFLAGS,
1175                         # LDFLAGS, and LIBS before we added the
1176                         # "--with-portaudio=" directory, as we didn't
1177                         # actually find portaudio there.
1178                         #
1179                         CFLAGS="$wireshark_save_CFLAGS"
1180                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1181                         LDFLAGS="$wireshark_save_LDFLAGS"
1182                         LIBS="$wireshark_save_LIBS"
1183                         PORTAUDIO_LIBS=""
1184                         # User requested --with-portaudio but it isn't available
1185                         if test "x$want_portaudio" = "xyes"
1186                         then
1187                                 AC_MSG_ERROR(Linking with libportaudio failed.)
1188                         fi
1189                         want_portaudio=no
1190                 ])
1191
1192         CFLAGS="$wireshark_save_CFLAGS"
1193         CPPFLAGS="$wireshark_save_CPPFLAGS"
1194         LDFLAGS="$wireshark_save_LDFLAGS"
1195         LIBS="$wireshark_save_LIBS"
1196         AC_SUBST(PORTAUDIO_LIBS)
1197         AC_SUBST(PORTAUDIO_INCLUDES)
1198
1199         fi
1200 ])
1201
1202 #
1203 # AC_WIRESHARK_RPM_CHECK
1204 # Looks for the rpm program, and checks to see if we can redefine "_topdir".
1205 #
1206 AC_DEFUN([AC_WIRESHARK_RPM_CHECK],
1207 [
1208         AC_CHECK_PROG(ac_cv_wireshark_have_rpm, rpm, "yes", "no")
1209         if test "x$ac_cv_wireshark_have_rpm" = "xyes"; then
1210                 rpm --define '_topdir /tmp' > /dev/null 2>&1
1211                 AC_MSG_CHECKING(to see if we can redefine _topdir)
1212                 if test $? -eq 0 ; then
1213                         AC_MSG_RESULT(yes)
1214                         HAVE_RPM=yes
1215                 else
1216                         AC_MSG_RESULT(no.  You'll have to build packages manually.)
1217                         HAVE_RPM=no
1218                 fi
1219         fi
1220 ])
1221
1222 #
1223 # AC_WIRESHARK_GNU_SED_CHECK
1224 # Checks if GNU sed is the first sed in PATH.
1225 #
1226 AC_DEFUN([AC_WIRESHARK_GNU_SED_CHECK],
1227 [
1228         AC_MSG_CHECKING(for GNU sed as first sed in PATH)
1229         if  ( sh -c "sed --version" </dev/null 2> /dev/null | grep "GNU sed" 2>&1 > /dev/null ) ;  then
1230                 AC_MSG_RESULT(yes)
1231                 HAVE_GNU_SED=yes
1232         else
1233                 AC_MSG_RESULT(no)
1234                 HAVE_GNU_SED=no
1235         fi
1236 ])
1237
1238 #
1239 # AC_WIRESHARK_ADNS_CHECK
1240 #
1241 AC_DEFUN([AC_WIRESHARK_ADNS_CHECK],
1242 [
1243         want_adns=defaultyes
1244
1245         if test "x$want_adns" = "xdefaultyes"; then
1246                 want_adns=yes
1247                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1248                         withval=/usr/local
1249                         if test -d "$withval"; then
1250                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1251                         fi
1252                 fi
1253         fi
1254
1255         if test "x$want_adns" = "xyes"; then
1256                 AC_CHECK_LIB(adns, adns_init,
1257                   [
1258                     ADNS_LIBS=-ladns
1259                 AC_DEFINE(HAVE_GNU_ADNS, 1, [Define to use GNU ADNS library])
1260                 have_good_adns=yes
1261                   ],, $SOCKET_LIBS $NSL_LIBS
1262                 )
1263         else
1264                 AC_MSG_RESULT(not required)
1265         fi
1266 ])
1267
1268
1269 #
1270 # AC_WIRESHARK_LIBCAP_CHECK
1271 #
1272 AC_DEFUN([AC_WIRESHARK_LIBCAP_CHECK],
1273 [
1274         want_libcap=defaultyes
1275
1276         if test "x$want_libcap" = "xdefaultyes"; then
1277                 want_libcap=yes
1278                 if test "x$ac_cv_enable_usr_local" = "xyes" ; then
1279                         withval=/usr/local
1280                         if test -d "$withval"; then
1281                                 AC_WIRESHARK_ADD_DASH_L(LDFLAGS, ${withval}/lib)
1282                         fi
1283                 fi
1284         fi
1285
1286         if test "x$want_libcap" = "xyes"; then
1287                 AC_CHECK_LIB(cap, cap_set_flag,
1288                   [
1289                     LIBCAP_LIBS=-lcap
1290                 AC_DEFINE(HAVE_LIBCAP, 1, [Define to use the libcap library])
1291                 have_good_libcap=yes
1292                   ],,
1293                 )
1294         else
1295                 AC_MSG_RESULT(not required)
1296         fi
1297 ])
1298
1299
1300 #
1301 # AC_WIRESHARK_KRB5_CHECK
1302 #
1303 AC_DEFUN([AC_WIRESHARK_KRB5_CHECK],
1304 [
1305         wireshark_save_CFLAGS="$CFLAGS"
1306         wireshark_save_CPPFLAGS="$CPPFLAGS"
1307         if test "x$krb5_dir" != "x"
1308         then
1309           #
1310           # The user specified a directory in which kerberos resides,
1311           # so add the "include" subdirectory of that directory to
1312           # the include file search path and the "lib" subdirectory
1313           # of that directory to the library search path.
1314           #
1315           # XXX - if there's also a kerberos in a directory that's
1316           # already in CFLAGS, CPPFLAGS, or LDFLAGS, this won't
1317           # make us find the version in the specified directory,
1318           # as the compiler and/or linker will search that other
1319           # directory before it searches the specified directory.
1320           #
1321           CFLAGS="$CFLAGS -I$krb5_dir/include"
1322           CPPFLAGS="$CPPFLAGS -I$krb5_dir/include"
1323           ac_heimdal_version=`grep heimdal $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*heimdal.*$/HEIMDAL/'`
1324           ac_mit_version=`grep 'Massachusetts Institute of Technology' $krb5_dir/include/krb5.h | head -n 1 | sed 's/^.*Massachusetts Institute of Technology.*$/MIT/'`
1325           ac_krb5_version="$ac_heimdal_version$ac_mit_version"
1326           if test "x$ac_krb5_version" = "xHEIMDAL"
1327               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lasn1 $SSL_LIBS -lroken -lcrypt"
1328           then
1329               KRB5_LIBS="-L$krb5_dir/lib -lkrb5 -lk5crypto -lcom_err"
1330           fi
1331           if test "x$ac_krb5_version" = "xMIT"
1332           then
1333             AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
1334           fi
1335         else
1336           AC_PATH_PROG(KRB5_CONFIG, krb5-config) 
1337           if test -x "$KRB5_CONFIG"
1338           then
1339             KRB5_FLAGS=`"$KRB5_CONFIG" --cflags`
1340             KRB5_LIBS=`"$KRB5_CONFIG" --libs`
1341             CFLAGS="$CFLAGS $KRB5_FLAGS"
1342             CPPFLAGS="$CPPFLAGS $KRB5_FLAGS"
1343             #
1344             # If -lcrypto is in KRB5_FLAGS, we require it to build
1345             # with Heimdal/MIT.  We don't want to built with it by
1346             # default, due to annoying license incompatibilities
1347             # between the OpenSSL license and the GPL, so:
1348             #
1349             #   if SSL_LIBS is set to a non-empty string, we
1350             #   remove -lcrypto from KRB5_LIBS and replace
1351             #   it with SSL_LIBS;
1352             #
1353             #   if SSL_LIBS is not set to a non-empty string
1354             #   we fail with an appropriate error message.
1355             #
1356             case "$KRB5_LIBS" in
1357             *-lcrypto*)
1358                 if test ! -z "$SSL_LIBS"
1359                 then
1360                     KRB5_LIBS=`echo $KRB5_LIBS | sed 's/-lcrypto//'`
1361                     KRB5_LIBS="$KRB5_LIBS $SSL_LIBS"
1362                 else
1363                     AC_MSG_ERROR([Kerberos library requires -lcrypto but --with-ssl not specified])
1364                 fi
1365                 ;;
1366             esac
1367             ac_krb5_version=`"$KRB5_CONFIG" --version | head -n 1 | sed -e 's/^.*heimdal.*$/HEIMDAL/' -e 's/^Kerberos .*$/MIT/'`
1368           fi
1369         fi
1370
1371         #
1372         # Make sure we have "krb5.h".  If we don't, it means we probably
1373         # don't have kerberos, so don't use it.
1374         #
1375         AC_CHECK_HEADER(krb5.h,,
1376           [
1377             if test "x$krb5_dir" != "x"
1378             then
1379               #
1380               # The user used "--with-krb5=" to specify a directory
1381               # containing kerberos, but we didn't find the header file
1382               # there; that either means they didn't specify the
1383               # right directory or are confused about whether kerberos
1384               # is, in fact, installed.  Report the error and give up.
1385               #
1386               AC_MSG_ERROR([kerberos header not found in directory specified in --with-krb5])
1387             else
1388               if test "x$want_krb5" = "xyes"
1389               then
1390                 #
1391                 # The user tried to force us to use the library, but we
1392                 # couldn't find the header file; report an error.
1393                 #
1394                 AC_MSG_ERROR(Header file krb5.h not found.)
1395               else
1396                 #
1397                 # We couldn't find the header file; don't use the
1398                 # library, as it's probably not present.
1399                 #
1400                 want_krb5=no
1401                 AC_MSG_RESULT(No Heimdal or MIT header found - disabling dissection for some kerberos data in packet decoding)
1402               fi
1403             fi
1404           ])
1405
1406         if test "x$want_krb5" != "xno"
1407         then
1408             #
1409             # Well, we at least have the krb5 header file.
1410             # Check whether this is Heimdal or MIT.
1411             #
1412             AC_MSG_CHECKING(whether the Kerberos library is Heimdal or MIT)
1413             if test "x$ac_krb5_version" = "xHEIMDAL" -o "x$ac_krb5_version" = "xMIT"
1414             then
1415                 #
1416                 # Yes.
1417                 # Check whether we have krb5_kt_resolve - and whether
1418                 # we need to link with -lresolv when linking with
1419                 # the Kerberos library.
1420                 #
1421                 AC_MSG_RESULT($ac_krb5_version)
1422                 wireshark_save_LIBS="$LIBS"
1423                 found_krb5_kt_resolve=no
1424                 for extras in "" "-lresolv"
1425                 do
1426                     LIBS="$KRB5_LIBS $extras"
1427                     if test -z "$extras"
1428                     then
1429                         AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve])
1430                     else
1431                         AC_MSG_CHECKING([whether $ac_krb5_version includes krb5_kt_resolve (linking with $extras)])
1432                     fi
1433                     AC_TRY_LINK(
1434                         [
1435                         ],
1436                         [
1437                             krb5_kt_resolve();
1438                         ],
1439                         [
1440                             #
1441                             # We found "krb5_kt_resolve()", and required
1442                             # the libraries in extras as well.
1443                             #
1444                             AC_MSG_RESULT(yes)
1445                             KRB5_LIBS="$LIBS"
1446                             AC_DEFINE(HAVE_KERBEROS, 1, [Define to use kerberos])
1447                             if test "x$ac_krb5_version" = "xHEIMDAL"
1448                             then
1449                                 AC_DEFINE(HAVE_HEIMDAL_KERBEROS, 1, [Define to use heimdal kerberos])
1450                             elif test "x$ac_krb5_version" = "xMIT"
1451                             then
1452                                 AC_DEFINE(HAVE_MIT_KERBEROS, 1, [Define to use MIT kerberos])
1453                             fi
1454                             found_krb5_kt_resolve=yes
1455                             break
1456                         ],
1457                         [
1458                             AC_MSG_RESULT(no)
1459                         ])
1460                 done
1461                 if test "$found_krb5_kt_resolve" = no
1462                 then
1463                     #
1464                     # We didn't find "krb5_kt_resolve()" in the
1465                     # Kerberos library, even when we tried linking
1466                     # with -lresolv; we can't link with kerberos.
1467                     #
1468                     if test "x$want_krb5" = "xyes"
1469                     then
1470                         #
1471                         # The user tried to force us to use the library,
1472                         # but we can't do so; report an error.
1473                         #
1474                         AC_MSG_ERROR(Usable $ac_krb5_version not found)
1475                     else
1476                         #
1477                         # Restore the versions of CFLAGS and CPPFLAGS
1478                         # from before we added the flags for Kerberos.
1479                         #
1480                         AC_MSG_RESULT(Usable $ac_krb5_version not found - disabling dissection for some kerberos data in packet decoding)
1481                         CFLAGS="$wireshark_save_CFLAGS"
1482                         CPPFLAGS="$wireshark_save_CPPFLAGS"
1483                         KRB5_LIBS=""
1484                         want_krb5=no
1485                     fi
1486                 else
1487                     #
1488                     # We can link with Kerberos; see whether krb5.h
1489                     # defines KEYTYPE_ARCFOUR_56 (where "defines" means
1490                     # "as a #define or as an enum member).
1491                     #
1492                     AC_MSG_CHECKING([whether krb5.h defines KEYTYPE_ARCFOUR_56])
1493                     AC_COMPILE_IFELSE(
1494                       [
1495                         AC_LANG_SOURCE(
1496                           [[
1497                             #include <krb5.h>
1498                             #include <stdio.h>
1499
1500                             main()
1501                             {
1502                               printf("%u\n", KEYTYPE_ARCFOUR_56);
1503                             }
1504                           ]])
1505                       ],
1506                       [
1507                         AC_MSG_RESULT(yes)
1508                         AC_DEFINE(HAVE_KEYTYPE_ARCFOUR_56, 1, [Define if krb5.h defines KEYTYPE_ARCFOUR_56])
1509                       ],
1510                       [
1511                         AC_MSG_RESULT(no)
1512                       ])
1513                 fi
1514                 LIBS="$wireshark_save_LIBS"
1515             else
1516                 #
1517                 # It's not Heimdal or MIT.
1518                 #
1519                 AC_MSG_RESULT(no)
1520                 if test "x$want_krb5" = "xyes"
1521                 then
1522                     #
1523                     # The user tried to force us to use the library,
1524                     # but we can't do so; report an error.
1525                     #
1526                     AC_MSG_ERROR(Kerberos not found)
1527                 else
1528                     #
1529                     # Restore the versions of CFLAGS and CPPFLAGS
1530                     # from before we added the flags for Kerberos.
1531                     #
1532                     AC_MSG_RESULT(Kerberos not found - disabling dissection for some kerberos data in packet decoding)
1533                     CFLAGS="$wireshark_save_CFLAGS"
1534                     CPPFLAGS="$wireshark_save_CPPFLAGS"
1535                     KRB5_LIBS=""
1536                     want_krb5=no
1537                 fi
1538             fi
1539         else
1540             #
1541             # The user asked us not to use Kerberos, or they didn't
1542             # say whether they wanted us to use it but we found
1543             # that we couldn't.
1544             #
1545             # Restore the versions of CFLAGS and CPPFLAGS
1546             # from before we added the flags for Kerberos.
1547             #
1548             CFLAGS="$wireshark_save_CFLAGS"
1549             CPPFLAGS="$wireshark_save_CPPFLAGS"
1550             KRB5_LIBS=""
1551             want_krb5=no
1552         fi
1553         AC_SUBST(KRB5_LIBS)
1554 ])
1555
1556 dnl
1557 dnl Check whether a given format can be used to print 64-bit integers
1558 dnl
1559 AC_DEFUN([AC_WIRESHARK_CHECK_64BIT_FORMAT],
1560 [
1561   AC_MSG_CHECKING([whether %$1x can be used to format 64-bit integers])
1562   AC_RUN_IFELSE(
1563     [
1564       AC_LANG_SOURCE(
1565         [[
1566           #include <glib.h>
1567           #if GTK_MAJOR_VERSION >= 2
1568           #include <glib/gprintf.h>
1569           #endif
1570           #include <stdio.h>
1571
1572           main()
1573           {
1574             guint64 t = 1;
1575             char strbuf[16+1];
1576           #if GTK_MAJOR_VERSION >= 2
1577             g_snprintf(strbuf, sizeof strbuf, "%016$1x", t << 32);
1578           #else
1579             snprintf(strbuf, sizeof strbuf, "%016$1x", t << 32);
1580           #endif
1581             if (strcmp(strbuf, "0000000100000000") == 0)
1582               exit(0);
1583             else
1584               exit(1);
1585           }
1586         ]])
1587     ],
1588     [
1589       AC_DEFINE(G_GINT64_MODIFIER, "$1", [Format modifier for printing 64-bit numbers])
1590       AC_MSG_RESULT(yes)
1591     ],
1592     [
1593       AC_MSG_RESULT(no)
1594       $2
1595     ])
1596 ])
1597
1598 #
1599 # AC_WIRESHARK_GCC_CFLAGS_CHECK
1600 #
1601 # $1 : cflags to test
1602 #
1603 # The macro first determines if the compiler is GCC. Then compile with the
1604 # defined cflags. The defined flags are added to CFLAGS only if the compilation
1605 # succeeds.
1606 #
1607 AC_DEFUN([AC_WIRESHARK_GCC_CFLAGS_CHECK],
1608 [GCC_OPTION="$1"
1609 AC_MSG_CHECKING(whether we can add $GCC_OPTION to CFLAGS)
1610 if test "x$GCC" != "x"; then
1611   CFLAGS_saved="$CFLAGS"
1612   CFLAGS="$CFLAGS $GCC_OPTION"
1613   AC_COMPILE_IFELSE([
1614     AC_LANG_SOURCE([[
1615                       int foo;
1616                   ]])],
1617                   [
1618                     AC_MSG_RESULT(yes)
1619                   ],
1620                   [
1621                     AC_MSG_RESULT(no)
1622                     CFLAGS="$CFLAGS_saved"
1623                   ])
1624 else
1625   AC_MSG_RESULT(no)
1626 fi
1627 ])