home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / internet / tcpipsrc / h / if / nameser < prev    next >
Text File  |  1995-02-22  |  7KB  |  231 lines

  1. /*
  2.  * Copyright (c) 1983, 1989 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that: (1) source distributions retain this entire copyright
  7.  * notice and comment, and (2) distributions including binaries display
  8.  * the following acknowledgement:  ``This product includes software
  9.  * developed by the University of California, Berkeley and its contributors''
  10.  * in the documentation or other materials provided with the distribution
  11.  * and in all advertising materials mentioning features or use of this
  12.  * software. Neither the name of the University nor the names of its
  13.  * contributors may be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  *
  19.  *    @(#)nameser.h    5.24 (Berkeley) 6/1/90
  20.  */
  21.  
  22. #ifndef u_int
  23. #define u_int unsigned int
  24. #endif
  25. #ifndef u_char
  26. #define u_char char
  27. #endif
  28. #ifndef u_short
  29. #define u_short unsigned short
  30. #endif
  31. #ifndef u_long
  32. #define u_long unsigned long
  33. #endif
  34. /*
  35.  * Define constants based on rfc883
  36.  */
  37. #define PACKETSZ    512        /* maximum packet size */
  38. #define MAXDNAME    256        /* maximum domain name */
  39. #define MAXCDNAME    255        /* maximum compressed domain name */
  40. #define MAXLABEL    63        /* maximum length of domain label */
  41.     /* Number of bytes of fixed size data in query structure */
  42. #define QFIXEDSZ    4
  43.     /* number of bytes of fixed size data in resource record */
  44. #define RRFIXEDSZ    10
  45.  
  46. /*
  47.  * Internet nameserver port number
  48.  */
  49. #define NAMESERVER_PORT    53
  50.  
  51. /*
  52.  * Currently defined opcodes
  53.  */
  54. #define QUERY        0x0        /* standard query */
  55. #define IQUERY        0x1        /* inverse query */
  56. #define STATUS        0x2        /* nameserver status query */
  57. /*#define xxx        0x3    */    /* 0x3 reserved */
  58.     /* non standard */
  59. #define UPDATEA        0x9        /* add resource record */
  60. #define UPDATED        0xa        /* delete a specific resource record */
  61. #define UPDATEDA    0xb        /* delete all nemed resource record */
  62. #define UPDATEM        0xc        /* modify a specific resource record */
  63. #define UPDATEMA    0xd        /* modify all named resource record */
  64.  
  65. #define ZONEINIT    0xe        /* initial zone transfer */
  66. #define ZONEREF        0xf        /* incremental zone referesh */
  67.  
  68. /*
  69.  * Currently defined response codes
  70.  */
  71. #define NOERROR        0        /* no error */
  72. #define FORMERR        1        /* format error */
  73. #define SERVFAIL    2        /* server failure */
  74. #define NXDOMAIN    3        /* non existent domain */
  75. #define NOTIMP        4        /* not implemented */
  76. #define REFUSED        5        /* query refused */
  77.     /* non standard */
  78. #define NOCHANGE    0xf        /* update failed to change db */
  79.  
  80. /*
  81.  * Type values for resources and queries
  82.  */
  83. #define T_A        1        /* host address */
  84. #define T_NS        2        /* authoritative server */
  85. #define T_MD        3        /* mail destination */
  86. #define T_MF        4        /* mail forwarder */
  87. #define T_CNAME        5        /* connonical name */
  88. #define T_SOA        6        /* start of authority zone */
  89. #define T_MB        7        /* mailbox domain name */
  90. #define T_MG        8        /* mail group member */
  91. #define T_MR        9        /* mail rename name */
  92. #define T_NULL        10        /* null resource record */
  93. #define T_WKS        11        /* well known service */
  94. #define T_PTR        12        /* domain name pointer */
  95. #define T_HINFO        13        /* host information */
  96. #define T_MINFO        14        /* mailbox information */
  97. #define T_MX        15        /* mail routing information */
  98. #define T_TXT        16        /* text strings */
  99.     /* non standard */
  100. #define T_UINFO        100        /* user (finger) information */
  101. #define T_UID        101        /* user ID */
  102. #define T_GID        102        /* group ID */
  103. #define T_UNSPEC    103        /* Unspecified format (binary data) */
  104.     /* Query type values which do not appear in resource records */
  105. #define T_AXFR        252        /* transfer zone of authority */
  106. #define T_MAILB        253        /* transfer mailbox records */
  107. #define T_MAILA        254        /* transfer mail agent records */
  108. #define T_ANY        255        /* wildcard match */
  109.  
  110. /*
  111.  * Values for class field
  112.  */
  113.  
  114. #define C_IN        1        /* the arpa internet */
  115. #define C_CHAOS        3        /* for chaos net at MIT */
  116. #define C_HS        4        /* for Hesiod name server at MIT */
  117.     /* Query class values which do not appear in resource records */
  118. #define C_ANY        255        /* wildcard match */
  119.  
  120. /*
  121.  * Status return codes for T_UNSPEC conversion routines
  122.  */
  123. #define CONV_SUCCESS 0
  124. #define CONV_OVERFLOW -1
  125. #define CONV_BADFMT -2
  126. #define CONV_BADCKSUM -3
  127. #define CONV_BADBUFLEN -4
  128.  
  129. #ifndef BYTE_ORDER
  130. #define    LITTLE_ENDIAN    1234    /* least-significant byte first (vax) */
  131. #define    BIG_ENDIAN    4321    /* most-significant byte first (IBM, net) */
  132. #define    PDP_ENDIAN    3412    /* LSB first in word, MSW first in long (pdp) */
  133.  
  134. #if defined(vax) || defined(ns32000) || defined(sun386) || defined(MIPSEL) || \
  135.     defined(BIT_ZERO_ON_RIGHT)
  136. #define BYTE_ORDER    LITTLE_ENDIAN
  137.  
  138. #endif
  139. #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
  140.     defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
  141.     defined(MIPSEB) || defined (BIT_ZERO_ON_LEFT)
  142. #define BYTE_ORDER    BIG_ENDIAN
  143. #endif
  144. #endif /* BYTE_ORDER */
  145.  
  146. #ifndef BYTE_ORDER
  147.     /* you must determine what the correct bit order is for your compiler */
  148.     UNDEFINED_BIT_ORDER;
  149. #endif
  150. /*
  151.  * Structure for query header, the order of the fields is machine and
  152.  * compiler dependent, in our case, the bits within a byte are assignd
  153.  * least significant first, while the order of transmition is most
  154.  * significant first.  This requires a somewhat confusing rearrangement.
  155.  */
  156.  
  157. typedef struct {
  158.     u_int    id:16;        /* query identification number */
  159.             /* fields in third byte */
  160.     u_int    rd:1;        /* recursion desired */
  161.     u_int    tc:1;        /* truncated message */
  162.     u_int    aa:1;        /* authoritive answer */
  163.     u_int    opcode:4;    /* purpose of message */
  164.     u_int    qr:1;        /* response flag */
  165.             /* fields in fourth byte */
  166.     u_int    rcode:4;    /* response code */
  167.     u_int    unused:2;    /* unused bits */
  168.     u_int    pr:1;        /* primary server required (non standard) */
  169.     u_int    ra:1;        /* recursion available */
  170.             /* remaining bytes */
  171.     u_short    qdcount;    /* number of question entries */
  172.     u_short    ancount;    /* number of answer entries */
  173.     u_short    nscount;    /* number of authority entries */
  174.     u_short    arcount;    /* number of resource entries */
  175. } HEADER;
  176.  
  177. /*
  178.  * Defines for handling compressed domain names
  179.  */
  180. #define INDIR_MASK    0xc0
  181.  
  182. /*
  183.  * Structure for passing resource records around.
  184.  */
  185. struct rrec {
  186.     short    r_zone;            /* zone number */
  187.     short    r_class;        /* class number */
  188.     short    r_type;            /* type number */
  189.     u_long    r_ttl;            /* time to live */
  190.     int    r_size;            /* size of data area */
  191.     char    *r_data;        /* pointer to data */
  192. };
  193.  
  194. extern    u_short    _getshort(u_char *msgp);
  195. extern    u_long    _getlong(u_char *msgp);
  196.  
  197. /*
  198.  * Inline versions of get/put short/long.
  199.  * Pointer is advanced; we assume that both arguments
  200.  * are lvalues and will already be in registers.
  201.  * cp MUST be u_char *.
  202.  */
  203. #define GETSHORT(s, cp) { \
  204.     (s) = *(cp)++ << 8; \
  205.     (s) |= *(cp)++; \
  206. }
  207.  
  208. #define GETLONG(l, cp) { \
  209.     (l) = *(cp)++ << 8; \
  210.     (l) |= *(cp)++; (l) <<= 8; \
  211.     (l) |= *(cp)++; (l) <<= 8; \
  212.     (l) |= *(cp)++; \
  213. }
  214.  
  215.  
  216. #define PUTSHORT(s, cp) { \
  217.     *(cp)++ = (s) >> 8; \
  218.     *(cp)++ = (s); \
  219. }
  220.  
  221. /*
  222.  * Warning: PUTLONG destroys its first argument.
  223.  */
  224. #define PUTLONG(l, cp) { \
  225.     (cp)[3] = l; \
  226.     (cp)[2] = (l >>= 8); \
  227.     (cp)[1] = (l >>= 8); \
  228.     (cp)[0] = l >> 8; \
  229.     (cp) += sizeof(u_long); \
  230. }
  231.