1 /*------------------------------------------------------------------------------
2  * File:        netdb.h
3  * Description: Resolver library header file
4  *
5  * Copyright (C) Nintendo.  All rights reserved.
6  * These coded instructions, statements, and computer programs contain
7  * proprietary information of Nintendo of America Inc. and/or Nintendo
8  * Company Ltd., and are protected by Federal copyright law.  They may
9  * not be disclosed to third parties or copied or duplicated in any form,
10  * in whole or in part, without the prior written consent of Nintendo.
11  *
12  *------------------------------------------------------------------------------
13  */
14 
15 
16 /*
17  * ++Portions Copyright++ 1980, 1983, 1988, 1993
18  * -
19  * Portions Copyright (c) 1980, 1983, 1988, 1993
20  *	The Regents of the University of California.  All rights reserved.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the above copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  *    notice, this list of conditions and the following disclaimer in the
29  *    documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  *    must display the following acknowledgement:
32  *	This product includes software developed by the University of
33  *	California, Berkeley and its contributors.
34  * 4. Neither the name of the University nor the names of its contributors
35  *    may be used to endorse or promote products derived from this software
36  *    without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
39  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
42  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * -
50  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
51  *
52  * Permission to use, copy, modify, and distribute this software for any
53  * purpose with or without fee is hereby granted, provided that the above
54  * copyright notice and this permission notice appear in all copies, and that
55  * the name of Digital Equipment Corporation not be used in advertising or
56  * publicity pertaining to distribution of the document or software without
57  * specific, written prior permission.
58  *
59  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
60  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
61  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
62  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
63  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
64  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
65  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
66  * SOFTWARE.
67  * -
68  * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
69  * All rights reserved.
70  *
71  * Redistribution and use in source and binary forms, with or without
72  * modification, are permitted provided that the following conditions
73  * are met:
74  * 1. Redistributions of source code must retain the above copyright
75  *    notice, this list of conditions and the following disclaimer.
76  * 2. Redistributions in binary form must reproduce the above copyright
77  *    notice, this list of conditions and the following disclaimer in the
78  *    documentation and/or other materials provided with the distribution.
79  * 3. All advertising materials mentioning features or use of this software
80  *    must display the following acknowledgement:
81  *    This product includes software developed by WIDE Project and
82  *    its contributors.
83  * 4. Neither the name of the project nor the names of its contributors
84  *    may be used to endorse or promote products derived from this software
85  *    without specific prior written permission.
86  *
87  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
88  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
89  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
90  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
91  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
92  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
93  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
94  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
95  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
96  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
97  * SUCH DAMAGE.
98  * -
99  * --Copyright--
100  */
101 
102 #ifndef	_NETDB_H
103 #define	_NETDB_H	1
104 
105 #ifdef __cplusplus
106 extern "C" {
107 #endif
108 
109 #define SOGetHostByName gethostbyname
110 #define SOGetHostByAddr gethostbyaddr
111 #define SOGetAddrInfo getaddrinfo
112 #define SOGetAddrInfoRSU getaddrinfo_rs
113 #define SOGetNameInfo getnameinfo
114 #define SOFreeAddrInfo freeaddrinfo
115 #define SOGaiStrerror gai_strerror
116 
117 /* Description of data base entry for a single host.  */
118 struct hostent
119 {
120    char *   h_name;        /* Official name of host. */
121    char **h_aliases;       /* Alias list.  */
122    int   h_addrtype;       /* Host address type.  */
123    int   h_length;         /* Length of address.  */
124    char **h_addr_list;     /* List of addresses from name server.  */
125 #define  h_addr   h_addr_list[0] /* Address, for backward compatibility.  */
126 };
127 
128 
129 /* AF_xxx defined in so.h */
130 /* SOCK_xxx defined in so.h */
131 
132 /* flags for addrinfo{ai_flags} */
133 #define   AI_PASSIVE          0x01
134 #define   AI_CANONNAME        0x02
135 #define   AI_NUMERICHOST      0x04
136 #define   AI_NUMERICSERV      0x08
137 
138 struct addrinfo {
139   int     ai_flags;     /* AI_PASSIVE, AI_CANONNAME,
140                            AI_NUMERICHOST, .. */
141   int     ai_family;    /* AF_xxx */
142   int     ai_socktype;  /* SOCK_xxx */
143   int     ai_protocol;  /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
144   int     ai_addrlen;   /* length of ai_addr */
145   char   *ai_canonname; /* canonical name for node name */
146   struct sockaddr  *ai_addr; /* binary address */
147   struct addrinfo  *ai_next; /* next structure in linked list */
148 };
149 
150 /* flags for getnameinfo() */
151 #define NI_NOFQDN            0x01
152 #define NI_NUMERICHOST       0x02
153 #define NI_NAMEREQD          0x04
154 #define NI_NUMERICSERV       0x08
155 #define NI_DGRAM             0x10
156 
157 /* for getnameinfo() */
158 #define NI_MAXHOST         1025
159 #define NI_MAXSERV           32
160 
161 #define h_errno (*(get_h_errno()))
162 
163 
164 #define NETDB_INTERNAL -1
165 #define NETDB_SUCCESS   0
166 #define HOST_NOT_FOUND  1
167 #define TRY_AGAIN       2
168 #define NO_RECOVERY     3
169 #define NO_DATA         4
170 #define NO_ADDRESS      NO_DATA
171 
172 /*
173  * Error return codes from getaddrinfo()
174  */
175 #define	EAI_ADDRFAMILY   1      /* address family for hostname not supported UNUSED */
176 #define	EAI_AGAIN        2      /* temporary failure in name resolution */
177 #define	EAI_BADFLAGS     3      /* invalid value for ai_flags */
178 #define	EAI_FAIL         4      /* non-recoverable failure in name resolution */
179 #define	EAI_FAMILY       5      /* ai_family not supported */
180 #define	EAI_MEMORY       6      /* memory allocation failure */
181 #define	EAI_NODATA       7      /* no address associated with hostname UNUSED */
182 #define	EAI_NONAME       8      /* hostname nor servname provided, or not known */
183 #define	EAI_SERVICE      9      /* servname not supported for ai_socktype */
184 #define	EAI_SOCKTYPE    10      /* ai_socktype not supported */
185 #define	EAI_SYSTEM      11      /* system error returned in errno */
186 #define	EAI_BADHINTS    12      /* UNUSED */
187 #define	EAI_PROTOCOL    13      /* UNUSED */
188 #define EAI_OVERFLOW    14
189 #define EAI_INPROGRESS  15
190 #define	EAI_MAX         16      /* marker, must be last */
191 
192 
193 int *get_h_errno(void);
194 void freeaddrinfo(struct addrinfo *);
195 int getaddrinfo(const char *, const char *, const struct addrinfo *, struct addrinfo **);
196 int getaddrinfo_rs(const char *, const char *, const struct addrinfo *, struct addrinfo **);
197 int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *node, socklen_t nodelen,
198                 char *service, socklen_t servicelen, int flags);
199 const char *gai_strerror(int);
200 struct hostent * gethostbyname(const char * name);
201 struct hostent * gethostbyaddr(const void* addr, int len, int type );
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 #endif	/* !_NETDB_H */
208