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