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>
62 * Check for inclusion of <time.h>, versus <sys/time.h>
63 * Taken verbatim from the autoconf manual.
65 #if TIME_WITH_SYS_TIME
66 # include <sys/time.h>
69 # ifdef HAVE_SYS_TIME_H
70 # include <sys/time.h>
77 * Don't look for winsock.h if we're on cygwin.
91 * Functions from missing.c
94 #ifndef HAVE_STRNCASECMP
95 extern int strncasecmp(char *s1, char *s2, int n);
98 #ifndef HAVE_STRCASECMP
99 extern int strcasecmp(char *s1, char *s2);
103 extern char *strsep(char **stringp, const char *delim);
106 #ifndef HAVE_LOCALTIME_R
108 struct tm *localtime_r(const time_t *l_clock, struct tm *result);
112 char *ctime_r(const time_t *l_clock, char *l_buf);
115 #if defined(NEED_DECLARATION_CRYPT) || !defined(HAVE_CRYPT)
116 char *crypt(char *key, char *salt);
119 #ifdef NEED_DECLARATION_STRNCASECMP
120 int strncasecmp(char *s1, char *s2, int n);
123 #ifdef NEED_DECLARATION_STRCASECMP
124 int strcasecmp(char *s1, char *s2);
127 #if defined(NEED_DECLARATION_INET_ATON) || !defined(HAVE_INET_ATON)
129 int inet_aton(const char *cp, struct in_addr *inp);
132 #ifndef HAVE_SETLINEBUF
134 #define setlinebuf(x) setvbuf(x, NULL, _IOLBF, 0)
136 #define setlinebuf(x) 0
140 #ifdef NEED_DECLARATION_SETLINEBUF
141 #define setlinebuf(x) 0
144 #ifdef NEED_DECLARATION_GETUSERSHELL
145 char *getusershell(void);
148 #ifdef NEED_DECLARATION_ENDUSERSHELL
149 void endusershell(void);
153 #define INADDR_ANY ((uint32_t) 0x00000000)
156 #ifndef INADDR_LOOPBACK
157 #define INADDR_LOOPBACK ((uint32_t) 0x7f000001) /* Inet 127.0.0.1 */
161 #define INADDR_NONE ((uint32_t) 0xffffffff)
168 #ifndef INET_ADDRSTRLEN
169 #define INET_ADDRSTRLEN 16
180 #ifndef HAVE_STRUCT_IN6_ADDR
184 uint8_t u6_addr8[16];
185 uint16_t u6_addr16[8];
186 uint32_t u6_addr32[4];
188 #define s6_addr in6_u.u6_addr8
189 #define s6_addr16 in6_u.u6_addr16
190 #define s6_addr32 in6_u.u6_addr32
197 #ifndef INET6_ADDRSTRLEN
198 #define INET6_ADDRSTRLEN 46
201 #ifndef IN6ADDR_ANY_INIT
202 #define IN6ADDR_ANY_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
205 #ifndef IN6ADDR_LOOPBACK_INIT
206 #define IN6ADDR_LOOPBACK_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
209 #ifndef IN6_IS_ADDR_UNSPECIFIED
210 #define IN6_IS_ADDR_UNSPECIFIED(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] == 0)
217 #ifndef IN6_IS_ADDR_LOOPBACK
218 #define IN6_IS_ADDR_LOOPBACK(a) \
219 (((__const uint32_t *) (a))[0] == 0 \
220 && ((__const uint32_t *) (a))[1] == 0 \
221 && ((__const uint32_t *) (a))[2] == 0 \
222 && ((__const uint32_t *) (a))[3] == htonl (1))
225 #ifndef IN6_IS_ADDR_MULTICAST
226 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
229 #ifndef IN6_IS_ADDR_LINKLOCAL
230 #define IN6_IS_ADDR_LINKLOCAL(a) \
231 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
232 == htonl (0xfe800000))
235 #ifndef IN6_IS_ADDR_SITELOCAL
236 #define IN6_IS_ADDR_SITELOCAL(a) \
237 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
238 == htonl (0xfec00000))
241 #ifndef IN6_IS_ADDR_V4MAPPED
242 #define IN6_IS_ADDR_V4MAPPED(a) \
243 ((((__const uint32_t *) (a))[0] == 0) \
244 && (((__const uint32_t *) (a))[1] == 0) \
245 && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
248 #ifndef IN6_IS_ADDR_V4COMPAT
249 #define IN6_IS_ADDR_V4COMPAT(a) \
250 ((((__const uint32_t *) (a))[0] == 0) \
251 && (((__const uint32_t *) (a))[1] == 0) \
252 && (((__const uint32_t *) (a))[2] == 0) \
253 && (ntohl (((__const uint32_t *) (a))[3]) > 1))
256 #ifndef IN6_ARE_ADDR_EQUAL
257 #define IN6_ARE_ADDR_EQUAL(a,b) \
258 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
259 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
260 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
261 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
264 #endif /* HAVE_STRUCT_IN6_ADDR */
267 * Functions from getaddrinfo.c
270 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
271 struct sockaddr_storage
273 uint16_t ss_family; /* Address family, etc. */
274 char ss_padding[128 - (sizeof(uint16_t))];
276 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
278 #ifndef HAVE_STRUCT_ADDRINFO
280 /* for old netdb.h */
283 #define EAI_FAMILY 5 /* ai_family not supported */
284 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
285 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
288 /* dummy value for old netdb.h */
291 #define AI_CANONNAME 2
292 #define AI_NUMERICHOST 4
293 #define NI_NUMERICHOST 2
294 #define NI_NAMEREQD 4
295 #define NI_NUMERICSERV 8
299 int ai_flags; /* Input flags. */
300 int ai_family; /* Protocol family for socket. */
301 int ai_socktype; /* Socket type. */
302 int ai_protocol; /* Protocol for socket. */
303 socklen_t ai_addrlen; /* Length of socket address. */
304 struct sockaddr *ai_addr; /* Socket address for socket. */
305 char *ai_canonname; /* Canonical name for service location. */
306 struct addrinfo *ai_next; /* Pointer to next in list. */
309 #endif /* AI_PASSIVE */
311 #endif /* HAVE_STRUCT_ADDRINFO */
313 /* Translate name of a service location and/or a service name to set of
315 #ifndef HAVE_GETADDRINFO
316 extern int getaddrinfo (const char *__name,
317 const char *__service,
318 const struct addrinfo *__req,
319 struct addrinfo **__pai);
321 /* Free `addrinfo' structure AI including associated storage. */
322 extern void freeaddrinfo (struct addrinfo *__ai);
324 /* Convert error return from getaddrinfo() to a string. */
325 extern const char *gai_strerror (int __ecode);
328 /* Translate a socket address to a location and service name. */
329 #ifndef HAVE_GETNAMEINFO
330 extern int getnameinfo (const struct sockaddr *__sa,
331 socklen_t __salen, char *__host,
332 size_t __hostlen, char *__serv,
333 size_t __servlen, unsigned int __flags);
337 * Functions from snprintf.c
340 #ifndef HAVE_VSNPRINTF
342 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
345 #ifndef HAVE_SNPRINTF
346 extern int snprintf(char *str, size_t count, const char *fmt, ...);
350 * Functions from strl{cat,cpy}.c
354 extern size_t strlcpy(char *dst, const char *src, size_t siz);
358 extern size_t strlcat(char *dst, const char *src, size_t siz);
365 #ifndef HAVE_GMTIME_R
366 struct tm *gmtime_r(const time_t *l_clock, struct tm *result);
369 #ifndef HAVE_GETTIMEOFDAY
370 int gettimeofday (struct timeval *tv, void *tz);
376 #define mkdir(_d, _p) mkdir(_d)
377 #define FR_DIR_SEP '\\'
378 #define FR_DIR_IS_RELATIVE(p) ((*p && (p[1] != ':')) || ((*p != '\\') && (*p != '\\')))
380 #define FR_DIR_SEP '/'
381 #define FR_DIR_IS_RELATIVE(p) ((*p) != '/')
384 #ifdef HAVE_SYS_LOCKING_H
385 #include <sys/locking.h>
387 #define lockf _locking
389 #define F_ULOCK _LK_UNLCK /* Unlock locked sections. */
390 #define F_LOCK _LK_LOCK /* Lock a section for exclusive use. */
391 #define F_TLOCK _LK_NBLCK /* Test and lock a section for exclusive use */
392 #define F_TEST _LK_RLCK /* Test section for locks by other processes. */
396 # define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
399 void timeval2ntp(const struct timeval *tv, uint8_t *ntp);
400 void ntp2timeval(struct timeval *tv, const char *ntp);
402 #endif /* _FR_MISSING_H */