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