home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / include / arpa / nameser.h < prev    next >
C/C++ Source or Header  |  1996-12-11  |  9KB  |  249 lines

  1. /*    $NetBSD: nameser.h,v 1.7 1994/10/26 00:56:45 cgd Exp $    */
  2.  
  3. /*
  4.  * Copyright (c) 1983, 1989 Regents of the University of California.
  5.  * 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.  *    @(#)nameser.h    5.25 (Berkeley) 4/3/91
  36.  */
  37.  
  38. #ifndef _NAMESER_H_
  39. #define    _NAMESER_H_
  40.  
  41. #include <machine/endian.h>
  42. #include <sys/cdefs.h>
  43.  
  44. /*
  45.  * Define constants based on rfc883
  46.  */
  47. #define PACKETSZ    512        /* maximum packet size */
  48. #define MAXDNAME    256        /* maximum domain name */
  49. #define MAXCDNAME    255        /* maximum compressed domain name */
  50. #define MAXLABEL    63        /* maximum length of domain label */
  51.     /* Number of bytes of fixed size data in query structure */
  52. #define QFIXEDSZ    4
  53.     /* number of bytes of fixed size data in resource record */
  54. #define RRFIXEDSZ    10
  55.  
  56. /*
  57.  * Internet nameserver port number
  58.  */
  59. #define NAMESERVER_PORT    53
  60.  
  61. /*
  62.  * Currently defined opcodes
  63.  */
  64. #define QUERY        0x0        /* standard query */
  65. #define IQUERY        0x1        /* inverse query */
  66. #define STATUS        0x2        /* nameserver status query */
  67. /*#define xxx        0x3*/        /* 0x3 reserved */
  68.     /* non standard */
  69. #define UPDATEA        0x9        /* add resource record */
  70. #define UPDATED        0xa        /* delete a specific resource record */
  71. #define UPDATEDA    0xb        /* delete all named resource record */
  72. #define UPDATEM        0xc        /* modify a specific resource record */
  73. #define UPDATEMA    0xd        /* modify all named resource record */
  74.  
  75. #define ZONEINIT    0xe        /* initial zone transfer */
  76. #define ZONEREF        0xf        /* incremental zone referesh */
  77.  
  78. /*
  79.  * Currently defined response codes
  80.  */
  81. #define NOERROR        0        /* no error */
  82. #define FORMERR        1        /* format error */
  83. #define SERVFAIL    2        /* server failure */
  84. #define NXDOMAIN    3        /* non existent domain */
  85. #define NOTIMP        4        /* not implemented */
  86. #define REFUSED        5        /* query refused */
  87.     /* non standard */
  88. #define NOCHANGE    0xf        /* update failed to change db */
  89.  
  90. /*
  91.  * Type values for resources and queries
  92.  */
  93. #define T_A        1        /* host address */
  94. #define T_NS        2        /* authoritative server */
  95. #define T_MD        3        /* mail destination */
  96. #define T_MF        4        /* mail forwarder */
  97. #define T_CNAME        5        /* connonical name */
  98. #define T_SOA        6        /* start of authority zone */
  99. #define T_MB        7        /* mailbox domain name */
  100. #define T_MG        8        /* mail group member */
  101. #define T_MR        9        /* mail rename name */
  102. #define T_NULL        10        /* null resource record */
  103. #define T_WKS        11        /* well known service */
  104. #define T_PTR        12        /* domain name pointer */
  105. #define T_HINFO        13        /* host information */
  106. #define T_MINFO        14        /* mailbox information */
  107. #define T_MX        15        /* mail routing information */
  108. #define T_TXT        16        /* text strings */
  109. #define T_RP        17        /* responsible person */
  110. #define T_AFSDB        18        /* AFS cell database */
  111. #define T_NSAP        22        /* NSAP address */
  112. #define T_NSAP_PTR    23        /* reverse lookup for NSAP */
  113.     /* non standard */
  114. #define T_UINFO        100        /* user (finger) information */
  115. #define T_UID        101        /* user ID */
  116. #define T_GID        102        /* group ID */
  117. #define T_UNSPEC    103        /* Unspecified format (binary data) */
  118. #define T_SA        200        /* shuffle address */
  119.     /* Query type values which do not appear in resource records */
  120. #define T_AXFR        252        /* transfer zone of authority */
  121. #define T_MAILB        253        /* transfer mailbox records */
  122. #define T_MAILA        254        /* transfer mail agent records */
  123. #define T_ANY        255        /* wildcard match */
  124.  
  125. /*
  126.  * Values for class field
  127.  */
  128. #define C_IN        1        /* the arpa internet */
  129. #define C_CHAOS        3        /* for chaos net at MIT */
  130. #define C_HS        4        /* for Hesiod name server at MIT */
  131.     /* Query class values which do not appear in resource records */
  132. #define C_ANY        255        /* wildcard match */
  133.  
  134. /*
  135.  * Status return codes for T_UNSPEC conversion routines
  136.  */
  137. #define CONV_SUCCESS 0
  138. #define CONV_OVERFLOW -1
  139. #define CONV_BADFMT -2
  140. #define CONV_BADCKSUM -3
  141. #define CONV_BADBUFLEN -4
  142.  
  143. /*
  144.  * Structure for query header, the order of the fields is machine and
  145.  * compiler dependent, in our case, the bits within a byte are assignd 
  146.  * least significant first, while the order of transmition is most 
  147.  * significant first.  This requires a somewhat confusing rearrangement.
  148.  */
  149. typedef struct {
  150.     u_short    id;        /* query identification number */
  151. #if BYTE_ORDER == BIG_ENDIAN
  152.             /* fields in third byte */
  153.     u_char    qr:1;        /* response flag */
  154.     u_char    opcode:4;    /* purpose of message */
  155.     u_char    aa:1;        /* authoritive answer */
  156.     u_char    tc:1;        /* truncated message */
  157.     u_char    rd:1;        /* recursion desired */
  158.             /* fields in fourth byte */
  159.     u_char    ra:1;        /* recursion available */
  160.     u_char    pr:1;        /* primary server required (non standard) */
  161.     u_char    unused:2;    /* unused bits */
  162.     u_char    rcode:4;    /* response code */
  163. #endif
  164. #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
  165.             /* fields in third byte */
  166.     u_char    rd:1;        /* recursion desired */
  167.     u_char    tc:1;        /* truncated message */
  168.     u_char    aa:1;        /* authoritive answer */
  169.     u_char    opcode:4;    /* purpose of message */
  170.     u_char    qr:1;        /* response flag */
  171.             /* fields in fourth byte */
  172.     u_char    rcode:4;    /* response code */
  173.     u_char    unused:2;    /* unused bits */
  174.     u_char    pr:1;        /* primary server required (non standard) */
  175.     u_char    ra:1;        /* recursion available */
  176. #endif
  177.             /* remaining bytes */
  178.     u_short    qdcount;    /* number of question entries */
  179.     u_short    ancount;    /* number of answer entries */
  180.     u_short    nscount;    /* number of authority entries */
  181.     u_short    arcount;    /* number of resource entries */
  182. } HEADER;
  183.  
  184. /*
  185.  * Defines for handling compressed domain names
  186.  */
  187. #define INDIR_MASK    0xc0
  188.  
  189. /*
  190.  * Structure for passing resource records around.
  191.  */
  192. struct rrec {
  193.     int16_t        r_zone;            /* zone number */
  194.     int16_t        r_class;        /* class number */
  195.     int16_t        r_type;            /* type number */
  196.     u_int32_t    r_ttl;            /* time to live */
  197.     int        r_size;            /* size of data area */
  198.     char        *r_data;        /* pointer to data */
  199. };
  200.  
  201. extern    u_int16_t    _getshort();
  202. extern    u_int32_t    _getlong();
  203.  
  204. /*
  205.  * Inline versions of get/put short/long.
  206.  * Pointer is advanced; we assume that both arguments
  207.  * are lvalues and will already be in registers.
  208.  * cp MUST be u_char *.
  209.  */
  210. #define GETSHORT(s, cp) { \
  211.     register u_char *t_cp = (u_char *)(cp); \
  212.     (s) = ((u_int16_t)t_cp[0] << 8) \
  213.         | ((u_int16_t)t_cp[1]) ;\
  214.     (cp) += sizeof(u_int16_t); \
  215. }
  216.  
  217. #define GETLONG(l, cp) { \
  218.     register u_char *t_cp = (u_char *)(cp); \
  219.     (l) = ((u_int32_t)t_cp[0] << 24) \
  220.         | ((u_int32_t)t_cp[1] << 16) \
  221.         | ((u_int32_t)t_cp[2] << 8) \
  222.         | ((u_int32_t)t_cp[3]) ;\
  223.     (cp) += sizeof(u_int32_t); \
  224. }
  225.  
  226. #define PUTSHORT(s, cp) { \
  227.     register u_int16_t t_s = (u_int16_t)(s); \
  228.     register u_char *t_cp = (u_char *)(cp); \
  229.     *t_cp++ = t_s >> 8; \
  230.     *t_cp   = t_s; \
  231.     (cp) += sizeof(u_int16_t); \
  232. }
  233.  
  234. /*
  235.  * Warning: PUTLONG --no-longer-- destroys its first argument.  if you
  236.  * were depending on this "feature", you will lose.
  237.  */
  238. #define PUTLONG(l, cp) { \
  239.     register u_int32_t t_l = (u_int32_t)(l); \
  240.     register u_char *t_cp = (u_char *)(cp); \
  241.     *t_cp++ = t_l >> 24; \
  242.     *t_cp++ = t_l >> 16; \
  243.     *t_cp++ = t_l >> 8; \
  244.     *t_cp   = t_l; \
  245.     (cp) += sizeof(u_int32_t); \
  246. }
  247.  
  248. #endif /* !_NAMESER_H_ */
  249.