xref: /dflybsd-src/contrib/cvs-1.12/lib/getaddrinfo.h (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino /* Get address information.
2*86d7f5d3SJohn Marino    Copyright (C) 1996-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3*86d7f5d3SJohn Marino    Contributed by Simon Josefsson <simon@josefsson.org>.
4*86d7f5d3SJohn Marino 
5*86d7f5d3SJohn Marino    This program is free software; you can redistribute it and/or modify
6*86d7f5d3SJohn Marino    it under the terms of the GNU General Public License as published by
7*86d7f5d3SJohn Marino    the Free Software Foundation; either version 2, or (at your option)
8*86d7f5d3SJohn Marino    any later version.
9*86d7f5d3SJohn Marino 
10*86d7f5d3SJohn Marino    This program is distributed in the hope that it will be useful,
11*86d7f5d3SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*86d7f5d3SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*86d7f5d3SJohn Marino    GNU General Public License for more details.
14*86d7f5d3SJohn Marino 
15*86d7f5d3SJohn Marino    You should have received a copy of the GNU General Public License
16*86d7f5d3SJohn Marino    along with this program; if not, write to the Free Software Foundation,
17*86d7f5d3SJohn Marino    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18*86d7f5d3SJohn Marino 
19*86d7f5d3SJohn Marino #ifndef GETADDRINFO_H
20*86d7f5d3SJohn Marino # define GETADDRINFO_H
21*86d7f5d3SJohn Marino 
22*86d7f5d3SJohn Marino /* Get getaddrinfo declarations, if available.  Also get 'socklen_t',
23*86d7f5d3SJohn Marino    and 'struct sockaddr' via sys/types.h which are used below. */
24*86d7f5d3SJohn Marino # include <sys/types.h>
25*86d7f5d3SJohn Marino # include <sys/socket.h>
26*86d7f5d3SJohn Marino # include <netdb.h>
27*86d7f5d3SJohn Marino 
28*86d7f5d3SJohn Marino # if !HAVE_GETADDRINFO
29*86d7f5d3SJohn Marino 
30*86d7f5d3SJohn Marino /* Structure to contain information about address of a service provider.  */
31*86d7f5d3SJohn Marino struct addrinfo
32*86d7f5d3SJohn Marino {
33*86d7f5d3SJohn Marino   int ai_flags;			/* Input flags.  */
34*86d7f5d3SJohn Marino   int ai_family;		/* Protocol family for socket.  */
35*86d7f5d3SJohn Marino   int ai_socktype;		/* Socket type.  */
36*86d7f5d3SJohn Marino   int ai_protocol;		/* Protocol for socket.  */
37*86d7f5d3SJohn Marino   socklen_t ai_addrlen;		/* Length of socket address.  */
38*86d7f5d3SJohn Marino   struct sockaddr *ai_addr;	/* Socket address for socket.  */
39*86d7f5d3SJohn Marino   char *ai_canonname;		/* Canonical name for service location.  */
40*86d7f5d3SJohn Marino   struct addrinfo *ai_next;	/* Pointer to next in list.  */
41*86d7f5d3SJohn Marino };
42*86d7f5d3SJohn Marino 
43*86d7f5d3SJohn Marino /* Possible values for `ai_flags' field in `addrinfo' structure.  */
44*86d7f5d3SJohn Marino # define AI_PASSIVE	0x0001	/* Socket address is intended for `bind'.  */
45*86d7f5d3SJohn Marino # define AI_CANONNAME	0x0002	/* Request for canonical name.  */
46*86d7f5d3SJohn Marino # define AI_NUMERICHOST	0x0004	/* Don't use name resolution.  */
47*86d7f5d3SJohn Marino # define AI_V4MAPPED	0x0008	/* IPv4 mapped addresses are acceptable.  */
48*86d7f5d3SJohn Marino # define AI_ALL		0x0010	/* Return IPv4 mapped and IPv6 addresses.  */
49*86d7f5d3SJohn Marino # define AI_ADDRCONFIG	0x0020	/* Use configuration of this host to choose
50*86d7f5d3SJohn Marino 				   returned address type..  */
51*86d7f5d3SJohn Marino 
52*86d7f5d3SJohn Marino /* Error values for `getaddrinfo' function.  */
53*86d7f5d3SJohn Marino # define EAI_BADFLAGS	  -1	/* Invalid value for `ai_flags' field.  */
54*86d7f5d3SJohn Marino # define EAI_NONAME	  -2	/* NAME or SERVICE is unknown.  */
55*86d7f5d3SJohn Marino # define EAI_AGAIN	  -3	/* Temporary failure in name resolution.  */
56*86d7f5d3SJohn Marino # define EAI_FAIL	  -4	/* Non-recoverable failure in name res.  */
57*86d7f5d3SJohn Marino # define EAI_NODATA	  -5	/* No address associated with NAME.  */
58*86d7f5d3SJohn Marino # define EAI_FAMILY	  -6	/* `ai_family' not supported.  */
59*86d7f5d3SJohn Marino # define EAI_SOCKTYPE	  -7	/* `ai_socktype' not supported.  */
60*86d7f5d3SJohn Marino # define EAI_SERVICE	  -8	/* SERVICE not supported for `ai_socktype'.  */
61*86d7f5d3SJohn Marino # define EAI_ADDRFAMILY	  -9	/* Address family for NAME not supported.  */
62*86d7f5d3SJohn Marino # define EAI_MEMORY	  -10	/* Memory allocation failure.  */
63*86d7f5d3SJohn Marino # define EAI_SYSTEM	  -11	/* System error returned in `errno'.  */
64*86d7f5d3SJohn Marino # define EAI_OVERFLOW	  -12	/* Argument buffer overflow.  */
65*86d7f5d3SJohn Marino # ifdef __USE_GNU
66*86d7f5d3SJohn Marino #  define EAI_INPROGRESS  -100	/* Processing request in progress.  */
67*86d7f5d3SJohn Marino #  define EAI_CANCELED	  -101	/* Request canceled.  */
68*86d7f5d3SJohn Marino #  define EAI_NOTCANCELED -102	/* Request not canceled.  */
69*86d7f5d3SJohn Marino #  define EAI_ALLDONE	  -103	/* All requests done.  */
70*86d7f5d3SJohn Marino #  define EAI_INTR	  -104	/* Interrupted by a signal.  */
71*86d7f5d3SJohn Marino #  define EAI_IDN_ENCODE  -105	/* IDN encoding failed.  */
72*86d7f5d3SJohn Marino # endif
73*86d7f5d3SJohn Marino 
74*86d7f5d3SJohn Marino /* Translate name of a service location and/or a service name to set of
75*86d7f5d3SJohn Marino    socket addresses.
76*86d7f5d3SJohn Marino    For more details, see the POSIX:2001 specification
77*86d7f5d3SJohn Marino    <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
78*86d7f5d3SJohn Marino extern int getaddrinfo (const char *restrict nodename,
79*86d7f5d3SJohn Marino 			const char *restrict servname,
80*86d7f5d3SJohn Marino 			const struct addrinfo *restrict hints,
81*86d7f5d3SJohn Marino 			struct addrinfo **restrict res);
82*86d7f5d3SJohn Marino 
83*86d7f5d3SJohn Marino /* Free `addrinfo' structure AI including associated storage.
84*86d7f5d3SJohn Marino    For more details, see the POSIX:2001 specification
85*86d7f5d3SJohn Marino    <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
86*86d7f5d3SJohn Marino extern void freeaddrinfo (struct addrinfo *ai);
87*86d7f5d3SJohn Marino 
88*86d7f5d3SJohn Marino /* Convert error return from getaddrinfo() to a string.
89*86d7f5d3SJohn Marino    For more details, see the POSIX:2001 specification
90*86d7f5d3SJohn Marino    <http://www.opengroup.org/susv3xsh/gai_strerror.html>.  */
91*86d7f5d3SJohn Marino extern const char *gai_strerror (int ecode);
92*86d7f5d3SJohn Marino 
93*86d7f5d3SJohn Marino # endif /* !HAVE_GETADDRINFO */
94*86d7f5d3SJohn Marino 
95*86d7f5d3SJohn Marino #endif /* GETADDRINFO_H */
96