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.
86 * Functions from missing.c
89 #ifndef HAVE_STRNCASECMP
90 extern int strncasecmp(char *s1, char *s2, int n);
93 #ifndef HAVE_STRCASECMP
94 extern int strcasecmp(char *s1, char *s2);
98 extern char *strsep(char **stringp, const char *delim);
101 #ifndef HAVE_LOCALTIME_R
103 struct tm *localtime_r(const time_t *l_clock, struct tm *result);
107 char *ctime_r(const time_t *l_clock, char *l_buf);
110 #ifdef NEED_DECLARATION_CRYPT
111 char *crypt(char *key, char *salt);
114 #ifdef NEED_DECLARATION_STRNCASECMP
115 int strncasecmp(char *s1, char *s2, int n);
118 #ifdef NEED_DECLARATION_STRCASECMP
119 int strcasecmp(char *s1, char *s2);
122 #ifdef NEED_DECLARATION_INET_ATON
124 int inet_aton(char *cp, struct in_addr *inp);
127 #ifndef HAVE_SETLINEBUF
129 #define setlinebuf(x) setvbuf(x, NULL, _IOLBF, 0)
131 #define setlinebuf(x) 0
135 #ifdef NEED_DECLARATION_SETLINEBUF
136 #define setlinebuf(x) 0
139 #ifdef NEED_DECLARATION_GETUSERSHELL
140 char *getusershell(void);
143 #ifdef NEED_DECLARATION_ENDUSERSHELL
144 void endusershell(void);
148 #define INADDR_ANY ((uint32_t) 0x00000000)
151 #ifndef INADDR_LOOPBACK
152 #define INADDR_LOOPBACK ((uint32_t) 0x7f000001) /* Inet 127.0.0.1 */
156 #define INADDR_NONE ((uint32_t) 0xffffffff)
163 #ifndef INET_ADDRSTRLEN
164 #define INET_ADDRSTRLEN 16
175 #ifndef HAVE_STRUCT_IN6_ADDR
179 uint8_t u6_addr8[16];
180 uint16_t u6_addr16[8];
181 uint32_t u6_addr32[4];
183 #define s6_addr in6_u.u6_addr8
184 #define s6_addr16 in6_u.u6_addr16
185 #define s6_addr32 in6_u.u6_addr32
192 #ifndef INET6_ADDRSTRLEN
193 #define INET6_ADDRSTRLEN 46
196 #ifndef IN6ADDR_ANY_INIT
197 #define IN6ADDR_ANY_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
200 #ifndef IN6ADDR_LOOPBACK_INIT
201 #define IN6ADDR_LOOPBACK_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
204 #ifndef IN6_IS_ADDR_UNSPECIFIED
205 #define IN6_IS_ADDR_UNSPECIFIED(a) \
206 (((__const uint32_t *) (a))[0] == 0 \
207 && ((__const uint32_t *) (a))[1] == 0 \
208 && ((__const uint32_t *) (a))[2] == 0 \
209 && ((__const uint32_t *) (a))[3] == 0)
212 #ifndef IN6_IS_ADDR_LOOPBACK
213 #define IN6_IS_ADDR_LOOPBACK(a) \
214 (((__const uint32_t *) (a))[0] == 0 \
215 && ((__const uint32_t *) (a))[1] == 0 \
216 && ((__const uint32_t *) (a))[2] == 0 \
217 && ((__const uint32_t *) (a))[3] == htonl (1))
220 #ifndef IN6_IS_ADDR_MULTICAST
221 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
224 #ifndef IN6_IS_ADDR_LINKLOCAL
225 #define IN6_IS_ADDR_LINKLOCAL(a) \
226 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
227 == htonl (0xfe800000))
230 #ifndef IN6_IS_ADDR_SITELOCAL
231 #define IN6_IS_ADDR_SITELOCAL(a) \
232 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
233 == htonl (0xfec00000))
236 #ifndef IN6_IS_ADDR_V4MAPPED
237 #define IN6_IS_ADDR_V4MAPPED(a) \
238 ((((__const uint32_t *) (a))[0] == 0) \
239 && (((__const uint32_t *) (a))[1] == 0) \
240 && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
243 #ifndef IN6_IS_ADDR_V4COMPAT
244 #define IN6_IS_ADDR_V4COMPAT(a) \
245 ((((__const uint32_t *) (a))[0] == 0) \
246 && (((__const uint32_t *) (a))[1] == 0) \
247 && (((__const uint32_t *) (a))[2] == 0) \
248 && (ntohl (((__const uint32_t *) (a))[3]) > 1))
251 #ifndef IN6_ARE_ADDR_EQUAL
252 #define IN6_ARE_ADDR_EQUAL(a,b) \
253 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
254 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
255 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
256 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
259 #endif /* HAVE_STRUCT_IN6_ADDR */
262 * Functions from getaddrinfo.c
265 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
266 struct sockaddr_storage
268 uint16_t ss_family; /* Address family, etc. */
269 char ss_padding[128 - (sizeof(uint16_t))];
271 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
273 #ifndef HAVE_STRUCT_ADDRINFO
275 /* for old netdb.h */
278 #define EAI_FAMILY 5 /* ai_family not supported */
279 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
280 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
283 /* dummy value for old netdb.h */
286 #define AI_CANONNAME 2
287 #define AI_NUMERICHOST 4
288 #define NI_NUMERICHOST 2
289 #define NI_NAMEREQD 4
290 #define NI_NUMERICSERV 8
294 int ai_flags; /* Input flags. */
295 int ai_family; /* Protocol family for socket. */
296 int ai_socktype; /* Socket type. */
297 int ai_protocol; /* Protocol for socket. */
298 socklen_t ai_addrlen; /* Length of socket address. */
299 struct sockaddr *ai_addr; /* Socket address for socket. */
300 char *ai_canonname; /* Canonical name for service location. */
301 struct addrinfo *ai_next; /* Pointer to next in list. */
304 #endif /* AI_PASSIVE */
306 #endif /* HAVE_STRUCT_ADDRINFO */
308 /* Translate name of a service location and/or a service name to set of
310 #ifndef HAVE_GETADDRINFO
311 extern int getaddrinfo (const char *__name,
312 const char *__service,
313 const struct addrinfo *__req,
314 struct addrinfo **__pai);
316 /* Free `addrinfo' structure AI including associated storage. */
317 extern void freeaddrinfo (struct addrinfo *__ai);
319 /* Convert error return from getaddrinfo() to a string. */
320 extern char *gai_strerror (int __ecode);
323 /* Translate a socket address to a location and service name. */
324 #ifndef HAVE_GETNAMEINFO
325 extern int getnameinfo (const struct sockaddr *__sa,
326 socklen_t __salen, char *__host,
327 size_t __hostlen, char *__serv,
328 size_t __servlen, unsigned int __flags);
332 * Functions from snprintf.c
335 #ifndef HAVE_VSNPRINTF
337 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
340 #ifndef HAVE_SNPRINTF
341 extern int snprintf(char *str, size_t count, const char *fmt, ...);
345 * Functions from strl{cat,cpy}.c
349 extern size_t strlcpy(char *dst, const char *src, size_t siz);
353 extern size_t strlcat(char *dst, const char *src, size_t siz);
360 #ifndef HAVE_GMTIME_R
361 struct tm *gmtime_r(const time_t *l_clock, struct tm *result);
364 #ifndef HAVE_GETTIMEOFDAY
365 int gettimeofday (struct timeval *tv, void *tz);
370 #define mkdir(_d, _p) mkdir(_d)
373 #endif /* _FR_MISSING_H */