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