Annotation of embedaddon/libnet/acinclude.m4, revision 1.1.1.2
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
1.1.1.2 ! misho 14: AC_DEFUN([AC_LIBNET_LINUX_PROCFS],
1.1 misho 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:
1.1.1.2 ! misho 40: AC_DEFUN([AC_LIBNET_CHECK_PF_PACKET],
1.1 misho 41: [
1.1.1.2 ! misho 42: AC_MSG_CHECKING(for packet socket (PF_PACKET))
! 43: AC_CACHE_VAL(libnet_cv_have_packet_socket,
1.1 misho 44:
1.1.1.2 ! misho 45: [
1.1 misho 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
1.1.1.2 ! misho 91: libnet_cv_have_packet_socket=choked
1.1 misho 92: else
1.1.1.2 ! misho 93: libnet_cv_have_packet_socket=`./pf_packet-test`;
1.1 misho 94: fi
1.1.1.2 ! misho 95: if test $libnet_cv_have_packet_socket = choked; then
1.1 misho 96: AC_MSG_RESULT(test program compile choked... assuming no)
1.1.1.2 ! misho 97: elif test $libnet_cv_have_packet_socket = yes; then
1.1 misho 98: AC_MSG_RESULT(yes)
1.1.1.2 ! misho 99: elif test $libnet_cv_have_packet_socket = probably; then
1.1 misho 100: AC_MSG_RESULT(test program got EPERM... assuming yes)
1.1.1.2 ! misho 101: elif test $libnet_cv_have_packet_socket = no; then
1.1 misho 102: AC_MSG_RESULT(no)
103: fi
104:
105: rm -f pf_packet-test* core core.pf_packet-test
106:
1.1.1.2 ! misho 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.])
1.1 misho 112: fi
113: ])
114:
115: dnl
116: dnl Looks for a previous libnet version and attempts to determine which verion
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:
1.1.1.2 ! misho 129: AC_DEFUN([AC_LIBNET_CHECK_LIBNET_VER],
1.1 misho 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:
1.1.1.2 ! misho 164: AC_DEFUN([AC_LIBNET_CHECK_IP_CSUM],
1.1 misho 165: [
166: AC_MSG_CHECKING([struct ip contains ip_csum])
167: AC_TRY_COMPILE([
168: #define __BSD_SOURCE
169: #define _BSD_SOURCE
170: #include <sys/types.h>
171: #include <netinet/in.h>
172: #include <netinet/in_systm.h>
173: #include <netinet/ip.h>],
174: [
175: struct ip ip;
176: ip.ip_csum = 0;
177: ],
178: [AC_MSG_RESULT(yes);
179: AC_DEFINE(HAVE_STRUCT_IP_CSUM)],
180: [AC_MSG_RESULT(no);
181: ])
182: ])
183:
184:
185: dnl
186: dnl Checks endianess
187: dnl
188: dnl usage:
189: dnl
190: dnl AC_LIBNET_ENDIAN_CHECK
191: dnl
192: dnl results:
193: dnl
194: dnl LIBNET_BIG_ENDIAN = 1 or
195: dnl LIBNET_LIL_ENDIAN = 1
196: dnl
197:
1.1.1.2 ! misho 198: AC_DEFUN([AC_LIBNET_ENDIAN_CHECK],
! 199: [AC_C_BIGENDIAN
! 200: if test $ac_cv_c_bigendian = yes ; then
! 201: AC_DEFINE(LIBNET_BIG_ENDIAN, 1,
! 202: [We are running on a big-endian machine.])
1.1 misho 203: ENDIANESS="LIBNET_BIG_ENDIAN"
204: LIBNET_CONFIG_DEFINES="$LIBNET_CONFIG_DEFINES -DLIBNET_BIG_ENDIAN"
1.1.1.2 ! misho 205: else
! 206: AC_DEFINE(LIBNET_LIL_ENDIAN, 1,
! 207: [We are running on a little-endian machine.])
1.1 misho 208: ENDIANESS="LIBNET_LIL_ENDIAN"
209: LIBNET_CONFIG_DEFINES="$LIBNET_CONFIG_DEFINES -DLIBNET_LIL_ENDIAN"
210: fi
211: ])
212:
213: dnl
214: dnl Improved version of AC_CHECK_LIB
215: dnl
216: dnl Thanks to John Hawkinson (jhawk@mit.edu)
217: dnl
218: dnl usage:
219: dnl
220: dnl AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
221: dnl ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
222: dnl
223: dnl results:
224: dnl
225: dnl LIBS
226: dnl
227:
1.1.1.2 ! misho 228: define([AC_LBL_CHECK_LIB],
1.1 misho 229: [AC_MSG_CHECKING([for $2 in -l$1])
230: dnl Use a cache variable name containing both the library and function name,
231: dnl because the test really is for library $1 defining function $2, not
232: dnl just for library $1. Separate tests with the same $1 and different $2's
233: dnl may have different results.
234: ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
235: AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
236: [ac_save_LIBS="$LIBS"
237: LIBS="-l$1 $5 $LIBS"
238: AC_TRY_LINK(dnl
239: ifelse([$2], [main], , dnl Avoid conflicting decl of main.
240: [/* Override any gcc2 internal prototype to avoid an error. */
241: ]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
242: extern "C"
243: #endif
244: ])dnl
245: [/* We use char because int might match the return type of a gcc2
246: builtin and then its argument prototype would still apply. */
247: char $2();
248: ]),
249: [$2()],
250: eval "ac_cv_lbl_lib_$ac_lib_var=yes",
251: eval "ac_cv_lbl_lib_$ac_lib_var=no")
252: LIBS="$ac_save_LIBS"
253: ])dnl
254: if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
255: AC_MSG_RESULT(yes)
256: ifelse([$3], ,
257: [changequote(, )dnl
258: ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
259: -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
260: changequote([, ])dnl
261: AC_DEFINE_UNQUOTED($ac_tr_lib)
262: LIBS="-l$1 $LIBS"
263: ], [$3])
264: else
265: AC_MSG_RESULT(no)
266: ifelse([$4], , , [$4
267: ])dnl
268: fi
269: ])
270:
271: dnl
272: dnl AC_LBL_LIBRARY_NET
273: dnl
274: dnl This test is for network applications that need socket() and
275: dnl gethostbyname() -ish functions. Under Solaris, those applications
276: dnl need to link with "-lsocket -lnsl". Under IRIX, they need to link
277: dnl with "-lnsl" but should *not* link with "-lsocket" because
278: dnl libsocket.a breaks a number of things (for instance:
279: dnl gethostbyname() under IRIX 5.2, and snoop sockets under most
280: dnl versions of IRIX).
281: dnl
282: dnl Unfortunately, many application developers are not aware of this,
283: dnl and mistakenly write tests that cause -lsocket to be used under
284: dnl IRIX. It is also easy to write tests that cause -lnsl to be used
285: dnl under operating systems where neither are necessary (or useful),
286: dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
287: dnl
288: dnl This test exists so that every application developer does not test
289: dnl this in a different, and subtly broken fashion.
290:
291: dnl It has been argued that this test should be broken up into two
292: dnl seperate tests, one for the resolver libraries, and one for the
293: dnl libraries necessary for using Sockets API. Unfortunately, the two
294: dnl are carefully intertwined and allowing the autoconf user to use
295: dnl them independantly potentially results in unfortunate ordering
296: dnl dependancies -- as such, such component macros would have to
297: dnl carefully use indirection and be aware if the other components were
298: dnl executed. Since other autoconf macros do not go to this trouble,
299: dnl and almost no applications use sockets without the resolver, this
300: dnl complexity has not been implemented.
301: dnl
302: dnl The check for libresolv is in case you are attempting to link
303: dnl statically and happen to have a libresolv.a lying around (and no
304: dnl libnsl.a).
305: dnl
1.1.1.2 ! misho 306: AC_DEFUN([AC_LBL_LIBRARY_NET],
! 307: [
1.1 misho 308: # Most operating systems have gethostbyname() in the default searched
309: # libraries (i.e. libc):
310: AC_CHECK_FUNC(gethostbyname, ,
311: # Some OSes (eg. Solaris) place it in libnsl:
312: AC_LBL_CHECK_LIB(nsl, gethostbyname, ,
313: # Some strange OSes (SINIX) have it in libsocket:
314: AC_LBL_CHECK_LIB(socket, gethostbyname, ,
315: # Unfortunately libsocket sometimes depends on libnsl.
316: # AC_CHECK_LIB's API is essentially broken so the
317: # following ugliness is necessary:
318: AC_LBL_CHECK_LIB(socket, gethostbyname,
319: LIBS="-lsocket -lnsl $LIBS",
320: AC_CHECK_LIB(resolv, gethostbyname),
321: -lnsl))))
322: AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
323: AC_LBL_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", ,
324: -lnsl)))
325: # DLPI needs putmsg under HPUX so test for -lstr while we're at it
326: AC_CHECK_LIB(str, putmsg)
327: ])
328:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>