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 /* Must be included before we include any system headers! */
21 #include "aconfig.h" /* autogenerated configuration header */
23 /* Standard includes */
27 #ifdef HAVE_SYS_TYPES_H
28 #include <sys/types.h>
31 #ifdef HAVE_SYS_STAT_H
58 #ifdef HAVE_INTTYPES_H
59 #ifdef INTTYPES_H_IS_SANE
76 #ifdef TIME_WITH_SYS_TIME
98 #ifdef HAVE_SYS_SOCKET_H
99 #include <sys/socket.h>
101 #ifdef HAVE_WINSOCK2_H
102 #include <winsock2.h>
104 #ifdef HAVE_WINSOCK_H
113 #ifdef HAVE_GETOPT_LONG
116 #include "lib/getopt.h"
119 /* Test for EAGAIN/EWOULDBLOCK */
121 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
122 #define E_WOULD_BLOCK(x) ((x) == EAGAIN || (x) == EWOULDBLOCK)
124 #define E_WOULD_BLOCK(x) ((x) == EAGAIN)
127 #define E_WOULD_BLOCK(x) ((x) == EWOULDBLOCK)
130 /* Some broken systems care about text versus binary, but
131 real Unix systems don't... */
132 #ifndef HAVE_O_TEXT_DEFINITION
135 #ifndef HAVE_O_BINARY_DEFINITION
139 /* If we don't have intmax_t, try creating it */
141 #ifndef HAVE_INTMAX_T
142 #ifdef HAVE_LONG_LONG
143 typedef long long intmax_t;
144 typedef unsigned long long uintmax_t;
145 #define PRIdMAX "lld"
146 #define PRIuMAX "llu"
147 #define PRIxMAX "llx"
148 #define INTMAX_C(x) (x##LL)
149 #define UINTMAX_C(x) (x##ULL)
151 typedef long intmax_t;
152 typedef unsigned long uintmax_t;
156 #define INTMAX_C(x) (x##L)
157 #define UINTMAX_C(x) (x##UL)
161 /* On some version of AIX, <inttypes.h> is buggy to the point of
162 unusability. We have to use macros here, not typedefs, to override. */
163 #ifdef HAVE_INTTYPES_H
164 #ifndef INTTYPES_H_IS_SANE
170 #undef HAVE_STRTOUMAX
172 #ifdef HAVE_LONG_LONG
173 #define intmax_t long long
174 #define uintmax_t unsigned long long
178 #define INTMAX_C(x) (x##LL)
179 #define UINTMAX_C(x) (x##ULL)
181 #define intmax_t long
182 #define uintmax_t unsigned long
186 #define INTMAX_C(x) (x##L)
187 #define UINTMAX_C(x) (x##UL)
192 /* Even if intmax_t is defined, we may need this (Solaris 8 braindamage) */
193 #ifndef HAVE_STRTOUMAX
194 #if defined(HAVE_LONG_LONG) && defined(HAVE_STRTOULL)
195 #define strtoumax(p,e,b) ((uintmax_t)strtoull(p,e,b))
197 #define strtoumax(p,e,b) ((uintmax_t)strtoul(p,e,b))
201 /* A lot of this is old BSD code. Some newer systems don't approve. */
203 /* The type used by htons(), ntohs() */
206 typedef uint16_t u_short
;
208 typedef unsigned short u_short
;
212 /* The type used to htonl(), ntohl() */
215 typedef uint32_t u_long
;
217 typedef unsigned long u_long
;
222 #ifndef HAVE_SOCKLEN_T
223 typedef int socklen_t
;
228 #ifdef HAVE_SYSEXITS_H
229 #include <sysexits.h>
231 #define EX_USAGE 64 /* command line usage error */
232 #define EX_DATAERR 65 /* data format error */
233 #define EX_NOINPUT 66 /* cannot open input */
234 #define EX_NOUSER 67 /* addressee unknown */
235 #define EX_NOHOST 68 /* host name unknown */
236 #define EX_UNAVAILABLE 69 /* service unavailable */
237 #define EX_SOFTWARE 70 /* internal software error */
238 #define EX_OSERR 71 /* system error (e.g., can't fork) */
239 #define EX_OSFILE 72 /* critical OS file missing */
240 #define EX_CANTCREAT 73 /* can't create (user) output file */
241 #define EX_IOERR 74 /* input/output error */
242 #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
243 #define EX_PROTOCOL 76 /* remote error in protocol */
244 #define EX_NOPERM 77 /* permission denied */
245 #define EX_CONFIG 78 /* configuration error */
248 /* If we don't have sigsetjmp() et all, setjmp() will have to do */
250 #ifndef HAVE_SIGSETJMP
251 #define sigsetjmp(x,y) setjmp(x)
252 #define siglongjmp(x,y) longjmp(x,y)
253 #define sigjmp_buf jmp_buf
256 /* How do we annotate unused data items? */
260 #define UNUSED __attribute__((unused))
266 /* netinet/in.h, and possible missing pieces */
268 #include <netinet/in.h>
270 #ifndef HAVE_IPPORT_TFTP_DEFINITION
272 #define IPPORT_TFTP 69
276 /* arpa/{inet,tftp}.h, and possible missing pieces */
278 #ifdef HAVE_ARPA_INET_H
279 #include <arpa/inet.h>
281 /* If we don't have arpa/tftp.h we have problems... */
282 #include <arpa/tftp.h>
291 /* Prototypes for libxtra functions */
293 void *xmalloc(size_t);
294 char *xstrdup(const char *);
296 #ifndef HAVE_BSD_SIGNAL
297 void (*bsd_signal(int, void (*)(int))) (int);
303 int daemon(int, int);
306 #ifndef HAVE_GETADDRINFO
307 #ifndef HAVE_STRUCT_ADDRINFO
314 struct sockaddr
*ai_addr
;
316 struct addrinfo
*ai_next
;
319 int getaddrinfo(const char *, const char *, const struct addrinfo
*,
321 void freeaddrinfo(struct addrinfo
*);
322 const char *gai_strerror(int);
326 #define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
328 #ifndef EAI_ADDRFAMILY
329 #define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
332 #define EAI_MEMORY -10 /* Memory allocation failure. */
335 #define EAI_SYSTEM -11 /* System error returned in `errno'. */
340 #define AI_CANONNAME 0
343 #ifndef AI_ADDRCONFIG
344 #define AI_ADDRCONFIG 0
347 #ifndef INET6_ADDRSTRLEN
348 #define INET6_ADDRSTRLEN 46
351 #ifndef HAVE_INET_NTOP
352 const char *inet_ntop(int, const void *, char *, socklen_t
);
355 /* tftp-hpa version and configuration strings */
360 #define WITH_READLINE_STR ", with readline"
362 #define WITH_READLINE_STR ", without readline"
366 #define WITH_REGEX_STR ", with remap"
368 #define WITH_REGEX_STR ", without remap"
372 #define HAVE_LIBWRAP_STR ", with tcpwrappers"
374 #define HAVE_LIBWRAP_STR ", without tcpwrappers"
377 #define TFTP_CONFIG_STR VERSION WITH_READLINE_STR
378 #define TFTPD_CONFIG_STR VERSION WITH_REGEX_STR HAVE_LIBWRAP_STR