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 * ----------------------------------------------------------------------- */
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 */
34 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
38 #ifdef HAVE_SYS_STAT_H
65 #ifdef HAVE_INTTYPES_H
66 #ifdef INTTYPES_H_IS_SANE
83 #ifdef TIME_WITH_SYS_TIME
105 #ifdef HAVE_SYS_SOCKET_H
106 #include <sys/socket.h>
108 #ifdef HAVE_WINSOCK2_H
109 #include <winsock2.h>
111 #ifdef HAVE_WINSOCK_H
120 #ifdef HAVE_GETOPT_LONG
123 #include "lib/getopt.h"
126 /* Test for EAGAIN/EWOULDBLOCK */
128 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
129 #define E_WOULD_BLOCK(x) ((x) == EAGAIN || (x) == EWOULDBLOCK)
131 #define E_WOULD_BLOCK(x) ((x) == EAGAIN)
134 #define E_WOULD_BLOCK(x) ((x) == EWOULDBLOCK)
137 /* Some broken systems care about text versus binary, but
138 real Unix systems don't... */
139 #ifndef HAVE_O_TEXT_DEFINITION
142 #ifndef HAVE_O_BINARY_DEFINITION
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)
158 typedef long intmax_t;
159 typedef unsigned long uintmax_t;
163 #define INTMAX_C(x) (x##L)
164 #define UINTMAX_C(x) (x##UL)
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
177 #undef HAVE_STRTOUMAX
179 #ifdef HAVE_LONG_LONG
180 #define intmax_t long long
181 #define uintmax_t unsigned long long
185 #define INTMAX_C(x) (x##LL)
186 #define UINTMAX_C(x) (x##ULL)
188 #define intmax_t long
189 #define uintmax_t unsigned long
193 #define INTMAX_C(x) (x##L)
194 #define UINTMAX_C(x) (x##UL)
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))
204 #define strtoumax(p,e,b) ((uintmax_t)strtoul(p,e,b))
208 /* A lot of this is old BSD code. Some newer systems don't approve. */
210 /* The type used by htons(), ntohs() */
213 typedef uint16_t u_short
;
215 typedef unsigned short u_short
;
219 /* The type used to htonl(), ntohl() */
222 typedef uint32_t u_long
;
224 typedef unsigned long u_long
;
229 #ifndef HAVE_SOCKLEN_T
230 typedef int socklen_t
;
235 #ifdef HAVE_SYSEXITS_H
236 #include <sysexits.h>
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 */
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
263 /* How do we annotate unused data items? */
267 #define UNUSED __attribute__((unused))
273 /* netinet/in.h, and possible missing pieces */
275 #include <netinet/in.h>
277 #ifndef HAVE_IPPORT_TFTP_DEFINITION
279 #define IPPORT_TFTP 69
283 /* arpa/{inet,tftp}.h, and possible missing pieces */
285 #ifdef HAVE_ARPA_INET_H
286 #include <arpa/inet.h>
288 /* If we don't have arpa/tftp.h we have problems... */
289 #include <arpa/tftp.h>
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);
310 int daemon(int, int);
313 #ifndef HAVE_GETADDRINFO
314 #ifndef HAVE_STRUCT_ADDRINFO
321 struct sockaddr
*ai_addr
;
323 struct addrinfo
*ai_next
;
326 int getaddrinfo(const char *, const char *, const struct addrinfo
*,
328 void freeaddrinfo(struct addrinfo
*);
329 const char *gai_strerror(int);
333 #define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
335 #ifndef EAI_ADDRFAMILY
336 #define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
339 #define EAI_MEMORY -10 /* Memory allocation failure. */
342 #define EAI_SYSTEM -11 /* System error returned in `errno'. */
347 #define AI_CANONNAME 0
350 #ifndef AI_ADDRCONFIG
351 #define AI_ADDRCONFIG 0
354 #ifndef INET6_ADDRSTRLEN
355 #define INET6_ADDRSTRLEN 46
358 #ifndef HAVE_INET_NTOP
359 const char *inet_ntop(int, const void *, char *, socklen_t
);
362 /* tftp-hpa version and configuration strings */
367 #define WITH_READLINE_STR ", with readline"
369 #define WITH_READLINE_STR ", without readline"
373 #define WITH_REGEX_STR ", with remap"
375 #define WITH_REGEX_STR ", without remap"
379 #define HAVE_LIBWRAP_STR ", with tcpwrappers"
381 #define HAVE_LIBWRAP_STR ", without tcpwrappers"
384 #define TFTP_CONFIG_STR VERSION WITH_READLINE_STR
385 #define TFTPD_CONFIG_STR VERSION WITH_REGEX_STR HAVE_LIBWRAP_STR