1 /*
   2  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
   3  * Use is subject to license terms.
   4  */
   5 
   6 /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
   7 /*        All Rights Reserved   */
   8 
   9 /*
  10  * BIND 4.9.3:
  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. All advertising materials mentioning features or use of this software
  24  *    must display the following acknowledgement:
  25  *      This product includes software developed by the University of
  26  *      California, Berkeley and its contributors.
  27  * 4. Neither the name of the University nor the names of its contributors
  28  *    may be used to endorse or promote products derived from this software
  29  *    without specific prior written permission.
  30  *
  31  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  32  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  35  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  39  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  40  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  41  * SUCH DAMAGE.
  42  * -
  43  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  44  *
  45  * Permission to use, copy, modify, and distribute this software for any
  46  * purpose with or without fee is hereby granted, provided that the above
  47  * copyright notice and this permission notice appear in all copies, and that
  48  * the name of Digital Equipment Corporation not be used in advertising or
  49  * publicity pertaining to distribution of the document or software without
  50  * specific, written prior permission.
  51  *
  52  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  53  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  54  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
  55  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  56  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  57  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  58  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  59  * SOFTWARE.
  60  * --Copyright--
  61  *
  62  * End BIND 4.9.3
  63  */
  64 
  65 /*
  66  * Structures returned by network data base library.
  67  * All addresses are supplied in host order, and
  68  * returned in network order (suitable for use in system calls).
  69  */
  70 
  71 #ifndef _NETDB_H
  72 #define _NETDB_H
  73 
  74 #include <sys/types.h>
  75 #include <netinet/in.h>
  76 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
  77 #include <sys/socket.h>
  78 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
  79 #include <sys/feature_tests.h>
  80 
  81 #ifdef  __cplusplus
  82 extern "C" {
  83 #endif
  84 
  85 #define _PATH_HEQUIV    "/etc/hosts.equiv"
  86 #define _PATH_HOSTS     "/etc/hosts"
  87 #define _PATH_IPNODES   "/etc/inet/ipnodes"
  88 #define _PATH_IPSECALGS "/etc/inet/ipsecalgs"
  89 #define _PATH_NETMASKS  "/etc/netmasks"
  90 #define _PATH_NETWORKS  "/etc/networks"
  91 #define _PATH_PROTOCOLS "/etc/protocols"
  92 #define _PATH_SERVICES  "/etc/services"
  93 
  94 struct  hostent {
  95         char    *h_name;        /* official name of host */
  96         char    **h_aliases;    /* alias list */
  97         int     h_addrtype;     /* host address type */
  98         int     h_length;       /* length of address */
  99         char    **h_addr_list;  /* list of addresses from name server */
 100 #define h_addr  h_addr_list[0]  /* address, for backward compatiblity */
 101 };
 102 
 103 
 104 /*
 105  * addrinfo introduced with IPv6 for Protocol-Independent Hostname
 106  * and Service Name Translation.
 107  */
 108 
 109 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
 110 struct addrinfo {
 111         int ai_flags;           /* AI_PASSIVE, AI_CANONNAME, ... */
 112         int ai_family;          /* PF_xxx */
 113         int ai_socktype;        /* SOCK_xxx */
 114         int ai_protocol;        /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
 115 #ifdef __sparcv9
 116         int _ai_pad;            /* for backwards compat with old size_t */
 117 #endif /* __sparcv9 */
 118         socklen_t ai_addrlen;
 119         char *ai_canonname;     /* canonical name for hostname */
 120         struct sockaddr *ai_addr;       /* binary address */
 121         struct addrinfo *ai_next;       /* next structure in linked list */
 122 };
 123 
 124 
 125 /* addrinfo flags */
 126 #define AI_PASSIVE      0x0008  /* intended for bind() + listen() */
 127 #define AI_CANONNAME    0x0010  /* return canonical version of host */
 128 #define AI_NUMERICHOST  0x0020  /* use numeric node address string */
 129 #define AI_NUMERICSERV  0x0040  /* servname is assumed numeric */
 130 
 131 /* getipnodebyname() flags */
 132 #define AI_V4MAPPED     0x0001  /* IPv4 mapped addresses if no IPv6 */
 133 #define AI_ALL          0x0002  /* IPv6 and IPv4 mapped addresses */
 134 #define AI_ADDRCONFIG   0x0004  /* AAAA or A records only if IPv6/IPv4 cnfg'd */
 135 
 136 
 137 /*
 138  * These were defined in RFC 2553 but not SUSv3
 139  * or RFC 3493 which obsoleted 2553.
 140  */
 141 #if !defined(_XPG6) || defined(__EXTENSIONS__)
 142 #define AI_DEFAULT      (AI_V4MAPPED | AI_ADDRCONFIG)
 143 
 144 /* addrinfo errors */
 145 #define EAI_ADDRFAMILY  1       /* address family not supported */
 146 #define EAI_NODATA      7       /* no address */
 147 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
 148 #define EAI_AGAIN       2       /* DNS temporary failure */
 149 #define EAI_BADFLAGS    3       /* invalid ai_flags */
 150 #define EAI_FAIL        4       /* DNS non-recoverable failure */
 151 #define EAI_FAMILY      5       /* ai_family not supported */
 152 #define EAI_MEMORY      6       /* memory allocation failure */
 153 #define EAI_NONAME      8       /* host/servname not known */
 154 #define EAI_SERVICE     9       /* servname not supported for ai_socktype */
 155 #define EAI_SOCKTYPE    10      /* ai_socktype not supported */
 156 #define EAI_SYSTEM      11      /* system error in errno */
 157 #define EAI_OVERFLOW    12      /* argument buffer overflow */
 158 #define EAI_PROTOCOL    13
 159 #define EAI_MAX         14
 160 
 161 /* getnameinfo flags */
 162 #define NI_NOFQDN       0x0001
 163 #define NI_NUMERICHOST  0x0002  /* return numeric form of address */
 164 #define NI_NAMEREQD     0x0004  /* request DNS name */
 165 #define NI_NUMERICSERV  0x0008
 166 #define NI_DGRAM        0x0010
 167 
 168 #if !defined(_XPG6) || defined(__EXTENSIONS__)
 169 /* Not listed in any standards document */
 170 #define NI_WITHSCOPEID  0x0020
 171 #define NI_NUMERICSCOPE 0x0040
 172 
 173 /* getnameinfo max sizes as defined in RFC 2553 obsoleted in RFC 3493 */
 174 #define NI_MAXHOST      1025
 175 #define NI_MAXSERV      32
 176 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
 177 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
 178 
 179 /*
 180  * Scope delimit character
 181  */
 182 #define SCOPE_DELIMITER '%'
 183 
 184 
 185 /*
 186  * Algorithm entry for /etc/inet/ipsecalgs which defines IPsec protocols
 187  * and algorithms.
 188  */
 189 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
 190 typedef struct ipsecalgent {
 191         char **a_names;         /* algorithm names */
 192         int a_proto_num;        /* protocol number */
 193         int a_alg_num;          /* algorithm number */
 194         char *a_mech_name;      /* encryption framework mechanism name */
 195         int *a_block_sizes;     /* supported block sizes */
 196         int *a_key_sizes;       /* supported key sizes */
 197         int a_key_increment;    /* key size increment */
 198         int *a_mech_params;     /* mechanism specific parameters */
 199         int a_alg_flags;        /* algorithm flags */
 200 } ipsecalgent_t;
 201 
 202 /* well-known IPsec protocol numbers */
 203 
 204 #define IPSEC_PROTO_AH          2
 205 #define IPSEC_PROTO_ESP         3
 206 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
 207 
 208 /*
 209  * Assumption here is that a network number
 210  * fits in 32 bits -- probably a poor one.
 211  */
 212 struct  netent {
 213         char            *n_name;        /* official name of net */
 214         char            **n_aliases;    /* alias list */
 215         int             n_addrtype;     /* net address type */
 216         in_addr_t       n_net;          /* network # */
 217 };
 218 
 219 struct  protoent {
 220         char    *p_name;        /* official protocol name */
 221         char    **p_aliases;    /* alias list */
 222         int     p_proto;        /* protocol # */
 223 };
 224 
 225 struct  servent {
 226         char    *s_name;        /* official service name */
 227         char    **s_aliases;    /* alias list */
 228         int     s_port;         /* port # */
 229         char    *s_proto;       /* protocol to use */
 230 };
 231 
 232 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
 233 struct hostent  *gethostbyname_r
 234         (const char *, struct hostent *, char *, int, int *h_errnop);
 235 struct hostent  *gethostbyaddr_r
 236         (const char *, int, int, struct hostent *, char *, int, int *h_errnop);
 237 struct hostent  *getipnodebyname(const char *, int, int, int *);
 238 struct hostent  *getipnodebyaddr(const void *, size_t, int, int *);
 239 void            freehostent(struct hostent *);
 240 struct hostent  *gethostent_r(struct hostent *, char *, int, int *h_errnop);
 241 
 242 struct servent  *getservbyname_r
 243         (const char *name, const char *, struct servent *, char *, int);
 244 struct servent  *getservbyport_r
 245         (int port, const char *, struct servent *, char *, int);
 246 struct servent  *getservent_r(struct    servent *, char *, int);
 247 
 248 struct netent   *getnetbyname_r
 249         (const char *, struct netent *, char *, int);
 250 struct netent   *getnetbyaddr_r(long, int, struct netent *, char *, int);
 251 struct netent   *getnetent_r(struct netent *, char *, int);
 252 
 253 struct protoent *getprotobyname_r
 254         (const char *, struct protoent *, char *, int);
 255 struct protoent *getprotobynumber_r
 256         (int, struct protoent *, char *, int);
 257 struct protoent *getprotoent_r(struct protoent *, char *, int);
 258 
 259 int getnetgrent_r(char **, char **, char **, char *, int);
 260 int innetgr(const char *, const char *, const char *, const char *);
 261 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
 262 
 263 /* Old interfaces that return a pointer to a static area;  MT-unsafe */
 264 #ifndef _STRICT_XPG7
 265 struct hostent  *gethostbyname(const char *);
 266 #endif
 267 struct hostent  *gethostent(void);
 268 struct netent   *getnetbyaddr(in_addr_t, int);
 269 struct netent   *getnetbyname(const char *);
 270 struct netent   *getnetent(void);
 271 struct protoent *getprotobyname(const char *);
 272 struct protoent *getprotobynumber(int);
 273 struct protoent *getprotoent(void);
 274 struct servent  *getservbyname(const char *, const char *);
 275 struct servent  *getservbyport(int, const char *);
 276 struct servent  *getservent(void);
 277 
 278 /*
 279  * gethostbyaddr() second argument is a size_t only in unix95/unix98,
 280  * removed in XPG issue 7
 281  */
 282 #if !defined(_STRICT_XPG7)
 283 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
 284 struct hostent  *gethostbyaddr(const void *, socklen_t, int);
 285 #else
 286 struct hostent  *gethostbyaddr(const void *, size_t, int);
 287 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
 288 #endif  /* !defined(_STRICT_XPG7) */
 289 
 290 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
 291 int endhostent(void);
 292 int endnetent(void);
 293 int endprotoent(void);
 294 int endservent(void);
 295 int sethostent(int);
 296 int setnetent(int);
 297 int setprotoent(int);
 298 int setservent(int);
 299 #else
 300 void endhostent(void);
 301 void endnetent(void);
 302 void endprotoent(void);
 303 void endservent(void);
 304 void sethostent(int);
 305 void setnetent(int);
 306 void setprotoent(int);
 307 void setservent(int);
 308 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
 309 
 310 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
 311 
 312 #ifdef  _XPG6
 313 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 314 #pragma redefine_extname getaddrinfo __xnet_getaddrinfo
 315 #else   /* __PRAGMA_REDEFINE_EXTNAME */
 316 #define getaddrinfo __xnet_getaddrinfo
 317 #endif  /* __PRAGMA_REDEFINE_EXTNAME */
 318 #endif  /* _XPG6 */
 319 
 320 int             getaddrinfo(const char *_RESTRICT_KYWD,
 321                         const char *_RESTRICT_KYWD,
 322                         const struct addrinfo *_RESTRICT_KYWD,
 323                         struct addrinfo **_RESTRICT_KYWD);
 324 void            freeaddrinfo(struct addrinfo *);
 325 const char      *gai_strerror(int);
 326 int             getnameinfo(const struct sockaddr *_RESTRICT_KYWD,
 327                         socklen_t, char *_RESTRICT_KYWD, socklen_t,
 328                         char *_RESTRICT_KYWD, socklen_t, int);
 329 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
 330 
 331 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
 332 int getnetgrent(char **, char **, char **);
 333 int setnetgrent(const char *);
 334 int endnetgrent(void);
 335 int rcmd(char **, unsigned short,
 336         const char *, const char *, const char *, int *);
 337 int rcmd_af(char **, unsigned short,
 338         const char *, const char *, const char *, int *, int);
 339 int rresvport_af(int *, int);
 340 int rresvport_addr(int *, struct sockaddr_storage *);
 341 int rexec(char **, unsigned short,
 342         const char *, const char *, const char *, int *);
 343 int rexec_af(char **, unsigned short,
 344         const char *, const char *, const char *, int *, int);
 345 int rresvport(int *);
 346 int ruserok(const char *, int, const char *, const char *);
 347 /* BIND */
 348 struct hostent  *gethostbyname2(const char *, int);
 349 void            herror(const char *);
 350 const char      *hstrerror(int);
 351 /* End BIND */
 352 
 353 /* IPsec algorithm prototype definitions */
 354 struct ipsecalgent *getipsecalgbyname(const char *, int, int *);
 355 struct ipsecalgent *getipsecalgbynum(int, int, int *);
 356 int getipsecprotobyname(const char *doi_name);
 357 char *getipsecprotobynum(int doi_domain);
 358 void freeipsecalgent(struct ipsecalgent *ptr);
 359 /* END IPsec algorithm prototype definitions */
 360 
 361 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
 362 
 363 /*
 364  * Error return codes from gethostbyname() and gethostbyaddr()
 365  * (when using the resolver)
 366  */
 367 
 368 /* h_errno was removed in Issue 7 */
 369 #if !defined(_STRICT_XPG7)
 370 extern  int h_errno;
 371 
 372 #ifdef  _REENTRANT
 373 extern int      *__h_errno(void);
 374 
 375 /* Only #define h_errno if there is no conflict with other use */
 376 #ifdef  H_ERRNO_IS_FUNCTION
 377 #define h_errno (*__h_errno())
 378 #endif  /* NO_H_ERRNO_DEFINE */
 379 #endif  /* _REENTRANT */
 380 
 381 /*
 382  * Error return codes from gethostbyname() and gethostbyaddr()
 383  * (left in extern int h_errno).
 384  */
 385 #define HOST_NOT_FOUND  1 /* Authoritive Answer Host not found */
 386 #define TRY_AGAIN       2 /* Non-Authoritive Host not found, or SERVERFAIL */
 387 #define NO_RECOVERY     3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
 388 #define NO_DATA         4 /* Valid name, no data record of requested type */
 389 
 390 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
 391 #define NO_ADDRESS      NO_DATA         /* no address, look for MX record */
 392 
 393 /* BIND */
 394 #define NETDB_INTERNAL  -1      /* see errno */
 395 #define NETDB_SUCCESS   0       /* no problem */
 396 /* End BIND */
 397 
 398 #endif  /* !defined(_STRICT_XPG7) */
 399 
 400 #define MAXHOSTNAMELEN  256
 401 
 402 #define MAXALIASES      35
 403 #define MAXADDRS        35
 404 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
 405 
 406 #ifdef  __cplusplus
 407 }
 408 #endif
 409 
 410 #endif  /* _NETDB_H */