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 #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
166 #ifndef HAVE_STRUCT_IN6_ADDR
170 uint8_t u6_addr8[16];
171 uint16_t u6_addr16[8];
172 uint32_t u6_addr32[4];
174 #define s6_addr in6_u.u6_addr8
175 #define s6_addr16 in6_u.u6_addr16
176 #define s6_addr32 in6_u.u6_addr32
183 #ifndef INET6_ADDRSTRLEN
184 #define INET6_ADDRSTRLEN 46
187 #ifndef IN6ADDR_ANY_INIT
188 #define IN6ADDR_ANY_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
191 #ifndef IN6ADDR_LOOPBACK_INIT
192 #define IN6ADDR_LOOPBACK_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
195 #ifndef IN6_IS_ADDR_UNSPECIFIED
196 #define IN6_IS_ADDR_UNSPECIFIED(a) \
197 (((__const uint32_t *) (a))[0] == 0 \
198 && ((__const uint32_t *) (a))[1] == 0 \
199 && ((__const uint32_t *) (a))[2] == 0 \
200 && ((__const uint32_t *) (a))[3] == 0)
203 #ifndef IN6_IS_ADDR_LOOPBACK
204 #define IN6_IS_ADDR_LOOPBACK(a) \
205 (((__const uint32_t *) (a))[0] == 0 \
206 && ((__const uint32_t *) (a))[1] == 0 \
207 && ((__const uint32_t *) (a))[2] == 0 \
208 && ((__const uint32_t *) (a))[3] == htonl (1))
211 #ifndef IN6_IS_ADDR_MULTICAST
212 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
215 #ifndef IN6_IS_ADDR_LINKLOCAL
216 #define IN6_IS_ADDR_LINKLOCAL(a) \
217 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
218 == htonl (0xfe800000))
221 #ifndef IN6_IS_ADDR_SITELOCAL
222 #define IN6_IS_ADDR_SITELOCAL(a) \
223 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
224 == htonl (0xfec00000))
227 #ifndef IN6_IS_ADDR_V4MAPPED
228 #define IN6_IS_ADDR_V4MAPPED(a) \
229 ((((__const uint32_t *) (a))[0] == 0) \
230 && (((__const uint32_t *) (a))[1] == 0) \
231 && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
234 #ifndef IN6_IS_ADDR_V4COMPAT
235 #define IN6_IS_ADDR_V4COMPAT(a) \
236 ((((__const uint32_t *) (a))[0] == 0) \
237 && (((__const uint32_t *) (a))[1] == 0) \
238 && (((__const uint32_t *) (a))[2] == 0) \
239 && (ntohl (((__const uint32_t *) (a))[3]) > 1))
242 #ifndef IN6_ARE_ADDR_EQUAL
243 #define IN6_ARE_ADDR_EQUAL(a,b) \
244 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
245 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
246 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
247 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
250 #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 size_t __hostlen, char *__serv,
319 size_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);
351 #endif /* _FR_MISSING_H */