tftpd: allow IPv4/6-specific remapping rules
[tftp-hpa.git] / config.h
blobb22d540afa3a1c22aaebdad166f1de381b7e1b4f
1 /* -*- c -*- ------------------------------------------------------------- *
3 * Copyright 2001-2006 H. Peter Anvin - All Rights Reserved
5 * This program is free software available under the same license
6 * as the "OpenBSD" operating system, distributed at
7 * http://www.openbsd.org/.
9 * ----------------------------------------------------------------------- */
12 * config.h
14 * Sets up a common baseline environment, based on "autoconf" findings...
17 #ifndef CONFIG_H
18 #define CONFIG_H 1
20 /* Feature enables for specific environments */
21 #ifdef __APPLE__
22 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1070
23 #define __APPLE_USE_RFC_3542 1
24 #endif
25 #endif
27 /* Must be included before we include any system headers! */
28 #include "aconfig.h" /* autogenerated configuration header */
30 /* Standard includes */
32 #include <stdio.h>
34 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
36 #endif
38 #ifdef HAVE_SYS_STAT_H
39 #include <sys/stat.h>
40 #endif
42 #ifdef STDC_HEADERS
43 #include <stdlib.h>
44 #include <stddef.h>
45 #else
46 #ifdef HAVE_STDLIB_H
47 #include <stdlib.h>
48 #endif
49 #endif
51 #ifdef HAVE_MEMORY_H
52 #ifndef STDC_HEADERS
53 #include <memory.h>
54 #endif
55 #endif
57 #ifdef HAVE_STRING_H
58 #include <string.h>
59 #endif
61 #ifdef HAVE_STRINGS_H
62 #include <strings.h>
63 #endif
65 #ifdef HAVE_INTTYPES_H
66 #ifdef INTTYPES_H_IS_SANE
67 #include <inttypes.h>
68 #endif
69 #else
70 #ifdef HAVE_STDINT_H
71 #include <stdint.h>
72 #endif
73 #endif
75 #ifdef HAVE_UNISTD_H
76 #include <unistd.h>
77 #endif
79 #ifdef HAVE_SETJMP_H
80 #include <setjmp.h>
81 #endif
83 #ifdef TIME_WITH_SYS_TIME
84 #include <sys/time.h>
85 #include <time.h>
86 #else
87 #if HAVE_SYS_TIME_H
88 #include <sys/time.h>
89 #else
90 #include <time.h>
91 #endif
92 #endif
94 #ifdef HAVE_GRP_H
95 #include <grp.h>
96 #endif
98 #ifdef HAVE_FCNTL_H
99 #include <fcntl.h>
100 #endif
102 #include <errno.h>
103 #include <signal.h>
105 #ifdef HAVE_SYS_SOCKET_H
106 #include <sys/socket.h>
107 #else
108 #ifdef HAVE_WINSOCK2_H
109 #include <winsock2.h>
110 #else
111 #ifdef HAVE_WINSOCK_H
112 #include <winsock.h>
113 #endif
114 #endif
115 #endif
116 #ifdef HAVE_NETDB_H
117 #include <netdb.h>
118 #endif
120 #ifdef HAVE_GETOPT_LONG
121 #include <getopt.h>
122 #else
123 #include "lib/getopt.h"
124 #endif
126 /* Test for EAGAIN/EWOULDBLOCK */
127 #ifdef EAGAIN
128 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
129 #define E_WOULD_BLOCK(x) ((x) == EAGAIN || (x) == EWOULDBLOCK)
130 #else
131 #define E_WOULD_BLOCK(x) ((x) == EAGAIN)
132 #endif
133 #else
134 #define E_WOULD_BLOCK(x) ((x) == EWOULDBLOCK)
135 #endif
137 /* Some broken systems care about text versus binary, but
138 real Unix systems don't... */
139 #ifndef HAVE_O_TEXT_DEFINITION
140 #define O_TEXT 0
141 #endif
142 #ifndef HAVE_O_BINARY_DEFINITION
143 #define O_BINARY 0
144 #endif
146 /* If we don't have intmax_t, try creating it */
148 #ifndef HAVE_INTMAX_T
149 #ifdef HAVE_LONG_LONG
150 typedef long long intmax_t;
151 typedef unsigned long long uintmax_t;
152 #define PRIdMAX "lld"
153 #define PRIuMAX "llu"
154 #define PRIxMAX "llx"
155 #define INTMAX_C(x) (x##LL)
156 #define UINTMAX_C(x) (x##ULL)
157 #else
158 typedef long intmax_t;
159 typedef unsigned long uintmax_t;
160 #define PRIdMAX "ld"
161 #define PRIuMAX "lu"
162 #define PRIxMAX "lx"
163 #define INTMAX_C(x) (x##L)
164 #define UINTMAX_C(x) (x##UL)
165 #endif
166 #endif
168 /* On some version of AIX, <inttypes.h> is buggy to the point of
169 unusability. We have to use macros here, not typedefs, to override. */
170 #ifdef HAVE_INTTYPES_H
171 #ifndef INTTYPES_H_IS_SANE
172 #undef PRIdMAX
173 #undef PRIuMAX
174 #undef PRIxMAX
175 #undef INTMAX_C
176 #undef UINTMAX_C
177 #undef HAVE_STRTOUMAX
179 #ifdef HAVE_LONG_LONG
180 #define intmax_t long long
181 #define uintmax_t unsigned long long
182 #define PRIdMAX "Ld"
183 #define PRIuMAX "Lu"
184 #define PRIxMAX "Lx"
185 #define INTMAX_C(x) (x##LL)
186 #define UINTMAX_C(x) (x##ULL)
187 #else
188 #define intmax_t long
189 #define uintmax_t unsigned long
190 #define PRIdMAX "ld"
191 #define PRIuMAX "lu"
192 #define PRIxMAX "lx"
193 #define INTMAX_C(x) (x##L)
194 #define UINTMAX_C(x) (x##UL)
195 #endif
196 #endif
197 #endif
199 /* Even if intmax_t is defined, we may need this (Solaris 8 braindamage) */
200 #ifndef HAVE_STRTOUMAX
201 #if defined(HAVE_LONG_LONG) && defined(HAVE_STRTOULL)
202 #define strtoumax(p,e,b) ((uintmax_t)strtoull(p,e,b))
203 #else
204 #define strtoumax(p,e,b) ((uintmax_t)strtoul(p,e,b))
205 #endif
206 #endif
208 /* A lot of this is old BSD code. Some newer systems don't approve. */
210 /* The type used by htons(), ntohs() */
211 #ifndef HAVE_U_SHORT
212 #ifdef HAVE_UINT16_T
213 typedef uint16_t u_short;
214 #else
215 typedef unsigned short u_short;
216 #endif
217 #endif
219 /* The type used to htonl(), ntohl() */
220 #ifndef HAVE_U_LONG
221 #ifdef HAVE_UINT32_T
222 typedef uint32_t u_long;
223 #else
224 typedef unsigned long u_long;
225 #endif
226 #endif
228 /* socklen_t */
229 #ifndef HAVE_SOCKLEN_T
230 typedef int socklen_t;
231 #endif
233 /* sysexits.h */
235 #ifdef HAVE_SYSEXITS_H
236 #include <sysexits.h>
237 #else
238 #define EX_USAGE 64 /* command line usage error */
239 #define EX_DATAERR 65 /* data format error */
240 #define EX_NOINPUT 66 /* cannot open input */
241 #define EX_NOUSER 67 /* addressee unknown */
242 #define EX_NOHOST 68 /* host name unknown */
243 #define EX_UNAVAILABLE 69 /* service unavailable */
244 #define EX_SOFTWARE 70 /* internal software error */
245 #define EX_OSERR 71 /* system error (e.g., can't fork) */
246 #define EX_OSFILE 72 /* critical OS file missing */
247 #define EX_CANTCREAT 73 /* can't create (user) output file */
248 #define EX_IOERR 74 /* input/output error */
249 #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
250 #define EX_PROTOCOL 76 /* remote error in protocol */
251 #define EX_NOPERM 77 /* permission denied */
252 #define EX_CONFIG 78 /* configuration error */
253 #endif
255 /* If we don't have sigsetjmp() et all, setjmp() will have to do */
257 #ifndef HAVE_SIGSETJMP
258 #define sigsetjmp(x,y) setjmp(x)
259 #define siglongjmp(x,y) longjmp(x,y)
260 #define sigjmp_buf jmp_buf
261 #endif
263 /* How do we annotate unused data items? */
265 #ifndef UNUSED
266 #ifdef __GNUC__
267 #define UNUSED __attribute__((unused))
268 #else
269 #define UNUSED
270 #endif
271 #endif
273 /* netinet/in.h, and possible missing pieces */
275 #include <netinet/in.h>
277 #ifndef HAVE_IPPORT_TFTP_DEFINITION
278 #ifndef IPPORT_TFTP
279 #define IPPORT_TFTP 69
280 #endif
281 #endif
283 /* arpa/{inet,tftp}.h, and possible missing pieces */
285 #ifdef HAVE_ARPA_INET_H
286 #include <arpa/inet.h>
287 #endif
288 /* If we don't have arpa/tftp.h we have problems... */
289 #include <arpa/tftp.h>
291 #ifndef OACK
292 #define OACK 6
293 #endif
294 #ifndef EOPTNEG
295 #define EOPTNEG 8
296 #endif
298 /* Prototypes for libxtra functions */
300 void *xmalloc(size_t);
301 char *xstrdup(const char *);
303 #ifndef HAVE_BSD_SIGNAL
304 void (*bsd_signal(int, void (*)(int))) (int);
305 #endif
306 #ifndef HAVE_DUP2
307 int dup2(int, int);
308 #endif
309 #ifndef HAVE_DAEMON
310 int daemon(int, int);
311 #endif
313 #ifndef HAVE_GETADDRINFO
314 #ifndef HAVE_STRUCT_ADDRINFO
315 struct addrinfo {
316 int ai_flags;
317 int ai_family;
318 int ai_socktype;
319 int ai_protocol;
320 size_t ai_addrlen;
321 struct sockaddr *ai_addr;
322 char *ai_canonname;
323 struct addrinfo *ai_next;
325 #endif
326 int getaddrinfo(const char *, const char *, const struct addrinfo *,
327 struct addrinfo **);
328 void freeaddrinfo(struct addrinfo *);
329 const char *gai_strerror(int);
332 #ifndef EAI_NONAME
333 #define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
334 #endif
335 #ifndef EAI_ADDRFAMILY
336 #define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
337 #endif
338 #ifndef EAI_MEMORY
339 #define EAI_MEMORY -10 /* Memory allocation failure. */
340 #endif
341 #ifndef EAI_SYSTEM
342 #define EAI_SYSTEM -11 /* System error returned in `errno'. */
343 #endif
344 #endif
346 #ifndef AI_CANONNAME
347 #define AI_CANONNAME 0
348 #endif
350 #ifndef AI_ADDRCONFIG
351 #define AI_ADDRCONFIG 0
352 #endif
354 #ifndef INET6_ADDRSTRLEN
355 #define INET6_ADDRSTRLEN 46
356 #endif
358 #ifndef HAVE_INET_NTOP
359 const char *inet_ntop(int, const void *, char *, socklen_t);
360 #endif
362 /* tftp-hpa version and configuration strings */
364 #include "version.h"
366 #ifdef WITH_READLINE
367 #define WITH_READLINE_STR ", with readline"
368 #else
369 #define WITH_READLINE_STR ", without readline"
370 #endif
372 #ifdef WITH_REGEX
373 #define WITH_REGEX_STR ", with remap"
374 #else
375 #define WITH_REGEX_STR ", without remap"
376 #endif
378 #ifdef HAVE_LIBWRAP
379 #define HAVE_LIBWRAP_STR ", with tcpwrappers"
380 #else
381 #define HAVE_LIBWRAP_STR ", without tcpwrappers"
382 #endif
384 #define TFTP_CONFIG_STR VERSION WITH_READLINE_STR
385 #define TFTPD_CONFIG_STR VERSION WITH_REGEX_STR HAVE_LIBWRAP_STR
387 #endif