home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / languages / netlib / !NetLib / arpa / h / nameser < prev   
Encoding:
Text File  |  1996-02-02  |  12.5 KB  |  353 lines

  1. /*
  2.  * ++Copyright++ 1983, 1989, 1993
  3.  * -
  4.  * Copyright (c) 1983, 1989, 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.  * --Copyright--
  54.  */
  55.  
  56. /*
  57.  *      @(#)nameser.h    8.1 (Berkeley) 6/2/93
  58.  *    $Id: nameser.h,v 8.2 1995/06/29 09:26:11 vixie Exp $
  59.  */
  60.  
  61. #ifndef _NAMESER_H_
  62. #define    _NAMESER_H_
  63.  
  64. /* Freenet programmers interface - arpa/nameser.h - edited by stewart 2/2/96 */
  65.  
  66. /*
  67.  * This file is severely hacked to compile cleanly with the rest of NetLib
  68.  * on ARM processors (in little-endian mode)
  69.  *
  70.  * S.N.Brodie@ecs.soton.ac.uk added this block for RISC OS NetLib
  71.  */
  72. #include "NetLib:sys.h.types"
  73. #define int16_t        short
  74. #define u_int16_t    unsigned short
  75. #define int32_t        long
  76. #define u_int32_t    unsigned long
  77. #ifndef BSD
  78. #define BSD 199103
  79. #endif
  80. /* End S.N.B. addition */
  81.  
  82. /*
  83.  * revision information.  this is the release date in YYYYMMDD format.
  84.  * it can change every day so the right thing to do with it is use it
  85.  * in preprocessor commands such as "#if (__BIND > 19931104)".  do not
  86.  * compare for equality; rather, use it to determine whether your resolver
  87.  * is new enough to contain a certain feature.
  88.  */
  89.  
  90. #define    __BIND        19950621    /* interface version stamp */
  91.  
  92. /*
  93.  * Define constants based on rfc883
  94.  */
  95. #define PACKETSZ    512        /* maximum packet size */
  96. #define MAXDNAME    256        /* maximum domain name */
  97. #define MAXCDNAME    255        /* maximum compressed domain name */
  98. #define MAXLABEL    63        /* maximum length of domain label */
  99. #define    HFIXEDSZ    12        /* #/bytes of fixed data in header */
  100. #define QFIXEDSZ    4        /* #/bytes of fixed data in query */
  101. #define RRFIXEDSZ    10        /* #/bytes of fixed data in r record */
  102. #define    INT32SZ        4        /* for systems without 32-bit ints */
  103. #define    INT16SZ        2        /* for systems without 16-bit ints */
  104. #define    INADDRSZ    4        /* for sizeof(struct inaddr) != 4 */
  105.  
  106. /*
  107.  * Internet nameserver port number
  108.  */
  109. #define NAMESERVER_PORT    53
  110.  
  111. /*
  112.  * Currently defined opcodes
  113.  */
  114. #define QUERY        0x0        /* standard query */
  115. #define IQUERY        0x1        /* inverse query */
  116. #define STATUS        0x2        /* nameserver status query */
  117. /*#define xxx        0x3        *//* 0x3 reserved */
  118. #define    NS_NOTIFY_OP    0x4        /* notify secondary of SOA change */
  119. #ifdef ALLOW_UPDATES
  120.     /* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */
  121. # define UPDATEA    0x9        /* add resource record */
  122. # define UPDATED    0xa        /* delete a specific resource record */
  123. # define UPDATEDA    0xb        /* delete all named resource record */
  124. # define UPDATEM    0xc        /* modify a specific resource record */
  125. # define UPDATEMA    0xd        /* modify all named resource record */
  126. # define ZONEINIT    0xe        /* initial zone transfer */
  127. # define ZONEREF    0xf        /* incremental zone referesh */
  128. #endif
  129.  
  130. /*
  131.  * Currently defined response codes
  132.  */
  133. #define NOERROR        0        /* no error */
  134. #define FORMERR        1        /* format error */
  135. #define SERVFAIL    2        /* server failure */
  136. #define NXDOMAIN    3        /* non existent domain */
  137. #define NOTIMP        4        /* not implemented */
  138. #define REFUSED        5        /* query refused */
  139. #ifdef ALLOW_UPDATES
  140.     /* non standard */
  141. # define NOCHANGE    0xf        /* update failed to change db */
  142. #endif
  143.  
  144. /*
  145.  * Type values for resources and queries
  146.  */
  147. #define T_A        1        /* host address */
  148. #define T_NS        2        /* authoritative server */
  149. #define T_MD        3        /* mail destination */
  150. #define T_MF        4        /* mail forwarder */
  151. #define T_CNAME        5        /* canonical name */
  152. #define T_SOA        6        /* start of authority zone */
  153. #define T_MB        7        /* mailbox domain name */
  154. #define T_MG        8        /* mail group member */
  155. #define T_MR        9        /* mail rename name */
  156. #define T_NULL        10        /* null resource record */
  157. #define T_WKS        11        /* well known service */
  158. #define T_PTR        12        /* domain name pointer */
  159. #define T_HINFO        13        /* host information */
  160. #define T_MINFO        14        /* mailbox information */
  161. #define T_MX        15        /* mail routing information */
  162. #define T_TXT        16        /* text strings */
  163. #define    T_RP        17        /* responsible person */
  164. #define T_AFSDB        18        /* AFS cell database */
  165. #define T_X25        19        /* X_25 calling address */
  166. #define T_ISDN        20        /* ISDN calling address */
  167. #define T_RT        21        /* router */
  168. #define T_NSAP        22        /* NSAP address */
  169. #define T_NSAP_PTR    23        /* reverse NSAP lookup (deprecated) */
  170. #define    T_SIG        24        /* security signature */
  171. #define    T_KEY        25        /* security key */
  172. #define    T_PX        26        /* X.400 mail mapping */
  173. #define    T_GPOS        27        /* geographical position (withdrawn) */
  174. #define    T_AAAA        28        /* IP6 Address */
  175. #define    T_LOC        29        /* Location Information */
  176.     /* non standard */
  177. #define T_UINFO        100        /* user (finger) information */
  178. #define T_UID        101        /* user ID */
  179. #define T_GID        102        /* group ID */
  180. #define T_UNSPEC    103        /* Unspecified format (binary data) */
  181.     /* Query type values which do not appear in resource records */
  182. #define T_AXFR        252        /* transfer zone of authority */
  183. #define T_MAILB        253        /* transfer mailbox records */
  184. #define T_MAILA        254        /* transfer mail agent records */
  185. #define T_ANY        255        /* wildcard match */
  186.  
  187. /*
  188.  * Values for class field
  189.  */
  190.  
  191. #define C_IN        1        /* the arpa internet */
  192. #define C_CHAOS        3        /* for chaos net (MIT) */
  193. #define C_HS        4        /* for Hesiod name server (MIT) (XXX) */
  194.     /* Query class values which do not appear in resource records */
  195. #define C_ANY        255        /* wildcard match */
  196.  
  197. /*
  198.  * Status return codes for T_UNSPEC conversion routines
  199.  */
  200. #define CONV_SUCCESS    0
  201. #define CONV_OVERFLOW    (-1)
  202. #define CONV_BADFMT    (-2)
  203. #define CONV_BADCKSUM    (-3)
  204. #define CONV_BADBUFLEN    (-4)
  205.  
  206. #ifndef BYTE_ORDER
  207. #if (BSD >= 199103) && !defined(__arm)
  208. # include <machine/endian.h>
  209. #else
  210. #ifdef linux
  211. # include <endian.h>
  212. #else
  213. #define    LITTLE_ENDIAN    1234    /* least-significant byte first (vax, pc) */
  214. #define    BIG_ENDIAN    4321    /* most-significant byte first (IBM, net) */
  215. #define    PDP_ENDIAN    3412    /* LSB first in word, MSW first in long (pdp)*/
  216.  
  217.  
  218. #if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
  219.     defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
  220.     defined(__alpha__) || defined(__alpha) || defined(__arm)
  221. #define BYTE_ORDER    LITTLE_ENDIAN
  222. #endif
  223.  
  224. #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
  225.     defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
  226.     defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
  227.     defined(apollo) || defined(__convex__) || defined(_CRAY) || \
  228.     defined(__hppa) || defined(__hp9000) || \
  229.     defined(__hp9000s300) || defined(__hp9000s700) || \
  230.     defined (BIT_ZERO_ON_LEFT) || defined(m68k)
  231. #define BYTE_ORDER    BIG_ENDIAN
  232. #endif
  233. #endif /* linux */
  234. #endif /* BSD */
  235. #endif /* BYTE_ORDER */
  236.  
  237. #if !defined(BYTE_ORDER) || \
  238.     (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
  239.     BYTE_ORDER != PDP_ENDIAN)
  240.     /* you must determine what the correct bit order is for
  241.      * your compiler - the next line is an intentional error
  242.      * which will force your compiles to bomb until you fix
  243.      * the above macros.
  244.      */
  245.   error "Undefined or invalid BYTE_ORDER";
  246. #endif
  247.  
  248. /*
  249.  * Structure for query header.  The order of the fields is machine- and
  250.  * compiler-dependent, depending on the byte/bit order and the layout
  251.  * of bit fields.  We use bit fields only in int variables, as this
  252.  * is all ANSI requires.  This requires a somewhat confusing rearrangement.
  253.  */
  254.  
  255. typedef struct {
  256.     unsigned    id :16;        /* query identification number */
  257. #if BYTE_ORDER == BIG_ENDIAN
  258.             /* fields in third byte */
  259.     unsigned    qr: 1;        /* response flag */
  260.     unsigned    opcode: 4;    /* purpose of message */
  261.     unsigned    aa: 1;        /* authoritive answer */
  262.     unsigned    tc: 1;        /* truncated message */
  263.     unsigned    rd: 1;        /* recursion desired */
  264.             /* fields in fourth byte */
  265.     unsigned    ra: 1;        /* recursion available */
  266.     unsigned    pr: 1;        /* primary required */
  267.     unsigned    unused :2;    /* unused bits (MBZ as of 4.9.3a3) */
  268.     unsigned    rcode :4;    /* response code */
  269. #endif
  270. #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
  271.             /* fields in third byte */
  272.     unsigned    rd :1;        /* recursion desired */
  273.     unsigned    tc :1;        /* truncated message */
  274.     unsigned    aa :1;        /* authoritive answer */
  275.     unsigned    opcode :4;    /* purpose of message */
  276.     unsigned    qr :1;        /* response flag */
  277.             /* fields in fourth byte */
  278.     unsigned    rcode :4;    /* response code */
  279.     unsigned    unused :2;    /* unused bits (MBZ as of 4.9.3a3) */
  280.     unsigned    pr: 1;        /* primary required */
  281.     unsigned    ra :1;        /* recursion available */
  282. #endif
  283.             /* remaining bytes */
  284.     unsigned    qdcount :16;    /* number of question entries */
  285.     unsigned    ancount :16;    /* number of answer entries */
  286.     unsigned    nscount :16;    /* number of authority entries */
  287.     unsigned    arcount :16;    /* number of resource entries */
  288. } HEADER;
  289.  
  290. /*
  291.  * Defines for handling compressed domain names
  292.  */
  293. #define INDIR_MASK    0xc0
  294.  
  295. /*
  296.  * Structure for passing resource records around.
  297.  */
  298. struct rrec {
  299.     int16_t        r_zone;            /* zone number */
  300.     int16_t        r_class;        /* class number */
  301.     int16_t        r_type;            /* type number */
  302.     u_int32_t    r_ttl;            /* time to live */
  303.     int        r_size;            /* size of data area */
  304.     char        *r_data;        /* pointer to data */
  305. };
  306.  
  307. extern    u_int16_t    _getshort(const u_char *);
  308. extern    u_int32_t    _getlong(const u_char *);
  309.  
  310. /*
  311.  * Inline versions of get/put short/long.  Pointer is advanced.
  312.  *
  313.  * These macros demonstrate the property of C whereby it can be
  314.  * portable or it can be elegant but rarely both.
  315.  */
  316. #define GETSHORT(s, cp) { \
  317.     register u_char *t_cp = (u_char *)(cp); \
  318.     (s) = ((u_int16_t)t_cp[0] << 8) \
  319.         | ((u_int16_t)t_cp[1]) \
  320.         ; \
  321.     (cp) += INT16SZ; \
  322. }
  323.  
  324. #define GETLONG(l, cp) { \
  325.     register u_char *t_cp = (u_char *)(cp); \
  326.     (l) = ((u_int32_t)t_cp[0] << 24) \
  327.         | ((u_int32_t)t_cp[1] << 16) \
  328.         | ((u_int32_t)t_cp[2] << 8) \
  329.         | ((u_int32_t)t_cp[3]) \
  330.         ; \
  331.     (cp) += INT32SZ; \
  332. }
  333.  
  334. #define PUTSHORT(s, cp) { \
  335.     register u_int16_t t_s = (u_int16_t)(s); \
  336.     register u_char *t_cp = (u_char *)(cp); \
  337.     *t_cp++ = t_s >> 8; \
  338.     *t_cp   = t_s; \
  339.     (cp) += INT16SZ; \
  340. }
  341.  
  342. #define PUTLONG(l, cp) { \
  343.     register u_int32_t t_l = (u_int32_t)(l); \
  344.     register u_char *t_cp = (u_char *)(cp); \
  345.     *t_cp++ = t_l >> 24; \
  346.     *t_cp++ = t_l >> 16; \
  347.     *t_cp++ = t_l >> 8; \
  348.     *t_cp   = t_l; \
  349.     (cp) += INT32SZ; \
  350. }
  351.  
  352. #endif /* !_NAMESER_H_ */
  353.