1 /* 2 * ++Copyright++ 1980, 1983, 1988, 1993 3 * - 4 * Copyright (c) 1980, 1983, 1988, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * - 35 * Portions Copyright (c) 1993 by Digital Equipment Corporation. 36 * 37 * Permission to use, copy, modify, and distribute this software for any 38 * purpose with or without fee is hereby granted, provided that the above 39 * copyright notice and this permission notice appear in all copies, and that 40 * the name of Digital Equipment Corporation not be used in advertising or 41 * publicity pertaining to distribution of the document or software without 42 * specific, written prior permission. 43 * 44 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 45 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 46 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 47 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 48 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 49 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 50 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 51 * SOFTWARE. 52 * - 53 * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 54 * All rights reserved. 55 * 56 * Redistribution and use in source and binary forms, with or without 57 * modification, are permitted provided that the following conditions 58 * are met: 59 * 1. Redistributions of source code must retain the above copyright 60 * notice, this list of conditions and the following disclaimer. 61 * 2. Redistributions in binary form must reproduce the above copyright 62 * notice, this list of conditions and the following disclaimer in the 63 * documentation and/or other materials provided with the distribution. 64 * 3. All advertising materials mentioning features or use of this software 65 * must display the following acknowledgement: 66 * This product includes software developed by WIDE Project and 67 * its contributors. 68 * 4. Neither the name of the project nor the names of its contributors 69 * may be used to endorse or promote products derived from this software 70 * without specific prior written permission. 71 * 72 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 73 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 74 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 75 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 76 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 77 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 78 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 79 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 80 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 81 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 82 * SUCH DAMAGE. 83 * - 84 * --Copyright-- 85 */ 86 87 /* 88 * @(#)netdb.h 8.1 (Berkeley) 6/2/93 89 * $Id$ 90 */ 91 92 #ifndef _NETDB_H_ 93 #define _NETDB_H_ 94 95 #include <sys/param.h> 96 #include <sys/bitypes.h> 97 #include <sys/cdefs.h> 98 #include <sys/socket.h> 99 #include <netinet/in.h> 100 #include <stdio.h> 101 102 #ifndef _PATH_HEQUIV 103 #define _PATH_HEQUIV "/etc/hosts.equiv" 104 #endif 105 #ifndef _PATH_HOSTS 106 #define _PATH_HOSTS "/etc/hosts" 107 #endif 108 #ifndef _PATH_NETWORKS 109 #define _PATH_NETWORKS "/etc/networks" 110 #endif 111 #ifndef _PATH_PROTOCOLS 112 #define _PATH_PROTOCOLS "/etc/protocols" 113 #endif 114 #ifndef _PATH_SERVICES 115 #define _PATH_SERVICES "/etc/services" 116 #endif 117 118 __BEGIN_DECLS 119 extern int * __h_errno __P((void)); 120 __END_DECLS 121 #define h_errno (*__h_errno()) 122 123 /* 124 * Structures returned by network data base library. All addresses are 125 * supplied in host order, and returned in network order (suitable for 126 * use in system calls). 127 */ 128 struct hostent { 129 char *h_name; /* official name of host */ 130 char **h_aliases; /* alias list */ 131 int h_addrtype; /* host address type */ 132 int h_length; /* length of address */ 133 char **h_addr_list; /* list of addresses from name server */ 134 #define h_addr h_addr_list[0] /* address, for backward compatiblity */ 135 }; 136 137 /* 138 * Assumption here is that a network number 139 * fits in an unsigned long -- probably a poor one. 140 */ 141 struct netent { 142 char *n_name; /* official name of net */ 143 char **n_aliases; /* alias list */ 144 int n_addrtype; /* net address type */ 145 unsigned long n_net; /* network # */ 146 }; 147 148 struct servent { 149 char *s_name; /* official service name */ 150 char **s_aliases; /* alias list */ 151 int s_port; /* port # */ 152 char *s_proto; /* protocol to use */ 153 }; 154 155 struct protoent { 156 char *p_name; /* official protocol name */ 157 char **p_aliases; /* alias list */ 158 int p_proto; /* protocol # */ 159 }; 160 161 struct addrinfo { 162 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ 163 int ai_family; /* PF_xxx */ 164 int ai_socktype; /* SOCK_xxx */ 165 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 166 size_t ai_addrlen; /* length of ai_addr */ 167 char *ai_canonname; /* canonical name for hostname */ 168 struct sockaddr *ai_addr; /* binary address */ 169 struct addrinfo *ai_next; /* next structure in linked list */ 170 }; 171 172 /* 173 * Error return codes from gethostbyname() and gethostbyaddr() 174 * (left in extern int h_errno). 175 */ 176 177 #define NETDB_INTERNAL -1 /* see errno */ 178 #define NETDB_SUCCESS 0 /* no problem */ 179 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 180 #define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */ 181 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 182 #define NO_DATA 4 /* Valid name, no data record of requested type */ 183 #define NO_ADDRESS NO_DATA /* no address, look for MX record */ 184 185 /* 186 * Error return codes from getaddrinfo() 187 */ 188 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 189 #define EAI_AGAIN 2 /* temporary failure in name resolution */ 190 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 191 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 192 #define EAI_FAMILY 5 /* ai_family not supported */ 193 #define EAI_MEMORY 6 /* memory allocation failure */ 194 #define EAI_NODATA 7 /* no address associated with hostname */ 195 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 196 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 197 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 198 #define EAI_SYSTEM 11 /* system error returned in errno */ 199 #define EAI_BADHINTS 12 200 #define EAI_PROTOCOL 13 201 #define EAI_MAX 14 202 203 /* 204 * Flag values for getaddrinfo() 205 */ 206 #define AI_PASSIVE 0x00000001 207 #define AI_CANONNAME 0x00000002 208 #define AI_NUMERICHOST 0x00000004 209 #define AI_MASK 0x00000007 210 211 /* 212 * Flag values for getipnodebyname() 213 */ 214 #define AI_V4MAPPED 0x00000008 215 #define AI_ALL 0x00000010 216 #define AI_ADDRCONFIG 0x00000020 217 #define AI_DEFAULT (AI_V4MAPPED|AI_ADDRCONFIG) 218 219 /* 220 * Constants for getnameinfo() 221 */ 222 #define NI_MAXHOST 1025 223 #define NI_MAXSERV 32 224 225 /* 226 * Flag values for getnameinfo() 227 */ 228 #define NI_NOFQDN 0x00000001 229 #define NI_NUMERICHOST 0x00000002 230 #define NI_NAMEREQD 0x00000004 231 #define NI_NUMERICSERV 0x00000008 232 #define NI_DGRAM 0x00000010 233 #define NI_WITHSCOPEID 0x00000020 234 #define NI_NUMERICSCOPE 0x00000040 235 236 /* 237 * Scope delimit character 238 */ 239 #define SCOPE_DELIMITER '%' 240 241 242 __BEGIN_DECLS 243 void endhostent __P((void)); 244 void endnetent __P((void)); 245 void endprotoent __P((void)); 246 void endservent __P((void)); 247 void freehostent __P((struct hostent *)); 248 struct hostent *gethostbyaddr __P((const char *, int, int)); 249 struct hostent *gethostbyname __P((const char *)); 250 struct hostent *gethostbyname2 __P((const char *, int)); 251 struct hostent *gethostent __P((void)); 252 struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); 253 struct hostent *getipnodebyname __P((const char *, int, int, int *)); 254 struct netent *getnetbyaddr __P((unsigned long, int)); 255 struct netent *getnetbyname __P((const char *)); 256 struct netent *getnetent __P((void)); 257 struct protoent *getprotobyname __P((const char *)); 258 struct protoent *getprotobynumber __P((int)); 259 struct protoent *getprotoent __P((void)); 260 struct servent *getservbyname __P((const char *, const char *)); 261 struct servent *getservbyport __P((int, const char *)); 262 struct servent *getservent __P((void)); 263 void herror __P((const char *)); 264 const char *hstrerror __P((int)); 265 void sethostent __P((int)); 266 /* void sethostfile __P((const char *)); */ 267 void setnetent __P((int)); 268 void setprotoent __P((int)); 269 void setservent __P((int)); 270 int getaddrinfo __P((const char *, const char *, 271 const struct addrinfo *, struct addrinfo **)); 272 int getnameinfo __P((const struct sockaddr *, size_t, char *, 273 size_t, char *, size_t, int)); 274 void freeaddrinfo __P((struct addrinfo *)); 275 const char *gai_strerror __P((int)); 276 struct hostent *getipnodebyname __P((const char *, int, int, int *)); 277 struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); 278 void freehostent __P((struct hostent *)); 279 280 struct hostent *gethostbyaddr_r __P((const char *, int, int, struct hostent *, 281 char *, int, int *)); 282 struct hostent *gethostbyname_r __P((const char *, struct hostent *, 283 char *, int, int *)); 284 struct hostent *gethostent_r __P((struct hostent *, char *, int, int *)); 285 void sethostent_r __P((int)); 286 void endhostent_r __P((void)); 287 288 struct netent *getnetbyname_r __P((const char *, struct netent *, 289 char *, int)); 290 struct netent *getnetbyaddr_r __P((long, int, struct netent *, 291 char *, int)); 292 struct netent *getnetent_r __P((struct netent *, char *, int)); 293 void setnetent_r __P((int)); 294 void endnetent_r __P((void)); 295 296 struct protoent *getprotobyname_r __P((const char *, 297 struct protoent *, char *, int)); 298 struct protoent *getprotobynumber_r __P((int, 299 struct protoent *, char *, int)); 300 struct protoent *getprotoent_r __P((struct protoent *, char *, int)); 301 void setprotoent_r __P((int)); 302 void endprotoent_r __P((void)); 303 304 struct servent *getservbyname_r __P((const char *name, const char *, 305 struct servent *, char *, int)); 306 struct servent *getservbyport_r __P((int port, const char *, 307 struct servent *, char *, int)); 308 struct servent *getservent_r __P((struct servent *, char *, int)); 309 void setservent_r __P((int)); 310 void endservent_r __P((void)); 311 __END_DECLS 312 313 #endif /* !_NETDB_H_ */ 314