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$")
19 #ifdef HAVE_SYS_TYPES_H
20 #include <sys/types.h>
24 * Functions from missing.c
27 #ifndef HAVE_STRNCASECMP
28 extern int strncasecmp(char *s1, char *s2, int n);
31 #ifndef HAVE_STRCASECMP
32 extern int strcasecmp(char *s1, char *s2);
36 extern char *strsep(char **stringp, const char *delim);
39 #ifndef HAVE_LOCALTIME_R
41 struct tm *localtime_r(const time_t *l_clock, struct tm *result);
45 char *ctime_r(const time_t *l_clock, char *l_buf);
48 #ifdef NEED_DECLARATION_CRYPT
49 char *crypt(char *key, char *salt);
52 #ifdef NEED_DECLARATION_STRNCASECMP
53 int strncasecmp(char *s1, char *s2, int n);
56 #ifdef NEED_DECLARATION_STRCASECMP
57 int strcasecmp(char *s1, char *s2);
60 #ifdef NEED_DECLARATION_INET_ATON
62 int inet_aton(char *cp, struct in_addr *inp);
65 #ifdef NEED_DECLARATION_GETHOSTNAME
66 int gethostname(char *name, int len);
69 #ifndef HAVE_SETLINEBUF
71 #define setlinebuf(x) setvbuf(x, NULL, _IOLBF, 0)
73 #define setlinebuf(x) 0
77 #ifdef NEED_DECLARATION_SETLINEBUF
78 #define setlinebuf(x) 0
81 #ifdef NEED_DECLARATION_GETUSERSHELL
82 char *getusershell(void);
85 #ifdef NEED_DECLARATION_ENDUSERSHELL
86 void endusershell(void);
90 #define INADDR_ANY ((uint32_t) 0x00000000)
93 #ifndef INADDR_LOOPBACK
94 #define INADDR_LOOPBACK ((uint32_t) 0x7f000001) /* Inet 127.0.0.1 */
98 #define INADDR_NONE ((uint32_t) 0xffffffff)
105 #ifndef INET_ADDRSTRLEN
106 #define INET_ADDRSTRLEN 16
116 #ifndef HAVE_STRUCT_IN6_ADDR
120 uint8_t u6_addr8[16];
121 uint16_t u6_addr16[8];
122 uint32_t u6_addr32[4];
124 #define s6_addr in6_u.u6_addr8
125 #define s6_addr16 in6_u.u6_addr16
126 #define s6_addr32 in6_u.u6_addr32
133 #ifndef INET6_ADDRSTRLEN
134 #define INET6_ADDRSTRLEN 46
137 #ifndef IN6ADDR_ANY_INIT
138 #define IN6ADDR_ANY_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
141 #ifndef IN6ADDR_LOOPBACK_INIT
142 #define IN6ADDR_LOOPBACK_INIT {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
145 #ifndef IN6_IS_ADDR_UNSPECIFIED
146 #define IN6_IS_ADDR_UNSPECIFIED(a) \
147 (((__const uint32_t *) (a))[0] == 0 \
148 && ((__const uint32_t *) (a))[1] == 0 \
149 && ((__const uint32_t *) (a))[2] == 0 \
150 && ((__const uint32_t *) (a))[3] == 0)
153 #ifndef IN6_IS_ADDR_LOOPBACK
154 #define IN6_IS_ADDR_LOOPBACK(a) \
155 (((__const uint32_t *) (a))[0] == 0 \
156 && ((__const uint32_t *) (a))[1] == 0 \
157 && ((__const uint32_t *) (a))[2] == 0 \
158 && ((__const uint32_t *) (a))[3] == htonl (1))
161 #ifndef IN6_IS_ADDR_MULTICAST
162 #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
165 #ifndef IN6_IS_ADDR_LINKLOCAL
166 #define IN6_IS_ADDR_LINKLOCAL(a) \
167 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
168 == htonl (0xfe800000))
171 #ifndef IN6_IS_ADDR_SITELOCAL
172 #define IN6_IS_ADDR_SITELOCAL(a) \
173 ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \
174 == htonl (0xfec00000))
177 #ifndef IN6_IS_ADDR_V4MAPPED
178 #define IN6_IS_ADDR_V4MAPPED(a) \
179 ((((__const uint32_t *) (a))[0] == 0) \
180 && (((__const uint32_t *) (a))[1] == 0) \
181 && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
184 #ifndef IN6_IS_ADDR_V4COMPAT
185 #define IN6_IS_ADDR_V4COMPAT(a) \
186 ((((__const uint32_t *) (a))[0] == 0) \
187 && (((__const uint32_t *) (a))[1] == 0) \
188 && (((__const uint32_t *) (a))[2] == 0) \
189 && (ntohl (((__const uint32_t *) (a))[3]) > 1))
192 #ifndef IN6_ARE_ADDR_EQUAL
193 #define IN6_ARE_ADDR_EQUAL(a,b) \
194 ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
195 && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
196 && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
197 && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
200 #endif /* HAVE_STRUCT_IN6_ADDR */
204 * Functions from getaddrinfo.c
207 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
208 struct sockaddr_storage
210 uint16_t ss_family; /* Address family, etc. */
211 char ss_padding[128 - (sizeof(uint16_t))];
213 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
215 #ifndef HAVE_STRUCT_ADDRINFO
217 /* for old netdb.h */
220 #define EAI_FAMILY 5 /* ai_family not supported */
221 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
222 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
225 /* dummy value for old netdb.h */
228 #define AI_CANONNAME 2
229 #define AI_NUMERICHOST 4
230 #define NI_NUMERICHOST 2
231 #define NI_NAMEREQD 4
232 #define NI_NUMERICSERV 8
236 int ai_flags; /* Input flags. */
237 int ai_family; /* Protocol family for socket. */
238 int ai_socktype; /* Socket type. */
239 int ai_protocol; /* Protocol for socket. */
240 socklen_t ai_addrlen; /* Length of socket address. */
241 struct sockaddr *ai_addr; /* Socket address for socket. */
242 char *ai_canonname; /* Canonical name for service location. */
243 struct addrinfo *ai_next; /* Pointer to next in list. */
246 #endif /* AI_PASSIVE */
248 #endif /* HAVE_STRUCT_ADDRINFO */
250 /* Translate name of a service location and/or a service name to set of
252 #ifndef HAVE_GETADDRINFO
253 extern int getaddrinfo (const char *__name,
254 const char *__service,
255 const struct addrinfo *__req,
256 struct addrinfo **__pai);
258 /* Free `addrinfo' structure AI including associated storage. */
259 extern void freeaddrinfo (struct addrinfo *__ai);
261 /* Convert error return from getaddrinfo() to a string. */
262 extern char *gai_strerror (int __ecode);
265 /* Translate a socket address to a location and service name. */
266 #ifndef HAVE_GETNAMEINFO
267 extern int getnameinfo (const struct sockaddr *__sa,
268 socklen_t __salen, char *__host,
269 socklen_t __hostlen, char *__serv,
270 socklen_t __servlen, unsigned int __flags);
274 * Functions from snprintf.c
277 #ifndef HAVE_VSNPRINTF
279 extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
282 #ifndef HAVE_SNPRINTF
283 extern int snprintf(char *str, size_t count, const char *fmt, ...);
287 * Functions from strl{cat,cpy}.c
291 extern size_t strlcpy(char *dst, const char *src, size_t siz);
295 extern size_t strlcat(char *dst, const char *src, size_t siz);
298 #endif /* _FR_MISSING_H */