OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / Libnet / aclocal.m4
1 dnl aclocal.m4 generated automatically by aclocal 1.4
2
3 dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7
8 dnl This program is distributed in the hope that it will be useful,
9 dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
10 dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11 dnl PARTICULAR PURPOSE.
12
13 dnl $Id: aclocal.m4,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
14 dnl
15 dnl Libnet specific autoconf macros
16 dnl Copyright (c) 1998, 1999, 2000 Mike D. Schiffman <mike@infonexus.com>
17 dnl All rights reserved.
18 dnl
19
20 dnl
21 dnl Checks to see if this linux kernel has a working PF_PACKET
22 dnl
23 dnl usage:
24 dnl
25 dnl     AC_LIBNET_CHECK_PF_PACKET
26 dnl
27 dnl results:
28 dnl
29 dnl     HAVE_PF_PACKET (DEFINED)
30 dnl
31
32 AC_DEFUN(AC_LIBNET_CHECK_PF_PACKET,
33 [
34     AC_MSG_CHECKING(for PF_PACKET)
35     AC_CACHE_VAL(ac_libnet_have_pf_packet,
36
37         [case "$target_os" in
38
39         linux)
40                 ac_libnet_have_pf_packet = no
41                 ;;
42         *)
43
44     cat > pf_packet-test.c << EOF
45 #include <net/if.h>
46 #if (__GLIBC__)
47 #include <netinet/if_ether.h>
48 #include <net/if_arp.h>
49 #else
50 #include <linux/if_arp.h>
51 #include <linux/if_ether.h>
52 #endif
53 #if (PF_PACKET)
54 #ifndef SOL_PACKET
55 #define SOL_PACKET 263
56 #endif  /* SOL_PACKET */
57 #include <linux/if_packet.h>
58 #endif
59 #include <stdlib.h>
60 #include <linux/sockios.h>
61
62 int
63 main()
64 {
65 #if (PF_PACKET)
66     int fd;
67     struct sockaddr_ll sa;
68     struct ifreq ifr;
69     struct packet_mreq mr;
70     char *device ="lo";
71
72     fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
73     if (fd == -1)
74     {
75         printf("choked");
76         exit (EXIT_FAILURE);
77     }
78
79     memset(&sa, 0, sizeof(sa));
80     strcpy(ifr.ifr_name, device);
81     if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0)
82     {
83         printf("choked");
84         exit (EXIT_FAILURE);
85     }
86     sa.sll_family = AF_PACKET;
87     sa.sll_ifindex = ifr.ifr_ifindex;
88     sa.sll_protocol = htons(ETH_P_ALL);
89
90     memset(&mr, 0, sizeof (mr));
91     mr.mr_ifindex = sa.sll_ifindex;
92     mr.mr_type = PACKET_MR_ALLMULTI;
93
94     if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, (char *)&mr,
95             sizeof (mr)) < 0)
96     {
97         printf("choked\n");
98         exit (EXIT_FAILURE);
99     }
100     /* yay.  we made it and it workz! */
101     printf("yes");
102 #else   /* PF_PACKET */
103     printf("no");
104 #endif
105     exit (EXIT_SUCCESS);
106 }
107 EOF
108     ${CC-cc} -o pf_packet-test $CFLAGS pf_packet-test.c >/dev/null 2>&1
109
110     # Oopz 4.3 BSD doesn't have this.  Sorry.
111     if test ! -x ./pf_packet-test ; then
112         ac_libnet_have_pf_packet=choked
113     else
114         ac_libnet_have_pf_packet=`./pf_packet-test`;
115     fi
116
117     if test $ac_libnet_have_pf_packet = choked; then
118         AC_MSG_RESULT(test program choked... assuming no)
119     elif test $ac_libnet_have_pf_packet = yes; then
120         AC_DEFINE(HAVE_PF_PACKET)
121         LIBNET_CONFIG_DEFINES="$LIBNET_CONFIG_DEFINES -DHAVE_PF_PACKET"
122     fi
123
124     if test $ac_libnet_have_pf_packet != choked; then
125         AC_MSG_RESULT($ac_libnet_have_pf_packet)
126     fi
127     rm -f pf_packet-test* core core.pf_packet-test
128     ;;
129     esac])
130 ])
131
132 dnl
133 dnl Looks for a previous libnet version and attempts to determine which verion
134 dnl it is.  Version 0.8 was the first version that actually knew internally
135 dnl what version it was.
136 dnl
137 dnl usage:
138 dnl
139 dnl     AC_LIBNET_CHECK_LIBNET_VERSION
140 dnl
141 dnl results:
142 dnl
143 dnl
144 dnl
145
146 AC_DEFUN(AC_LIBNET_CHECK_LIBNET_VER,
147 [
148     AC_CHECK_LIB(net, libnet_build_ip, AC_MSG_CHECKING(version) \
149
150 changequote(<<, >>)dnl
151     if [[ ! -f $LIB_PREFIX/libnet.a ]] ; then
152 changequote([, ])dnl
153         AC_MSG_RESULT($LIB_PREFIX/libnet.a doesn't exist)
154         AC_MSG_RESULT(previous libnet install lives elsewhere, you should probably find it)
155     else
156         __LIBNET_VERSION=`strings $LIB_PREFIX/libnet.a | grep "libnet version"\
157                 | cut -f3 -d" "`;\
158         if test -z "$__LIBNET_VERSION"; then
159             AC_MSG_RESULT(<0.8)
160         else
161             AC_MSG_RESULT($__LIBNET_VERSION)
162         fi
163     fi\
164     )
165 ])
166
167
168 dnl
169 dnl Checks to see if this linux kernel uses ip_sum or ip_csum
170 dnl (Pulled from queso)
171 dnl
172 dnl usage:
173 dnl
174 dnl     AC_LIBNET_CHECK_IP_CSUM
175 dnl
176 dnl results:
177 dnl
178 dnl     HAVE_STRUCT_IP_CSUM (DEFINED)
179 dnl
180
181 AC_DEFUN(AC_LIBNET_CHECK_IP_CSUM,
182 [
183     AC_MSG_CHECKING([struct ip contains ip_csum])
184     AC_TRY_COMPILE([
185         #define __BSD_SOURCE
186         #define _BSD_SOURCE
187         #include <sys/types.h>
188         #include <netinet/in.h>
189         #include <netinet/in_systm.h>
190         #include <netinet/ip.h>],
191         [
192             struct ip ip;
193             ip.ip_csum = 0;
194         ],
195         [AC_MSG_RESULT(yes);
196         AC_DEFINE(HAVE_STRUCT_IP_CSUM)],
197         [AC_MSG_RESULT(no);
198     ])
199 ])
200
201 dnl
202 dnl Checks to see if unaligned memory accesses fail
203 dnl (Pulled from libpcap)
204 dnl
205 dnl usage:
206 dnl
207 dnl     AC_LBL_UNALIGNED_ACCESS
208 dnl
209 dnl results:
210 dnl
211 dnl     LBL_ALIGN (DEFINED)
212 dnl
213
214 AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
215     [AC_MSG_CHECKING(if unaligned accesses fail)
216     AC_CACHE_VAL(ac_cv_lbl_unaligned_fail,
217         [case "$target_cpu" in
218
219         alpha|hp*|mips|sparc)
220                 ac_cv_lbl_unaligned_fail=yes
221                 ;;
222
223         *)
224                 cat >conftest.c <<EOF
225 #                   include <sys/types.h>
226 #                   include <sys/wait.h>
227 #                   include <stdio.h>
228                     unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
229                     main()
230                     {
231                         unsigned int i;
232                         pid_t pid;
233                         int status;
234                         /* avoid "core dumped" message */
235                         pid = fork();
236                         if (pid <  0)
237                         {
238                             exit(2);
239                         }
240                         if (pid > 0)
241                         {
242                             /* parent */
243                             pid = waitpid(pid, &status, 0);
244                             if (pid < 0)
245                             {
246                                 exit(3);
247                             }
248                             exit(!WIFEXITED(status));
249                         }
250                         /* child */
251                         i = *(unsigned int *)&a[[1]];
252                         printf("%d\n", i);
253                         exit(0);
254                     }
255 EOF
256                 ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
257                     conftest.c $LIBS > /dev/null 2>&1
258                 # Oopz 4.3 BSD doesn't have this.  Sorry.
259                 if test ! -x conftest ; then
260                         dnl failed to compile for some reason
261                         ac_cv_lbl_unaligned_fail=yes
262                 else
263                         ./conftest > conftest.out
264                         if test ! -s conftest.out ; then
265                                 ac_cv_lbl_unaligned_fail=yes
266                         else
267                                 ac_cv_lbl_unaligned_fail=no
268                         fi
269                 fi
270                 rm -f conftest* core core.conftest
271                 ;;
272         esac])
273     AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
274     if test $ac_cv_lbl_unaligned_fail = yes ; then
275             AC_DEFINE(LBL_ALIGN)
276     fi
277 ])
278
279
280 dnl
281 dnl Checks endianess
282 dnl
283 dnl usage:
284 dnl
285 dnl     AC_LIBNET_ENDIAN_CHECK
286 dnl
287 dnl results:
288 dnl
289 dnl     LIBNET_BIG_ENDIAN = 1   or
290 dnl     LIBNET_LIL_ENDIAN = 1
291 dnl
292
293 AC_DEFUN(AC_LIBNET_ENDIAN_CHECK,
294     [AC_MSG_CHECKING(machine endianess)
295
296     cat > conftest.c << EOF
297 #       include <stdio.h>
298 #       include <stdlib.h>
299
300         int main()
301         {
302             union
303             {
304                 short s;
305                 char c[[sizeof(short)]];
306             } un;
307
308             un.s = 0x0102;
309             if (sizeof (short) == 2)
310             {
311                 if (un.c [[0]] == 1 && un.c [[1]] == 2)
312                 {
313                     printf("B\n");
314                 }
315                 else
316                 {
317                     if (un.c [[0]] == 2 && un.c [[1]] == 1)
318                     {
319                         printf("L\n");
320                     }
321                 }
322             }
323             else
324             {
325                 printf("?\n");
326             }
327             return (EXIT_SUCCESS);
328         }
329 EOF
330         ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.c $LIBS > /dev/null 2>&1
331         # Oopz 4.3 BSD doesn't have this.  Sorry.
332         if test ! -x conftest ; then
333 dnl failed to compile for some reason
334             ac_cv_libnet_endianess=unknown
335         else
336             ./conftest > conftest.out
337             result=`cat conftest.out`
338             if test $result = "B"; then
339                 ac_cv_libnet_endianess=big
340             elif test $result = "L"; then
341                 ac_cv_libnet_endianess=lil
342             else
343                 ac_cv_libnet_endianess=unknown
344             fi                                
345         fi
346         rm -f conftest* core core.conftest
347
348         AC_MSG_RESULT($ac_cv_libnet_endianess)
349
350         if test $ac_cv_libnet_endianess = big ; then
351             AC_DEFINE(LIBNET_BIG_ENDIAN)
352         LIBNET_CONFIG_DEFINES="$LIBNET_CONFIG_DEFINES -DLIBNET_BIG_ENDIAN"
353         elif test $ac_cv_libnet_endianess = lil ; then
354             AC_DEFINE(LIBNET_LIL_ENDIAN)
355         LIBNET_CONFIG_DEFINES="$LIBNET_CONFIG_DEFINES -DLIBNET_LIL_ENDIAN"
356         fi
357     ])
358