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