OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / Libnet / acinclude.m4
1 dnl $Id: acinclude.m4,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
2 dnl
3 dnl Libnet specific autoconf macros
4 dnl Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
5 dnl All rights reserved.
6 dnl
7
8 dnl
9 dnl Checks to see if this linux kernel has a working PF_PACKET
10 dnl
11 dnl usage:
12 dnl
13 dnl     AC_LIBNET_CHECK_PF_PACKET
14 dnl
15 dnl results:
16 dnl
17 dnl     HAVE_PF_PACKET (DEFINED)
18 dnl
19
20 AC_DEFUN(AC_LIBNET_CHECK_PF_PACKET,
21 [
22     AC_MSG_CHECKING(for PF_PACKET)
23     AC_CACHE_VAL(ac_libnet_have_pf_packet,
24
25         [case "$target_os" in
26
27         linux)
28                 ac_libnet_have_pf_packet = no
29                 ;;
30         *)
31
32     cat > pf_packet-test.c << EOF
33 #include <net/if.h>
34 #if (__GLIBC__)
35 #include <netinet/if_ether.h>
36 #include <net/if_arp.h>
37 #else
38 #include <linux/if_arp.h>
39 #include <linux/if_ether.h>
40 #endif
41 #if (PF_PACKET)
42 #ifndef SOL_PACKET
43 #define SOL_PACKET 263
44 #endif  /* SOL_PACKET */
45 #include <linux/if_packet.h>
46 #endif
47 #include "./include/libnet.h"
48
49 int
50 main()
51 {
52 #if (PF_PACKET)
53     int fd;
54     struct sockaddr_ll sa;
55     struct ifreq ifr;
56     struct packet_mreq mr;
57     char *device ="lo";
58
59     fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
60     if (fd == -1)
61     {
62         printf("choked");
63         exit (EXIT_FAILURE);
64     }
65
66     memset(&sa, 0, sizeof(sa));
67     strcpy(ifr.ifr_name, device);
68     if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0)
69     {
70         printf("choked");
71         exit (EXIT_FAILURE);
72     }
73     sa.sll_family = AF_PACKET;
74     sa.sll_ifindex = ifr.ifr_ifindex;
75     sa.sll_protocol = htons(ETH_P_ALL);
76
77     memset(&mr, 0, sizeof (mr));
78     mr.mr_ifindex = sa.sll_ifindex;
79     mr.mr_type = PACKET_MR_ALLMULTI;
80
81     if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, (char *)&mr,
82             sizeof (mr)) < 0)
83     {
84         printf("choked\n");
85         exit (EXIT_FAILURE);
86     }
87     /* yay.  we made it and it workz! */
88     printf("yes");
89 #else   /* PF_PACKET */
90     printf("no");
91 #endif
92     exit (EXIT_SUCCESS);
93 }
94 EOF
95     ${CC-cc} -o pf_packet-test $CFLAGS pf_packet-test.c >/dev/null 2>&1
96
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
100     else
101         ac_libnet_have_pf_packet=`./pf_packet-test`;
102     fi
103
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"
109     fi
110
111     if test $ac_libnet_have_pf_packet != choked; then
112         AC_MSG_RESULT($ac_libnet_have_pf_packet)
113     fi
114     rm -f pf_packet-test* core core.pf_packet-test
115     ;;
116     esac])
117 ])
118
119 dnl
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.
123 dnl
124 dnl usage:
125 dnl
126 dnl     AC_LIBNET_CHECK_LIBNET_VERSION
127 dnl
128 dnl results:
129 dnl
130 dnl
131 dnl
132
133 AC_DEFUN(AC_LIBNET_CHECK_LIBNET_VER,
134 [
135     AC_CHECK_LIB(net, libnet_build_ip, AC_MSG_CHECKING(version) \
136
137 changequote(<<, >>)dnl
138     if [[ ! -f $LIB_PREFIX/libnet.a ]] ; then
139 changequote([, ])dnl
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)
142     else
143         __LIBNET_VERSION=`strings $LIB_PREFIX/libnet.a | grep "libnet version"\
144                 | cut -f3 -d" "`;\
145         if test -z "$__LIBNET_VERSION"; then
146             AC_MSG_RESULT(<0.8)
147         else
148             AC_MSG_RESULT($__LIBNET_VERSION)
149         fi
150     fi\
151     )
152 ])
153
154
155 dnl
156 dnl Checks to see if this linux kernel uses ip_sum or ip_csum
157 dnl (Pulled from queso)
158 dnl
159 dnl usage:
160 dnl
161 dnl     AC_LIBNET_CHECK_IP_CSUM
162 dnl
163 dnl results:
164 dnl
165 dnl     HAVE_STRUCT_IP_CSUM (DEFINED)
166 dnl
167
168 AC_DEFUN(AC_LIBNET_CHECK_IP_CSUM,
169 [
170     AC_MSG_CHECKING([struct ip contains ip_csum])
171     AC_TRY_COMPILE([
172         #define __BSD_SOURCE
173         #define _BSD_SOURCE
174         #include <sys/types.h>
175         #include <netinet/in.h>
176         #include <netinet/in_systm.h>
177         #include <netinet/ip.h>],
178         [
179             struct ip ip;
180             ip.ip_csum = 0;
181         ],
182         [AC_MSG_RESULT(yes);
183         AC_DEFINE(HAVE_STRUCT_IP_CSUM)],
184         [AC_MSG_RESULT(no);
185     ])
186 ])
187
188 dnl
189 dnl Checks to see if unaligned memory accesses fail
190 dnl (Pulled from libpcap)
191 dnl
192 dnl usage:
193 dnl
194 dnl     AC_LBL_UNALIGNED_ACCESS
195 dnl
196 dnl results:
197 dnl
198 dnl     LBL_ALIGN (DEFINED)
199 dnl
200
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
205
206         alpha|hp*|mips|sparc)
207                 ac_cv_lbl_unaligned_fail=yes
208                 ;;
209
210         *)
211                 cat >conftest.c <<EOF
212 #                   include <sys/types.h>
213 #                   include <sys/wait.h>
214 #                   include <stdio.h>
215                     unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
216                     main()
217                     {
218                         unsigned int i;
219                         pid_t pid;
220                         int status;
221                         /* avoid "core dumped" message */
222                         pid = fork();
223                         if (pid <  0)
224                         {
225                             exit(2);
226                         }
227                         if (pid > 0)
228                         {
229                             /* parent */
230                             pid = waitpid(pid, &status, 0);
231                             if (pid < 0)
232                             {
233                                 exit(3);
234                             }
235                             exit(!WIFEXITED(status));
236                         }
237                         /* child */
238                         i = *(unsigned int *)&a[[1]];
239                         printf("%d\n", i);
240                         exit(0);
241                     }
242 EOF
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
249                 else
250                         ./conftest > conftest.out
251                         if test ! -s conftest.out ; then
252                                 ac_cv_lbl_unaligned_fail=yes
253                         else
254                                 ac_cv_lbl_unaligned_fail=no
255                         fi
256                 fi
257                 rm -f conftest* core core.conftest
258                 ;;
259         esac])
260     AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
261     if test $ac_cv_lbl_unaligned_fail = yes ; then
262             AC_DEFINE(LBL_ALIGN)
263     fi
264 ])
265
266
267 dnl
268 dnl Checks endianess
269 dnl
270 dnl usage:
271 dnl
272 dnl     AC_LIBNET_ENDIAN_CHECK
273 dnl
274 dnl results:
275 dnl
276 dnl     LIBNET_BIG_ENDIAN = 1   or
277 dnl     LIBNET_LIL_ENDIAN = 1
278 dnl
279
280 AC_DEFUN(AC_LIBNET_ENDIAN_CHECK,
281     [AC_MSG_CHECKING(machine endianess)
282
283     cat > conftest.c << EOF
284 #       include <stdio.h>
285 #       include <stdlib.h>
286
287         int main()
288         {
289             union
290             {
291                 short s;
292                 char c[[sizeof(short)]];
293             } un;
294
295             un.s = 0x0102;
296             if (sizeof (short) == 2)
297             {
298                 if (un.c [[0]] == 1 && un.c [[1]] == 2)
299                 {
300                     printf("B\n");
301                 }
302                 else
303                 {
304                     if (un.c [[0]] == 2 && un.c [[1]] == 1)
305                     {
306                         printf("L\n");
307                     }
308                 }
309             }
310             else
311             {
312                 printf("?\n");
313             }
314             return (EXIT_SUCCESS);
315         }
316 EOF
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
322         else
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
329             else
330                 ac_cv_libnet_endianess=unknown
331             fi                                
332         fi
333         rm -f conftest* core core.conftest
334
335         AC_MSG_RESULT($ac_cv_libnet_endianess)
336
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"
343         fi
344     ])