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 * ----------------------------------------------------------------------- */
14 * Sets up a common baseline environment, based on "autoconf" findings...
20 /* Feature enables for specific environments */
22 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1070
23 #define __APPLE_USE_RFC_3542 1
27 /* Must be included before we include any system headers! */
28 #include "aconfig.h" /* autogenerated configuration header */
30 /* Standard includes */
38 #ifdef HAVE_SYS_TYPES_H
39 #include <sys/types.h>
42 #ifdef HAVE_SYS_STAT_H
54 #ifdef HAVE_INTTYPES_H
55 #ifdef INTTYPES_H_IS_SANE
72 #ifdef HAVE_SYS_TIME_H
84 #ifdef HAVE_SYS_SOCKET_H
85 #include <sys/socket.h>
87 #ifdef HAVE_WINSOCK2_H
99 #ifdef HAVE_GETOPT_LONG
102 #include "lib/getopt.h"
105 /* Test for EAGAIN/EWOULDBLOCK */
107 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
108 #define E_WOULD_BLOCK(x) ((x) == EAGAIN || (x) == EWOULDBLOCK)
110 #define E_WOULD_BLOCK(x) ((x) == EAGAIN)
113 #define E_WOULD_BLOCK(x) ((x) == EWOULDBLOCK)
116 /* Some broken systems care about text versus binary, but
117 real Unix systems don't... */
118 #ifndef HAVE_O_TEXT_DEFINITION
121 #ifndef HAVE_O_BINARY_DEFINITION
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)
137 typedef long intmax_t;
138 typedef unsigned long uintmax_t;
142 #define INTMAX_C(x) (x##L)
143 #define UINTMAX_C(x) (x##UL)
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
156 #undef HAVE_STRTOUMAX
158 #ifdef HAVE_LONG_LONG
159 #define intmax_t long long
160 #define uintmax_t unsigned long long
164 #define INTMAX_C(x) (x##LL)
165 #define UINTMAX_C(x) (x##ULL)
167 #define intmax_t long
168 #define uintmax_t unsigned long
172 #define INTMAX_C(x) (x##L)
173 #define UINTMAX_C(x) (x##UL)
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))
183 #define strtoumax(p,e,b) ((uintmax_t)strtoul(p,e,b))
187 /* A lot of this is old BSD code. Some newer systems don't approve. */
189 /* The type used by htons(), ntohs() */
192 typedef uint16_t u_short
;
194 typedef unsigned short u_short
;
198 /* The type used to htonl(), ntohl() */
201 typedef uint32_t u_long
;
203 typedef unsigned long u_long
;
208 #ifndef HAVE_SOCKLEN_T
209 typedef int socklen_t
;
214 #ifdef HAVE_SYSEXITS_H
215 #include <sysexits.h>
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 */
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
242 /* How do we annotate unused data items? */
246 #define UNUSED __attribute__((unused))
252 /* netinet/in.h, and possible missing pieces */
254 #include <netinet/in.h>
256 #ifndef HAVE_IPPORT_TFTP_DEFINITION
258 #define IPPORT_TFTP 69
262 /* arpa/{inet,tftp}.h, and possible missing pieces */
264 #ifdef HAVE_ARPA_INET_H
265 #include <arpa/inet.h>
267 /* If we don't have arpa/tftp.h we have problems... */
268 #include <arpa/tftp.h>
277 /* Prototypes for libxtra functions */
279 void *xmalloc(size_t);
280 char *xstrdup(const char *);
282 #ifndef HAVE_SIGHANDLER_T
283 typedef void (*sighandler_t
)(int);
288 sighandler_t
tftp_signal(int, sighandler_t
);
294 int daemon(int, int);
297 #ifndef HAVE_GETADDRINFO
298 #ifndef HAVE_STRUCT_ADDRINFO
305 struct sockaddr
*ai_addr
;
307 struct addrinfo
*ai_next
;
310 int getaddrinfo(const char *, const char *, const struct addrinfo
*,
312 void freeaddrinfo(struct addrinfo
*);
313 const char *gai_strerror(int);
317 #define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
319 #ifndef EAI_ADDRFAMILY
320 #define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
323 #define EAI_MEMORY -10 /* Memory allocation failure. */
326 #define EAI_SYSTEM -11 /* System error returned in `errno'. */
331 #define AI_CANONNAME 0
334 #ifndef AI_ADDRCONFIG
335 #define AI_ADDRCONFIG 0
338 #ifndef INET6_ADDRSTRLEN
339 #define INET6_ADDRSTRLEN 46
342 #ifndef HAVE_INET_NTOP
343 const char *inet_ntop(int, const void *, char *, socklen_t
);
346 /* tftp-hpa version and configuration strings */
351 #define WITH_READLINE_STR ", with readline"
353 #define WITH_READLINE_STR ", without readline"
357 #define WITH_REGEX_STR ", with remap"
359 #define WITH_REGEX_STR ", without remap"
363 #define HAVE_LIBWRAP_STR ", with tcpwrappers"
365 #define HAVE_LIBWRAP_STR ", without tcpwrappers"
368 #define TFTP_CONFIG_STR VERSION WITH_READLINE_STR
369 #define TFTPD_CONFIG_STR VERSION WITH_REGEX_STR HAVE_LIBWRAP_STR