186d7f5d3SJohn Marino /* Get address information. 286d7f5d3SJohn Marino Copyright (C) 1996-2002, 2003, 2004, 2005 Free Software Foundation, Inc. 386d7f5d3SJohn Marino Contributed by Simon Josefsson <simon@josefsson.org>. 486d7f5d3SJohn Marino 586d7f5d3SJohn Marino This program is free software; you can redistribute it and/or modify 686d7f5d3SJohn Marino it under the terms of the GNU General Public License as published by 786d7f5d3SJohn Marino the Free Software Foundation; either version 2, or (at your option) 886d7f5d3SJohn Marino any later version. 986d7f5d3SJohn Marino 1086d7f5d3SJohn Marino This program is distributed in the hope that it will be useful, 1186d7f5d3SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 1286d7f5d3SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1386d7f5d3SJohn Marino GNU General Public License for more details. 1486d7f5d3SJohn Marino 1586d7f5d3SJohn Marino You should have received a copy of the GNU General Public License 1686d7f5d3SJohn Marino along with this program; if not, write to the Free Software Foundation, 1786d7f5d3SJohn Marino Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 1886d7f5d3SJohn Marino 1986d7f5d3SJohn Marino #ifndef GETADDRINFO_H 2086d7f5d3SJohn Marino # define GETADDRINFO_H 2186d7f5d3SJohn Marino 2286d7f5d3SJohn Marino /* Get getaddrinfo declarations, if available. Also get 'socklen_t', 2386d7f5d3SJohn Marino and 'struct sockaddr' via sys/types.h which are used below. */ 2486d7f5d3SJohn Marino # include <sys/types.h> 2586d7f5d3SJohn Marino # include <sys/socket.h> 2686d7f5d3SJohn Marino # include <netdb.h> 2786d7f5d3SJohn Marino 2886d7f5d3SJohn Marino # if !HAVE_GETADDRINFO 2986d7f5d3SJohn Marino 3086d7f5d3SJohn Marino /* Structure to contain information about address of a service provider. */ 3186d7f5d3SJohn Marino struct addrinfo 3286d7f5d3SJohn Marino { 3386d7f5d3SJohn Marino int ai_flags; /* Input flags. */ 3486d7f5d3SJohn Marino int ai_family; /* Protocol family for socket. */ 3586d7f5d3SJohn Marino int ai_socktype; /* Socket type. */ 3686d7f5d3SJohn Marino int ai_protocol; /* Protocol for socket. */ 3786d7f5d3SJohn Marino socklen_t ai_addrlen; /* Length of socket address. */ 3886d7f5d3SJohn Marino struct sockaddr *ai_addr; /* Socket address for socket. */ 3986d7f5d3SJohn Marino char *ai_canonname; /* Canonical name for service location. */ 4086d7f5d3SJohn Marino struct addrinfo *ai_next; /* Pointer to next in list. */ 4186d7f5d3SJohn Marino }; 4286d7f5d3SJohn Marino 4386d7f5d3SJohn Marino /* Possible values for `ai_flags' field in `addrinfo' structure. */ 4486d7f5d3SJohn Marino # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */ 4586d7f5d3SJohn Marino # define AI_CANONNAME 0x0002 /* Request for canonical name. */ 4686d7f5d3SJohn Marino # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */ 4786d7f5d3SJohn Marino # define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */ 4886d7f5d3SJohn Marino # define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */ 4986d7f5d3SJohn Marino # define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose 5086d7f5d3SJohn Marino returned address type.. */ 5186d7f5d3SJohn Marino 5286d7f5d3SJohn Marino /* Error values for `getaddrinfo' function. */ 5386d7f5d3SJohn Marino # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */ 5486d7f5d3SJohn Marino # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */ 5586d7f5d3SJohn Marino # define EAI_AGAIN -3 /* Temporary failure in name resolution. */ 5686d7f5d3SJohn Marino # define EAI_FAIL -4 /* Non-recoverable failure in name res. */ 5786d7f5d3SJohn Marino # define EAI_NODATA -5 /* No address associated with NAME. */ 5886d7f5d3SJohn Marino # define EAI_FAMILY -6 /* `ai_family' not supported. */ 5986d7f5d3SJohn Marino # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */ 6086d7f5d3SJohn Marino # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */ 6186d7f5d3SJohn Marino # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */ 6286d7f5d3SJohn Marino # define EAI_MEMORY -10 /* Memory allocation failure. */ 6386d7f5d3SJohn Marino # define EAI_SYSTEM -11 /* System error returned in `errno'. */ 6486d7f5d3SJohn Marino # define EAI_OVERFLOW -12 /* Argument buffer overflow. */ 6586d7f5d3SJohn Marino # ifdef __USE_GNU 6686d7f5d3SJohn Marino # define EAI_INPROGRESS -100 /* Processing request in progress. */ 6786d7f5d3SJohn Marino # define EAI_CANCELED -101 /* Request canceled. */ 6886d7f5d3SJohn Marino # define EAI_NOTCANCELED -102 /* Request not canceled. */ 6986d7f5d3SJohn Marino # define EAI_ALLDONE -103 /* All requests done. */ 7086d7f5d3SJohn Marino # define EAI_INTR -104 /* Interrupted by a signal. */ 7186d7f5d3SJohn Marino # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */ 7286d7f5d3SJohn Marino # endif 7386d7f5d3SJohn Marino 7486d7f5d3SJohn Marino /* Translate name of a service location and/or a service name to set of 7586d7f5d3SJohn Marino socket addresses. 7686d7f5d3SJohn Marino For more details, see the POSIX:2001 specification 7786d7f5d3SJohn Marino <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */ 7886d7f5d3SJohn Marino extern int getaddrinfo (const char *restrict nodename, 7986d7f5d3SJohn Marino const char *restrict servname, 8086d7f5d3SJohn Marino const struct addrinfo *restrict hints, 8186d7f5d3SJohn Marino struct addrinfo **restrict res); 8286d7f5d3SJohn Marino 8386d7f5d3SJohn Marino /* Free `addrinfo' structure AI including associated storage. 8486d7f5d3SJohn Marino For more details, see the POSIX:2001 specification 8586d7f5d3SJohn Marino <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */ 8686d7f5d3SJohn Marino extern void freeaddrinfo (struct addrinfo *ai); 8786d7f5d3SJohn Marino 8886d7f5d3SJohn Marino /* Convert error return from getaddrinfo() to a string. 8986d7f5d3SJohn Marino For more details, see the POSIX:2001 specification 9086d7f5d3SJohn Marino <http://www.opengroup.org/susv3xsh/gai_strerror.html>. */ 9186d7f5d3SJohn Marino extern const char *gai_strerror (int ecode); 9286d7f5d3SJohn Marino 9386d7f5d3SJohn Marino # endif /* !HAVE_GETADDRINFO */ 9486d7f5d3SJohn Marino 9586d7f5d3SJohn Marino #endif /* GETADDRINFO_H */ 96