Massively cleaned up #include's, so they're in a consistent
[freeradius.git] / src / include / missing.h
1 #ifndef _FR_MISSING_H
2 #define _FR_MISSING_H
3
4 /*
5  * missing.h    Replacements for functions that are or can be
6  *              missing on some platforms.
7  *
8  * Version:     $Id$
9  *
10  */
11
12 #include <freeradius-devel/ident.h>
13 RCSIDH(missing_h, "$Id$")
14
15 #include <freeradius-devel/autoconf.h>
16
17 #ifdef HAVE_STDINT_H
18 #include <stdint.h>
19 #endif
20
21 #ifdef HAVE_SYS_TYPES_H
22 #include <sys/types.h>
23 #endif
24
25 #ifdef HAVE_INTTYPES_H
26 #include <inttypes.h>
27 #endif
28
29 #ifdef HAVE_STRINGS_H
30 #include <strings.h>
31 #endif
32
33 #ifdef HAVE_STRING_H
34 #include <string.h>
35 #endif
36
37 #ifdef HAVE_NETDB_H
38 #include <netdb.h>
39 #endif
40
41 #ifdef HAVE_NETINET_IN_H
42 #include        <netinet/in.h>
43 #endif
44
45 #ifdef HAVE_ARPA_INET_H
46 #include        <arpa/inet.h>
47 #endif
48
49 #ifdef HAVE_SYS_SELECT_H
50 #include <sys/select.h>
51 #endif
52
53 #ifdef HAVE_UNISTD_H
54 #include <unistd.h>
55 #endif
56
57 /*
58  *  Check for inclusion of <time.h>, versus <sys/time.h>
59  *  Taken verbatim from the autoconf manual.
60  */
61 #if TIME_WITH_SYS_TIME
62 # include <sys/time.h>
63 # include <time.h>
64 #else
65 # ifdef HAVE_SYS_TIME_H
66 #  include <sys/time.h>
67 # else
68 #  include <time.h>
69 # endif
70 #endif
71
72 /*
73  *      Functions from missing.c
74  */
75
76 #ifndef HAVE_STRNCASECMP
77 extern int strncasecmp(char *s1, char *s2, int n);
78 #endif
79
80 #ifndef HAVE_STRCASECMP
81 extern int strcasecmp(char *s1, char *s2);
82 #endif
83
84 #ifndef HAVE_STRSEP
85 extern char *strsep(char **stringp, const char *delim);
86 #endif
87
88 #ifndef HAVE_LOCALTIME_R
89 struct tm;
90 struct tm *localtime_r(const time_t *l_clock, struct tm *result);
91 #endif
92
93 #ifndef HAVE_CTIME_R
94 char *ctime_r(const time_t *l_clock, char *l_buf);
95 #endif
96
97 #ifdef NEED_DECLARATION_CRYPT
98 char *crypt(char *key, char *salt);
99 #endif
100
101 #ifdef NEED_DECLARATION_STRNCASECMP
102 int strncasecmp(char *s1, char *s2, int n);
103 #endif
104
105 #ifdef NEED_DECLARATION_STRCASECMP
106 int strcasecmp(char *s1, char *s2);
107 #endif
108
109 #ifdef NEED_DECLARATION_INET_ATON
110 struct in_addr;
111 int inet_aton(char *cp, struct in_addr *inp);
112 #endif
113
114 #ifdef NEED_DECLARATION_GETHOSTNAME
115 int gethostname(char *name, int len);
116 #endif
117
118 #ifndef HAVE_SETLINEBUF
119 #ifdef HAVE_SETVBUF
120 #define setlinebuf(x) setvbuf(x, NULL, _IOLBF, 0)
121 #else
122 #define setlinebuf(x)     0
123 #endif
124 #endif
125
126 #ifdef NEED_DECLARATION_SETLINEBUF
127 #define setlinebuf(x)     0
128 #endif
129
130 #ifdef NEED_DECLARATION_GETUSERSHELL
131 char *getusershell(void);
132 #endif
133
134 #ifdef NEED_DECLARATION_ENDUSERSHELL
135 void endusershell(void);
136 #endif
137
138 #ifndef INADDR_ANY
139 #define INADDR_ANY      ((uint32_t) 0x00000000)
140 #endif
141
142 #ifndef INADDR_LOOPBACK
143 #define INADDR_LOOPBACK ((uint32_t) 0x7f000001) /* Inet 127.0.0.1 */
144 #endif
145
146 #ifndef INADDR_NONE
147 #define INADDR_NONE     ((uint32_t) 0xffffffff)
148 #endif
149
150 #ifndef INADDRSZ
151 #define INADDRSZ 4
152 #endif
153
154 #ifndef INET_ADDRSTRLEN
155 #define INET_ADDRSTRLEN 16
156 #endif
157
158 #ifndef AF_UNSPEC
159 #define AF_UNSPEC 0
160 #endif
161
162 #ifndef AF_INET6
163 #define AF_INET6 10
164
165 #ifndef HAVE_STRUCT_IN6_ADDR
166 struct in6_addr
167 {
168         union {
169                 uint8_t u6_addr8[16];
170                 uint16_t u6_addr16[8];
171                 uint32_t u6_addr32[4];
172         } in6_u;
173 #define s6_addr                 in6_u.u6_addr8
174 #define s6_addr16               in6_u.u6_addr16
175 #define s6_addr32               in6_u.u6_addr32
176 };
177
178 #ifndef IN6ADDRSZ
179 #define IN6ADDRSZ 16
180 #endif
181
182 #ifndef INET6_ADDRSTRLEN
183 #define INET6_ADDRSTRLEN 46
184 #endif
185
186 #ifndef IN6ADDR_ANY_INIT
187 #define IN6ADDR_ANY_INIT        {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
188 #endif
189
190 #ifndef IN6ADDR_LOOPBACK_INIT
191 #define IN6ADDR_LOOPBACK_INIT   {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
192 #endif
193
194 #ifndef IN6_IS_ADDR_UNSPECIFIED
195 #define IN6_IS_ADDR_UNSPECIFIED(a) \
196         (((__const uint32_t *) (a))[0] == 0                                   \
197          && ((__const uint32_t *) (a))[1] == 0                                \
198          && ((__const uint32_t *) (a))[2] == 0                                \
199          && ((__const uint32_t *) (a))[3] == 0)
200 #endif
201
202 #ifndef IN6_IS_ADDR_LOOPBACK
203 #define IN6_IS_ADDR_LOOPBACK(a) \
204         (((__const uint32_t *) (a))[0] == 0                                   \
205          && ((__const uint32_t *) (a))[1] == 0                                \
206          && ((__const uint32_t *) (a))[2] == 0                                \
207          && ((__const uint32_t *) (a))[3] == htonl (1))
208 #endif
209
210 #ifndef IN6_IS_ADDR_MULTICAST
211 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
212 #endif
213
214 #ifndef IN6_IS_ADDR_LINKLOCAL
215 #define IN6_IS_ADDR_LINKLOCAL(a) \
216         ((((__const uint32_t *) (a))[0] & htonl (0xffc00000))                 \
217          == htonl (0xfe800000))
218 #endif
219
220 #ifndef IN6_IS_ADDR_SITELOCAL
221 #define IN6_IS_ADDR_SITELOCAL(a) \
222         ((((__const uint32_t *) (a))[0] & htonl (0xffc00000))                 \
223          == htonl (0xfec00000))
224 #endif
225
226 #ifndef IN6_IS_ADDR_V4MAPPED
227 #define IN6_IS_ADDR_V4MAPPED(a) \
228         ((((__const uint32_t *) (a))[0] == 0)                                 \
229          && (((__const uint32_t *) (a))[1] == 0)                              \
230          && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
231 #endif
232
233 #ifndef IN6_IS_ADDR_V4COMPAT
234 #define IN6_IS_ADDR_V4COMPAT(a) \
235         ((((__const uint32_t *) (a))[0] == 0)                                 \
236          && (((__const uint32_t *) (a))[1] == 0)                              \
237          && (((__const uint32_t *) (a))[2] == 0)                              \
238          && (ntohl (((__const uint32_t *) (a))[3]) > 1))
239 #endif
240
241 #ifndef IN6_ARE_ADDR_EQUAL
242 #define IN6_ARE_ADDR_EQUAL(a,b) \
243         ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0])     \
244          && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1])  \
245          && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2])  \
246          && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
247 #endif
248
249 #endif /* HAVE_STRUCT_IN6_ADDR */
250 #endif
251
252 /*
253  *      Functions from getaddrinfo.c
254  */
255
256 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
257 struct sockaddr_storage
258 {
259     uint16_t ss_family;         /* Address family, etc.  */
260     char ss_padding[128 - (sizeof(uint16_t))];
261 };
262 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
263
264 #ifndef HAVE_STRUCT_ADDRINFO
265
266 /* for old netdb.h */
267 #ifndef EAI_SERVICE
268 #define EAI_MEMORY      2
269 #define EAI_FAMILY      5    /* ai_family not supported */
270 #define EAI_NONAME      8    /* hostname nor servname provided, or not known */
271 #define EAI_SERVICE     9   /* servname not supported for ai_socktype */
272 #endif
273
274 /* dummy value for old netdb.h */
275 #ifndef AI_PASSIVE
276 #define AI_PASSIVE      1
277 #define AI_CANONNAME    2
278 #define AI_NUMERICHOST  4
279 #define NI_NUMERICHOST  2
280 #define NI_NAMEREQD     4
281 #define NI_NUMERICSERV  8
282
283 struct addrinfo
284 {
285   int ai_flags;                 /* Input flags.  */
286   int ai_family;                /* Protocol family for socket.  */
287   int ai_socktype;              /* Socket type.  */
288   int ai_protocol;              /* Protocol for socket.  */
289   socklen_t ai_addrlen;         /* Length of socket address.  */
290   struct sockaddr *ai_addr;     /* Socket address for socket.  */
291   char *ai_canonname;           /* Canonical name for service location.  */
292   struct addrinfo *ai_next;     /* Pointer to next in list.  */
293 };
294
295 #endif /* AI_PASSIVE */
296
297 #endif /* HAVE_STRUCT_ADDRINFO */
298
299 /* Translate name of a service location and/or a service name to set of
300    socket addresses. */
301 #ifndef HAVE_GETADDRINFO
302 extern int getaddrinfo (const char *__name,
303                         const char *__service,
304                         const struct addrinfo *__req,
305                         struct addrinfo **__pai);
306
307 /* Free `addrinfo' structure AI including associated storage.  */
308 extern void freeaddrinfo (struct addrinfo *__ai);
309
310 /* Convert error return from getaddrinfo() to a string.  */
311 extern char *gai_strerror (int __ecode);
312 #endif
313
314 /* Translate a socket address to a location and service name. */
315 #ifndef HAVE_GETNAMEINFO
316 extern int getnameinfo (const struct sockaddr *__sa,
317                         socklen_t __salen, char *__host,
318                         socklen_t __hostlen, char *__serv,
319                         socklen_t __servlen, unsigned int __flags);
320 #endif
321
322 /*
323  *      Functions from snprintf.c
324  */
325
326 #ifndef HAVE_VSNPRINTF
327 #include <stdarg.h>
328 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
329 #endif
330
331 #ifndef HAVE_SNPRINTF
332 extern int snprintf(char *str, size_t count, const char *fmt, ...);
333 #endif
334
335 /*
336  *      Functions from strl{cat,cpy}.c
337  */
338
339 #ifndef HAVE_STRLCPY
340 extern size_t strlcpy(char *dst, const char *src, size_t siz);
341 #endif
342
343 #ifndef HAVE_STRLCAT
344 extern size_t strlcat(char *dst, const char *src, size_t siz);
345 #endif
346
347 #endif /* _FR_MISSING_H */