2 * Replacement implementation of getaddrinfo.
4 * This is an implementation of the getaddrinfo family of functions for
5 * systems that lack it, so that code can use getaddrinfo always. It provides
6 * IPv4 support only; for IPv6 support, a native getaddrinfo implemenation is
9 * The canonical version of this file is maintained in the rra-c-util package,
10 * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
12 * Written by Russ Allbery <rra@stanford.edu>
14 * The authors hereby relinquish any claim to any copyright that they may have
15 * in this work, whether granted under contract or by operation of law or
16 * international treaty, and hereby commit to the public, at large, that they
17 * shall not, at any time in the future, seek to enforce any copyright in this
18 * work against any person or entity, or prevent any person or entity from
19 * copying, publishing, distributing or creating derivative works of this
23 #ifndef _COMPAT_GETADDRINFO_H
24 #define _COMPAT_GETADDRINFO_H
28 /* Skip this entire file if a system getaddrinfo was detected. */
29 #ifndef HAVE_GETADDRINFO
31 /* OpenBSD likes to have sys/types.h included before sys/socket.h. */
32 #include <sys/types.h>
33 #include <sys/socket.h>
35 /* The struct returned by getaddrinfo, from RFC 3493. */
37 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, .. */
38 int ai_family; /* AF_xxx */
39 int ai_socktype; /* SOCK_xxx */
40 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
41 socklen_t ai_addrlen; /* Length of ai_addr */
42 char *ai_canonname; /* Canonical name for nodename */
43 struct sockaddr *ai_addr; /* Binary address */
44 struct addrinfo *ai_next; /* Next structure in linked list */
47 /* Constants for ai_flags from RFC 3493, combined with binary or. */
48 #define AI_PASSIVE 0x0001
49 #define AI_CANONNAME 0x0002
50 #define AI_NUMERICHOST 0x0004
51 #define AI_NUMERICSERV 0x0008
52 #define AI_V4MAPPED 0x0010
54 #define AI_ADDRCONFIG 0x0040
56 /* Error return codes from RFC 3493. */
57 #define EAI_AGAIN 1 /* Temporary name resolution failure */
58 #define EAI_BADFLAGS 2 /* Invalid value in ai_flags parameter */
59 #define EAI_FAIL 3 /* Permanent name resolution failure */
60 #define EAI_FAMILY 4 /* Address family not recognized */
61 #define EAI_MEMORY 5 /* Memory allocation failure */
62 #define EAI_NONAME 6 /* nodename or servname unknown */
63 #define EAI_SERVICE 7 /* Service not recognized for socket type */
64 #define EAI_SOCKTYPE 8 /* Socket type not recognized */
65 #define EAI_SYSTEM 9 /* System error occurred, see errno */
66 #define EAI_OVERFLOW 10 /* An argument buffer overflowed */
68 /* Function prototypes. */
69 int getaddrinfo(const char *nodename, const char *servname,
70 const struct addrinfo *hints, struct addrinfo **res);
71 void freeaddrinfo(struct addrinfo *ai);
72 const char *gai_strerror(int ecode);
74 #endif /* !HAVE_GETADDRINFO */
75 #endif /* _COMPAT_GETADDRINFO_H */