1 dnl $Id: acinclude.m4,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
3 dnl Libnet specific autoconf macros
4 dnl Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
5 dnl All rights reserved.
9 dnl Checks to see if this linux kernel has a working PF_PACKET
13 dnl AC_LIBNET_CHECK_PF_PACKET
17 dnl HAVE_PF_PACKET (DEFINED)
20 AC_DEFUN(AC_LIBNET_CHECK_PF_PACKET,
22 AC_MSG_CHECKING(for PF_PACKET)
23 AC_CACHE_VAL(ac_libnet_have_pf_packet,
28 ac_libnet_have_pf_packet = no
32 cat > pf_packet-test.c << EOF
35 #include <netinet/if_ether.h>
36 #include <net/if_arp.h>
38 #include <linux/if_arp.h>
39 #include <linux/if_ether.h>
43 #define SOL_PACKET 263
44 #endif /* SOL_PACKET */
45 #include <linux/if_packet.h>
47 #include "./include/libnet.h"
54 struct sockaddr_ll sa;
56 struct packet_mreq mr;
59 fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
66 memset(&sa, 0, sizeof(sa));
67 strcpy(ifr.ifr_name, device);
68 if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0)
73 sa.sll_family = AF_PACKET;
74 sa.sll_ifindex = ifr.ifr_ifindex;
75 sa.sll_protocol = htons(ETH_P_ALL);
77 memset(&mr, 0, sizeof (mr));
78 mr.mr_ifindex = sa.sll_ifindex;
79 mr.mr_type = PACKET_MR_ALLMULTI;
81 if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, (char *)&mr,
87 /* yay. we made it and it workz! */
95 ${CC-cc} -o pf_packet-test $CFLAGS pf_packet-test.c >/dev/null 2>&1
97 # Oopz 4.3 BSD doesn't have this. Sorry.
98 if test ! -x ./pf_packet-test ; then
99 ac_libnet_have_pf_packet=choked
101 ac_libnet_have_pf_packet=`./pf_packet-test`;
104 if test $ac_libnet_have_pf_packet = choked; then
105 AC_MSG_RESULT(test program choked... assuming no)
106 elif test $ac_libnet_have_pf_packet = yes; then
107 AC_DEFINE(HAVE_PF_PACKET)
108 LIBNET_CONFIG_DEFINES="$LIBNET_CONFIG_DEFINES -DHAVE_PF_PACKET"
111 if test $ac_libnet_have_pf_packet != choked; then
112 AC_MSG_RESULT($ac_libnet_have_pf_packet)
114 rm -f pf_packet-test* core core.pf_packet-test
120 dnl Looks for a previous libnet version and attempts to determine which verion
121 dnl it is. Version 0.8 was the first version that actually knew internally
122 dnl what version it was.
126 dnl AC_LIBNET_CHECK_LIBNET_VERSION
133 AC_DEFUN(AC_LIBNET_CHECK_LIBNET_VER,
135 AC_CHECK_LIB(net, libnet_build_ip, AC_MSG_CHECKING(version) \
137 changequote(<<, >>)dnl
138 if [[ ! -f $LIB_PREFIX/libnet.a ]] ; then
140 AC_MSG_RESULT($LIB_PREFIX/libnet.a doesn't exist)
141 AC_MSG_RESULT(previous libnet install lives elsewhere, you should probably find it)
143 __LIBNET_VERSION=`strings $LIB_PREFIX/libnet.a | grep "libnet version"\
145 if test -z "$__LIBNET_VERSION"; then
148 AC_MSG_RESULT($__LIBNET_VERSION)
156 dnl Checks to see if this linux kernel uses ip_sum or ip_csum
157 dnl (Pulled from queso)
161 dnl AC_LIBNET_CHECK_IP_CSUM
165 dnl HAVE_STRUCT_IP_CSUM (DEFINED)
168 AC_DEFUN(AC_LIBNET_CHECK_IP_CSUM,
170 AC_MSG_CHECKING([struct ip contains ip_csum])
174 #include <sys/types.h>
175 #include <netinet/in.h>
176 #include <netinet/in_systm.h>
177 #include <netinet/ip.h>],
183 AC_DEFINE(HAVE_STRUCT_IP_CSUM)],
189 dnl Checks to see if unaligned memory accesses fail
190 dnl (Pulled from libpcap)
194 dnl AC_LBL_UNALIGNED_ACCESS
198 dnl LBL_ALIGN (DEFINED)
201 AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
202 [AC_MSG_CHECKING(if unaligned accesses fail)
203 AC_CACHE_VAL(ac_cv_lbl_unaligned_fail,
204 [case "$target_cpu" in
206 alpha|hp*|mips|sparc)
207 ac_cv_lbl_unaligned_fail=yes
211 cat >conftest.c <<EOF
212 # include <sys/types.h>
213 # include <sys/wait.h>
215 unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
221 /* avoid "core dumped" message */
230 pid = waitpid(pid, &status, 0);
235 exit(!WIFEXITED(status));
238 i = *(unsigned int *)&a[[1]];
243 ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
244 conftest.c $LIBS > /dev/null 2>&1
245 # Oopz 4.3 BSD doesn't have this. Sorry.
246 if test ! -x conftest ; then
247 dnl failed to compile for some reason
248 ac_cv_lbl_unaligned_fail=yes
250 ./conftest > conftest.out
251 if test ! -s conftest.out ; then
252 ac_cv_lbl_unaligned_fail=yes
254 ac_cv_lbl_unaligned_fail=no
257 rm -f conftest* core core.conftest
260 AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
261 if test $ac_cv_lbl_unaligned_fail = yes ; then
272 dnl AC_LIBNET_ENDIAN_CHECK
276 dnl LIBNET_BIG_ENDIAN = 1 or
277 dnl LIBNET_LIL_ENDIAN = 1
280 AC_DEFUN(AC_LIBNET_ENDIAN_CHECK,
281 [AC_MSG_CHECKING(machine endianess)
283 cat > conftest.c << EOF
292 char c[[sizeof(short)]];
296 if (sizeof (short) == 2)
298 if (un.c [[0]] == 1 && un.c [[1]] == 2)
304 if (un.c [[0]] == 2 && un.c [[1]] == 1)
314 return (EXIT_SUCCESS);
317 ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.c $LIBS > /dev/null 2>&1
318 # Oopz 4.3 BSD doesn't have this. Sorry.
319 if test ! -x conftest ; then
320 dnl failed to compile for some reason
321 ac_cv_libnet_endianess=unknown
323 ./conftest > conftest.out
324 result=`cat conftest.out`
325 if test $result = "B"; then
326 ac_cv_libnet_endianess=big
327 elif test $result = "L"; then
328 ac_cv_libnet_endianess=lil
330 ac_cv_libnet_endianess=unknown
333 rm -f conftest* core core.conftest
335 AC_MSG_RESULT($ac_cv_libnet_endianess)
337 if test $ac_cv_libnet_endianess = big ; then
338 AC_DEFINE(LIBNET_BIG_ENDIAN)
339 LIBNET_CONFIG_DEFINES="$LIBNET_CONFIG_DEFINES -DLIBNET_BIG_ENDIAN"
340 elif test $ac_cv_libnet_endianess = lil ; then
341 AC_DEFINE(LIBNET_LIL_ENDIAN)
342 LIBNET_CONFIG_DEFINES="$LIBNET_CONFIG_DEFINES -DLIBNET_LIL_ENDIAN"