opcode.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  9. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  10. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  12. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  13. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  14. * PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /* $Id$ */
  17. #include <stdint.h>
  18. #include <ostream>
  19. #ifndef __OPCODE_H
  20. #define __OPCODE_H 1
  21. namespace isc {
  22. namespace dns {
  23. /// \brief The \c Opcode class objects represent standard OPCODEs
  24. /// of the header section of DNS messages as defined in RFC1035.
  25. ///
  26. /// Note: since there are only 15 possible values, it may make more sense to
  27. /// simply define an enum type to represent these values.
  28. ///
  29. /// Constant objects are defined for standard flags.
  30. class Opcode {
  31. public:
  32. enum CodeValue {
  33. QUERY_CODE = 0,
  34. IQUERY_CODE = 1,
  35. STATUS_CODE = 2,
  36. RESERVED3_CODE = 3,
  37. NOTIFY_CODE = 4,
  38. UPDATE_CODE = 5,
  39. RESERVED6_CODE = 6,
  40. RESERVED7_CODE = 7,
  41. RESERVED8_CODE = 8,
  42. RESERVED9_CODE = 9,
  43. RESERVED10_CODE = 10,
  44. RESERVED11_CODE = 11,
  45. RESERVED12_CODE = 12,
  46. RESERVED13_CODE = 13,
  47. RESERVED14_CODE = 14,
  48. RESERVED15_CODE = 15,
  49. MAX_CODE = 15
  50. };
  51. explicit Opcode(const uint16_t code);
  52. CodeValue getCode() const { return (code_); }
  53. /// \brief Return true iff two Opcodes are equal.
  54. bool equals(const Opcode& other) const
  55. { return (code_ == other.code_); }
  56. bool operator==(const Opcode& other) const { return (equals(other)); }
  57. bool nequals(const Opcode& other) const
  58. { return (code_ != other.code_); }
  59. bool operator!=(const Opcode& other) const { return (nequals(other)); }
  60. std::string toText() const;
  61. static const Opcode& QUERY();
  62. static const Opcode& IQUERY();
  63. static const Opcode& STATUS();
  64. static const Opcode& RESERVED3();
  65. static const Opcode& NOTIFY();
  66. static const Opcode& UPDATE();
  67. static const Opcode& RESERVED6();
  68. static const Opcode& RESERVED7();
  69. static const Opcode& RESERVED8();
  70. static const Opcode& RESERVED9();
  71. static const Opcode& RESERVED10();
  72. static const Opcode& RESERVED11();
  73. static const Opcode& RESERVED12();
  74. static const Opcode& RESERVED13();
  75. static const Opcode& RESERVED14();
  76. static const Opcode& RESERVED15();
  77. private:
  78. CodeValue code_;
  79. };
  80. inline const Opcode&
  81. Opcode::QUERY() {
  82. static Opcode c(0);
  83. return (c);
  84. }
  85. inline const Opcode&
  86. Opcode::IQUERY() {
  87. static Opcode c(1);
  88. return (c);
  89. }
  90. inline const Opcode&
  91. Opcode::STATUS() {
  92. static Opcode c(2);
  93. return (c);
  94. }
  95. inline const Opcode&
  96. Opcode::RESERVED3() {
  97. static Opcode c(3);
  98. return (c);
  99. }
  100. inline const Opcode&
  101. Opcode::NOTIFY() {
  102. static Opcode c(4);
  103. return (c);
  104. }
  105. inline const Opcode&
  106. Opcode::UPDATE() {
  107. static Opcode c(5);
  108. return (c);
  109. }
  110. inline const Opcode&
  111. Opcode::RESERVED6() {
  112. static Opcode c(6);
  113. return (c);
  114. }
  115. inline const Opcode&
  116. Opcode::RESERVED7() {
  117. static Opcode c(7);
  118. return (c);
  119. }
  120. inline const Opcode&
  121. Opcode::RESERVED8() {
  122. static Opcode c(8);
  123. return (c);
  124. }
  125. inline const Opcode&
  126. Opcode::RESERVED9() {
  127. static Opcode c(9);
  128. return (c);
  129. }
  130. inline const Opcode&
  131. Opcode::RESERVED10() {
  132. static Opcode c(10);
  133. return (c);
  134. }
  135. inline const Opcode&
  136. Opcode::RESERVED11() {
  137. static Opcode c(11);
  138. return (c);
  139. }
  140. inline const Opcode&
  141. Opcode::RESERVED12() {
  142. static Opcode c(12);
  143. return (c);
  144. }
  145. inline const Opcode&
  146. Opcode::RESERVED13() {
  147. static Opcode c(13);
  148. return (c);
  149. }
  150. inline const Opcode&
  151. Opcode::RESERVED14() {
  152. static Opcode c(14);
  153. return (c);
  154. }
  155. inline const Opcode&
  156. Opcode::RESERVED15() {
  157. static Opcode c(15);
  158. return (c);
  159. }
  160. /// \brief Insert the \c Opcode as a string into stream.
  161. ///
  162. /// This method convert \c opcode into a string and inserts it into the
  163. /// output stream \c os.
  164. ///
  165. /// \param os A \c std::ostream object on which the insertion operation is
  166. /// performed.
  167. /// \param opcode A reference to an \c Opcode object output by the operation.
  168. /// \return A reference to the same \c std::ostream object referenced by
  169. /// parameter \c os after the insertion operation.
  170. std::ostream& operator<<(std::ostream& os, const Opcode& opcode);
  171. }
  172. }
  173. #endif // OPCODE_H
  174. // Local Variables:
  175. // mode: c++
  176. // End: