/*1* Replacement implementation of getaddrinfo.2*3* This is an implementation of the getaddrinfo family of functions for4* systems that lack it, so that code can use getaddrinfo always. It provides5* IPv4 support only; for IPv6 support, a system getaddrinfo implementation is6* required.7*8* The canonical version of this file is maintained in the rra-c-util package,9* which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.10*11* Written by Russ Allbery <[email protected]>12*13* The authors hereby relinquish any claim to any copyright that they may have14* in this work, whether granted under contract or by operation of law or15* international treaty, and hereby commit to the public, at large, that they16* shall not, at any time in the future, seek to enforce any copyright in this17* work against any person or entity, or prevent any person or entity from18* copying, publishing, distributing or creating derivative works of this19* work.20*/2122#ifndef COMPAT_GETADDRINFO_H23#define COMPAT_GETADDRINFO_H2425#include <config.h>2627/* Skip this entire file if a system getaddrinfo was detected. */28#ifndef HAVE_GETADDRINFO2930/* OpenBSD likes to have sys/types.h included before sys/socket.h. */31#include <sys/types.h>32#include <sys/socket.h>3334/* The struct returned by getaddrinfo, from RFC 3493. */35struct addrinfo {36int ai_flags; /* AI_PASSIVE, AI_CANONNAME, .. */37int ai_family; /* AF_xxx */38int ai_socktype; /* SOCK_xxx */39int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */40socklen_t ai_addrlen; /* Length of ai_addr */41char *ai_canonname; /* Canonical name for nodename */42struct sockaddr *ai_addr; /* Binary address */43struct addrinfo *ai_next; /* Next structure in linked list */44};4546/* Constants for ai_flags from RFC 3493, combined with binary or. */47#define AI_PASSIVE 0x000148#define AI_CANONNAME 0x000249#define AI_NUMERICHOST 0x000450#define AI_NUMERICSERV 0x000851#define AI_V4MAPPED 0x001052#define AI_ALL 0x002053#define AI_ADDRCONFIG 0x00405455/* Error return codes from RFC 3493. */56#define EAI_AGAIN 1 /* Temporary name resolution failure */57#define EAI_BADFLAGS 2 /* Invalid value in ai_flags parameter */58#define EAI_FAIL 3 /* Permanent name resolution failure */59#define EAI_FAMILY 4 /* Address family not recognized */60#define EAI_MEMORY 5 /* Memory allocation failure */61#define EAI_NONAME 6 /* nodename or servname unknown */62#define EAI_SERVICE 7 /* Service not recognized for socket type */63#define EAI_SOCKTYPE 8 /* Socket type not recognized */64#define EAI_SYSTEM 9 /* System error occurred, see errno */65#define EAI_OVERFLOW 10 /* An argument buffer overflowed */6667/* Function prototypes. */68sudo_dso_public int sudo_getaddrinfo(const char *nodename, const char *servname,69const struct addrinfo *hints, struct addrinfo **res);70sudo_dso_public void sudo_freeaddrinfo(struct addrinfo *ai);71sudo_dso_public const char *sudo_gai_strerror(int ecode);7273/* Map sudo_* to RFC 3493 names. */74#undef getaddrinfo75#define getaddrinfo(_a, _b, _c, _d) sudo_getaddrinfo((_a), (_b), (_c), (_d))76#undef freeaddrinfo77#define freeaddrinfo(_a) sudo_freeaddrinfo((_a))78#undef gai_strerror79#define gai_strerror(_a) sudo_gai_strerror((_a))8081#endif /* !HAVE_GETADDRINFO */82#endif /* COMPAT_GETADDRINFO_H */838485