/contrib/bind9/lib/lwres/include/lwres/lwpacket.h

https://bitbucket.org/freebsd/freebsd-head/ · C Header · 159 lines · 27 code · 15 blank · 117 comment · 0 complexity · e62b809cd2c2d76bd575e91121cd9f15 MD5 · raw file

  1. /*
  2. * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 1999-2001 Internet Software Consortium.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. * PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /* $Id: lwpacket.h,v 1.24 2007/06/19 23:47:23 tbox Exp $ */
  18. #ifndef LWRES_LWPACKET_H
  19. #define LWRES_LWPACKET_H 1
  20. #include <lwres/lang.h>
  21. #include <lwres/lwbuffer.h>
  22. #include <lwres/result.h>
  23. /*% lwres_lwpacket_t */
  24. typedef struct lwres_lwpacket lwres_lwpacket_t;
  25. /*% lwres_lwpacket structure */
  26. struct lwres_lwpacket {
  27. /*! The overall packet length, including the
  28. * entire packet header.
  29. * This field is filled in by the
  30. * \link lwres_gabn.c lwres_gabn_*()\endlink
  31. * and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
  32. */
  33. lwres_uint32_t length;
  34. /*! Specifies the header format. Currently,
  35. * there is only one format, #LWRES_LWPACKETVERSION_0.
  36. * This field is filled in by the
  37. * \link lwres_gabn.c lwres_gabn_*()\endlink
  38. * and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
  39. */
  40. lwres_uint16_t version;
  41. /*! Specifies library-defined flags for this packet, such as
  42. * whether the packet is a request or a reply. None of
  43. * these are definable by the caller, but library-defined values
  44. * can be set by the caller. For example, one bit in this field
  45. * indicates if the packet is a request or a response.
  46. * This field is filled in by
  47. * the application wits the exception of the
  48. * #LWRES_LWPACKETFLAG_RESPONSE bit, which is set by the library
  49. * in the
  50. * \link lwres_gabn.c lwres_gabn_*()\endlink
  51. * and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
  52. */
  53. lwres_uint16_t pktflags;
  54. /*! Set by the requestor and is returned in all replies.
  55. * If two packets from the same source have the same serial
  56. * number and are from the same source, they are assumed to
  57. * be duplicates and the latter ones may be dropped.
  58. * (The library does not do this by default on replies, but
  59. * does so on requests.)
  60. */
  61. lwres_uint32_t serial;
  62. /*! Opcodes between 0x04000000 and 0xffffffff
  63. * are application defined. Opcodes between
  64. * 0x00000000 and 0x03ffffff are
  65. * reserved for library use.
  66. * This field is filled in by the
  67. * \link lwres_gabn.c lwres_gabn_*()\endlink
  68. * and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
  69. */
  70. lwres_uint32_t opcode;
  71. /*! Only valid for results.
  72. * Results between 0x04000000 and 0xffffffff are application
  73. * defined.
  74. * Results between 0x00000000 and 0x03ffffff are reserved for
  75. * library use.
  76. * (This is the same reserved range defined in <isc/resultclass.h>,
  77. * so it
  78. * would be trivial to map ISC_R_* result codes into packet result
  79. * codes when appropriate.)
  80. * This field is filled in by the
  81. * \link lwres_gabn.c lwres_gabn_*()\endlink
  82. * and \link lwres_gnba.c lwres_gnba_*()\endlink calls.
  83. */
  84. lwres_uint32_t result;
  85. /*! Set to the maximum buffer size that the receiver can
  86. * handle on requests, and the size of the buffer needed to
  87. * satisfy a request
  88. * when the buffer is too large for replies.
  89. * This field is supplied by the application.
  90. */
  91. lwres_uint32_t recvlength;
  92. /*! The packet level auth type used.
  93. * Authtypes between 0x1000 and 0xffff are application defined.
  94. * Authtypes
  95. * between 0x0000 and 0x0fff are reserved for library use.
  96. * This is currently
  97. * unused and MUST be set to zero.
  98. */
  99. lwres_uint16_t authtype;
  100. /*! The length of the authentication data.
  101. * See the specific
  102. * authtypes for more information on what is contained
  103. * in this field. This is currently unused, and
  104. * MUST be set to zero.
  105. */
  106. lwres_uint16_t authlength;
  107. };
  108. #define LWRES_LWPACKET_LENGTH (4 * 5 + 2 * 4) /*%< Overall length. */
  109. #define LWRES_LWPACKETFLAG_RESPONSE 0x0001U /*%< If set, pkt is a response. */
  110. #define LWRES_LWPACKETVERSION_0 0 /*%< Header format. */
  111. /*! \file lwres/lwpacket.h
  112. *
  113. *
  114. * The remainder of the packet consists of two regions, one described by
  115. * "authlen" and one of "length - authlen - sizeof(lwres_lwpacket_t)".
  116. *
  117. * That is:
  118. *
  119. * \code
  120. * pkt header
  121. * authlen bytes of auth information
  122. * data bytes
  123. * \endcode
  124. *
  125. * Currently defined opcodes:
  126. *
  127. *\li #LWRES_OPCODE_NOOP. Success is always returned, with the packet contents echoed.
  128. *
  129. *\li #LWRES_OPCODE_GETADDRSBYNAME. Return all known addresses for a given name.
  130. * This may return NIS or /etc/hosts info as well as DNS
  131. * information. Flags will be provided to indicate ip4/ip6
  132. * addresses are desired.
  133. *
  134. *\li #LWRES_OPCODE_GETNAMEBYADDR. Return the hostname for the given address. Once
  135. * again, it will return data from multiple sources.
  136. */
  137. LWRES_LANG_BEGINDECLS
  138. /* XXXMLG document */
  139. lwres_result_t
  140. lwres_lwpacket_renderheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt);
  141. lwres_result_t
  142. lwres_lwpacket_parseheader(lwres_buffer_t *b, lwres_lwpacket_t *pkt);
  143. LWRES_LANG_ENDDECLS
  144. #endif /* LWRES_LWPACKET_H */