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