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