remap: *actually* build, and fix masked logic errors
[tftp-hpa.git] / config.h
bloba8c55ac071d588d15d32587d208c782fe83a38be
1 /* -*- c -*- ------------------------------------------------------------- *
3 * Copyright 2001-2024 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 "config/config.h" /* autogenerated configuration header */
30 /* Standard includes */
32 #include <stdio.h>
33 #include <time.h>
34 #include <stdlib.h>
35 #include <errno.h>
36 #include <signal.h>
38 #ifdef HAVE_SYS_TYPES_H
39 #include <sys/types.h>
40 #endif
42 #ifdef HAVE_SYS_STAT_H
43 #include <sys/stat.h>
44 #endif
46 #ifdef HAVE_STRING_H
47 #include <string.h>
48 #endif
50 #ifdef HAVE_STRINGS_H
51 #include <strings.h>
52 #endif
54 #ifdef HAVE_INTTYPES_H
55 #ifdef INTTYPES_H_IS_SANE
56 #include <inttypes.h>
57 #endif
58 #else
59 #ifdef HAVE_STDINT_H
60 #include <stdint.h>
61 #endif
62 #endif
64 #ifdef HAVE_UNISTD_H
65 #include <unistd.h>
66 #endif
68 #ifdef HAVE_SETJMP_H
69 #include <setjmp.h>
70 #endif
72 #ifdef HAVE_SYS_TIME_H
73 #include <sys/time.h>
74 #endif
76 #ifdef HAVE_GRP_H
77 #include <grp.h>
78 #endif
80 #ifdef HAVE_FCNTL_H
81 #include <fcntl.h>
82 #endif
84 #ifdef HAVE_SYS_SOCKET_H
85 #include <sys/socket.h>
86 #else
87 #ifdef HAVE_WINSOCK2_H
88 #include <winsock2.h>
89 #else
90 #ifdef HAVE_WINSOCK_H
91 #include <winsock.h>
92 #endif
93 #endif
94 #endif
95 #ifdef HAVE_NETDB_H
96 #include <netdb.h>
97 #endif
99 #ifdef HAVE_GETOPT_LONG
100 #include <getopt.h>
101 #else
102 #include "lib/getopt.h"
103 #endif
105 /* Test for EAGAIN/EWOULDBLOCK */
106 #ifdef EAGAIN
107 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
108 #define E_WOULD_BLOCK(x) ((x) == EAGAIN || (x) == EWOULDBLOCK)
109 #else
110 #define E_WOULD_BLOCK(x) ((x) == EAGAIN)
111 #endif
112 #else
113 #define E_WOULD_BLOCK(x) ((x) == EWOULDBLOCK)
114 #endif
116 /* Some broken systems care about text versus binary, but
117 real Unix systems don't... */
118 #if !HAVE_DECL_O_TEXT
119 #define O_TEXT 0
120 #endif
121 #if !HAVE_DECL_O_BINARY
122 #define O_BINARY 0
123 #endif
125 /* If we don't have intmax_t, try creating it */
127 #ifndef HAVE_INTMAX_T
128 #ifdef HAVE_LONG_LONG
129 typedef long long intmax_t;
130 typedef unsigned long long uintmax_t;
131 #define PRIdMAX "lld"
132 #define PRIuMAX "llu"
133 #define PRIxMAX "llx"
134 #define INTMAX_C(x) (x##LL)
135 #define UINTMAX_C(x) (x##ULL)
136 #else
137 typedef long intmax_t;
138 typedef unsigned long uintmax_t;
139 #define PRIdMAX "ld"
140 #define PRIuMAX "lu"
141 #define PRIxMAX "lx"
142 #define INTMAX_C(x) (x##L)
143 #define UINTMAX_C(x) (x##UL)
144 #endif
145 #endif
147 /* On some version of AIX, <inttypes.h> is buggy to the point of
148 unusability. We have to use macros here, not typedefs, to override. */
149 #ifdef HAVE_INTTYPES_H
150 #ifndef INTTYPES_H_IS_SANE
151 #undef PRIdMAX
152 #undef PRIuMAX
153 #undef PRIxMAX
154 #undef INTMAX_C
155 #undef UINTMAX_C
156 #undef HAVE_STRTOUMAX
158 #ifdef HAVE_LONG_LONG
159 #define intmax_t long long
160 #define uintmax_t unsigned long long
161 #define PRIdMAX "Ld"
162 #define PRIuMAX "Lu"
163 #define PRIxMAX "Lx"
164 #define INTMAX_C(x) (x##LL)
165 #define UINTMAX_C(x) (x##ULL)
166 #else
167 #define intmax_t long
168 #define uintmax_t unsigned long
169 #define PRIdMAX "ld"
170 #define PRIuMAX "lu"
171 #define PRIxMAX "lx"
172 #define INTMAX_C(x) (x##L)
173 #define UINTMAX_C(x) (x##UL)
174 #endif
175 #endif
176 #endif
178 /* Even if intmax_t is defined, we may need this (Solaris 8 braindamage) */
179 #ifndef HAVE_STRTOUMAX
180 #if defined(HAVE_LONG_LONG) && defined(HAVE_STRTOULL)
181 #define strtoumax(p,e,b) ((uintmax_t)strtoull(p,e,b))
182 #else
183 #define strtoumax(p,e,b) ((uintmax_t)strtoul(p,e,b))
184 #endif
185 #endif
187 /* A lot of this is old BSD code. Some newer systems don't approve. */
189 /* The type used by htons(), ntohs() */
190 #ifndef HAVE_U_SHORT
191 #ifdef HAVE_UINT16_T
192 typedef uint16_t u_short;
193 #else
194 typedef unsigned short u_short;
195 #endif
196 #endif
198 /* The type used to htonl(), ntohl() */
199 #ifndef HAVE_U_LONG
200 #ifdef HAVE_UINT32_T
201 typedef uint32_t u_long;
202 #else
203 typedef unsigned long u_long;
204 #endif
205 #endif
207 /* socklen_t */
208 #ifndef HAVE_SOCKLEN_T
209 typedef int socklen_t;
210 #endif
212 /* sysexits.h */
214 #ifdef HAVE_SYSEXITS_H
215 #include <sysexits.h>
216 #else
217 #define EX_USAGE 64 /* command line usage error */
218 #define EX_DATAERR 65 /* data format error */
219 #define EX_NOINPUT 66 /* cannot open input */
220 #define EX_NOUSER 67 /* addressee unknown */
221 #define EX_NOHOST 68 /* host name unknown */
222 #define EX_UNAVAILABLE 69 /* service unavailable */
223 #define EX_SOFTWARE 70 /* internal software error */
224 #define EX_OSERR 71 /* system error (e.g., can't fork) */
225 #define EX_OSFILE 72 /* critical OS file missing */
226 #define EX_CANTCREAT 73 /* can't create (user) output file */
227 #define EX_IOERR 74 /* input/output error */
228 #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
229 #define EX_PROTOCOL 76 /* remote error in protocol */
230 #define EX_NOPERM 77 /* permission denied */
231 #define EX_CONFIG 78 /* configuration error */
232 #endif
234 /* If we don't have sigsetjmp() et all, setjmp() will have to do */
236 #ifndef HAVE_SIGSETJMP
237 #define sigsetjmp(x,y) setjmp(x)
238 #define siglongjmp(x,y) longjmp(x,y)
239 #define sigjmp_buf jmp_buf
240 #endif
242 /* How do we annotate unused data items? */
244 #ifndef UNUSED
245 #ifdef __GNUC__
246 #define UNUSED __attribute__((unused))
247 #else
248 #define UNUSED
249 #endif
250 #endif
252 /* netinet/in.h, and possible missing pieces */
254 #include <netinet/in.h>
256 #if !HAVE_DECL_IPPORT_TFTP && !defined(IPPORT_TFTP)
257 #define IPPORT_TFTP 69
258 #endif
260 /* arpa/{inet,tftp}.h, and possible missing pieces */
262 #ifdef HAVE_ARPA_INET_H
263 #include <arpa/inet.h>
264 #endif
265 /* If we don't have arpa/tftp.h we have problems... */
266 #include <arpa/tftp.h>
268 #ifndef OACK
269 #define OACK 6
270 #endif
271 #ifndef EOPTNEG
272 #define EOPTNEG 8
273 #endif
275 /* Prototypes for libxtra functions */
277 void *xmalloc(size_t);
278 char *xstrdup(const char *);
280 #ifndef HAVE_SIGHANDLER_T
281 typedef void (*sighandler_t)(int);
282 #endif
283 int tftp_signal(int, sighandler_t, int);
285 #ifndef HAVE_DUP2
286 int dup2(int, int);
287 #endif
288 #ifndef HAVE_DAEMON
289 int daemon(int, int);
290 #endif
292 #ifndef HAVE_GETADDRINFO
293 #ifndef HAVE_STRUCT_ADDRINFO
294 struct addrinfo {
295 int ai_flags;
296 int ai_family;
297 int ai_socktype;
298 int ai_protocol;
299 size_t ai_addrlen;
300 struct sockaddr *ai_addr;
301 char *ai_canonname;
302 struct addrinfo *ai_next;
304 #endif
305 int getaddrinfo(const char *, const char *, const struct addrinfo *,
306 struct addrinfo **);
307 void freeaddrinfo(struct addrinfo *);
308 const char *gai_strerror(int);
311 #ifndef EAI_NONAME
312 #define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
313 #endif
314 #ifndef EAI_ADDRFAMILY
315 #define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
316 #endif
317 #ifndef EAI_MEMORY
318 #define EAI_MEMORY -10 /* Memory allocation failure. */
319 #endif
320 #ifndef EAI_SYSTEM
321 #define EAI_SYSTEM -11 /* System error returned in `errno'. */
322 #endif
323 #endif
325 #ifndef AI_CANONNAME
326 #define AI_CANONNAME 0
327 #endif
329 #ifndef AI_ADDRCONFIG
330 #define AI_ADDRCONFIG 0
331 #endif
333 #ifndef INET6_ADDRSTRLEN
334 #define INET6_ADDRSTRLEN 46
335 #endif
337 #ifndef HAVE_INET_NTOP
338 const char *inet_ntop(int, const void *, char *, socklen_t);
339 #endif
341 /* tftp-hpa version and configuration strings */
343 #include "version.h"
345 #ifdef WITH_READLINE
346 #define WITH_READLINE_STR ", with readline"
347 #else
348 #define WITH_READLINE_STR ", without readline"
349 #endif
351 #ifdef WITH_REGEX
352 #define WITH_REGEX_STR ", with remap"
353 #else
354 #define WITH_REGEX_STR ", without remap"
355 #endif
357 #ifdef HAVE_LIBWRAP
358 #define HAVE_LIBWRAP_STR ", with tcpwrappers"
359 #else
360 #define HAVE_LIBWRAP_STR ", without tcpwrappers"
361 #endif
363 #define TFTP_CONFIG_STR VERSION WITH_READLINE_STR
364 #define TFTPD_CONFIG_STR VERSION WITH_REGEX_STR HAVE_LIBWRAP_STR
366 #endif