Update version for release 0.49
[tftp-hpa.git] / config.h
blob76c751430834c92835452f52e3b54657791227c7
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 /* Must be included before we include any system headers! */
21 #include "aconfig.h" /* autogenerated configuration header */
23 /* Standard includes */
25 #include <stdio.h>
27 #ifdef HAVE_SYS_TYPES_H
28 #include <sys/types.h>
29 #endif
31 #ifdef HAVE_SYS_STAT_H
32 #include <sys/stat.h>
33 #endif
35 #ifdef STDC_HEADERS
36 #include <stdlib.h>
37 #include <stddef.h>
38 #else
39 #ifdef HAVE_STDLIB_H
40 #include <stdlib.h>
41 #endif
42 #endif
44 #ifdef HAVE_MEMORY_H
45 #ifndef STDC_HEADERS
46 #include <memory.h>
47 #endif
48 #endif
50 #ifdef HAVE_STRING_H
51 #include <string.h>
52 #endif
54 #ifdef HAVE_STRINGS_H
55 #include <strings.h>
56 #endif
58 #ifdef HAVE_INTTYPES_H
59 #ifdef INTTYPES_H_IS_SANE
60 #include <inttypes.h>
61 #endif
62 #else
63 #ifdef HAVE_STDINT_H
64 #include <stdint.h>
65 #endif
66 #endif
68 #ifdef HAVE_UNISTD_H
69 #include <unistd.h>
70 #endif
72 #ifdef HAVE_SETJMP_H
73 #include <setjmp.h>
74 #endif
76 #ifdef TIME_WITH_SYS_TIME
77 #include <sys/time.h>
78 #include <time.h>
79 #else
80 #if HAVE_SYS_TIME_H
81 #include <sys/time.h>
82 #else
83 #include <time.h>
84 #endif
85 #endif
87 #ifdef HAVE_GRP_H
88 #include <grp.h>
89 #endif
91 #ifdef HAVE_FCNTL_H
92 #include <fcntl.h>
93 #endif
95 #include <errno.h>
96 #include <signal.h>
98 #ifdef HAVE_SYS_SOCKET_H
99 #include <sys/socket.h>
100 #else
101 #ifdef HAVE_WINSOCK2_H
102 #include <winsock2.h>
103 #else
104 #ifdef HAVE_WINSOCK_H
105 #include <winsock.h>
106 #endif
107 #endif
108 #endif
109 #ifdef HAVE_NETDB_H
110 #include <netdb.h>
111 #endif
113 #ifdef HAVE_GETOPT_LONG
114 #include <getopt.h>
115 #else
116 #include "lib/getopt.h"
117 #endif
119 /* Test for EAGAIN/EWOULDBLOCK */
120 #ifdef EAGAIN
121 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
122 #define E_WOULD_BLOCK(x) ((x) == EAGAIN || (x) == EWOULDBLOCK)
123 #else
124 #define E_WOULD_BLOCK(x) ((x) == EAGAIN)
125 #endif
126 #else
127 #define E_WOULD_BLOCK(x) ((x) == EWOULDBLOCK)
128 #endif
130 /* Some broken systems care about text versus binary, but
131 real Unix systems don't... */
132 #ifndef HAVE_O_TEXT_DEFINITION
133 #define O_TEXT 0
134 #endif
135 #ifndef HAVE_O_BINARY_DEFINITION
136 #define O_BINARY 0
137 #endif
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)
150 #else
151 typedef long intmax_t;
152 typedef unsigned long uintmax_t;
153 #define PRIdMAX "ld"
154 #define PRIuMAX "lu"
155 #define PRIxMAX "lx"
156 #define INTMAX_C(x) (x##L)
157 #define UINTMAX_C(x) (x##UL)
158 #endif
159 #endif
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
165 #undef PRIdMAX
166 #undef PRIuMAX
167 #undef PRIxMAX
168 #undef INTMAX_C
169 #undef UINTMAX_C
170 #undef HAVE_STRTOUMAX
172 #ifdef HAVE_LONG_LONG
173 #define intmax_t long long
174 #define uintmax_t unsigned long long
175 #define PRIdMAX "Ld"
176 #define PRIuMAX "Lu"
177 #define PRIxMAX "Lx"
178 #define INTMAX_C(x) (x##LL)
179 #define UINTMAX_C(x) (x##ULL)
180 #else
181 #define intmax_t long
182 #define uintmax_t unsigned long
183 #define PRIdMAX "ld"
184 #define PRIuMAX "lu"
185 #define PRIxMAX "lx"
186 #define INTMAX_C(x) (x##L)
187 #define UINTMAX_C(x) (x##UL)
188 #endif
189 #endif
190 #endif
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))
196 #else
197 #define strtoumax(p,e,b) ((uintmax_t)strtoul(p,e,b))
198 #endif
199 #endif
201 /* A lot of this is old BSD code. Some newer systems don't approve. */
203 /* The type used by htons(), ntohs() */
204 #ifndef HAVE_U_SHORT
205 #ifdef HAVE_UINT16_T
206 typedef uint16_t u_short;
207 #else
208 typedef unsigned short u_short;
209 #endif
210 #endif
212 /* The type used to htonl(), ntohl() */
213 #ifndef HAVE_U_LONG
214 #ifdef HAVE_UINT32_T
215 typedef uint32_t u_long;
216 #else
217 typedef unsigned long u_long;
218 #endif
219 #endif
221 /* socklen_t */
222 #ifndef HAVE_SOCKLEN_T
223 typedef int socklen_t;
224 #endif
226 /* sysexits.h */
228 #ifdef HAVE_SYSEXITS_H
229 #include <sysexits.h>
230 #else
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 */
246 #endif
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
254 #endif
256 /* How do we annotate unused data items? */
258 #ifndef UNUSED
259 #ifdef __GNUC__
260 #define UNUSED __attribute__((unused))
261 #else
262 #define UNUSED
263 #endif
264 #endif
266 /* netinet/in.h, and possible missing pieces */
268 #include <netinet/in.h>
270 #ifndef HAVE_IPPORT_TFTP_DEFINITION
271 #ifndef IPPORT_TFTP
272 #define IPPORT_TFTP 69
273 #endif
274 #endif
276 /* arpa/{inet,tftp}.h, and possible missing pieces */
278 #ifdef HAVE_ARPA_INET_H
279 #include <arpa/inet.h>
280 #endif
281 /* If we don't have arpa/tftp.h we have problems... */
282 #include <arpa/tftp.h>
284 #ifndef OACK
285 #define OACK 6
286 #endif
287 #ifndef EOPTNEG
288 #define EOPTNEG 8
289 #endif
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);
298 #endif
299 #ifndef HAVE_DUP2
300 int dup2(int, int);
301 #endif
302 #ifndef HAVE_DAEMON
303 int daemon(int, int);
304 #endif
306 #ifndef HAVE_GETADDRINFO
307 #ifndef HAVE_STRUCT_ADDRINFO
308 struct addrinfo {
309 int ai_flags;
310 int ai_family;
311 int ai_socktype;
312 int ai_protocol;
313 size_t ai_addrlen;
314 struct sockaddr *ai_addr;
315 char *ai_canonname;
316 struct addrinfo *ai_next;
318 #endif
319 int getaddrinfo(const char *, const char *, const struct addrinfo *,
320 struct addrinfo **);
321 void freeaddrinfo(struct addrinfo *);
322 const char *gai_strerror(int);
324 #ifndef AI_CANONNAME
325 #define AI_CANONNAME 0x0002 /* Request for canonical name. */
326 #endif
328 #ifndef AI_ADDRCONFIG
329 #define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose
330 returned address type.. */
331 #endif
333 #ifndef EAI_NONAME
334 #define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
335 #endif
336 #ifndef EAI_ADDRFAMILY
337 #define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
338 #endif
339 #ifndef EAI_MEMORY
340 #define EAI_MEMORY -10 /* Memory allocation failure. */
341 #endif
342 #ifndef EAI_SYSTEM
343 #define EAI_SYSTEM -11 /* System error returned in `errno'. */
344 #endif
345 #endif
347 #ifndef INET6_ADDRSTRLEN
348 #define INET6_ADDRSTRLEN 46
349 #endif
351 #ifndef HAVE_INET_NTOP
352 const char *inet_ntop(int, const void *, char *, socklen_t);
353 #endif
355 /* tftp-hpa version and configuration strings */
357 #include "version.h"
359 #ifdef WITH_READLINE
360 #define WITH_READLINE_STR ", with readline"
361 #else
362 #define WITH_READLINE_STR ", without readline"
363 #endif
365 #ifdef WITH_REGEX
366 #define WITH_REGEX_STR ", with remap"
367 #else
368 #define WITH_REGEX_STR ", without remap"
369 #endif
371 #ifdef HAVE_LIBWRAP
372 #define HAVE_LIBWRAP_STR ", with tcpwrappers"
373 #else
374 #define HAVE_LIBWRAP_STR ", without tcpwrappers"
375 #endif
377 #define TFTP_CONFIG_STR VERSION WITH_READLINE_STR
378 #define TFTPD_CONFIG_STR VERSION WITH_REGEX_STR HAVE_LIBWRAP_STR
380 #endif