1*b636d99dSDavid van Moolenbroek /* 2*b636d99dSDavid van Moolenbroek * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 3*b636d99dSDavid van Moolenbroek * All rights reserved. 4*b636d99dSDavid van Moolenbroek * 5*b636d99dSDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without 6*b636d99dSDavid van Moolenbroek * modification, are permitted provided that the following conditions 7*b636d99dSDavid van Moolenbroek * are met: 8*b636d99dSDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright 9*b636d99dSDavid van Moolenbroek * notice, this list of conditions and the following disclaimer. 10*b636d99dSDavid van Moolenbroek * 2. Redistributions in binary form must reproduce the above copyright 11*b636d99dSDavid van Moolenbroek * notice, this list of conditions and the following disclaimer in the 12*b636d99dSDavid van Moolenbroek * documentation and/or other materials provided with the distribution. 13*b636d99dSDavid van Moolenbroek * 3. Neither the name of the project nor the names of its contributors 14*b636d99dSDavid van Moolenbroek * may be used to endorse or promote products derived from this software 15*b636d99dSDavid van Moolenbroek * without specific prior written permission. 16*b636d99dSDavid van Moolenbroek * 17*b636d99dSDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18*b636d99dSDavid van Moolenbroek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*b636d99dSDavid van Moolenbroek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*b636d99dSDavid van Moolenbroek * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21*b636d99dSDavid van Moolenbroek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22*b636d99dSDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23*b636d99dSDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24*b636d99dSDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25*b636d99dSDavid van Moolenbroek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26*b636d99dSDavid van Moolenbroek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27*b636d99dSDavid van Moolenbroek * SUCH DAMAGE. 28*b636d99dSDavid van Moolenbroek */ 29*b636d99dSDavid van Moolenbroek 30*b636d99dSDavid van Moolenbroek #ifndef HAVE_ADDRINFO 31*b636d99dSDavid van Moolenbroek 32*b636d99dSDavid van Moolenbroek /* 33*b636d99dSDavid van Moolenbroek * Error return codes from getaddrinfo() 34*b636d99dSDavid van Moolenbroek */ 35*b636d99dSDavid van Moolenbroek #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 36*b636d99dSDavid van Moolenbroek #define EAI_AGAIN 2 /* temporary failure in name resolution */ 37*b636d99dSDavid van Moolenbroek #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 38*b636d99dSDavid van Moolenbroek #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 39*b636d99dSDavid van Moolenbroek #define EAI_FAMILY 5 /* ai_family not supported */ 40*b636d99dSDavid van Moolenbroek #define EAI_MEMORY 6 /* memory allocation failure */ 41*b636d99dSDavid van Moolenbroek #define EAI_NODATA 7 /* no address associated with hostname */ 42*b636d99dSDavid van Moolenbroek #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 43*b636d99dSDavid van Moolenbroek #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 44*b636d99dSDavid van Moolenbroek #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 45*b636d99dSDavid van Moolenbroek #define EAI_SYSTEM 11 /* system error returned in errno */ 46*b636d99dSDavid van Moolenbroek #define EAI_BADHINTS 12 47*b636d99dSDavid van Moolenbroek #define EAI_PROTOCOL 13 48*b636d99dSDavid van Moolenbroek #define EAI_MAX 14 49*b636d99dSDavid van Moolenbroek 50*b636d99dSDavid van Moolenbroek /* internal error */ 51*b636d99dSDavid van Moolenbroek #define NETDB_INTERNAL -1 /* see errno */ 52*b636d99dSDavid van Moolenbroek 53*b636d99dSDavid van Moolenbroek /* 54*b636d99dSDavid van Moolenbroek * Flag values for getaddrinfo() 55*b636d99dSDavid van Moolenbroek */ 56*b636d99dSDavid van Moolenbroek #define AI_PASSIVE 0x00000001 /* get address to use bind() */ 57*b636d99dSDavid van Moolenbroek #define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 58*b636d99dSDavid van Moolenbroek #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 59*b636d99dSDavid van Moolenbroek /* valid flags for addrinfo */ 60*b636d99dSDavid van Moolenbroek #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) 61*b636d99dSDavid van Moolenbroek 62*b636d99dSDavid van Moolenbroek #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 63*b636d99dSDavid van Moolenbroek #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 64*b636d99dSDavid van Moolenbroek #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 65*b636d99dSDavid van Moolenbroek #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 66*b636d99dSDavid van Moolenbroek /* special recommended flags for getipnodebyname */ 67*b636d99dSDavid van Moolenbroek #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) 68*b636d99dSDavid van Moolenbroek 69*b636d99dSDavid van Moolenbroek struct addrinfo { 70*b636d99dSDavid van Moolenbroek int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ 71*b636d99dSDavid van Moolenbroek int ai_family; /* PF_xxx */ 72*b636d99dSDavid van Moolenbroek int ai_socktype; /* SOCK_xxx */ 73*b636d99dSDavid van Moolenbroek int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 74*b636d99dSDavid van Moolenbroek size_t ai_addrlen; /* length of ai_addr */ 75*b636d99dSDavid van Moolenbroek char *ai_canonname; /* canonical name for hostname */ 76*b636d99dSDavid van Moolenbroek struct sockaddr *ai_addr; /* binary address */ 77*b636d99dSDavid van Moolenbroek struct addrinfo *ai_next; /* next structure in linked list */ 78*b636d99dSDavid van Moolenbroek }; 79*b636d99dSDavid van Moolenbroek 80*b636d99dSDavid van Moolenbroek extern void freeaddrinfo (struct addrinfo *); 81*b636d99dSDavid van Moolenbroek extern void freehostent (struct hostent *); 82*b636d99dSDavid van Moolenbroek extern int getnameinfo (const struct sockaddr *, size_t, char *, 83*b636d99dSDavid van Moolenbroek size_t, char *, size_t, int); 84*b636d99dSDavid van Moolenbroek extern struct hostent *getipnodebyaddr (const void *, size_t, int, int *); 85*b636d99dSDavid van Moolenbroek extern struct hostent *getipnodebyname (const char *, int, int, int *); 86*b636d99dSDavid van Moolenbroek extern int inet_pton (int, const char *, void *); 87*b636d99dSDavid van Moolenbroek extern const char *inet_ntop (int, const void *, char *, size_t); 88*b636d99dSDavid van Moolenbroek #endif /* HAVE_ADDRINFO */ 89*b636d99dSDavid van Moolenbroek 90*b636d99dSDavid van Moolenbroek /* 91*b636d99dSDavid van Moolenbroek * Constants for getnameinfo() 92*b636d99dSDavid van Moolenbroek */ 93*b636d99dSDavid van Moolenbroek #ifndef NI_MAXHOST 94*b636d99dSDavid van Moolenbroek #define NI_MAXHOST 1025 95*b636d99dSDavid van Moolenbroek #endif 96*b636d99dSDavid van Moolenbroek #ifndef NI_MAXSERV 97*b636d99dSDavid van Moolenbroek #define NI_MAXSERV 32 98*b636d99dSDavid van Moolenbroek #endif 99*b636d99dSDavid van Moolenbroek 100*b636d99dSDavid van Moolenbroek /* 101*b636d99dSDavid van Moolenbroek * Flag values for getnameinfo() 102*b636d99dSDavid van Moolenbroek */ 103*b636d99dSDavid van Moolenbroek #ifndef NI_NOFQDN 104*b636d99dSDavid van Moolenbroek #define NI_NOFQDN 0x00000001 105*b636d99dSDavid van Moolenbroek #endif 106*b636d99dSDavid van Moolenbroek #ifndef NI_NUMERICHOST 107*b636d99dSDavid van Moolenbroek #define NI_NUMERICHOST 0x00000002 108*b636d99dSDavid van Moolenbroek #endif 109*b636d99dSDavid van Moolenbroek #ifndef NI_NAMEREQD 110*b636d99dSDavid van Moolenbroek #define NI_NAMEREQD 0x00000004 111*b636d99dSDavid van Moolenbroek #endif 112*b636d99dSDavid van Moolenbroek #ifndef NI_NUMERICSERV 113*b636d99dSDavid van Moolenbroek #define NI_NUMERICSERV 0x00000008 114*b636d99dSDavid van Moolenbroek #endif 115*b636d99dSDavid van Moolenbroek #ifndef NI_DGRAM 116*b636d99dSDavid van Moolenbroek #define NI_DGRAM 0x00000010 117*b636d99dSDavid van Moolenbroek #endif 118