ISC DHCP  4.4.3-P1
A reference DHCPv4 and DHCPv6 implementation
osdep.h
Go to the documentation of this file.
1 /* osdep.h
2 
3  Operating system dependencies... */
4 
5 /*
6  * Copyright (C) 2004-2022 Internet Systems Consortium,Inc. ("ISC")
7  * Copyright (c) 1996-2003 by Internet Software Consortium
8  *
9  * This Source Code Form is subject to the terms of the Mozilla Public
10  * License, v. 2.0. If a copy of the MPL was not distributed with this
11  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  *
21  * Internet Systems Consortium, Inc.
22  * PO Box 360
23  * Newmarket, NH 03857 USA
24  * <info@isc.org>
25  * https://www.isc.org/
26  *
27  */
28 
29 #if !defined (__ISC_DHCP_OSDEP_H__)
30 #define __ISC_DHCP_OSDEP_H__
31 
32 #include "site.h"
33 
34 #include "config.h"
35 
36 #include <inttypes.h>
37 
38 #ifndef LITTLE_ENDIAN
39 #define LITTLE_ENDIAN 1234
40 #endif /* LITTLE_ENDIAN */
41 
42 #ifndef BIG_ENDIAN
43 #define BIG_ENDIAN 4321
44 #endif /* BIG_ENDIAN */
45 
46 #ifndef BYTE_ORDER
47 #define BYTE_ORDER DHCP_BYTE_ORDER
48 #endif /* BYTE_ORDER */
49 
50 /* Porting::
51 
52  If you add a new network API, you must add a check for it below: */
53 
54 #if !defined (USE_SOCKETS) && \
55  !defined (USE_SOCKET_SEND) && \
56  !defined (USE_SOCKET_RECEIVE) && \
57  !defined (USE_RAW_SOCKETS) && \
58  !defined (USE_RAW_SEND) && \
59  !defined (USE_SOCKET_RECEIVE) && \
60  !defined (USE_BPF) && \
61  !defined (USE_BPF_SEND) && \
62  !defined (USE_BPF_RECEIVE) && \
63  !defined (USE_LPF) && \
64  !defined (USE_LPF_SEND) && \
65  !defined (USE_LPF_RECEIVE) && \
66  !defined (USE_NIT) && \
67  !defined (USE_NIT_SEND) && \
68  !defined (USE_NIT_RECEIVE) && \
69  !defined (USE_DLPI_SEND) && \
70  !defined (USE_DLPI_RECEIVE)
71 /* Determine default socket API to USE. */
72 # if defined(HAVE_BPF)
73 # define USE_BPF 1
74 # elif defined(HAVE_LPF)
75 # define USE_LPF 1
76 # elif defined(HAVE_DLPI)
77 # define USE_DLPI 1
78 # endif
79 #endif
80 
81 #if !defined (TIME_MAX)
82 # define TIME_MAX 2147483647
83 #endif
84 
85 /* snprintf/vsnprintf hacks. for systems with no libc versions only. */
86 #ifdef NO_SNPRINTF
87  extern int isc_print_snprintf(char *, size_t, const char *, ...);
88  extern int isc_print_vsnprintf(char *, size_t, const char *, va_list ap);
89 # define snprintf isc_print_snprintf
90 # define vsnprintf isc_print_vsnprintf
91 #endif
92 
93 /* Porting::
94 
95  If you add a new network API, and have it set up so that it can be
96  used for sending or receiving, but doesn't have to be used for both,
97  then set up an ifdef like the ones below: */
98 
99 #ifdef USE_SOCKETS
100 # define USE_SOCKET_SEND
101 # define USE_SOCKET_RECEIVE
102 # if defined(HAVE_DLPI) && !defined(sun) && !defined(USE_V4_PKTINFO)
103 # define USE_DLPI_HWADDR
104 # elif defined(HAVE_LPF)
105 # define USE_LPF_HWADDR
106 # elif defined(HAVE_BPF)
107 # define USE_BPF_HWADDR
108 # endif
109 #endif
110 
111 #ifdef USE_RAW_SOCKETS
112 # define USE_RAW_SEND
113 # define USE_SOCKET_RECEIVE
114 #endif
115 
116 #ifdef USE_BPF
117 # define USE_BPF_SEND
118 # define USE_BPF_RECEIVE
119 #endif
120 
121 #ifdef USE_LPF
122 # define USE_LPF_SEND
123 # define USE_LPF_RECEIVE
124 #endif
125 
126 #ifdef USE_NIT
127 # define USE_NIT_SEND
128 # define USE_NIT_RECEIVE
129 #endif
130 
131 #ifdef USE_DLPI
132 # define USE_DLPI_SEND
133 # define USE_DLPI_RECEIVE
134 #endif
135 
136 #ifdef USE_UPF
137 # define USE_UPF_SEND
138 # define USE_UPF_RECEIVE
139 #endif
140 
141 #if defined (SO_BINDTODEVICE) && !defined (HAVE_SO_BINDTODEVICE)
142 # define HAVE_SO_BINDTODEVICE
143 #endif
144 
145 /* Porting::
146 
147  If you add support for sending packets directly out an interface,
148  and your support does not do ARP or routing, you must use a fallback
149  mechanism to deal with packets that need to be sent to routers.
150  Currently, all low-level packet interfaces use BSD sockets as a
151  fallback. */
152 
153 #if defined (USE_BPF_SEND) || defined (USE_NIT_SEND) || \
154  defined (USE_DLPI_SEND) || defined (USE_UPF_SEND) || \
155  defined (USE_LPF_SEND) || \
156  (defined (USE_SOCKET_SEND) && defined (HAVE_SO_BINDTODEVICE))
157 # define USE_SOCKET_FALLBACK
158 # define USE_FALLBACK
159 #endif
160 
161 /* Porting::
162 
163  If you add support for sending packets directly out an interface
164  and need to be able to assemble packets, add the USE_XXX_SEND
165  definition for your interface to the list tested below. */
166 
167 #if defined (USE_RAW_SEND) || defined (USE_BPF_SEND) || \
168  defined (USE_NIT_SEND) || defined (USE_UPF_SEND) || \
169  defined (USE_DLPI_SEND) || defined (USE_LPF_SEND)
170 # define PACKET_ASSEMBLY
171 #endif
172 
173 /* Porting::
174 
175  If you add support for receiving packets directly from an interface
176  and need to be able to decode raw packets, add the USE_XXX_RECEIVE
177  definition for your interface to the list tested below. */
178 
179 #if defined (USE_RAW_RECEIVE) || defined (USE_BPF_SEND) || \
180  defined (USE_NIT_RECEIVE) || defined (USE_UPF_RECEIVE) || \
181  defined (USE_DLPI_RECEIVE) || defined (USE_LPF_RECEIVE)
182 # define PACKET_DECODING
183 #endif
184 
185 /* If we don't have a DLPI packet filter, we have to filter in userland.
186  Probably not worth doing, actually. */
187 #if defined (USE_DLPI_RECEIVE) && !defined (USE_DLPI_PFMOD)
188 # define USERLAND_FILTER
189 #endif
190 
191 /* jmp_buf is assumed to be a struct unless otherwise defined in the
192  system header. */
193 #ifndef jbp_decl
194 # define jbp_decl(x) jmp_buf *x
195 #endif
196 #ifndef jref
197 # define jref(x) (&(x))
198 #endif
199 #ifndef jdref
200 # define jdref(x) (*(x))
201 #endif
202 #ifndef jrefproto
203 # define jrefproto jmp_buf *
204 #endif
205 
206 #ifndef BPF_FORMAT
207 # define BPF_FORMAT "/dev/bpf%d"
208 #endif
209 
210 #if defined (F_SETFD) && !defined (HAVE_SETFD)
211 # define HAVE_SETFD
212 #endif
213 
214 #if defined (IFF_POINTOPOINT) && !defined (HAVE_IFF_POINTOPOINT)
215 # define HAVE_IFF_POINTOPOINT
216 #endif
217 
218 #if defined (AF_LINK) && !defined (HAVE_AF_LINK)
219 # define HAVE_AF_LINK
220 #endif
221 
222 #if defined (ARPHRD_TUNNEL) && !defined (HAVE_ARPHRD_TUNNEL)
223 # define HAVE_ARPHRD_TUNNEL
224 #endif
225 
226 #if defined (ARPHRD_LOOPBACK) && !defined (HAVE_ARPHRD_LOOPBACK)
227 # define HAVE_ARPHRD_LOOPBACK
228 #endif
229 
230 #if defined (ARPHRD_ROSE) && !defined (HAVE_ARPHRD_ROSE)
231 # define HAVE_ARPHRD_ROSE
232 #endif
233 
234 #if defined (ARPHRD_IRDA) && !defined (HAVE_ARPHRD_IRDA)
235 # define HAVE_ARPHRD_IRDA
236 #endif
237 
238 #if defined (ARPHRD_SIT) && !defined (HAVE_ARPHRD_SIT)
239 # define HAVE_ARPHRD_SIT
240 #endif
241 
242 #if defined (ARPHRD_IEEE1394) & !defined (HAVE_ARPHRD_IEEE1394)
243 # define HAVE_ARPHRD_IEEE1394
244 #endif
245 
246 #if defined (ARPHRD_IEEE802) && !defined (HAVE_ARPHRD_IEEE802)
247 # define HAVE_ARPHRD_IEEE802
248 #endif
249 
250 #if defined (ARPHRD_IEEE802_TR) && !defined (HAVE_ARPHRD_IEEE802_TR)
251 # define HAVE_ARPHRD_IEEE802_TR
252 #endif
253 
254 #if defined (ARPHRD_FDDI) && !defined (HAVE_ARPHRD_FDDI)
255 # define HAVE_ARPHRD_FDDI
256 #endif
257 
258 #if defined (ARPHRD_AX25) && !defined (HAVE_ARPHRD_AX25)
259 # define HAVE_ARPHRD_AX25
260 #endif
261 
262 #if defined (ARPHRD_NETROM) && !defined (HAVE_ARPHRD_NETROM)
263 # define HAVE_ARPHRD_NETROM
264 #endif
265 
266 #if defined (ARPHRD_METRICOM) && !defined (HAVE_ARPHRD_METRICOM)
267 # define HAVE_ARPHRD_METRICOM
268 #endif
269 
270 #if defined (AF_LINK) && !defined (HAVE_AF_LINK)
271 # define HAVE_AF_LINK
272 #endif
273 
274 /* Linux needs to define SHUT_* in /usr/include/sys/socket.h someday... */
275 #if !defined (SHUT_RD)
276 # define SHUT_RD 0
277 #endif
278 
279 #if !defined (SOCKLEN_T)
280 # define SOCKLEN_T socklen_t
281 #elif defined(_AIX)
282 #undef SOCKLEN_T
283 #define SOCKLEN_T socklen_t
284 #endif
285 
286 #if !defined (STDERR_FILENO)
287 # define STDERR_FILENO 2
288 #endif
289 
290 #endif /* __ISC_DHCP_OSDEP_H__ */