Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:33:34

0001 //
0002 // ip/icmp.hpp
0003 // ~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_IP_ICMP_HPP
0012 #define BOOST_ASIO_IP_ICMP_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/detail/socket_types.hpp>
0020 #include <boost/asio/basic_raw_socket.hpp>
0021 #include <boost/asio/ip/basic_endpoint.hpp>
0022 #include <boost/asio/ip/basic_resolver.hpp>
0023 #include <boost/asio/ip/basic_resolver_iterator.hpp>
0024 #include <boost/asio/ip/basic_resolver_query.hpp>
0025 
0026 #include <boost/asio/detail/push_options.hpp>
0027 
0028 namespace boost {
0029 namespace asio {
0030 namespace ip {
0031 
0032 /// Encapsulates the flags needed for ICMP.
0033 /**
0034  * The boost::asio::ip::icmp class contains flags necessary for ICMP sockets.
0035  *
0036  * @par Thread Safety
0037  * @e Distinct @e objects: Safe.@n
0038  * @e Shared @e objects: Safe.
0039  *
0040  * @par Concepts:
0041  * Protocol, InternetProtocol.
0042  */
0043 class icmp
0044 {
0045 public:
0046   /// The type of a ICMP endpoint.
0047   typedef basic_endpoint<icmp> endpoint;
0048 
0049   /// Construct to represent the IPv4 ICMP protocol.
0050   static icmp v4() noexcept
0051   {
0052     return icmp(BOOST_ASIO_OS_DEF(IPPROTO_ICMP),
0053         BOOST_ASIO_OS_DEF(AF_INET));
0054   }
0055 
0056   /// Construct to represent the IPv6 ICMP protocol.
0057   static icmp v6() noexcept
0058   {
0059     return icmp(BOOST_ASIO_OS_DEF(IPPROTO_ICMPV6),
0060         BOOST_ASIO_OS_DEF(AF_INET6));
0061   }
0062 
0063   /// Obtain an identifier for the type of the protocol.
0064   int type() const noexcept
0065   {
0066     return BOOST_ASIO_OS_DEF(SOCK_RAW);
0067   }
0068 
0069   /// Obtain an identifier for the protocol.
0070   int protocol() const noexcept
0071   {
0072     return protocol_;
0073   }
0074 
0075   /// Obtain an identifier for the protocol family.
0076   int family() const noexcept
0077   {
0078     return family_;
0079   }
0080 
0081   /// The ICMP socket type.
0082   typedef basic_raw_socket<icmp> socket;
0083 
0084   /// The ICMP resolver type.
0085   typedef basic_resolver<icmp> resolver;
0086 
0087   /// Compare two protocols for equality.
0088   friend bool operator==(const icmp& p1, const icmp& p2)
0089   {
0090     return p1.protocol_ == p2.protocol_ && p1.family_ == p2.family_;
0091   }
0092 
0093   /// Compare two protocols for inequality.
0094   friend bool operator!=(const icmp& p1, const icmp& p2)
0095   {
0096     return p1.protocol_ != p2.protocol_ || p1.family_ != p2.family_;
0097   }
0098 
0099 private:
0100   // Construct with a specific family.
0101   explicit icmp(int protocol_id, int protocol_family) noexcept
0102     : protocol_(protocol_id),
0103       family_(protocol_family)
0104   {
0105   }
0106 
0107   int protocol_;
0108   int family_;
0109 };
0110 
0111 } // namespace ip
0112 } // namespace asio
0113 } // namespace boost
0114 
0115 #include <boost/asio/detail/pop_options.hpp>
0116 
0117 #endif // BOOST_ASIO_IP_ICMP_HPP