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>
83 * Functions from missing.c
86 #ifndef HAVE_STRNCASECMP
87 extern int strncasecmp(char *s1, char *s2, int n);
90 #ifndef HAVE_STRCASECMP
91 extern int strcasecmp(char *s1, char *s2);
95 extern char *strsep(char **stringp, const char *delim);
98 #ifndef HAVE_LOCALTIME_R
100 struct tm *localtime_r(const time_t *l_clock, struct tm *result);
104 char *ctime_r(const time_t *l_clock, char *l_buf);
107 #ifdef NEED_DECLARATION_CRYPT
108 char *crypt(char *key, char *salt);
111 #ifdef NEED_DECLARATION_STRNCASECMP
112 int strncasecmp(char *s1, char *s2, int n);
115 #ifdef NEED_DECLARATION_STRCASECMP
116 int strcasecmp(char *s1, char *s2);
119 #ifdef NEED_DECLARATION_INET_ATON
121 int inet_aton(char *cp, struct in_addr *inp);
124 #ifndef HAVE_SETLINEBUF
126 #define setlinebuf(x) setvbuf(x, NULL, _IOLBF, 0)
128 #define setlinebuf(x) 0
132 #ifdef NEED_DECLARATION_SETLINEBUF
133 #define setlinebuf(x) 0
136 #ifdef NEED_DECLARATION_GETUSERSHELL
137 char *getusershell(void);
140 #ifdef NEED_DECLARATION_ENDUSERSHELL
141 void endusershell(void);
145 #define INADDR_ANY ((uint32_t) 0x00000000)
148 #ifndef INADDR_LOOPBACK
149 #define INADDR_LOOPBACK ((uint32_t) 0x7f000001) /* Inet 127.0.0.1 */
153 #define INADDR_NONE ((uint32_t) 0xffffffff)
160 #ifndef INET_ADDRSTRLEN
161 #define INET_ADDRSTRLEN 16
172 #ifndef HAVE_STRUCT_IN6_ADDR
176 uint8_t u6_addr8[16];
177 uint16_t u6_addr16[8];
178 uint32_t u6_addr32[4];
180 #define s6_addr in6_u.u6_addr8
181 #define s6_addr16 in6_u.u6_addr16
182 #define s6_addr32 in6_u.u6_addr32
189 #ifndef INET6_ADDRSTRLEN
190 #define INET6_ADDRSTRLEN 46
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 }}}
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 }}}
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)
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))
217 #ifndef IN6_IS_ADDR_MULTICAST
218 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
221 #ifndef IN6_IS_ADDR_LINKLOCAL
222 #define IN6_IS_ADDR_LINKLOCAL(a) \
223 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
224 == htonl (0xfe800000))
227 #ifndef IN6_IS_ADDR_SITELOCAL
228 #define IN6_IS_ADDR_SITELOCAL(a) \
229 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
230 == htonl (0xfec00000))
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)))
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))
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]))
256 #endif /* HAVE_STRUCT_IN6_ADDR */
259 * Functions from getaddrinfo.c
262 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
263 struct sockaddr_storage
265 uint16_t ss_family; /* Address family, etc. */
266 char ss_padding[128 - (sizeof(uint16_t))];
268 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
270 #ifndef HAVE_STRUCT_ADDRINFO
272 /* for old netdb.h */
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 */
280 /* dummy value for old netdb.h */
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
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. */
301 #endif /* AI_PASSIVE */
303 #endif /* HAVE_STRUCT_ADDRINFO */
305 /* Translate name of a service location and/or a service name to set of
307 #ifndef HAVE_GETADDRINFO
308 extern int getaddrinfo (const char *__name,
309 const char *__service,
310 const struct addrinfo *__req,
311 struct addrinfo **__pai);
313 /* Free `addrinfo' structure AI including associated storage. */
314 extern void freeaddrinfo (struct addrinfo *__ai);
316 /* Convert error return from getaddrinfo() to a string. */
317 extern char *gai_strerror (int __ecode);
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);
329 * Functions from snprintf.c
332 #ifndef HAVE_VSNPRINTF
334 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
337 #ifndef HAVE_SNPRINTF
338 extern int snprintf(char *str, size_t count, const char *fmt, ...);
342 * Functions from strl{cat,cpy}.c
346 extern size_t strlcpy(char *dst, const char *src, size_t siz);
350 extern size_t strlcat(char *dst, const char *src, size_t siz);
357 #ifndef HAVE_GMTIME_R
358 struct tm *gmtime_r(const time_t *l_clock, struct tm *result);
361 #ifndef HAVE_GETTIMEOFDAY
362 int gettimeofday (struct timeval *tv, void *tz);
367 #define mkdir(_d, _p) mkdir(_d)
370 #endif /* _FR_MISSING_H */