Annotation of embedaddon/libnet/m4/acinclude.m4, revision 1.1

1.1     ! misho       1: dnl $Id: acinclude.m4,v 1.3 2004/01/15 23:53:06 mike Exp $
        !             2: dnl
        !             3: dnl Libnet specific autoconf macros
        !             4: dnl Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
        !             5: dnl All rights reserved.
        !             6: dnl
        !             7: 
        !             8: dnl
        !             9: dnl Check for the Linux /proc filesystem
        !            10: dnl
        !            11: dnl usage:      AC_LIBNET_LINUX_PROCFS
        !            12: dnl results:    HAVE_LINUX_PROCFS
        !            13: dnl
        !            14: AC_DEFUN([AC_LIBNET_LINUX_PROCFS],
        !            15:     [AC_MSG_CHECKING(for Linux proc filesystem)
        !            16:     AC_CACHE_VAL(ac_cv_libnet_linux_procfs,
        !            17:         if test "x`cat /proc/sys/kernel/ostype 2>&-`" = "xLinux" ; then
        !            18:             ac_cv_libnet_linux_procfs=yes
        !            19:         else
        !            20:             ac_cv_libnet_linux_procfs=no
        !            21:         fi)
        !            22:     AC_MSG_RESULT($ac_cv_libnet_linux_procfs)
        !            23:     if test $ac_cv_libnet_linux_procfs = yes ; then
        !            24:         AC_DEFINE(HAVE_LINUX_PROCFS, 1,
        !            25:                   [Define if you have the Linux /proc filesystem.])
        !            26:     fi])
        !            27: 
        !            28: dnl
        !            29: dnl Checks to see if this linux kernel has a working PF_PACKET
        !            30: dnl
        !            31: dnl usage:
        !            32: dnl
        !            33: dnl     AC_LIBNET_CHECK_PF_PACKET
        !            34: dnl
        !            35: dnl results:
        !            36: dnl
        !            37: dnl     HAVE_PACKET_SOCKET (DEFINED)
        !            38: dnl
        !            39: 
        !            40: AC_DEFUN([AC_LIBNET_CHECK_PF_PACKET],
        !            41: [
        !            42:     AC_MSG_CHECKING(for packet socket (PF_PACKET))
        !            43:     AC_CACHE_VAL(libnet_cv_have_packet_socket,
        !            44: 
        !            45:         [
        !            46:     cat > pf_packet-test.c << EOF
        !            47: #include <stdio.h>
        !            48: #include <errno.h>
        !            49: #include <stdlib.h>
        !            50: #include <netinet/in.h>
        !            51: #include <sys/socket.h>
        !            52: #include <features.h>    /* for the glibc version number */
        !            53: #if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
        !            54: #include <netpacket/packet.h>
        !            55: #include <net/ethernet.h>     /* the L2 protocols */
        !            56: #else
        !            57: #include <asm/types.h>
        !            58: #include <linux/if_packet.h>
        !            59: #include <linux/if_ether.h>   /* The L2 protocols */
        !            60: #endif
        !            61:  
        !            62: #ifndef SOL_PACKET
        !            63: #define SOL_PACKET 263
        !            64: #endif  /* SOL_PACKET */
        !            65:  
        !            66: int
        !            67: main(int argc, char **argv)
        !            68: {
        !            69:     int fd;
        !            70:  
        !            71:     fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
        !            72:     if (fd == -1)
        !            73:     {
        !            74:         if (errno == EPERM)
        !            75:         {
        !            76:             /* user's UID != 0 */
        !            77:             printf("probably");
        !            78:             exit (EXIT_FAILURE);
        !            79:         }
        !            80:         printf("no");
        !            81:         exit (EXIT_FAILURE);
        !            82:     }
        !            83:     printf("yes");
        !            84:     exit (EXIT_SUCCESS);
        !            85: }
        !            86: EOF
        !            87:     ${CC-cc} -o pf_packet-test $CFLAGS pf_packet-test.c >/dev/null 2>&1
        !            88: 
        !            89:     # Oopz 4.3 BSD doesn't have this.  Sorry.
        !            90:     if test ! -x ./pf_packet-test ; then
        !            91:         libnet_cv_have_packet_socket=choked
        !            92:     else
        !            93:         libnet_cv_have_packet_socket=`./pf_packet-test`;
        !            94:     fi
        !            95:     if test $libnet_cv_have_packet_socket = choked; then
        !            96:         AC_MSG_RESULT(test program compile choked... assuming no)
        !            97:     elif test $libnet_cv_have_packet_socket = yes; then
        !            98:         AC_MSG_RESULT(yes)
        !            99:     elif test $libnet_cv_have_packet_socket = probably; then
        !           100:         AC_MSG_RESULT(test program got EPERM... assuming yes)
        !           101:     elif test $libnet_cv_have_packet_socket = no; then
        !           102:         AC_MSG_RESULT(no)
        !           103:     fi
        !           104: 
        !           105:     rm -f pf_packet-test* core core.pf_packet-test
        !           106: 
        !           107:     ])
        !           108: 
        !           109:     if test $libnet_cv_have_packet_socket = yes -o $libnet_cv_have_packet_socket = probably; then
        !           110:         AC_DEFINE(HAVE_PACKET_SOCKET, 1,
        !           111:           [Define if we're running on a Linux system with PF_PACKET sockets.])
        !           112:     fi
        !           113: ])
        !           114: 
        !           115: dnl
        !           116: dnl Looks for a previous libnet version and attempts to determine which version
        !           117: dnl it is.  Version 0.8 was the first version that actually knew internally
        !           118: dnl what version it was.
        !           119: dnl
        !           120: dnl usage:
        !           121: dnl
        !           122: dnl     AC_LIBNET_CHECK_LIBNET_VERSION
        !           123: dnl
        !           124: dnl results:
        !           125: dnl
        !           126: dnl
        !           127: dnl
        !           128: 
        !           129: AC_DEFUN([AC_LIBNET_CHECK_LIBNET_VER],
        !           130: [
        !           131:     AC_CHECK_LIB(net, libnet_build_ip, AC_MSG_CHECKING(version) \
        !           132: 
        !           133: changequote(<<, >>)dnl
        !           134:     if [[ ! -f $LIB_PREFIX/libnet.a ]] ; then
        !           135: changequote([, ])dnl
        !           136:         AC_MSG_RESULT($LIB_PREFIX/libnet.a doesn't exist)
        !           137:         AC_MSG_RESULT(previous libnet install lives elsewhere, you should probably find it)
        !           138:     else
        !           139:         __LIBNET_VERSION=`strings $LIB_PREFIX/libnet.a | grep "libnet version"\
        !           140:                 | cut -f3 -d" "`;\
        !           141:         if test -z "$__LIBNET_VERSION"; then
        !           142:             AC_MSG_RESULT(<0.8)
        !           143:         else
        !           144:             AC_MSG_RESULT($__LIBNET_VERSION)
        !           145:         fi
        !           146:     fi\
        !           147:     )
        !           148: ])
        !           149: 
        !           150: 
        !           151: dnl
        !           152: dnl Checks to see if this linux kernel uses ip_sum or ip_csum
        !           153: dnl (Pulled from queso)
        !           154: dnl
        !           155: dnl usage:
        !           156: dnl
        !           157: dnl     AC_LIBNET_CHECK_IP_CSUM
        !           158: dnl
        !           159: dnl results:
        !           160: dnl
        !           161: dnl     HAVE_STRUCT_IP_CSUM (DEFINED)
        !           162: dnl
        !           163: 
        !           164: AC_DEFUN([AC_LIBNET_CHECK_IP_CSUM],
        !           165: [
        !           166:     AC_MSG_CHECKING([struct ip contains ip_csum])
        !           167:     AC_TRY_COMPILE([
        !           168:         #define __BSD_SOURCE
        !           169:         #define _BSD_SOURCE
        !           170:         #define _DEFAULT_SOURCE
        !           171:         #include <sys/types.h>
        !           172:         #include <netinet/in.h>
        !           173:         #include <netinet/in_systm.h>
        !           174:         #include <netinet/ip.h>],
        !           175:         [
        !           176:             struct ip ip;
        !           177:             ip.ip_csum = 0;
        !           178:         ],
        !           179:         [AC_MSG_RESULT(yes);
        !           180:         AC_DEFINE(HAVE_STRUCT_IP_CSUM)],
        !           181:         [AC_MSG_RESULT(no);
        !           182:     ])
        !           183: ])
        !           184: 
        !           185: 
        !           186: dnl
        !           187: dnl Checks endianess
        !           188: dnl
        !           189: dnl usage:
        !           190: dnl
        !           191: dnl     AC_LIBNET_ENDIAN_CHECK
        !           192: dnl
        !           193: dnl results:
        !           194: dnl
        !           195: dnl     LIBNET_BIG_ENDIAN = 1   or
        !           196: dnl     LIBNET_LIL_ENDIAN = 1
        !           197: dnl
        !           198: 
        !           199: AC_DEFUN([AC_LIBNET_ENDIAN_CHECK],
        !           200:     [AC_C_BIGENDIAN
        !           201:        if test $ac_cv_c_bigendian = yes ; then
        !           202:             AC_DEFINE(LIBNET_BIG_ENDIAN, 1,
        !           203:                 [We are running on a big-endian machine.])
        !           204:             ENDIANESS="LIBNET_BIG_ENDIAN"
        !           205:             PKG_CONFIG_DEFINES="$PKG_CONFIG_DEFINES -DLIBNET_BIG_ENDIAN"
        !           206:         else
        !           207:             AC_DEFINE(LIBNET_LIL_ENDIAN, 1, 
        !           208:                 [We are running on a little-endian machine.])
        !           209:             ENDIANESS="LIBNET_LIL_ENDIAN"
        !           210:             PKG_CONFIG_DEFINES="$PKG_CONFIG_DEFINES -DLIBNET_LIL_ENDIAN"
        !           211:         fi
        !           212:     ])
        !           213: 
        !           214: dnl
        !           215: dnl Improved version of AC_CHECK_LIB
        !           216: dnl
        !           217: dnl Thanks to John Hawkinson (jhawk@mit.edu)
        !           218: dnl
        !           219: dnl usage:
        !           220: dnl
        !           221: dnl     AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
        !           222: dnl         ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
        !           223: dnl
        !           224: dnl results:
        !           225: dnl
        !           226: dnl     LIBS
        !           227: dnl
        !           228:  
        !           229: define([AC_LBL_CHECK_LIB],
        !           230: [AC_MSG_CHECKING([for $2 in -l$1])
        !           231: dnl Use a cache variable name containing both the library and function name,
        !           232: dnl because the test really is for library $1 defining function $2, not
        !           233: dnl just for library $1.  Separate tests with the same $1 and different $2's
        !           234: dnl may have different results.
        !           235: ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
        !           236: AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
        !           237: [ac_save_LIBS="$LIBS"
        !           238: LIBS="-l$1 $5 $LIBS"
        !           239: AC_TRY_LINK(dnl
        !           240: ifelse([$2], [main], , dnl Avoid conflicting decl of main.
        !           241: [/* Override any gcc2 internal prototype to avoid an error.  */
        !           242: ]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
        !           243: extern "C"
        !           244: #endif
        !           245: ])dnl
        !           246: [/* We use char because int might match the return type of a gcc2
        !           247:     builtin and then its argument prototype would still apply.  */
        !           248: char $2();
        !           249: ]),
        !           250:             [$2()],
        !           251:             eval "ac_cv_lbl_lib_$ac_lib_var=yes",
        !           252:             eval "ac_cv_lbl_lib_$ac_lib_var=no")
        !           253: LIBS="$ac_save_LIBS"
        !           254: ])dnl
        !           255: if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
        !           256:   AC_MSG_RESULT(yes)
        !           257:   ifelse([$3], ,
        !           258: [changequote(, )dnl
        !           259:   ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
        !           260:     -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
        !           261: changequote([, ])dnl
        !           262:   AC_DEFINE_UNQUOTED($ac_tr_lib)
        !           263:   LIBS="-l$1 $LIBS"
        !           264: ], [$3])
        !           265: else
        !           266:   AC_MSG_RESULT(no)
        !           267: ifelse([$4], , , [$4
        !           268: ])dnl
        !           269: fi
        !           270: ])
        !           271: 
        !           272: dnl
        !           273: dnl AC_LBL_LIBRARY_NET
        !           274: dnl
        !           275: dnl This test is for network applications that need socket() and
        !           276: dnl gethostbyname() -ish functions.  Under Solaris, those applications
        !           277: dnl need to link with "-lsocket -lnsl".  Under IRIX, they need to link
        !           278: dnl with "-lnsl" but should *not* link with "-lsocket" because
        !           279: dnl libsocket.a breaks a number of things (for instance:
        !           280: dnl gethostbyname() under IRIX 5.2, and snoop sockets under most
        !           281: dnl versions of IRIX).
        !           282: dnl
        !           283: dnl Unfortunately, many application developers are not aware of this,
        !           284: dnl and mistakenly write tests that cause -lsocket to be used under
        !           285: dnl IRIX.  It is also easy to write tests that cause -lnsl to be used
        !           286: dnl under operating systems where neither are necessary (or useful),
        !           287: dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
        !           288: dnl
        !           289: dnl This test exists so that every application developer does not test
        !           290: dnl this in a different, and subtly broken fashion.
        !           291:  
        !           292: dnl It has been argued that this test should be broken up into two
        !           293: dnl separate tests, one for the resolver libraries, and one for the
        !           294: dnl libraries necessary for using Sockets API. Unfortunately, the two
        !           295: dnl are carefully intertwined and allowing the autoconf user to use
        !           296: dnl them independently potentially results in unfortunate ordering of
        !           297: dnl dependencies -- as such, such component macros would have to
        !           298: dnl carefully use indirection and be aware if the other components were
        !           299: dnl executed. Since other autoconf macros do not go to this trouble,
        !           300: dnl and almost no applications use sockets without the resolver, this
        !           301: dnl complexity has not been implemented.
        !           302: dnl
        !           303: dnl The check for libresolv is in case you are attempting to link
        !           304: dnl statically and happen to have a libresolv.a lying around (and no
        !           305: dnl libnsl.a).
        !           306: dnl
        !           307: AC_DEFUN([AC_LBL_LIBRARY_NET],
        !           308: [
        !           309:     # Most operating systems have gethostbyname() in the default searched
        !           310:     # libraries (i.e. libc):
        !           311:     AC_CHECK_FUNC(gethostbyname, ,
        !           312:         # Some OSes (eg. Solaris) place it in libnsl:
        !           313:         AC_LBL_CHECK_LIB(nsl, gethostbyname, ,
        !           314:             # Some strange OSes (SINIX) have it in libsocket:
        !           315:             AC_LBL_CHECK_LIB(socket, gethostbyname, ,
        !           316:                 # Unfortunately libsocket sometimes depends on libnsl.
        !           317:                 # AC_CHECK_LIB's API is essentially broken so the
        !           318:                 # following ugliness is necessary:
        !           319:                 AC_LBL_CHECK_LIB(socket, gethostbyname,
        !           320:                     LIBS="-lsocket -lnsl $LIBS",
        !           321:                     AC_CHECK_LIB(resolv, gethostbyname),
        !           322:                     -lnsl))))
        !           323:     AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
        !           324:         AC_LBL_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", ,
        !           325:             -lnsl)))
        !           326:     # DLPI needs putmsg under HPUX so test for -lstr while we're at it
        !           327:     AC_CHECK_LIB(str, putmsg)
        !           328:     ])
        !           329: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>