1/** @file
2
3    Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
4    This program and the accompanying materials
5    are licensed and made available under the terms and conditions of the BSD License
6    which accompanies this distribution.  The full text of the license may be found at
7    http://opensource.org/licenses/bsd-license.php
8
9    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10    WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 * Copyright (c) 1980, 1983, 1988, 1993
13 *  The Regents of the University of California.  All rights reserved.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 *    notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 *    notice, this list of conditions and the following disclaimer in the
22 *    documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of the University nor the names of its contributors
24 *    may be used to endorse or promote products derived from this software
25 *    without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 * -
39 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
40 *
41 * Permission to use, copy, modify, and distribute this software for any
42 * purpose with or without fee is hereby granted, provided that the above
43 * copyright notice and this permission notice appear in all copies, and that
44 * the name of Digital Equipment Corporation not be used in advertising or
45 * publicity pertaining to distribution of the document or software without
46 * specific, written prior permission.
47 *
48 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
49 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
50 * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
51 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
52 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
53 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
54 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
55 * SOFTWARE.
56 * -
57 * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
58 * All rights reserved.
59 *
60 * Redistribution and use in source and binary forms, with or without
61 * modification, are permitted provided that the following conditions
62 * are met:
63 * 1. Redistributions of source code must retain the above copyright
64 *    notice, this list of conditions and the following disclaimer.
65 * 2. Redistributions in binary form must reproduce the above copyright
66 *    notice, this list of conditions and the following disclaimer in the
67 *    documentation and/or other materials provided with the distribution.
68 * 3. All advertising materials mentioning features or use of this software
69 *    must display the following acknowledgement:
70 *    This product includes software developed by WIDE Project and
71 *    its contributors.
72 * 4. Neither the name of the project nor the names of its contributors
73 *    may be used to endorse or promote products derived from this software
74 *    without specific prior written permission.
75 *
76 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
77 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
78 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
79 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
80 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
81 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
82 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
83 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
84 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
85 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
86 * SUCH DAMAGE.
87 * -
88 *      @(#)netdb.h 8.1 (Berkeley) 6/2/93
89 *      netdb.h,v 1.15.18.6 2006/10/02 01:23:09 marka Exp
90 *      netdb.h,v 1.55.2.1 2007/05/17 21:25:10 jdc Exp
91 */
92#ifndef _NETDB_H_
93#define _NETDB_H_
94
95#include <machine/ansi.h>
96#include <machine/endian_machdep.h>
97#include <sys/ansi.h>
98#include <sys/cdefs.h>
99#include <sys/featuretest.h>
100#include <inttypes.h>
101#include <paths.h>
102
103/* Data types */
104#ifndef socklen_t
105typedef __socklen_t socklen_t;
106#define socklen_t   __socklen_t
107#endif
108
109#ifdef _EFI_SIZE_T_
110  typedef _EFI_SIZE_T_  size_t;
111  #undef  _EFI_SIZE_T_
112  #undef  _BSD_SIZE_T_
113#endif
114
115__BEGIN_DECLS
116extern int h_errno;
117__END_DECLS
118
119/** Structures returned by network data base library.  All addresses are
120 *  supplied in host order, and returned in network order (suitable for
121 *  use in system calls).
122 */
123struct  hostent {
124  char   *h_name;       /**< official name of host */
125  char  **h_aliases;    /**< alias list */
126  int     h_addrtype;   /**< host address type */
127  int     h_length;     /**< length of address */
128  char  **h_addr_list;  /**< list of addresses from name server */
129};
130#define h_addr  h_addr_list[0]  /**< address, for backward compatiblity */
131
132/** Assumption here is that a network number
133 *  fits in an unsigned long -- probably a poor one.
134 */
135struct  netent {
136  char     *n_name;     /**< official name of net */
137  char    **n_aliases;  /**< alias list */
138  int       n_addrtype; /**< net address type */
139  uint32_t  n_net;      /**< network # */
140#if defined(__alpha__) || (defined(__i386__) && defined(_LP64)) || \
141    (defined(__sh__) && defined(_LP64) && (_BYTE_ORDER == _LITTLE_ENDIAN))
142  int       __n_pad0;   /* ABI compatibility */
143#endif
144};
145
146struct  servent {
147  char   *s_name;     /**< official service name */
148  char  **s_aliases;  /**< alias list */
149  int     s_port;     /**< port # */
150  char   *s_proto;    /**< protocol to use */
151};
152
153struct  protoent {
154  char   *p_name;     /**< official protocol name */
155  char  **p_aliases;  /**< alias list */
156  int     p_proto;    /**< protocol # */
157};
158
159/* Note: ai_addrlen used to be a size_t, per RFC 2553.
160 * In XNS5.2, and subsequently in POSIX-2001 and
161 * draft-ietf-ipngwg-rfc2553bis-02.txt it was changed to a socklen_t.
162 * To accommodate for this while preserving binary compatibility with the
163 * old interface, we prepend or append 32 bits of padding, depending on
164 * the (LP64) architecture's endianness.
165 *
166 * This should be deleted the next time the libc major number is
167 * incremented.
168 */
169struct addrinfo {
170  int               ai_flags;     /**< AI_PASSIVE, AI_CANONNAME */
171  int               ai_family;    /**< PF_xxx */
172  int               ai_socktype;  /**< SOCK_xxx */
173  int               ai_protocol;  /**< 0 or IPPROTO_xxx for IPv4 and IPv6 */
174  socklen_t         ai_addrlen;   /**< length of ai_addr */
175#if defined(__alpha__) || (defined(__i386__) && defined(_LP64))
176  int               __ai_pad0;    /* ABI compatibility */
177#endif
178  char             *ai_canonname; /**< canonical name for hostname */
179  struct sockaddr  *ai_addr;      /**< binary address */
180  struct addrinfo  *ai_next;      /**< next structure in linked list */
181};
182
183/* Error return codes from gethostbyname() and gethostbyaddr()
184 * (left in extern int h_errno).
185*/
186
187#define NETDB_INTERNAL   -1         /**< see errno */
188#define NETDB_SUCCESS     0         /**< no problem */
189#define NO_ADDRESS        NO_DATA   /* no address, look for MX record */
190#define HOST_NOT_FOUND    1         /**< Authoritative Answer Host not found */
191#define TRY_AGAIN         2         /**< Non-Authoritive Host not found, or SERVERFAIL */
192#define NO_RECOVERY       3         /**< Non recoverable errors, FORMERR, REFUSED, NOTIMP */
193#define NO_DATA           4         /**< Valid name, no data record of requested type */
194
195/* Error return codes from getaddrinfo() */
196#define EAI_ADDRFAMILY    1   /**< address family for hostname not supported */
197#define EAI_AGAIN         2   /**< temporary failure in name resolution */
198#define EAI_BADFLAGS      3   /**< invalid value for ai_flags */
199#define EAI_FAIL          4   /**< non-recoverable failure in name resolution */
200#define EAI_FAMILY        5   /**< ai_family not supported */
201#define EAI_MEMORY        6   /**< memory allocation failure */
202#define EAI_NODATA        7   /**< no address associated with hostname */
203#define EAI_NONAME        8   /**< hostname nor servname provided, or not known */
204#define EAI_SERVICE       9   /**< servname not supported for ai_socktype */
205#define EAI_SOCKTYPE      10  /**< ai_socktype not supported */
206#define EAI_SYSTEM        11  /**< system error returned in errno */
207#define EAI_BADHINTS      12  /**< invalid value for hints */
208#define EAI_PROTOCOL      13  /**< resolved protocol is unknown */
209#define EAI_OVERFLOW      14  /**< argument buffer overflow */
210#define EAI_MAX           15
211
212/* Flag values for getaddrinfo() */
213#define AI_PASSIVE      0x00000001  /* get address to use bind() */
214#define AI_CANONNAME    0x00000002  /* fill ai_canonname */
215
216#define AI_NUMERICHOST  0x00000004  /* prevent host name resolution */
217#define AI_NUMERICSERV  0x00000008  /* prevent service name resolution */
218/* valid flags for addrinfo (not a standard def, apps should not use it) */
219#define AI_MASK         (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV)
220
221/* Constants for getnameinfo() */
222#define NI_MAXHOST      1025
223#define NI_MAXSERV      32
224
225/* Flag values for getnameinfo() */
226#define NI_NOFQDN       0x00000001
227#define NI_NUMERICHOST  0x00000002
228#define NI_NAMEREQD     0x00000004
229#define NI_NUMERICSERV  0x00000008
230#define NI_DGRAM        0x00000010
231#define NI_NUMERICSCOPE 0x00000040
232
233/** Scope delimit character */
234#define SCOPE_DELIMITER '%'
235
236__BEGIN_DECLS
237void              endhostent      (void);
238void              endnetent       (void);
239void              endprotoent     (void);
240void              endservent      (void);
241struct hostent   *gethostbyaddr   (const char *, socklen_t, int);
242struct hostent   *gethostbyname   (const char *);
243struct hostent   *gethostbyname2  (const char *, int);
244struct hostent   *gethostent      (void);
245struct netent    *getnetbyaddr    (uint32_t, int);
246struct netent    *getnetbyname    (const char *);
247struct netent    *getnetent       (void);
248struct protoent  *getprotobyname  (const char *);
249struct protoent  *getprotobynumber(int);
250struct protoent  *getprotoent     (void);
251struct servent   *getservbyname   (const char *, const char *);
252struct servent   *getservbyport   (int, const char *);
253struct servent   *getservent      (void);
254void              sethostent      (int);
255void              setnetent       (int);
256void              setprotoent     (int);
257void              setservent      (int);
258int               getaddrinfo     ( const char * __restrict, const char * __restrict,
259                                    const struct addrinfo * __restrict,
260                                    struct addrinfo ** __restrict);
261int               getnameinfo     ( const struct sockaddr * __restrict, socklen_t,
262                                    char * __restrict, socklen_t,
263                                    char * __restrict, socklen_t, int);
264void              freeaddrinfo    (struct addrinfo *);
265const char       *gai_strerror    (int);
266void              setservent      (int);
267
268__END_DECLS
269
270#endif /* !_NETDB_H_ */
271