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>
73 * Functions from missing.c
76 #ifndef HAVE_STRNCASECMP
77 extern int strncasecmp(char *s1, char *s2, int n);
80 #ifndef HAVE_STRCASECMP
81 extern int strcasecmp(char *s1, char *s2);
85 extern char *strsep(char **stringp, const char *delim);
88 #ifndef HAVE_LOCALTIME_R
90 struct tm *localtime_r(const time_t *l_clock, struct tm *result);
94 char *ctime_r(const time_t *l_clock, char *l_buf);
97 #ifdef NEED_DECLARATION_CRYPT
98 char *crypt(char *key, char *salt);
101 #ifdef NEED_DECLARATION_STRNCASECMP
102 int strncasecmp(char *s1, char *s2, int n);
105 #ifdef NEED_DECLARATION_STRCASECMP
106 int strcasecmp(char *s1, char *s2);
109 #ifdef NEED_DECLARATION_INET_ATON
111 int inet_aton(char *cp, struct in_addr *inp);
114 #ifdef NEED_DECLARATION_GETHOSTNAME
115 int gethostname(char *name, int len);
118 #ifndef HAVE_SETLINEBUF
120 #define setlinebuf(x) setvbuf(x, NULL, _IOLBF, 0)
122 #define setlinebuf(x) 0
126 #ifdef NEED_DECLARATION_SETLINEBUF
127 #define setlinebuf(x) 0
130 #ifdef NEED_DECLARATION_GETUSERSHELL
131 char *getusershell(void);
134 #ifdef NEED_DECLARATION_ENDUSERSHELL
135 void endusershell(void);
139 #define INADDR_ANY ((uint32_t) 0x00000000)
142 #ifndef INADDR_LOOPBACK
143 #define INADDR_LOOPBACK ((uint32_t) 0x7f000001) /* Inet 127.0.0.1 */
147 #define INADDR_NONE ((uint32_t) 0xffffffff)
154 #ifndef INET_ADDRSTRLEN
155 #define INET_ADDRSTRLEN 16
165 #ifndef HAVE_STRUCT_IN6_ADDR
169 uint8_t u6_addr8[16];
170 uint16_t u6_addr16[8];
171 uint32_t u6_addr32[4];
173 #define s6_addr in6_u.u6_addr8
174 #define s6_addr16 in6_u.u6_addr16
175 #define s6_addr32 in6_u.u6_addr32
182 #ifndef INET6_ADDRSTRLEN
183 #define INET6_ADDRSTRLEN 46
186 #ifndef IN6ADDR_ANY_INIT
187 #define IN6ADDR_ANY_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
190 #ifndef IN6ADDR_LOOPBACK_INIT
191 #define IN6ADDR_LOOPBACK_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
194 #ifndef IN6_IS_ADDR_UNSPECIFIED
195 #define IN6_IS_ADDR_UNSPECIFIED(a) \
196 (((__const uint32_t *) (a))[0] == 0 \
197 && ((__const uint32_t *) (a))[1] == 0 \
198 && ((__const uint32_t *) (a))[2] == 0 \
199 && ((__const uint32_t *) (a))[3] == 0)
202 #ifndef IN6_IS_ADDR_LOOPBACK
203 #define IN6_IS_ADDR_LOOPBACK(a) \
204 (((__const uint32_t *) (a))[0] == 0 \
205 && ((__const uint32_t *) (a))[1] == 0 \
206 && ((__const uint32_t *) (a))[2] == 0 \
207 && ((__const uint32_t *) (a))[3] == htonl (1))
210 #ifndef IN6_IS_ADDR_MULTICAST
211 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
214 #ifndef IN6_IS_ADDR_LINKLOCAL
215 #define IN6_IS_ADDR_LINKLOCAL(a) \
216 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
217 == htonl (0xfe800000))
220 #ifndef IN6_IS_ADDR_SITELOCAL
221 #define IN6_IS_ADDR_SITELOCAL(a) \
222 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
223 == htonl (0xfec00000))
226 #ifndef IN6_IS_ADDR_V4MAPPED
227 #define IN6_IS_ADDR_V4MAPPED(a) \
228 ((((__const uint32_t *) (a))[0] == 0) \
229 && (((__const uint32_t *) (a))[1] == 0) \
230 && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
233 #ifndef IN6_IS_ADDR_V4COMPAT
234 #define IN6_IS_ADDR_V4COMPAT(a) \
235 ((((__const uint32_t *) (a))[0] == 0) \
236 && (((__const uint32_t *) (a))[1] == 0) \
237 && (((__const uint32_t *) (a))[2] == 0) \
238 && (ntohl (((__const uint32_t *) (a))[3]) > 1))
241 #ifndef IN6_ARE_ADDR_EQUAL
242 #define IN6_ARE_ADDR_EQUAL(a,b) \
243 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
244 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
245 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
246 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
249 #endif /* HAVE_STRUCT_IN6_ADDR */
253 * Functions from getaddrinfo.c
256 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
257 struct sockaddr_storage
259 uint16_t ss_family; /* Address family, etc. */
260 char ss_padding[128 - (sizeof(uint16_t))];
262 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
264 #ifndef HAVE_STRUCT_ADDRINFO
266 /* for old netdb.h */
269 #define EAI_FAMILY 5 /* ai_family not supported */
270 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
271 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
274 /* dummy value for old netdb.h */
277 #define AI_CANONNAME 2
278 #define AI_NUMERICHOST 4
279 #define NI_NUMERICHOST 2
280 #define NI_NAMEREQD 4
281 #define NI_NUMERICSERV 8
285 int ai_flags; /* Input flags. */
286 int ai_family; /* Protocol family for socket. */
287 int ai_socktype; /* Socket type. */
288 int ai_protocol; /* Protocol for socket. */
289 socklen_t ai_addrlen; /* Length of socket address. */
290 struct sockaddr *ai_addr; /* Socket address for socket. */
291 char *ai_canonname; /* Canonical name for service location. */
292 struct addrinfo *ai_next; /* Pointer to next in list. */
295 #endif /* AI_PASSIVE */
297 #endif /* HAVE_STRUCT_ADDRINFO */
299 /* Translate name of a service location and/or a service name to set of
301 #ifndef HAVE_GETADDRINFO
302 extern int getaddrinfo (const char *__name,
303 const char *__service,
304 const struct addrinfo *__req,
305 struct addrinfo **__pai);
307 /* Free `addrinfo' structure AI including associated storage. */
308 extern void freeaddrinfo (struct addrinfo *__ai);
310 /* Convert error return from getaddrinfo() to a string. */
311 extern char *gai_strerror (int __ecode);
314 /* Translate a socket address to a location and service name. */
315 #ifndef HAVE_GETNAMEINFO
316 extern int getnameinfo (const struct sockaddr *__sa,
317 socklen_t __salen, char *__host,
318 socklen_t __hostlen, char *__serv,
319 socklen_t __servlen, unsigned int __flags);
323 * Functions from snprintf.c
326 #ifndef HAVE_VSNPRINTF
328 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
331 #ifndef HAVE_SNPRINTF
332 extern int snprintf(char *str, size_t count, const char *fmt, ...);
336 * Functions from strl{cat,cpy}.c
340 extern size_t strlcpy(char *dst, const char *src, size_t siz);
344 extern size_t strlcat(char *dst, const char *src, size_t siz);
347 #endif /* _FR_MISSING_H */