159deaec5SRodney W. Grimes /*- 259deaec5SRodney W. Grimes * Copyright (c) 1980, 1983, 1988, 1993 359deaec5SRodney W. Grimes * The Regents of the University of California. All rights reserved. 459deaec5SRodney W. Grimes * 559deaec5SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 659deaec5SRodney W. Grimes * modification, are permitted provided that the following conditions 759deaec5SRodney W. Grimes * are met: 859deaec5SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 959deaec5SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 1059deaec5SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 1159deaec5SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 1259deaec5SRodney W. Grimes * documentation and/or other materials provided with the distribution. 1359deaec5SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 1459deaec5SRodney W. Grimes * must display the following acknowledgement: 1559deaec5SRodney W. Grimes * This product includes software developed by the University of 1659deaec5SRodney W. Grimes * California, Berkeley and its contributors. 1759deaec5SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 1859deaec5SRodney W. Grimes * may be used to endorse or promote products derived from this software 1959deaec5SRodney W. Grimes * without specific prior written permission. 2059deaec5SRodney W. Grimes * 2159deaec5SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2259deaec5SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2359deaec5SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2459deaec5SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2559deaec5SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2659deaec5SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2759deaec5SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2859deaec5SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2959deaec5SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3059deaec5SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3159deaec5SRodney W. Grimes * SUCH DAMAGE. 3259deaec5SRodney W. Grimes * 3359deaec5SRodney W. Grimes * - 3459deaec5SRodney W. Grimes * Portions Copyright (c) 1993 by Digital Equipment Corporation. 3559deaec5SRodney W. Grimes * 3659deaec5SRodney W. Grimes * Permission to use, copy, modify, and distribute this software for any 3759deaec5SRodney W. Grimes * purpose with or without fee is hereby granted, provided that the above 3859deaec5SRodney W. Grimes * copyright notice and this permission notice appear in all copies, and that 3959deaec5SRodney W. Grimes * the name of Digital Equipment Corporation not be used in advertising or 4059deaec5SRodney W. Grimes * publicity pertaining to distribution of the document or software without 4159deaec5SRodney W. Grimes * specific, written prior permission. 4259deaec5SRodney W. Grimes * 4359deaec5SRodney W. Grimes * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 4459deaec5SRodney W. Grimes * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 4559deaec5SRodney W. Grimes * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 4659deaec5SRodney W. Grimes * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 4759deaec5SRodney W. Grimes * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 4859deaec5SRodney W. Grimes * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 4959deaec5SRodney W. Grimes * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 5059deaec5SRodney W. Grimes * SOFTWARE. 5159deaec5SRodney W. Grimes * - 5259deaec5SRodney W. Grimes * --Copyright-- 5359deaec5SRodney W. Grimes */ 5459deaec5SRodney W. Grimes 550160f9c0SPeter Wemm /* 560160f9c0SPeter Wemm * @(#)netdb.h 8.1 (Berkeley) 6/2/93 570160f9c0SPeter Wemm * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $ 58a4add9a9SPeter Wemm * $FreeBSD$ 590160f9c0SPeter Wemm */ 600160f9c0SPeter Wemm 6159deaec5SRodney W. Grimes #ifndef _NETDB_H_ 6259deaec5SRodney W. Grimes #define _NETDB_H_ 6359deaec5SRodney W. Grimes 64315d6d9cSPeter Wemm #include <sys/cdefs.h> 653e9c0bd5SBruce Evans #include <machine/ansi.h> 66ad9fdc8fSHajimu UMEMOTO 67ad9fdc8fSHajimu UMEMOTO #ifdef _BSD_SIZE_T_ 68ad9fdc8fSHajimu UMEMOTO typedef _BSD_SIZE_T_ size_t; 69ad9fdc8fSHajimu UMEMOTO #undef _BSD_SIZE_T_ 70ad9fdc8fSHajimu UMEMOTO #endif 71315d6d9cSPeter Wemm 723e9c0bd5SBruce Evans #ifdef _BSD_SOCKLEN_T_ 733e9c0bd5SBruce Evans typedef _BSD_SOCKLEN_T_ socklen_t; 743e9c0bd5SBruce Evans #undef _BSD_SOCKLEN_T_ 753e9c0bd5SBruce Evans #endif 763e9c0bd5SBruce Evans 770160f9c0SPeter Wemm #ifndef _PATH_HEQUIV 7859deaec5SRodney W. Grimes # define _PATH_HEQUIV "/etc/hosts.equiv" 790160f9c0SPeter Wemm #endif 8059deaec5SRodney W. Grimes #define _PATH_HOSTS "/etc/hosts" 8159deaec5SRodney W. Grimes #define _PATH_NETWORKS "/etc/networks" 8259deaec5SRodney W. Grimes #define _PATH_PROTOCOLS "/etc/protocols" 8359deaec5SRodney W. Grimes #define _PATH_SERVICES "/etc/services" 8459deaec5SRodney W. Grimes 85d58a9efdSPeter Wemm extern int h_errno; 86d58a9efdSPeter Wemm 8759deaec5SRodney W. Grimes /* 8859deaec5SRodney W. Grimes * Structures returned by network data base library. All addresses are 8959deaec5SRodney W. Grimes * supplied in host order, and returned in network order (suitable for 9059deaec5SRodney W. Grimes * use in system calls). 9159deaec5SRodney W. Grimes */ 9259deaec5SRodney W. Grimes struct hostent { 9359deaec5SRodney W. Grimes char *h_name; /* official name of host */ 9459deaec5SRodney W. Grimes char **h_aliases; /* alias list */ 9559deaec5SRodney W. Grimes int h_addrtype; /* host address type */ 9659deaec5SRodney W. Grimes int h_length; /* length of address */ 9759deaec5SRodney W. Grimes char **h_addr_list; /* list of addresses from name server */ 9871d9c781SMike Pritchard #define h_addr h_addr_list[0] /* address, for backward compatibility */ 9959deaec5SRodney W. Grimes }; 10059deaec5SRodney W. Grimes 10159deaec5SRodney W. Grimes /* 10259deaec5SRodney W. Grimes * Assumption here is that a network number 10359deaec5SRodney W. Grimes * fits in an unsigned long -- probably a poor one. 10459deaec5SRodney W. Grimes */ 10559deaec5SRodney W. Grimes struct netent { 10659deaec5SRodney W. Grimes char *n_name; /* official name of net */ 10759deaec5SRodney W. Grimes char **n_aliases; /* alias list */ 10859deaec5SRodney W. Grimes int n_addrtype; /* net address type */ 10959deaec5SRodney W. Grimes unsigned long n_net; /* network # */ 11059deaec5SRodney W. Grimes }; 11159deaec5SRodney W. Grimes 11259deaec5SRodney W. Grimes struct servent { 11359deaec5SRodney W. Grimes char *s_name; /* official service name */ 11459deaec5SRodney W. Grimes char **s_aliases; /* alias list */ 11559deaec5SRodney W. Grimes int s_port; /* port # */ 11659deaec5SRodney W. Grimes char *s_proto; /* protocol to use */ 11759deaec5SRodney W. Grimes }; 11859deaec5SRodney W. Grimes 11959deaec5SRodney W. Grimes struct protoent { 12059deaec5SRodney W. Grimes char *p_name; /* official protocol name */ 12159deaec5SRodney W. Grimes char **p_aliases; /* alias list */ 12259deaec5SRodney W. Grimes int p_proto; /* protocol # */ 12359deaec5SRodney W. Grimes }; 12459deaec5SRodney W. Grimes 1257d56d374SYoshinobu Inoue struct addrinfo { 1267d56d374SYoshinobu Inoue int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 1277d56d374SYoshinobu Inoue int ai_family; /* PF_xxx */ 1287d56d374SYoshinobu Inoue int ai_socktype; /* SOCK_xxx */ 1297d56d374SYoshinobu Inoue int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 1307d56d374SYoshinobu Inoue size_t ai_addrlen; /* length of ai_addr */ 1317d56d374SYoshinobu Inoue char *ai_canonname; /* canonical name for hostname */ 1327d56d374SYoshinobu Inoue struct sockaddr *ai_addr; /* binary address */ 1337d56d374SYoshinobu Inoue struct addrinfo *ai_next; /* next structure in linked list */ 1347d56d374SYoshinobu Inoue }; 1357d56d374SYoshinobu Inoue 13659deaec5SRodney W. Grimes /* 13759deaec5SRodney W. Grimes * Error return codes from gethostbyname() and gethostbyaddr() 13859deaec5SRodney W. Grimes * (left in extern int h_errno). 13959deaec5SRodney W. Grimes */ 14059deaec5SRodney W. Grimes 141d58a9efdSPeter Wemm #define NETDB_INTERNAL -1 /* see errno */ 142d58a9efdSPeter Wemm #define NETDB_SUCCESS 0 /* no problem */ 14359deaec5SRodney W. Grimes #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 14471d9c781SMike Pritchard #define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ 14559deaec5SRodney W. Grimes #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 14659deaec5SRodney W. Grimes #define NO_DATA 4 /* Valid name, no data record of requested type */ 14759deaec5SRodney W. Grimes #define NO_ADDRESS NO_DATA /* no address, look for MX record */ 14859deaec5SRodney W. Grimes 1497d56d374SYoshinobu Inoue /* 1507d56d374SYoshinobu Inoue * Error return codes from getaddrinfo() 1517d56d374SYoshinobu Inoue */ 1527d56d374SYoshinobu Inoue #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 1537d56d374SYoshinobu Inoue #define EAI_AGAIN 2 /* temporary failure in name resolution */ 1547d56d374SYoshinobu Inoue #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 1557d56d374SYoshinobu Inoue #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 1567d56d374SYoshinobu Inoue #define EAI_FAMILY 5 /* ai_family not supported */ 1577d56d374SYoshinobu Inoue #define EAI_MEMORY 6 /* memory allocation failure */ 1587d56d374SYoshinobu Inoue #define EAI_NODATA 7 /* no address associated with hostname */ 1597d56d374SYoshinobu Inoue #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 1607d56d374SYoshinobu Inoue #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 1617d56d374SYoshinobu Inoue #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 1627d56d374SYoshinobu Inoue #define EAI_SYSTEM 11 /* system error returned in errno */ 1637d56d374SYoshinobu Inoue #define EAI_BADHINTS 12 1647d56d374SYoshinobu Inoue #define EAI_PROTOCOL 13 16569b58b03SHajimu UMEMOTO #define EAI_MAX 14 1667d56d374SYoshinobu Inoue 1677d56d374SYoshinobu Inoue /* 1687d56d374SYoshinobu Inoue * Flag values for getaddrinfo() 1697d56d374SYoshinobu Inoue */ 1707d56d374SYoshinobu Inoue #define AI_PASSIVE 0x00000001 /* get address to use bind() */ 1717d56d374SYoshinobu Inoue #define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 1727d56d374SYoshinobu Inoue #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 1737d56d374SYoshinobu Inoue /* valid flags for addrinfo */ 17492826806SHajimu UMEMOTO #define AI_MASK \ 17592826806SHajimu UMEMOTO (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG) 1767d56d374SYoshinobu Inoue 1777d56d374SYoshinobu Inoue #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 1787d56d374SYoshinobu Inoue #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 1797d56d374SYoshinobu Inoue #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 1807d56d374SYoshinobu Inoue #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 1817d56d374SYoshinobu Inoue /* special recommended flags for getipnodebyname */ 1827d56d374SYoshinobu Inoue #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG) 1837d56d374SYoshinobu Inoue 1847d56d374SYoshinobu Inoue /* 1857d56d374SYoshinobu Inoue * Constants for getnameinfo() 1867d56d374SYoshinobu Inoue */ 1877d56d374SYoshinobu Inoue #define NI_MAXHOST 1025 1887d56d374SYoshinobu Inoue #define NI_MAXSERV 32 1897d56d374SYoshinobu Inoue 1907d56d374SYoshinobu Inoue /* 1917d56d374SYoshinobu Inoue * Flag values for getnameinfo() 1927d56d374SYoshinobu Inoue */ 1937d56d374SYoshinobu Inoue #define NI_NOFQDN 0x00000001 1947d56d374SYoshinobu Inoue #define NI_NUMERICHOST 0x00000002 1957d56d374SYoshinobu Inoue #define NI_NAMEREQD 0x00000004 1967d56d374SYoshinobu Inoue #define NI_NUMERICSERV 0x00000008 1977d56d374SYoshinobu Inoue #define NI_DGRAM 0x00000010 1987d56d374SYoshinobu Inoue #define NI_WITHSCOPEID 0x00000020 1997d56d374SYoshinobu Inoue 2007d56d374SYoshinobu Inoue /* 2017d56d374SYoshinobu Inoue * Scope delimit character 2027d56d374SYoshinobu Inoue */ 20312cefbccSYoshinobu Inoue #define SCOPE_DELIMITER '%' 2047d56d374SYoshinobu Inoue 20559deaec5SRodney W. Grimes __BEGIN_DECLS 20659deaec5SRodney W. Grimes void endhostent __P((void)); 20759deaec5SRodney W. Grimes void endnetent __P((void)); 2088f150781SAlfred Perlstein void endnetgrent __P((void)); 20959deaec5SRodney W. Grimes void endprotoent __P((void)); 21059deaec5SRodney W. Grimes void endservent __P((void)); 2117d56d374SYoshinobu Inoue void freehostent __P((struct hostent *)); 21259deaec5SRodney W. Grimes struct hostent *gethostbyaddr __P((const char *, int, int)); 21359deaec5SRodney W. Grimes struct hostent *gethostbyname __P((const char *)); 21474b3fad6SPeter Wemm struct hostent *gethostbyname2 __P((const char *, int)); 21559deaec5SRodney W. Grimes struct hostent *gethostent __P((void)); 2167d56d374SYoshinobu Inoue struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); 2177d56d374SYoshinobu Inoue struct hostent *getipnodebyname __P((const char *, int, int, int *)); 218315d6d9cSPeter Wemm struct netent *getnetbyaddr __P((unsigned long, int)); 21959deaec5SRodney W. Grimes struct netent *getnetbyname __P((const char *)); 22059deaec5SRodney W. Grimes struct netent *getnetent __P((void)); 2218f150781SAlfred Perlstein int getnetgrent __P((char **, char **, char **)); 22259deaec5SRodney W. Grimes struct protoent *getprotobyname __P((const char *)); 22359deaec5SRodney W. Grimes struct protoent *getprotobynumber __P((int)); 22459deaec5SRodney W. Grimes struct protoent *getprotoent __P((void)); 22559deaec5SRodney W. Grimes struct servent *getservbyname __P((const char *, const char *)); 22659deaec5SRodney W. Grimes struct servent *getservbyport __P((int, const char *)); 22759deaec5SRodney W. Grimes struct servent *getservent __P((void)); 22859deaec5SRodney W. Grimes void herror __P((const char *)); 229fcd57f5cSSteve Price __const char *hstrerror __P((int)); 2308f150781SAlfred Perlstein int innetgr __P((const char *, const char *, const char *, 2318f150781SAlfred Perlstein const char *)); 23259deaec5SRodney W. Grimes void sethostent __P((int)); 23359deaec5SRodney W. Grimes /* void sethostfile __P((const char *)); */ 23459deaec5SRodney W. Grimes void setnetent __P((int)); 23559deaec5SRodney W. Grimes void setprotoent __P((int)); 2367d56d374SYoshinobu Inoue int getaddrinfo __P((const char *, const char *, 2377d56d374SYoshinobu Inoue const struct addrinfo *, struct addrinfo **)); 238ad9fdc8fSHajimu UMEMOTO int getnameinfo __P((const struct sockaddr *, socklen_t, char *, 2397d56d374SYoshinobu Inoue size_t, char *, size_t, int)); 2407d56d374SYoshinobu Inoue void freeaddrinfo __P((struct addrinfo *)); 2417d56d374SYoshinobu Inoue char *gai_strerror __P((int)); 2428f150781SAlfred Perlstein void setnetgrent __P((const char *)); 24359deaec5SRodney W. Grimes void setservent __P((int)); 24474b3fad6SPeter Wemm 24574b3fad6SPeter Wemm /* 24674b3fad6SPeter Wemm * PRIVATE functions specific to the FreeBSD implementation 24774b3fad6SPeter Wemm */ 24874b3fad6SPeter Wemm 24974b3fad6SPeter Wemm /* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */ 25074b3fad6SPeter Wemm void _sethosthtent __P((int)); 25174b3fad6SPeter Wemm void _endhosthtent __P((void)); 25274b3fad6SPeter Wemm void _sethostdnsent __P((int)); 25374b3fad6SPeter Wemm void _endhostdnsent __P((void)); 25474b3fad6SPeter Wemm void _setnethtent __P((int)); 25574b3fad6SPeter Wemm void _endnethtent __P((void)); 25674b3fad6SPeter Wemm void _setnetdnsent __P((int)); 25774b3fad6SPeter Wemm void _endnetdnsent __P((void)); 25874b3fad6SPeter Wemm struct hostent * _gethostbynisname __P((const char *, int)); 25974b3fad6SPeter Wemm struct hostent * _gethostbynisaddr __P((const char *, int, int)); 260e5c24b8eSMike Barcroft void _map_v4v6_address __P((const char *, char *)); 261e5c24b8eSMike Barcroft void _map_v4v6_hostent __P((struct hostent *, char **, int *)); 26259deaec5SRodney W. Grimes __END_DECLS 26359deaec5SRodney W. Grimes 26459deaec5SRodney W. Grimes #endif /* !_NETDB_H_ */ 265