icmp.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // ip/icmp.hpp
  3. // ~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_IP_ICMP_HPP
  11. #define BOOST_ASIO_IP_ICMP_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/socket_types.hpp>
  17. #include <boost/asio/basic_raw_socket.hpp>
  18. #include <boost/asio/ip/basic_endpoint.hpp>
  19. #include <boost/asio/ip/basic_resolver.hpp>
  20. #include <boost/asio/ip/basic_resolver_iterator.hpp>
  21. #include <boost/asio/ip/basic_resolver_query.hpp>
  22. #include <boost/asio/detail/push_options.hpp>
  23. namespace boost {
  24. namespace asio {
  25. namespace ip {
  26. /// Encapsulates the flags needed for ICMP.
  27. /**
  28. * The boost::asio::ip::icmp class contains flags necessary for ICMP sockets.
  29. *
  30. * @par Thread Safety
  31. * @e Distinct @e objects: Safe.@n
  32. * @e Shared @e objects: Safe.
  33. *
  34. * @par Concepts:
  35. * Protocol, InternetProtocol.
  36. */
  37. class icmp
  38. {
  39. public:
  40. /// The type of a ICMP endpoint.
  41. typedef basic_endpoint<icmp> endpoint;
  42. /// Construct to represent the IPv4 ICMP protocol.
  43. static icmp v4() BOOST_ASIO_NOEXCEPT
  44. {
  45. return icmp(BOOST_ASIO_OS_DEF(IPPROTO_ICMP),
  46. BOOST_ASIO_OS_DEF(AF_INET));
  47. }
  48. /// Construct to represent the IPv6 ICMP protocol.
  49. static icmp v6() BOOST_ASIO_NOEXCEPT
  50. {
  51. return icmp(BOOST_ASIO_OS_DEF(IPPROTO_ICMPV6),
  52. BOOST_ASIO_OS_DEF(AF_INET6));
  53. }
  54. /// Obtain an identifier for the type of the protocol.
  55. int type() const BOOST_ASIO_NOEXCEPT
  56. {
  57. return BOOST_ASIO_OS_DEF(SOCK_RAW);
  58. }
  59. /// Obtain an identifier for the protocol.
  60. int protocol() const BOOST_ASIO_NOEXCEPT
  61. {
  62. return protocol_;
  63. }
  64. /// Obtain an identifier for the protocol family.
  65. int family() const BOOST_ASIO_NOEXCEPT
  66. {
  67. return family_;
  68. }
  69. /// The ICMP socket type.
  70. typedef basic_raw_socket<icmp> socket;
  71. /// The ICMP resolver type.
  72. typedef basic_resolver<icmp> resolver;
  73. /// Compare two protocols for equality.
  74. friend bool operator==(const icmp& p1, const icmp& p2)
  75. {
  76. return p1.protocol_ == p2.protocol_ && p1.family_ == p2.family_;
  77. }
  78. /// Compare two protocols for inequality.
  79. friend bool operator!=(const icmp& p1, const icmp& p2)
  80. {
  81. return p1.protocol_ != p2.protocol_ || p1.family_ != p2.family_;
  82. }
  83. private:
  84. // Construct with a specific family.
  85. explicit icmp(int protocol_id, int protocol_family) BOOST_ASIO_NOEXCEPT
  86. : protocol_(protocol_id),
  87. family_(protocol_family)
  88. {
  89. }
  90. int protocol_;
  91. int family_;
  92. };
  93. } // namespace ip
  94. } // namespace asio
  95. } // namespace boost
  96. #include <boost/asio/detail/pop_options.hpp>
  97. #endif // BOOST_ASIO_IP_ICMP_HPP