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>
77 * Functions from missing.c
80 #ifndef HAVE_STRNCASECMP
81 extern int strncasecmp(char *s1, char *s2, int n);
84 #ifndef HAVE_STRCASECMP
85 extern int strcasecmp(char *s1, char *s2);
89 extern char *strsep(char **stringp, const char *delim);
92 #ifndef HAVE_LOCALTIME_R
94 struct tm *localtime_r(const time_t *l_clock, struct tm *result);
98 char *ctime_r(const time_t *l_clock, char *l_buf);
101 #ifdef NEED_DECLARATION_CRYPT
102 char *crypt(char *key, char *salt);
105 #ifdef NEED_DECLARATION_STRNCASECMP
106 int strncasecmp(char *s1, char *s2, int n);
109 #ifdef NEED_DECLARATION_STRCASECMP
110 int strcasecmp(char *s1, char *s2);
113 #ifdef NEED_DECLARATION_INET_ATON
115 int inet_aton(char *cp, struct in_addr *inp);
118 #ifdef NEED_DECLARATION_GETHOSTNAME
119 int gethostname(char *name, int len);
122 #ifndef HAVE_SETLINEBUF
124 #define setlinebuf(x) setvbuf(x, NULL, _IOLBF, 0)
126 #define setlinebuf(x) 0
130 #ifdef NEED_DECLARATION_SETLINEBUF
131 #define setlinebuf(x) 0
134 #ifdef NEED_DECLARATION_GETUSERSHELL
135 char *getusershell(void);
138 #ifdef NEED_DECLARATION_ENDUSERSHELL
139 void endusershell(void);
143 #define INADDR_ANY ((uint32_t) 0x00000000)
146 #ifndef INADDR_LOOPBACK
147 #define INADDR_LOOPBACK ((uint32_t) 0x7f000001) /* Inet 127.0.0.1 */
151 #define INADDR_NONE ((uint32_t) 0xffffffff)
158 #ifndef INET_ADDRSTRLEN
159 #define INET_ADDRSTRLEN 16
170 #ifndef HAVE_STRUCT_IN6_ADDR
174 uint8_t u6_addr8[16];
175 uint16_t u6_addr16[8];
176 uint32_t u6_addr32[4];
178 #define s6_addr in6_u.u6_addr8
179 #define s6_addr16 in6_u.u6_addr16
180 #define s6_addr32 in6_u.u6_addr32
187 #ifndef INET6_ADDRSTRLEN
188 #define INET6_ADDRSTRLEN 46
191 #ifndef IN6ADDR_ANY_INIT
192 #define IN6ADDR_ANY_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
195 #ifndef IN6ADDR_LOOPBACK_INIT
196 #define IN6ADDR_LOOPBACK_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
199 #ifndef IN6_IS_ADDR_UNSPECIFIED
200 #define IN6_IS_ADDR_UNSPECIFIED(a) \
201 (((__const uint32_t *) (a))[0] == 0 \
202 && ((__const uint32_t *) (a))[1] == 0 \
203 && ((__const uint32_t *) (a))[2] == 0 \
204 && ((__const uint32_t *) (a))[3] == 0)
207 #ifndef IN6_IS_ADDR_LOOPBACK
208 #define IN6_IS_ADDR_LOOPBACK(a) \
209 (((__const uint32_t *) (a))[0] == 0 \
210 && ((__const uint32_t *) (a))[1] == 0 \
211 && ((__const uint32_t *) (a))[2] == 0 \
212 && ((__const uint32_t *) (a))[3] == htonl (1))
215 #ifndef IN6_IS_ADDR_MULTICAST
216 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
219 #ifndef IN6_IS_ADDR_LINKLOCAL
220 #define IN6_IS_ADDR_LINKLOCAL(a) \
221 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
222 == htonl (0xfe800000))
225 #ifndef IN6_IS_ADDR_SITELOCAL
226 #define IN6_IS_ADDR_SITELOCAL(a) \
227 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
228 == htonl (0xfec00000))
231 #ifndef IN6_IS_ADDR_V4MAPPED
232 #define IN6_IS_ADDR_V4MAPPED(a) \
233 ((((__const uint32_t *) (a))[0] == 0) \
234 && (((__const uint32_t *) (a))[1] == 0) \
235 && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
238 #ifndef IN6_IS_ADDR_V4COMPAT
239 #define IN6_IS_ADDR_V4COMPAT(a) \
240 ((((__const uint32_t *) (a))[0] == 0) \
241 && (((__const uint32_t *) (a))[1] == 0) \
242 && (((__const uint32_t *) (a))[2] == 0) \
243 && (ntohl (((__const uint32_t *) (a))[3]) > 1))
246 #ifndef IN6_ARE_ADDR_EQUAL
247 #define IN6_ARE_ADDR_EQUAL(a,b) \
248 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
249 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
250 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
251 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
254 #endif /* HAVE_STRUCT_IN6_ADDR */
257 * Functions from getaddrinfo.c
260 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
261 struct sockaddr_storage
263 uint16_t ss_family; /* Address family, etc. */
264 char ss_padding[128 - (sizeof(uint16_t))];
266 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
268 #ifndef HAVE_STRUCT_ADDRINFO
270 /* for old netdb.h */
273 #define EAI_FAMILY 5 /* ai_family not supported */
274 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
275 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
278 /* dummy value for old netdb.h */
281 #define AI_CANONNAME 2
282 #define AI_NUMERICHOST 4
283 #define NI_NUMERICHOST 2
284 #define NI_NAMEREQD 4
285 #define NI_NUMERICSERV 8
289 int ai_flags; /* Input flags. */
290 int ai_family; /* Protocol family for socket. */
291 int ai_socktype; /* Socket type. */
292 int ai_protocol; /* Protocol for socket. */
293 socklen_t ai_addrlen; /* Length of socket address. */
294 struct sockaddr *ai_addr; /* Socket address for socket. */
295 char *ai_canonname; /* Canonical name for service location. */
296 struct addrinfo *ai_next; /* Pointer to next in list. */
299 #endif /* AI_PASSIVE */
301 #endif /* HAVE_STRUCT_ADDRINFO */
303 /* Translate name of a service location and/or a service name to set of
305 #ifndef HAVE_GETADDRINFO
306 extern int getaddrinfo (const char *__name,
307 const char *__service,
308 const struct addrinfo *__req,
309 struct addrinfo **__pai);
311 /* Free `addrinfo' structure AI including associated storage. */
312 extern void freeaddrinfo (struct addrinfo *__ai);
314 /* Convert error return from getaddrinfo() to a string. */
315 extern char *gai_strerror (int __ecode);
318 /* Translate a socket address to a location and service name. */
319 #ifndef HAVE_GETNAMEINFO
320 extern int getnameinfo (const struct sockaddr *__sa,
321 socklen_t __salen, char *__host,
322 socklen_t __hostlen, char *__serv,
323 socklen_t __servlen, unsigned int __flags);
327 * Functions from snprintf.c
330 #ifndef HAVE_VSNPRINTF
332 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
335 #ifndef HAVE_SNPRINTF
336 extern int snprintf(char *str, size_t count, const char *fmt, ...);
340 * Functions from strl{cat,cpy}.c
344 extern size_t strlcpy(char *dst, const char *src, size_t siz);
348 extern size_t strlcat(char *dst, const char *src, size_t siz);
351 #endif /* _FR_MISSING_H */