Fix a pathology where a client sending ACKs for the wrong
[tftp-hpa.git] / config.h
bloba3370ff556e029e7547e6ab27142396cb278d17b
1 /* -*- c -*- ------------------------------------------------------------- *
2 *
3 * Copyright 2001 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 * ----------------------------------------------------------------------- */
10 /* $Id$ */
13 * config.h
15 * Sets up a common baseline environment, based on "autoconf" findings...
18 #ifndef CONFIG_H
19 #define CONFIG_H 1
21 /* Must be included before we include any system headers! */
22 #include "aconfig.h" /* autogenerated configuration header */
24 /* Standard includes */
26 #include <stdio.h>
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
30 #endif
32 #ifdef HAVE_SYS_STAT_H
33 #include <sys/stat.h>
34 #endif
36 #ifdef STDC_HEADERS
37 #include <stdlib.h>
38 #include <stddef.h>
39 #else
40 #ifdef HAVE_STDLIB_H
41 #include <stdlib.h>
42 #endif
43 #endif
45 #ifdef HAVE_MEMORY_H
46 #ifndef STDC_HEADERS
47 #include <memory.h>
48 #endif
49 #endif
51 #ifdef HAVE_STRING_H
52 #include <string.h>
53 #endif
55 #ifdef HAVE_STRINGS_H
56 #include <strings.h>
57 #endif
59 #ifdef HAVE_INTTYPES_H
60 #ifdef INTTYPES_H_IS_SANE
61 #include <inttypes.h>
62 #endif
63 #else
64 #ifdef HAVE_STDINT_H
65 #include <stdint.h>
66 #endif
67 #endif
69 #ifdef HAVE_UNISTD_H
70 #include <unistd.h>
71 #endif
73 #ifdef HAVE_SETJMP_H
74 #include <setjmp.h>
75 #endif
77 #ifdef TIME_WITH_SYS_TIME
78 #include <sys/time.h>
79 #include <time.h>
80 #else
81 #if HAVE_SYS_TIME_H
82 #include <sys/time.h>
83 #else
84 #include <time.h>
85 #endif
86 #endif
88 #ifdef HAVE_GRP_H
89 #include <grp.h>
90 #endif
92 #ifdef HAVE_FCNTL_H
93 #include <fcntl.h>
94 #endif
96 #include <errno.h>
97 #include <signal.h>
99 #ifdef HAVE_SYS_SOCKET_H
100 #include <sys/socket.h>
101 #else
102 #ifdef HAVE_WINSOCK2_H
103 #include <winsock2.h>
104 #else
105 #ifdef HAVE_WINSOCK_H
106 #include <winsock.h>
107 #endif
108 #endif
109 #endif
111 /* Test for EAGAIN/EWOULDBLOCK */
112 #ifdef EAGAIN
113 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
114 #define E_WOULD_BLOCK(x) ((x) == EAGAIN || (x) == EWOULDBLOCK)
115 #else
116 #define E_WOULD_BLOCK(x) ((x) == EAGAIN)
117 #endif
118 #else
119 #define E_WOULD_BLOCK(x) ((x) == EWOULDBLOCK)
120 #endif
122 /* Some broken systems care about text versus binary, but
123 real Unix systems don't... */
124 #ifndef HAVE_O_TEXT_DEFINITION
125 #define O_TEXT 0
126 #endif
127 #ifndef HAVE_O_BINARY_DEFINITION
128 #define O_BINARY 0
129 #endif
131 /* If we don't have intmax_t, try creating it */
133 #ifndef HAVE_INTMAX_T
134 #ifdef HAVE_LONG_LONG
135 typedef long long intmax_t;
136 typedef unsigned long long uintmax_t;
137 #define PRIdMAX "lld"
138 #define PRIuMAX "llu"
139 #define PRIxMAX "llx"
140 #define INTMAX_C(x) (x##LL)
141 #define UINTMAX_C(x) (x##ULL)
142 #else
143 typedef long intmax_t;
144 typedef unsigned long uintmax_t;
145 #define PRIdMAX "ld"
146 #define PRIuMAX "lu"
147 #define PRIxMAX "lx"
148 #define INTMAX_C(x) (x##L)
149 #define UINTMAX_C(x) (x##UL)
150 #endif
151 #endif
153 /* On some version of AIX, <inttypes.h> is buggy to the point of
154 unusability. We have to use macros here, not typedefs, to override. */
155 #ifdef HAVE_INTTYPES_H
156 #ifndef INTTYPES_H_IS_SANE
157 #undef PRIdMAX
158 #undef PRIuMAX
159 #undef PRIxMAX
160 #undef INTMAX_C
161 #undef UINTMAX_C
162 #undef HAVE_STRTOUMAX
164 #ifdef HAVE_LONG_LONG
165 #define intmax_t long long
166 #define uintmax_t unsigned long long
167 #define PRIdMAX "Ld"
168 #define PRIuMAX "Lu"
169 #define PRIxMAX "Lx"
170 #define INTMAX_C(x) (x##LL)
171 #define UINTMAX_C(x) (x##ULL)
172 #else
173 #define intmax_t long
174 #define uintmax_t unsigned long
175 #define PRIdMAX "ld"
176 #define PRIuMAX "lu"
177 #define PRIxMAX "lx"
178 #define INTMAX_C(x) (x##L)
179 #define UINTMAX_C(x) (x##UL)
180 #endif
181 #endif
182 #endif
184 /* Even if intmax_t is defined, we may need this (Solaris 8 braindamage) */
185 #ifndef HAVE_STRTOUMAX
186 #if defined(HAVE_LONG_LONG) && defined(HAVE_STRTOULL)
187 #define strtoumax(p,e,b) ((uintmax_t)strtoull(p,e,b))
188 #else
189 #define strtoumax(p,e,b) ((uintmax_t)strtoul(p,e,b))
190 #endif
191 #endif
193 /* A lot of this is old BSD code. Some newer systems don't approve. */
195 /* The type used by htons(), ntohs() */
196 #ifndef HAVE_U_SHORT
197 #ifdef HAVE_UINT16_T
198 typedef uint16_t u_short;
199 #else
200 typedef unsigned short u_short;
201 #endif
202 #endif
204 /* The type used to htonl(), ntohl() */
205 #ifndef HAVE_U_LONG
206 #ifdef HAVE_UINT32_T
207 typedef uint32_t u_long;
208 #else
209 typedef unsigned long u_long;
210 #endif
211 #endif
213 /* sysexits.h */
215 #ifdef HAVE_SYSEXITS_H
216 #include <sysexits.h>
217 #else
218 #define EX_USAGE 64 /* command line usage error */
219 #define EX_DATAERR 65 /* data format error */
220 #define EX_NOINPUT 66 /* cannot open input */
221 #define EX_NOUSER 67 /* addressee unknown */
222 #define EX_NOHOST 68 /* host name unknown */
223 #define EX_UNAVAILABLE 69 /* service unavailable */
224 #define EX_SOFTWARE 70 /* internal software error */
225 #define EX_OSERR 71 /* system error (e.g., can't fork) */
226 #define EX_OSFILE 72 /* critical OS file missing */
227 #define EX_CANTCREAT 73 /* can't create (user) output file */
228 #define EX_IOERR 74 /* input/output error */
229 #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
230 #define EX_PROTOCOL 76 /* remote error in protocol */
231 #define EX_NOPERM 77 /* permission denied */
232 #define EX_CONFIG 78 /* configuration error */
233 #endif
235 /* If we don't have sigsetjmp() et all, setjmp() will have to do */
237 #ifndef HAVE_SIGSETJMP
238 #define sigsetjmp(x,y) setjmp(x)
239 #define siglongjmp(x,y) longjmp(x,y)
240 #define sigjmp_buf jmp_buf
241 #endif
243 /* How do we annotate unused data items? */
245 #ifndef UNUSED
246 #ifdef __GNUC__
247 #define UNUSED __attribute__((unused))
248 #else
249 #define UNUSED
250 #endif
251 #endif
253 /* netinet/in.h, and possible missing pieces */
255 #include <netinet/in.h>
257 #ifndef HAVE_IPPORT_TFTP_DEFINITION
258 #ifndef IPPORT_TFTP
259 #define IPPORT_TFTP 69
260 #endif
261 #endif
263 /* arpa/{inet,tftp}.h, and possible missing pieces */
265 #ifdef HAVE_ARPA_INET_H
266 #include <arpa/inet.h>
267 #endif
268 /* If we don't have arpa/tftp.h we have problems... */
269 #include <arpa/tftp.h>
271 #ifndef OACK
272 #define OACK 6
273 #endif
274 #ifndef EOPTNEG
275 #define EOPTNEG 8
276 #endif
278 /* tftp-hpa version and configuration strings */
280 #include "version.h"
282 #ifdef WITH_READLINE
283 #define WITH_READLINE_STR ", with readline"
284 #else
285 #define WITH_READLINE_STR ", without readline"
286 #endif
288 #ifdef WITH_REGEX
289 #define WITH_REGEX_STR ", with remap"
290 #else
291 #define WITH_REGEX_STR ", without remap"
292 #endif
294 #ifdef HAVE_LIBWRAP
295 #define HAVE_LIBWRAP_STR ", with tcpwrappers"
296 #else
297 #define HAVE_LIBWRAP_STR ", without tcpwrappers"
298 #endif
300 #define TFTP_CONFIG_STR VERSION WITH_READLINE_STR
301 #define TFTPD_CONFIG_STR VERSION WITH_REGEX_STR HAVE_LIBWRAP_STR
303 #endif