5 * missing.h Replacements for functions that are or can be
6 * missing on some platforms.
12 #include <freeradius-devel/ident.h>
13 RCSIDH(missing_h, "$Id$")
15 #include <freeradius-devel/autoconf.h>
21 #ifdef HAVE_SYS_TYPES_H
22 #include <sys/types.h>
25 #ifdef HAVE_INTTYPES_H
41 #ifdef HAVE_NETINET_IN_H
42 #include <netinet/in.h>
45 #ifdef HAVE_ARPA_INET_H
46 #include <arpa/inet.h>
49 #ifdef HAVE_SYS_SELECT_H
50 #include <sys/select.h>
58 * Check for inclusion of <time.h>, versus <sys/time.h>
59 * Taken verbatim from the autoconf manual.
61 #if TIME_WITH_SYS_TIME
62 # include <sys/time.h>
65 # ifdef HAVE_SYS_TIME_H
66 # include <sys/time.h>
79 * Functions from missing.c
82 #ifndef HAVE_STRNCASECMP
83 extern int strncasecmp(char *s1, char *s2, int n);
86 #ifndef HAVE_STRCASECMP
87 extern int strcasecmp(char *s1, char *s2);
91 extern char *strsep(char **stringp, const char *delim);
94 #ifndef HAVE_LOCALTIME_R
96 struct tm *localtime_r(const time_t *l_clock, struct tm *result);
100 char *ctime_r(const time_t *l_clock, char *l_buf);
103 #ifdef NEED_DECLARATION_CRYPT
104 char *crypt(char *key, char *salt);
107 #ifdef NEED_DECLARATION_STRNCASECMP
108 int strncasecmp(char *s1, char *s2, int n);
111 #ifdef NEED_DECLARATION_STRCASECMP
112 int strcasecmp(char *s1, char *s2);
115 #ifdef NEED_DECLARATION_INET_ATON
117 int inet_aton(char *cp, struct in_addr *inp);
120 #ifndef HAVE_SETLINEBUF
122 #define setlinebuf(x) setvbuf(x, NULL, _IOLBF, 0)
124 #define setlinebuf(x) 0
128 #ifdef NEED_DECLARATION_SETLINEBUF
129 #define setlinebuf(x) 0
132 #ifdef NEED_DECLARATION_GETUSERSHELL
133 char *getusershell(void);
136 #ifdef NEED_DECLARATION_ENDUSERSHELL
137 void endusershell(void);
141 #define INADDR_ANY ((uint32_t) 0x00000000)
144 #ifndef INADDR_LOOPBACK
145 #define INADDR_LOOPBACK ((uint32_t) 0x7f000001) /* Inet 127.0.0.1 */
149 #define INADDR_NONE ((uint32_t) 0xffffffff)
156 #ifndef INET_ADDRSTRLEN
157 #define INET_ADDRSTRLEN 16
168 #ifndef HAVE_STRUCT_IN6_ADDR
172 uint8_t u6_addr8[16];
173 uint16_t u6_addr16[8];
174 uint32_t u6_addr32[4];
176 #define s6_addr in6_u.u6_addr8
177 #define s6_addr16 in6_u.u6_addr16
178 #define s6_addr32 in6_u.u6_addr32
185 #ifndef INET6_ADDRSTRLEN
186 #define INET6_ADDRSTRLEN 46
189 #ifndef IN6ADDR_ANY_INIT
190 #define IN6ADDR_ANY_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
193 #ifndef IN6ADDR_LOOPBACK_INIT
194 #define IN6ADDR_LOOPBACK_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
197 #ifndef IN6_IS_ADDR_UNSPECIFIED
198 #define IN6_IS_ADDR_UNSPECIFIED(a) \
199 (((__const uint32_t *) (a))[0] == 0 \
200 && ((__const uint32_t *) (a))[1] == 0 \
201 && ((__const uint32_t *) (a))[2] == 0 \
202 && ((__const uint32_t *) (a))[3] == 0)
205 #ifndef IN6_IS_ADDR_LOOPBACK
206 #define IN6_IS_ADDR_LOOPBACK(a) \
207 (((__const uint32_t *) (a))[0] == 0 \
208 && ((__const uint32_t *) (a))[1] == 0 \
209 && ((__const uint32_t *) (a))[2] == 0 \
210 && ((__const uint32_t *) (a))[3] == htonl (1))
213 #ifndef IN6_IS_ADDR_MULTICAST
214 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
217 #ifndef IN6_IS_ADDR_LINKLOCAL
218 #define IN6_IS_ADDR_LINKLOCAL(a) \
219 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
220 == htonl (0xfe800000))
223 #ifndef IN6_IS_ADDR_SITELOCAL
224 #define IN6_IS_ADDR_SITELOCAL(a) \
225 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
226 == htonl (0xfec00000))
229 #ifndef IN6_IS_ADDR_V4MAPPED
230 #define IN6_IS_ADDR_V4MAPPED(a) \
231 ((((__const uint32_t *) (a))[0] == 0) \
232 && (((__const uint32_t *) (a))[1] == 0) \
233 && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
236 #ifndef IN6_IS_ADDR_V4COMPAT
237 #define IN6_IS_ADDR_V4COMPAT(a) \
238 ((((__const uint32_t *) (a))[0] == 0) \
239 && (((__const uint32_t *) (a))[1] == 0) \
240 && (((__const uint32_t *) (a))[2] == 0) \
241 && (ntohl (((__const uint32_t *) (a))[3]) > 1))
244 #ifndef IN6_ARE_ADDR_EQUAL
245 #define IN6_ARE_ADDR_EQUAL(a,b) \
246 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
247 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
248 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
249 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
252 #endif /* HAVE_STRUCT_IN6_ADDR */
255 * Functions from getaddrinfo.c
258 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
259 struct sockaddr_storage
261 uint16_t ss_family; /* Address family, etc. */
262 char ss_padding[128 - (sizeof(uint16_t))];
264 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
266 #ifndef HAVE_STRUCT_ADDRINFO
268 /* for old netdb.h */
271 #define EAI_FAMILY 5 /* ai_family not supported */
272 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
273 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
276 /* dummy value for old netdb.h */
279 #define AI_CANONNAME 2
280 #define AI_NUMERICHOST 4
281 #define NI_NUMERICHOST 2
282 #define NI_NAMEREQD 4
283 #define NI_NUMERICSERV 8
287 int ai_flags; /* Input flags. */
288 int ai_family; /* Protocol family for socket. */
289 int ai_socktype; /* Socket type. */
290 int ai_protocol; /* Protocol for socket. */
291 socklen_t ai_addrlen; /* Length of socket address. */
292 struct sockaddr *ai_addr; /* Socket address for socket. */
293 char *ai_canonname; /* Canonical name for service location. */
294 struct addrinfo *ai_next; /* Pointer to next in list. */
297 #endif /* AI_PASSIVE */
299 #endif /* HAVE_STRUCT_ADDRINFO */
301 /* Translate name of a service location and/or a service name to set of
303 #ifndef HAVE_GETADDRINFO
304 extern int getaddrinfo (const char *__name,
305 const char *__service,
306 const struct addrinfo *__req,
307 struct addrinfo **__pai);
309 /* Free `addrinfo' structure AI including associated storage. */
310 extern void freeaddrinfo (struct addrinfo *__ai);
312 /* Convert error return from getaddrinfo() to a string. */
313 extern char *gai_strerror (int __ecode);
316 /* Translate a socket address to a location and service name. */
317 #ifndef HAVE_GETNAMEINFO
318 extern int getnameinfo (const struct sockaddr *__sa,
319 socklen_t __salen, char *__host,
320 size_t __hostlen, char *__serv,
321 size_t __servlen, unsigned int __flags);
325 * Functions from snprintf.c
328 #ifndef HAVE_VSNPRINTF
330 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
333 #ifndef HAVE_SNPRINTF
334 extern int snprintf(char *str, size_t count, const char *fmt, ...);
338 * Functions from strl{cat,cpy}.c
342 extern size_t strlcpy(char *dst, const char *src, size_t siz);
346 extern size_t strlcat(char *dst, const char *src, size_t siz);
353 #ifndef HAVE_GMTIME_R
354 struct tm *gmtime_r(const time_t *l_clock, struct tm *result);
357 #ifndef HAVE_GETTIMEOFDAY
358 int gettimeofday (struct timeval *tv, void *tz);
363 #define mkdir(_d, _p) mkdir(_d)
366 #endif /* _FR_MISSING_H */