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>
53 #ifdef HAVE_SYS_SOCKET_H
54 #include <sys/socket.h>
61 #ifndef HAVE_VSNPRINTF
65 #ifdef HAVE_SYS_LOCKING_H
66 #include <sys/locking.h>
70 * Check for inclusion of <time.h>, versus <sys/time.h>
71 * Taken verbatim from the autoconf manual.
73 #if TIME_WITH_SYS_TIME
74 # include <sys/time.h>
77 # ifdef HAVE_SYS_TIME_H
78 # include <sys/time.h>
85 * Don't look for winsock.h if we're on cygwin.
103 * Functions from missing.c
106 #ifndef HAVE_STRNCASECMP
107 extern int strncasecmp(char *s1, char *s2, int n);
110 #ifndef HAVE_STRCASECMP
111 extern int strcasecmp(char *s1, char *s2);
115 extern char *strsep(char **stringp, const char *delim);
118 #ifndef HAVE_LOCALTIME_R
120 struct tm *localtime_r(const time_t *l_clock, struct tm *result);
124 char *ctime_r(const time_t *l_clock, char *l_buf);
127 #if defined(NEED_DECLARATION_CRYPT) || !defined(HAVE_CRYPT)
128 char *crypt(char *key, char *salt);
131 #ifdef NEED_DECLARATION_STRNCASECMP
132 int strncasecmp(char *s1, char *s2, int n);
135 #ifdef NEED_DECLARATION_STRCASECMP
136 int strcasecmp(char *s1, char *s2);
139 #if defined(NEED_DECLARATION_INET_ATON) || !defined(HAVE_INET_ATON)
141 int inet_aton(const char *cp, struct in_addr *inp);
144 #ifndef HAVE_SETLINEBUF
146 #define setlinebuf(x) setvbuf(x, NULL, _IOLBF, 0)
148 #define setlinebuf(x) 0
152 #ifdef NEED_DECLARATION_SETLINEBUF
153 #define setlinebuf(x) 0
156 #ifdef NEED_DECLARATION_GETUSERSHELL
157 char *getusershell(void);
160 #ifdef NEED_DECLARATION_ENDUSERSHELL
161 void endusershell(void);
165 #define INADDR_ANY ((uint32_t) 0x00000000)
168 #ifndef INADDR_LOOPBACK
169 #define INADDR_LOOPBACK ((uint32_t) 0x7f000001) /* Inet 127.0.0.1 */
173 #define INADDR_NONE ((uint32_t) 0xffffffff)
180 #ifndef INET_ADDRSTRLEN
181 #define INET_ADDRSTRLEN 16
192 #ifndef HAVE_STRUCT_IN6_ADDR
196 uint8_t u6_addr8[16];
197 uint16_t u6_addr16[8];
198 uint32_t u6_addr32[4];
200 #define s6_addr in6_u.u6_addr8
201 #define s6_addr16 in6_u.u6_addr16
202 #define s6_addr32 in6_u.u6_addr32
209 #ifndef INET6_ADDRSTRLEN
210 #define INET6_ADDRSTRLEN 46
213 #ifndef IN6ADDR_ANY_INIT
214 #define IN6ADDR_ANY_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
217 #ifndef IN6ADDR_LOOPBACK_INIT
218 #define IN6ADDR_LOOPBACK_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
221 #ifndef IN6_IS_ADDR_UNSPECIFIED
222 #define IN6_IS_ADDR_UNSPECIFIED(a) \
223 (((__const uint32_t *) (a))[0] == 0 \
224 && ((__const uint32_t *) (a))[1] == 0 \
225 && ((__const uint32_t *) (a))[2] == 0 \
226 && ((__const uint32_t *) (a))[3] == 0)
229 #ifndef IN6_IS_ADDR_LOOPBACK
230 #define IN6_IS_ADDR_LOOPBACK(a) \
231 (((__const uint32_t *) (a))[0] == 0 \
232 && ((__const uint32_t *) (a))[1] == 0 \
233 && ((__const uint32_t *) (a))[2] == 0 \
234 && ((__const uint32_t *) (a))[3] == htonl (1))
237 #ifndef IN6_IS_ADDR_MULTICAST
238 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
241 #ifndef IN6_IS_ADDR_LINKLOCAL
242 #define IN6_IS_ADDR_LINKLOCAL(a) \
243 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
244 == htonl (0xfe800000))
247 #ifndef IN6_IS_ADDR_SITELOCAL
248 #define IN6_IS_ADDR_SITELOCAL(a) \
249 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
250 == htonl (0xfec00000))
253 #ifndef IN6_IS_ADDR_V4MAPPED
254 #define IN6_IS_ADDR_V4MAPPED(a) \
255 ((((__const uint32_t *) (a))[0] == 0) \
256 && (((__const uint32_t *) (a))[1] == 0) \
257 && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
260 #ifndef IN6_IS_ADDR_V4COMPAT
261 #define IN6_IS_ADDR_V4COMPAT(a) \
262 ((((__const uint32_t *) (a))[0] == 0) \
263 && (((__const uint32_t *) (a))[1] == 0) \
264 && (((__const uint32_t *) (a))[2] == 0) \
265 && (ntohl (((__const uint32_t *) (a))[3]) > 1))
268 #ifndef IN6_ARE_ADDR_EQUAL
269 #define IN6_ARE_ADDR_EQUAL(a,b) \
270 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
271 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
272 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
273 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
276 #endif /* HAVE_STRUCT_IN6_ADDR */
279 * Functions from getaddrinfo.c
282 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
283 struct sockaddr_storage
285 uint16_t ss_family; /* Address family, etc. */
286 char ss_padding[128 - (sizeof(uint16_t))];
288 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
290 #ifndef HAVE_STRUCT_ADDRINFO
292 /* for old netdb.h */
295 #define EAI_FAMILY 5 /* ai_family not supported */
296 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
297 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
300 /* dummy value for old netdb.h */
303 #define AI_CANONNAME 2
304 #define AI_NUMERICHOST 4
305 #define NI_NUMERICHOST 2
306 #define NI_NAMEREQD 4
307 #define NI_NUMERICSERV 8
311 int ai_flags; /* Input flags. */
312 int ai_family; /* Protocol family for socket. */
313 int ai_socktype; /* Socket type. */
314 int ai_protocol; /* Protocol for socket. */
315 socklen_t ai_addrlen; /* Length of socket address. */
316 struct sockaddr *ai_addr; /* Socket address for socket. */
317 char *ai_canonname; /* Canonical name for service location. */
318 struct addrinfo *ai_next; /* Pointer to next in list. */
321 #endif /* AI_PASSIVE */
323 #endif /* HAVE_STRUCT_ADDRINFO */
325 /* Translate name of a service location and/or a service name to set of
327 #ifndef HAVE_GETADDRINFO
328 extern int getaddrinfo (const char *__name,
329 const char *__service,
330 const struct addrinfo *__req,
331 struct addrinfo **__pai);
333 /* Free `addrinfo' structure AI including associated storage. */
334 extern void freeaddrinfo (struct addrinfo *__ai);
336 /* Convert error return from getaddrinfo() to a string. */
337 extern const char *gai_strerror (int __ecode);
340 /* Translate a socket address to a location and service name. */
341 #ifndef HAVE_GETNAMEINFO
342 extern int getnameinfo (const struct sockaddr *__sa,
343 socklen_t __salen, char *__host,
344 size_t __hostlen, char *__serv,
345 size_t __servlen, unsigned int __flags);
349 * Functions from snprintf.c
352 #ifndef HAVE_VSNPRINTF
353 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
356 #ifndef HAVE_SNPRINTF
357 extern int snprintf(char *str, size_t count, const char *fmt, ...);
361 * Functions from strl{cat,cpy}.c
365 extern size_t strlcpy(char *dst, const char *src, size_t siz);
369 extern size_t strlcat(char *dst, const char *src, size_t siz);
376 #ifndef HAVE_GMTIME_R
377 struct tm *gmtime_r(const time_t *l_clock, struct tm *result);
380 #ifndef HAVE_GETTIMEOFDAY
381 int gettimeofday (struct timeval *tv, void *tz);
387 #define mkdir(_d, _p) mkdir(_d)
388 #define FR_DIR_SEP '\\'
389 #define FR_DIR_IS_RELATIVE(p) ((*p && (p[1] != ':')) || ((*p != '\\') && (*p != '\\')))
391 #define FR_DIR_SEP '/'
392 #define FR_DIR_IS_RELATIVE(p) ((*p) != '/')
395 #ifdef HAVE_SYS_LOCKING_H
396 #define lockf _locking
398 #define F_ULOCK _LK_UNLCK /* Unlock locked sections. */
399 #define F_LOCK _LK_LOCK /* Lock a section for exclusive use. */
400 #define F_TLOCK _LK_NBLCK /* Test and lock a section for exclusive use */
401 #define F_TEST _LK_RLCK /* Test section for locks by other processes. */
405 # define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
408 void timeval2ntp(const struct timeval *tv, uint8_t *ntp);
409 void ntp2timeval(struct timeval *tv, const char *ntp);
415 #endif /* _FR_MISSING_H */