option_info.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __OPTION_INFO_H
  15. #define __OPTION_INFO_H
  16. #include <stdint.h>
  17. #include "exceptions/exceptions.h"
  18. namespace isc {
  19. namespace badpacket {
  20. /// \brief Option Information
  21. ///
  22. /// Holds details about the options that can be specified on the command line
  23. /// that require values. Some of these options correspond to fields in the
  24. /// DNS message header, and information about these fields is supplied.
  25. class OptionInfo {
  26. public:
  27. /// \brief Array Indexes
  28. ///
  29. /// The data for the flags options are held in an array. This enum
  30. /// specifies the position of the data for each flags field.
  31. enum Index {
  32. QR = 0,
  33. OP = 1,
  34. AA = 2,
  35. TC = 3,
  36. RD = 4,
  37. RA = 5,
  38. Z = 6,
  39. AD = 7,
  40. CD = 8,
  41. RC = 9,
  42. SIZE = 10 // Number of index values
  43. };
  44. /// \brief Option Parameters
  45. ///
  46. /// Defines a structure that holds information associated with each of the
  47. /// flags field command options.
  48. struct Parameter {
  49. const char* long_form; // Long form of the command switch
  50. uint16_t mask; // Bit mask of the field in the flags word
  51. int offset; // Offset of field in flags word
  52. uint32_t minval; // Minimum valid value for this field
  53. uint32_t maxval; // Maximum valid value for this field
  54. };
  55. /// \brief Return long form of command switch for this field
  56. static const char* name(Index i);
  57. /// \brief Return mask associated with switch field
  58. static uint16_t mask(Index i);
  59. /// \brief Return offset associated with switch field
  60. static int offset(Index i);
  61. /// \brief Return minimum allowed value of field
  62. static uint32_t minval(Index i);
  63. /// \brief Return maximum allowed value of field
  64. static uint32_t maxval(Index i);
  65. private:
  66. /// \brief Check Array Index
  67. ///
  68. /// Checks the passed field index and throws an exception if out of range.
  69. static void checkIndex(Index i) {
  70. if ((i < 0) || (i >= SIZE)) {
  71. isc_throw(isc::OutOfRange, "option index must be in the range "
  72. "0 to " << SIZE);
  73. }
  74. }
  75. };
  76. } // namespace badpacket
  77. } // namespace isc
  78. #endif // __OPTION_INFO_H