scan.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 __SCAN_H
  15. #define __SCAN_H
  16. #include <stdint.h>
  17. #include <boost/scoped_ptr.hpp>
  18. #include <config.h>
  19. #include <asiolink/io_fetch.h>
  20. #include <asiolink/io_service.h>
  21. #include <dns/buffer.h>
  22. #include "command_options.h"
  23. namespace isc {
  24. namespace badpacket {
  25. /// \brief Field Scan
  26. ///
  27. /// This class implements a field scan. Given a CommandOptions object, it
  28. /// will cycle through combinations of the given options, sending and
  29. /// receiving packets. For each packet exchange, a summary is written to
  30. /// stdout.
  31. class Scan : public asiolink::IOFetch::Callback {
  32. public:
  33. /// \brief Constructor
  34. Scan() : service_(), result_()
  35. {}
  36. /// \brief Run Scan
  37. ///
  38. /// \param options Command-line options
  39. void scan(const CommandOptions& options);
  40. /// \brief Callback
  41. ///
  42. /// This class is derived from the IOFetch::Callback class as it acts as the
  43. /// callback object. When an asynchronous I/I has completed, this method
  44. /// will be called.
  45. ///
  46. /// \param result Result of the asynchronous I/O. Zero implies success.
  47. virtual void operator()(asiolink::IOFetch::Result result);
  48. private:
  49. /// \brief Scan One Value
  50. ///
  51. /// Performs one exchange of packets with the remote nameserver, sending
  52. /// the specified message.
  53. ///
  54. /// \param msgbuf Message that will be sent to the remote nameserver. The
  55. /// QID given will be ignored - the value used will be determined by
  56. /// the sending code
  57. /// \param options Command-line options (the important ones being address,
  58. /// port and timeout).
  59. void scanOne(isc::dns::OutputBufferPtr& msgbuf,
  60. const CommandOptions& options);
  61. /// \brief Perform I/O
  62. ///
  63. /// Performs a single query to the nameserver and reads the response. It
  64. /// outputs a summary of the result.
  65. ///
  66. /// \param sendbuf Buffer sent to the nameserver
  67. /// \param recvbuf Buffer to hold reply from the nameserver
  68. /// \param options Command-line options
  69. void performIO(isc::dns::OutputBufferPtr& sendbuf,
  70. isc::dns::OutputBufferPtr& recvbuf,
  71. const CommandOptions& options);
  72. /// \brief Get Fields
  73. ///
  74. /// Interprets the flags fields in a DNS message and converts them to a
  75. /// terxtual format.
  76. ///
  77. /// \param msg Message for which the header is value
  78. ///
  79. /// \return A string that holds a textual interpretation of all the fields
  80. /// in the header.
  81. std::string getFields(isc::dns::OutputBufferPtr& msgbuf);
  82. // Member variables
  83. boost::scoped_ptr<asiolink::IOService> service_;///< Service to run the scan
  84. asiolink::IOFetch::Result result_; ///< Result of the I/O
  85. };
  86. } // namespace test
  87. } // namespace isc
  88. #endif // __SCAN_H