1 /*
   2  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
   3  * Use is subject to license terms.
   4  *
   5  * Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T
   6  * All Rights Reserved
   7  *
   8  * Portions of this source code were derived from Berkeley
   9  * 4.3 BSD under license from the regents of the University of
  10  * California.
  11  */
  12 
  13 /*
  14  * BIND 4.9.4:
  15  */
  16 
  17 /*
  18  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  19  *
  20  * Permission to use, copy, modify, and distribute this software for any
  21  * purpose with or without fee is hereby granted, provided that the above
  22  * copyright notice and this permission notice appear in all copies, and that
  23  * the name of Digital Equipment Corporation not be used in advertising or
  24  * publicity pertaining to distribution of the document or software without
  25  * specific, written prior permission.
  26  *
  27  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  28  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  29  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
  30  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  31  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  32  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  33  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34  * SOFTWARE.
  35  * --Copyright--
  36  *
  37  * End BIND 4.9.4
  38  */
  39 
  40 /*
  41  * Copyright (c) 1983, 1987, 1989
  42  *    The Regents of the University of California.  All rights reserved.
  43  *
  44  * Redistribution and use in source and binary forms, with or without
  45  * modification, are permitted provided that the following conditions
  46  * are met:
  47  * 1. Redistributions of source code must retain the above copyright
  48  *    notice, this list of conditions and the following disclaimer.
  49  * 2. Redistributions in binary form must reproduce the above copyright
  50  *    notice, this list of conditions and the following disclaimer in the
  51  *    documentation and/or other materials provided with the distribution.
  52  * 3. All advertising materials mentioning features or use of this software
  53  *    must display the following acknowledgement:
  54  *      This product includes software developed by the University of
  55  *      California, Berkeley and its contributors.
  56  * 4. Neither the name of the University nor the names of its contributors
  57  *    may be used to endorse or promote products derived from this software
  58  *    without specific prior written permission.
  59  *
  60  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  61  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  62  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  64  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  65  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  66  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  67  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  69  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  70  * SUCH DAMAGE.
  71  */
  72 
  73 /*
  74  * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
  75  *
  76  * Permission to use, copy, modify, and distribute this software for any
  77  * purpose with or without fee is hereby granted, provided that the above
  78  * copyright notice and this permission notice appear in all copies.
  79  *
  80  * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
  81  * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
  82  * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
  83  * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  84  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  85  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  86  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  87  * SOFTWARE.
  88  */
  89 
  90 /*
  91  *      @(#)resolv.h    8.1 (Berkeley) 6/2/93
  92  *      $Id: resolv.h,v 8.52 2003/04/29 02:27:03 marka Exp $
  93  */
  94 
  95 #ifndef _RESOLV_H_
  96 #define _RESOLV_H_
  97 
  98 #include <sys/param.h>
  99 
 100 #include <stdio.h>
 101 #include <arpa/nameser.h>
 102 #include <sys/socket.h>
 103 
 104 #ifdef  __cplusplus
 105 extern "C" {
 106 #endif
 107 
 108 /*
 109  * Revision information.  This is the release date in YYYYMMDD format.
 110  * It can change every day so the right thing to do with it is use it
 111  * in preprocessor commands such as "#if (__RES > 19931104)".  Do not
 112  * compare for equality; rather, use it to determine whether your resolver
 113  * is new enough to contain a certain feature.
 114  */
 115 
 116 #define __RES   20090302
 117 
 118 #define RES_SET_H_ERRNO(r, x)   __h_errno_set(r, x)
 119 struct __res_state;                                     /* forward */
 120 
 121 void __h_errno_set(struct __res_state *res, int err);
 122 
 123 /*
 124  * Resolver configuration file.
 125  * Normally not present, but may contain the address of the
 126  * initial name server(s) to query and the domain search list.
 127  */
 128 
 129 #ifndef _PATH_RESCONF
 130 #define _PATH_RESCONF           "/etc/resolv.conf"
 131 #endif
 132 
 133 #ifdef __STDC__
 134 #ifndef __P
 135 #define __P(x)  x
 136 #endif
 137 #else
 138 #ifndef __P
 139 #define __P(x)  ()
 140 #endif
 141 #endif /* __STDC__ */
 142 
 143 typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
 144         res_sendhookact;
 145 
 146 typedef res_sendhookact (*res_send_qhook)__P((struct sockaddr * const *ns,
 147                                                 const uchar_t **query,
 148                                                 int *querylen,
 149                                                 uchar_t *ans,
 150                                                 int anssiz,
 151                                                 int *resplen));
 152 
 153 typedef res_sendhookact (*res_send_rhook)__P((const struct sockaddr *ns,
 154                                                 const uchar_t *query,
 155                                                 int querylen,
 156                                                 uchar_t *ans,
 157                                                 int anssiz,
 158                                                 int *resplen));
 159 
 160 struct res_sym {
 161         int             number;    /* Identifying number, like T_MX */
 162         const char      *name;     /* Its symbolic name, like "MX" */
 163         const char      *humanname; /* Its fun name, like "mail exchanger" */
 164 };
 165 
 166 /*
 167  * Global defines and variables for resolver stub.
 168  */
 169 /* ADDRSORT and MAXADDR retained for compatibility; not used */
 170 #define ADDRSORT        1       /* enable the address-sorting option */
 171 #define MAXADDR         10      /* max # addresses to sort by */
 172 
 173 #define MAXNS                   3       /* max # name servers we'll track */
 174 #define MAXDFLSRCH              3       /* # default domain levels to try */
 175 #define MAXDNSRCH               6       /* max # domains in search path */
 176 #define LOCALDOMAINPARTS        2       /* min levels in name that is "local" */
 177 
 178 #define RES_TIMEOUT             5       /* min. seconds between retries */
 179 #define MAXRESOLVSORT           10      /* number of net to sort on */
 180 #define RES_MAXNDOTS            15      /* should reflect bit field size */
 181 #define RES_MAXRETRANS          30      /* only for resolv.conf/RES_OPTIONS */
 182 #define RES_MAXRETRY            5       /* only for resolv.conf/RES_OPTIONS */
 183 #define RES_DFLRETRY            2       /* Default #/tries. */
 184 #define RES_MAXTIME             65535   /* Infinity, in milliseconds. */
 185 
 186 struct __res_state_ext;
 187 
 188 struct __res_state {
 189         int     retrans;                /* retransmission time interval */
 190         int     retry;                  /* number of times to retransmit */
 191 #ifdef __sun
 192         uint_t  options;                /* option flags - see below. */
 193 #else
 194         ulong_t options;                /* option flags - see below. */
 195 #endif
 196         int     nscount;                /* number of name servers */
 197         struct sockaddr_in
 198                 nsaddr_list[MAXNS];     /* address of name server */
 199 #define nsaddr  nsaddr_list[0]          /* for backward compatibility */
 200         ushort_t id;                    /* current packet id */
 201         char    *dnsrch[MAXDNSRCH+1];   /* components of domain to search */
 202         char    defdname[256];          /* default domain (deprecated) */
 203 #ifdef __sun
 204         uint_t  pfcode;                 /* RES_PRF_ flags - see below. */
 205 #else
 206         ulong_t pfcode;                 /* RES_PRF_ flags - see below. */
 207 #endif
 208         unsigned ndots:4;               /* threshold for initial abs. query */
 209         unsigned nsort:4;               /* number of elements in sort_list[] */
 210         char    unused[3];
 211         struct {
 212                 struct in_addr  addr;
 213                 unsigned int    mask;
 214         } sort_list[MAXRESOLVSORT];
 215         res_send_qhook qhook;           /* query hook */
 216         res_send_rhook rhook;           /* response hook */
 217         int             res_h_errno;    /* last one set for this context */
 218         int             _vcsock;        /* PRIVATE: for res_send VC i/o */
 219         uint_t  _flags;         /* PRIVATE: see below */
 220         uint_t  _pad;                   /* make _u 64 bit aligned */
 221         union {
 222                 /* On an 32-bit arch this means 512b total. */
 223                 char    pad[72 - 4*sizeof (int) - 2*sizeof (void *)];
 224                 struct {
 225                         uint16_t                nscount;
 226                         uint16_t                nstimes[MAXNS]; /* ms. */
 227                         int                     nssocks[MAXNS];
 228                         struct __res_state_ext *ext;    /* extention for IPv6 */
 229                         uchar_t _rnd[16];       /* PRIVATE: random state */
 230                 } _ext;
 231         } _u;
 232 };
 233 
 234 typedef struct __res_state      *res_state;
 235 
 236 union res_sockaddr_union {
 237         struct sockaddr_in      sin;
 238 #ifdef IN6ADDR_ANY_INIT
 239         struct sockaddr_in6     sin6;
 240 #endif
 241 #ifdef ISC_ALIGN64
 242         int64_t                 __align64;      /* 64bit alignment */
 243 #else
 244         int32_t                 __align32;      /* 32bit alignment */
 245 #endif
 246         char                    __space[128];   /* max size */
 247 };
 248 
 249 /*
 250  * Resolver flags (used to be discrete per-module statics ints).
 251  */
 252 #define RES_F_VC        0x00000001      /* socket is TCP */
 253 #define RES_F_CONN      0x00000002      /* socket is connected */
 254 #define RES_F_EDNS0ERR  0x00000004      /* EDNS0 caused errors */
 255 #define RES_F__UNUSED   0x00000008      /* (unused) */
 256 #define RES_F_LASTMASK  0x000000F0      /* ordinal server of last res_nsend */
 257 #define RES_F_LASTSHIFT 4               /* bit position of LASTMASK "flag" */
 258 #define RES_GETLAST(res) (((res)._flags & RES_F_LASTMASK) >> RES_F_LASTSHIFT)
 259 
 260 /* res_findzonecut2() options */
 261 #define RES_EXHAUSTIVE  0x00000001      /* always do all queries */
 262 #define RES_IPV4ONLY    0x00000002      /* IPv4 only */
 263 #define RES_IPV6ONLY    0x00000004      /* IPv6 only */
 264 
 265 /*
 266  * Resolver options (keep these in synch with res_debug.c, please)
 267  */
 268 #define RES_INIT        0x00000001      /* address initialized */
 269 #define RES_DEBUG       0x00000002      /* print debug messages */
 270 #define RES_AAONLY      0x00000004      /* authoritative answers only (!IMPL) */
 271 #define RES_USEVC       0x00000008      /* use virtual circuit */
 272 #define RES_PRIMARY     0x00000010      /* query primary server only (!IMPL) */
 273 #define RES_IGNTC       0x00000020      /* ignore trucation errors */
 274 #define RES_RECURSE     0x00000040      /* recursion desired */
 275 #define RES_DEFNAMES    0x00000080      /* use default domain name */
 276 #define RES_STAYOPEN    0x00000100      /* Keep TCP socket open */
 277 #define RES_DNSRCH      0x00000200      /* search up local domain tree */
 278 #define RES_INSECURE1   0x00000400      /* type 1 security disabled */
 279 #define RES_INSECURE2   0x00000800      /* type 2 security disabled */
 280 #define RES_NOALIASES   0x00001000      /* shuts off HOSTALIASES feature */
 281 #define RES_USE_INET6   0x00002000      /* use/map IPv6 in gethostbyname() */
 282 #define RES_ROTATE      0x00004000      /* rotate ns list after each query */
 283 #define RES_NOCHECKNAME 0x00008000      /* do not check names for sanity. */
 284 #define RES_KEEPTSIG    0x00010000      /* do not strip TSIG records */
 285 #define RES_BLAST       0x00020000      /* blast all recursive servers */
 286 #define RES_NO_NIBBLE   0x00040000      /* disable IPv6 nibble mode reverse */
 287 #define RES_NO_BITSTRING 0x00080000     /* disable IPv6 bitstring mode revrse */
 288 #define RES_NOTLDQUERY  0x00100000      /* don't unqualified name as a tld */
 289 #define RES_USE_DNSSEC  0x00200000      /* use DNSSEC using OK bit in OPT */
 290 /* KAME extensions: use higher bit to avoid conflict with ISC use */
 291 #define RES_USE_DNAME   0x10000000      /* use DNAME */
 292 #define RES_USE_EDNS0   0x40000000      /* use EDNS0 if configured */
 293 #define RES_NO_NIBBLE2  0x80000000      /* disable alternate nibble lookup */
 294 
 295 #define RES_DEFAULT     (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
 296 
 297 /*
 298  * Resolver "pfcode" values.  Used by dig.
 299  */
 300 #define RES_PRF_STATS   0x00000001
 301 #define RES_PRF_UPDATE  0x00000002
 302 #define RES_PRF_CLASS   0x00000004
 303 #define RES_PRF_CMD             0x00000008
 304 #define RES_PRF_QUES    0x00000010
 305 #define RES_PRF_ANS             0x00000020
 306 #define RES_PRF_AUTH    0x00000040
 307 #define RES_PRF_ADD             0x00000080
 308 #define RES_PRF_HEAD1   0x00000100
 309 #define RES_PRF_HEAD2   0x00000200
 310 #define RES_PRF_TTLID   0x00000400
 311 #define RES_PRF_HEADX   0x00000800
 312 #define RES_PRF_QUERY   0x00001000
 313 #define RES_PRF_REPLY   0x00002000
 314 #define RES_PRF_INIT    0x00004000
 315 #define RES_PRF_TRUNC   0x00008000
 316 /*                      0x00010000      */
 317 
 318 /* Things involving an internal (static) resolver context. */
 319 #ifdef _REENTRANT
 320 extern struct __res_state *__res_state(void);
 321 #define _res (*__res_state())
 322 #else
 323 #ifndef __BIND_NOSTATIC
 324 extern struct __res_state _res;
 325 #endif
 326 #endif
 327 
 328 #ifndef __BIND_NOSTATIC
 329 void            fp_nquery __P((const uchar_t *, int, FILE *));
 330 void            fp_query __P((const uchar_t *, FILE *));
 331 const char *hostalias __P((const char *));
 332 void            p_query __P((const uchar_t *));
 333 void            res_close __P((void));
 334 int             res_init __P((void));
 335 int             res_isourserver __P((const struct sockaddr_in *));
 336 int             res_mkquery __P((int, const char *, int, int, const uchar_t *,
 337                                 int, const uchar_t *, uchar_t *, int));
 338 int             res_query       __P((const char *, int, int, uchar_t *, int));
 339 int             res_querydomain __P((const char *, const char *, int, int,
 340                                 uchar_t *, int));
 341 int             res_search __P((const char *, int, int, uchar_t *, int));
 342 int             res_send __P((const uchar_t *, int, uchar_t *, int));
 343 int             res_sendsigned __P((const uchar_t *, int, ns_tsig_key *,
 344                                     uchar_t *, int));
 345 #endif  /* __BIND_NOSTATIC */
 346 
 347 extern const struct res_sym __p_key_syms[];
 348 extern const struct res_sym __p_cert_syms[];
 349 extern const struct res_sym __p_class_syms[];
 350 extern const struct res_sym __p_type_syms[];
 351 extern const struct res_sym __p_rcode_syms[];
 352 
 353 int             res_hnok __P((const char *));
 354 int             res_ownok __P((const char *));
 355 int             res_mailok __P((const char *));
 356 int             res_dnok __P((const char *));
 357 int             sym_ston __P((const struct res_sym *, const char *, int *));
 358 const char      *sym_ntos __P((const struct res_sym *, int, int *));
 359 const char      *sym_ntop __P((const struct res_sym *, int, int *));
 360 int             b64_ntop __P((uchar_t const *, size_t, char *, size_t));
 361 int             b64_pton __P((char const *, uchar_t *, size_t));
 362 int             loc_aton __P((const char *ascii, uchar_t *binary));
 363 const char      *loc_ntoa __P((const uchar_t *binary, char *ascii));
 364 int             dn_skipname __P((const uchar_t *, const uchar_t *));
 365 void            putlong __P((unsigned int, uchar_t *));
 366 void            putshort __P((unsigned short, uchar_t *));
 367 const char      *p_class __P((int));
 368 const char      *p_time __P((unsigned int));
 369 const char      *p_type __P((int));
 370 const char      *p_rcode __P((int));
 371 const char      *p_sockun __P((union res_sockaddr_union, char *, size_t));
 372 const uchar_t   *p_cdnname __P((const uchar_t *, const uchar_t *, int,
 373                         FILE *));
 374 const uchar_t   *p_cdname __P((const uchar_t *, const uchar_t *, FILE *));
 375 const uchar_t   *p_fqnname __P((const uchar_t *cp, const uchar_t *msg,
 376                         int, char *, int));
 377 const uchar_t   *p_fqname __P((const uchar_t *, const uchar_t *, FILE *));
 378 const char      *p_option __P((uint_t option));
 379 char            *p_secstodate __P((uint_t));
 380 int             dn_count_labels __P((const char *));
 381 int             dn_comp __P((const char *, uchar_t *, int,
 382                                 uchar_t **, uchar_t **));
 383 int             dn_expand __P((const uchar_t *, const uchar_t *,
 384                         const uchar_t *, char *, int));
 385 void            res_rndinit __P((res_state));
 386 uint_t          res_randomid __P((void));
 387 uint_t          res_nrandomid __P((res_state));
 388 int             res_nameinquery __P((const char *, int, int,
 389                                 const uchar_t *, const uchar_t *));
 390 int             res_queriesmatch __P((const uchar_t *, const uchar_t *,
 391                                 const uchar_t *, const uchar_t *));
 392 const char      *p_section __P((int section, int opcode));
 393 
 394 
 395 /* Things involving a resolver context. */
 396 int             res_ninit __P((res_state));
 397 int             res_nisourserver __P((const res_state,
 398                                 const struct sockaddr_in *));
 399 void    fp_resstat __P((const res_state, FILE *));
 400 void    res_pquery      __P((const res_state, const uchar_t *, int, FILE *));
 401 const char      *res_hostalias __P((const res_state, const char *,
 402                                 char *, size_t));
 403 int             res_nquery __P((res_state,
 404                                 const char *, int, int, uchar_t *, int));
 405 int             res_nsearch __P((res_state, const char *, int,
 406                                 int, uchar_t *, int));
 407 int             res_nquerydomain __P((res_state,
 408                                 const char *, const char *, int, int,
 409                                 uchar_t *, int));
 410 int             res_nmkquery __P((res_state,
 411                                 int, const char *, int, int, const uchar_t *,
 412                                 int, const uchar_t *, uchar_t *, int));
 413 int             res_nsend __P((res_state, const uchar_t *, int, uchar_t *,
 414                                 int));
 415 int             res_nsendsigned __P((res_state, const uchar_t *, int,
 416                                 ns_tsig_key *, uchar_t *, int));
 417 int             res_findzonecut __P((res_state, const char *, ns_class, int,
 418                                 char *, size_t, struct in_addr *, int));
 419 int             res_findzonecut2 __P((res_state, const char *, ns_class, int,
 420                                 char *, size_t, union res_sockaddr_union *,
 421                                 int));
 422 void            res_nclose __P((res_state));
 423 int             res_nopt __P((res_state, int, uchar_t *, int, int));
 424 int             res_nopt_rdata __P((res_state, int, uchar_t *, int, uchar_t *,
 425                                     ushort_t, ushort_t, uchar_t *));
 426 void            res_send_setqhook __P((res_send_qhook hook));
 427 void            res_send_setrhook __P((res_send_rhook hook));
 428 int             __res_vinit __P((res_state, int));
 429 void            res_destroyservicelist __P((void));
 430 const char      *res_servicename __P((uint16_t port, const char *proto));
 431 const char      *res_protocolname __P((int num));
 432 void            res_destroyprotolist __P((void));
 433 void            res_buildprotolist __P((void));
 434 const char      *res_get_nibblesuffix __P((res_state));
 435 const char      *res_get_nibblesuffix2 __P((res_state));
 436 void            res_ndestroy __P((res_state));
 437 uint16_t        res_nametoclass __P((const char *buf, int *success));
 438 uint16_t        res_nametotype __P((const char *buf, int *success));
 439 void            res_setservers __P((res_state,
 440                                     const union res_sockaddr_union *, int));
 441 int             res_getservers __P((res_state,
 442                                     union res_sockaddr_union *, int));
 443 
 444 
 445 #ifdef  __cplusplus
 446 }
 447 #endif
 448 
 449 #endif /* !_RESOLV_H_ */