c50d32e2139655e9ba8563fab0888f75a8c0f1d8
[openwrt/openwrt.git] / tools / missing-macros / src / m4 / dnet.m4
1 dnl
2 dnl Check for 4.4 BSD sa_len member in sockaddr struct
3 dnl
4 dnl usage: AC_DNET_SOCKADDR_SA_LEN
5 dnl results: HAVE_SOCKADDR_SA_LEN (defined)
6 dnl
7 AC_DEFUN([AC_DNET_SOCKADDR_SA_LEN],
8 [AC_MSG_CHECKING(for sa_len in sockaddr struct)
9 AC_CACHE_VAL(ac_cv_dnet_sockaddr_has_sa_len,
10 AC_TRY_COMPILE([
11 # ifndef _SOCKADDR_LEN
12 # define _SOCKADDR_LEN 1
13 # endif
14 # include <sys/types.h>
15 # include <sys/socket.h>],
16 [u_int i = sizeof(((struct sockaddr *)0)->sa_len)],
17 ac_cv_dnet_sockaddr_has_sa_len=yes,
18 ac_cv_dnet_sockaddr_has_sa_len=no))
19 AC_MSG_RESULT($ac_cv_dnet_sockaddr_has_sa_len)
20 if test $ac_cv_dnet_sockaddr_has_sa_len = yes ; then
21 AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1,
22 [Define if sockaddr struct has sa_len.])
23 fi])
24
25 dnl
26 dnl Check for sockaddr_in6 struct in <netinet/in.h>
27 dnl
28 dnl usage: AC_DNET_SOCKADDR_IN6
29 dnl results: HAVE_SOCKADDR_IN6
30 dnl
31 AC_DEFUN([AC_DNET_SOCKADDR_IN6],
32 [AC_MSG_CHECKING(for sockaddr_in6 struct in <netinet/in.h>)
33 AC_CACHE_VAL(ac_cv_dnet_netinet_in_h_has_sockaddr_in6,
34 AC_TRY_COMPILE([
35 # include <sys/types.h>
36 # include <sys/socket.h>
37 # include <netinet/in.h>],
38 [struct sockaddr_in6 sin6; sin6.sin6_family = AF_INET6;],
39 ac_cv_dnet_netinet_in_h_has_sockaddr_in6=yes,
40 ac_cv_dnet_netinet_in_h_has_sockaddr_in6=no))
41 AC_MSG_RESULT($ac_cv_dnet_netinet_in_h_has_sockaddr_in6)
42 if test $ac_cv_dnet_netinet_in_h_has_sockaddr_in6 = yes ; then
43 AC_DEFINE(HAVE_SOCKADDR_IN6, 1,
44 [Define if <netinet/in.h> has sockaddr_in6 struct.])
45 fi])
46
47 dnl
48 dnl Check for arp_dev member in arpreq struct
49 dnl
50 dnl usage: AC_DNET_ARPREQ_ARP_DEV
51 dnl results: HAVE_ARPREQ_ARP_DEV (defined)
52 dnl
53 AC_DEFUN([AC_DNET_ARPREQ_ARP_DEV],
54 [AC_MSG_CHECKING(for arp_dev in arpreq struct)
55 AC_CACHE_VAL(ac_cv_dnet_arpreq_has_arp_dev,
56 AC_TRY_COMPILE([
57 # include <sys/types.h>
58 # include <sys/socket.h>
59 # include <net/if_arp.h>],
60 [void *p = ((struct arpreq *)0)->arp_dev],
61 ac_cv_dnet_arpreq_has_arp_dev=yes,
62 ac_cv_dnet_arpreq_has_arp_dev=no))
63 AC_MSG_RESULT($ac_cv_dnet_arpreq_has_arp_dev)
64 if test $ac_cv_dnet_arpreq_has_arp_dev = yes ; then
65 AC_DEFINE(HAVE_ARPREQ_ARP_DEV, 1,
66 [Define if arpreq struct has arp_dev.])
67 fi])
68
69 dnl
70 dnl Check for rt_msghdr struct in <net/route.h>
71 dnl
72 dnl usage: AC_DNET_ROUTE_RT_MSGHDR
73 dnl results: HAVE_ROUTE_RT_MSGHDR
74 dnl
75 AC_DEFUN([AC_DNET_ROUTE_RT_MSGHDR],
76 [AC_MSG_CHECKING(for rt_msghdr struct in <net/route.h>)
77 AC_CACHE_VAL(ac_cv_dnet_route_h_has_rt_msghdr,
78 AC_TRY_COMPILE([
79 # include <sys/types.h>
80 # include <sys/socket.h>
81 # include <net/if.h>
82 # include <net/route.h>],
83 [struct rt_msghdr rtm; rtm.rtm_msglen = 0;],
84 ac_cv_dnet_route_h_has_rt_msghdr=yes,
85 ac_cv_dnet_route_h_has_rt_msghdr=no))
86 AC_MSG_RESULT($ac_cv_dnet_route_h_has_rt_msghdr)
87 if test $ac_cv_dnet_route_h_has_rt_msghdr = yes ; then
88 AC_DEFINE(HAVE_ROUTE_RT_MSGHDR, 1,
89 [Define if <net/route.h> has rt_msghdr struct.])
90 fi])
91
92 dnl
93 dnl Check for the Berkeley Packet Filter
94 dnl
95 dnl usage: AC_DNET_BSD_BPF
96 dnl results: HAVE_BSD_BPF
97 dnl
98 AC_DEFUN([AC_DNET_BSD_BPF],
99 [AC_MSG_CHECKING(for Berkeley Packet Filter)
100 AC_CACHE_VAL(ac_cv_dnet_bsd_bpf,
101 if test -c /dev/bpf0 ; then
102 ac_cv_dnet_bsd_bpf=yes
103 else
104 ac_cv_dnet_bsd_bpf=no
105 fi)
106 AC_MSG_RESULT($ac_cv_dnet_bsd_bpf)
107 if test $ac_cv_dnet_bsd_bpf = yes ; then
108 AC_DEFINE(HAVE_BSD_BPF, 1,
109 [Define if you have the Berkeley Packet Filter.])
110 fi])
111
112 dnl
113 dnl Check for the Linux /proc filesystem
114 dnl
115 dnl usage: AC_DNET_LINUX_PROCFS
116 dnl results: HAVE_LINUX_PROCFS
117 dnl
118 AC_DEFUN([AC_DNET_LINUX_PROCFS],
119 [AC_MSG_CHECKING(for Linux proc filesystem)
120 AC_CACHE_VAL(ac_cv_dnet_linux_procfs,
121 if test "x`cat /proc/sys/kernel/ostype 2>&-`" = "xLinux" ; then
122 ac_cv_dnet_linux_procfs=yes
123 else
124 ac_cv_dnet_linux_procfs=no
125 fi)
126 AC_MSG_RESULT($ac_cv_dnet_linux_procfs)
127 if test $ac_cv_dnet_linux_procfs = yes ; then
128 AC_DEFINE(HAVE_LINUX_PROCFS, 1,
129 [Define if you have the Linux /proc filesystem.])
130 fi])
131
132 dnl
133 dnl Check for Linux PF_PACKET sockets
134 dnl
135 dnl usage: AC_DNET_LINUX_PF_PACKET
136 dnl results: HAVE_LINUX_PF_PACKET
137 dnl
138 AC_DEFUN([AC_DNET_LINUX_PF_PACKET],
139 [AC_MSG_CHECKING(for Linux PF_PACKET sockets)
140 AC_CACHE_VAL(ac_cv_dnet_linux_pf_packet,
141 if test -f /usr/include/netpacket/packet.h ; then
142 ac_cv_dnet_linux_pf_packet=yes
143 else
144 ac_cv_dnet_linux_pf_packet=no
145 fi)
146 AC_MSG_RESULT($ac_cv_dnet_linux_pf_packet)
147 if test $ac_cv_dnet_linux_pf_packet = yes ; then
148 AC_DEFINE(HAVE_LINUX_PF_PACKET, 1,
149 [Define if you have Linux PF_PACKET sockets.])
150 fi])
151
152 dnl
153 dnl Check for SNMP MIB2 STREAMS (Solaris only?)
154 dnl
155 dnl usage: AC_DNET_STREAMS_MIB2
156 dnl results: HAVE_STREAMS_MIB2
157 dnl
158 AC_DEFUN([AC_DNET_STREAMS_MIB2],
159 [AC_MSG_CHECKING(for SNMP MIB2 STREAMS)
160 AC_CACHE_VAL(ac_cv_dnet_streams_mib2,
161 if test -f /usr/include/inet/mib2.h -a -c /dev/ip ; then
162 ac_cv_dnet_streams_mib2=yes
163 else
164 ac_cv_dnet_streams_mib2=no
165 fi)
166 AC_MSG_RESULT($ac_cv_dnet_streams_mib2)
167 if test $ac_cv_dnet_streams_mib2 = yes ; then
168 AC_DEFINE(HAVE_STREAMS_MIB2, 1,
169 [Define if you have SNMP MIB2 STREAMS.])
170 fi])
171
172 dnl
173 dnl Check for route(7) STREAMS (UnixWare only?)
174 dnl
175 dnl usage: AC_DNET_STREAMS_ROUTE
176 dnl results: HAVE_STREAMS_ROUTE
177 dnl
178 AC_DEFUN([AC_DNET_STREAMS_ROUTE],
179 [AC_MSG_CHECKING(for route(7) STREAMS)
180 AC_CACHE_VAL(ac_cv_dnet_streams_route,
181 if grep RTSTR_SEND /usr/include/net/route.h >/dev/null 2>&1 ; then
182 ac_cv_dnet_streams_route=yes
183 else
184 ac_cv_dnet_streams_route=no
185 fi)
186 AC_MSG_RESULT($ac_cv_dnet_streams_route)
187 if test $ac_cv_dnet_streams_route = yes ; then
188 AC_DEFINE(HAVE_STREAMS_ROUTE, 1,
189 [Define if you have route(7) STREAMS.])
190 fi])
191
192 dnl
193 dnl Check for arp(7) ioctls
194 dnl
195 dnl usage: AC_DNET_IOCTL_ARP
196 dnl results: HAVE_IOCTL_ARP
197 dnl
198 AC_DEFUN([AC_DNET_IOCTL_ARP],
199 [AC_MSG_CHECKING(for arp(7) ioctls)
200 AC_CACHE_VAL(ac_cv_dnet_ioctl_arp,
201 AC_EGREP_CPP(werd, [
202 # include <sys/types.h>
203 # define BSD_COMP
204 # include <sys/ioctl.h>
205 # ifdef SIOCGARP
206 werd
207 # endif],
208 ac_cv_dnet_ioctl_arp=yes,
209 ac_cv_dnet_ioctl_arp=no))
210 case "$host_os" in
211 irix*)
212 ac_cv_dnet_ioctl_arp=no ;;
213 esac
214 AC_MSG_RESULT($ac_cv_dnet_ioctl_arp)
215 if test $ac_cv_dnet_ioctl_arp = yes ; then
216 AC_DEFINE(HAVE_IOCTL_ARP, 1,
217 [Define if you have arp(7) ioctls.])
218 fi])
219
220 dnl
221 dnl Check for raw IP sockets ip_{len,off} host byte ordering
222 dnl
223 dnl usage: AC_DNET_RAWIP_HOST_OFFLEN
224 dnl results: HAVE_RAWIP_HOST_OFFLEN
225 dnl
226 AC_DEFUN([AC_DNET_RAWIP_HOST_OFFLEN],
227 [AC_MSG_CHECKING([for raw IP sockets ip_{len,off} host byte ordering])
228 AC_CACHE_VAL(ac_cv_dnet_rawip_host_offlen, [
229 case "$host_os" in
230 *openbsd*)
231 ac_cv_dnet_rawip_host_offlen=no ;;
232 *bsd*|*osf*|*unixware*)
233 ac_cv_dnet_rawip_host_offlen=yes ;;
234 *)
235 ac_cv_dnet_rawip_host_offlen=no ;;
236 esac])
237 AC_MSG_RESULT($ac_cv_dnet_rawip_host_offlen)
238 if test $ac_cv_dnet_rawip_host_offlen = yes ; then
239 AC_DEFINE(HAVE_RAWIP_HOST_OFFLEN, 1,
240 [Define if raw IP sockets require host byte ordering for ip_off, ip_len.])
241 fi])
242
243 dnl
244 dnl Check for cooked raw IP sockets
245 dnl
246 dnl usage: AC_DNET_RAWIP_COOKED
247 dnl results: HAVE_RAWIP_COOKED
248 dnl
249 AC_DEFUN([AC_DNET_RAWIP_COOKED],
250 [AC_MSG_CHECKING(for cooked raw IP sockets)
251 AC_CACHE_VAL(ac_cv_dnet_rawip_cooked, [
252 case "$host_os" in
253 solaris*|irix*)
254 ac_cv_dnet_rawip_cooked=yes ;;
255 *)
256 ac_cv_dnet_rawip_cooked=no ;;
257 esac])
258 AC_MSG_RESULT($ac_cv_dnet_rawip_cooked)
259 if test $ac_cv_dnet_rawip_cooked = yes ; then
260 AC_DEFINE(HAVE_RAWIP_COOKED, 1,
261 [Define if you have cooked raw IP sockets.])
262 fi])
263
264 dnl
265 dnl AC_LBL_LIBRARY_NET
266 dnl
267 dnl This test is for network applications that need socket() and
268 dnl gethostbyname() -ish functions. Under Solaris, those applications
269 dnl need to link with "-lsocket -lnsl". Under IRIX, they need to link
270 dnl with "-lnsl" but should *not* link with "-lsocket" because
271 dnl libsocket.a breaks a number of things (for instance:
272 dnl gethostbyname() under IRIX 5.2, and snoop sockets under most
273 dnl versions of IRIX).
274 dnl
275 dnl Unfortunately, many application developers are not aware of this,
276 dnl and mistakenly write tests that cause -lsocket to be used under
277 dnl IRIX. It is also easy to write tests that cause -lnsl to be used
278 dnl under operating systems where neither are necessary (or useful),
279 dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
280 dnl
281 dnl This test exists so that every application developer does not test
282 dnl this in a different, and subtly broken fashion.
283
284 dnl It has been argued that this test should be broken up into two
285 dnl seperate tests, one for the resolver libraries, and one for the
286 dnl libraries necessary for using Sockets API. Unfortunately, the two
287 dnl are carefully intertwined and allowing the autoconf user to use
288 dnl them independantly potentially results in unfortunate ordering
289 dnl dependancies -- as such, such component macros would have to
290 dnl carefully use indirection and be aware if the other components were
291 dnl executed. Since other autoconf macros do not go to this trouble,
292 dnl and almost no applications use sockets without the resolver, this
293 dnl complexity has not been implemented.
294 dnl
295 dnl The check for libresolv is in case you are attempting to link
296 dnl statically and happen to have a libresolv.a lying around (and no
297 dnl libnsl.a).
298 dnl
299 AC_DEFUN([AC_LBL_LIBRARY_NET], [
300 # Most operating systems have gethostbyname() in the default searched
301 # libraries (i.e. libc):
302 AC_CHECK_FUNC(gethostbyname, ,
303 # Some OSes (eg. Solaris) place it in libnsl:
304 AC_CHECK_LIB(nsl, gethostbyname, ,
305 # Some strange OSes (SINIX) have it in libsocket:
306 AC_CHECK_LIB(socket, gethostbyname, ,
307 # Unfortunately libsocket sometimes depends on libnsl.
308 # AC_CHECK_LIB's API is essentially broken so the
309 # following ugliness is necessary:
310 AC_CHECK_LIB(socket, gethostbyname,
311 LIBS="-lsocket -lnsl $LIBS",
312 AC_CHECK_LIB(resolv, gethostbyname),
313 -lnsl))))
314 AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
315 AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", ,
316 -lnsl)))
317 # DLPI needs putmsg under HPUX so test for -lstr while we're at it
318 AC_CHECK_LIB(str, putmsg)
319 ])
320