1//
2// ip/icmp.hpp
3// ~~~~~~~~~~~
4//
5// Copyright (c) 2003-2024 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
11#ifndef BOOST_ASIO_IP_ICMP_HPP
12#define BOOST_ASIO_IP_ICMP_HPP
13
14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15# pragma once
16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18#include <boost/asio/detail/config.hpp>
19#include <boost/asio/detail/socket_types.hpp>
20#include <boost/asio/basic_raw_socket.hpp>
21#include <boost/asio/ip/basic_endpoint.hpp>
22#include <boost/asio/ip/basic_resolver.hpp>
23#include <boost/asio/ip/basic_resolver_iterator.hpp>
24#include <boost/asio/ip/basic_resolver_query.hpp>
25
26#include <boost/asio/detail/push_options.hpp>
27
28namespace boost {
29namespace asio {
30namespace ip {
31
32/// Encapsulates the flags needed for ICMP.
33/**
34 * The boost::asio::ip::icmp class contains flags necessary for ICMP sockets.
35 *
36 * @par Thread Safety
37 * @e Distinct @e objects: Safe.@n
38 * @e Shared @e objects: Safe.
39 *
40 * @par Concepts:
41 * Protocol, InternetProtocol.
42 */
43class icmp
44{
45public:
46 /// The type of a ICMP endpoint.
47 typedef basic_endpoint<icmp> endpoint;
48
49 /// Construct to represent the IPv4 ICMP protocol.
50 static icmp v4() noexcept
51 {
52 return icmp(BOOST_ASIO_OS_DEF(IPPROTO_ICMP),
53 BOOST_ASIO_OS_DEF(AF_INET));
54 }
55
56 /// Construct to represent the IPv6 ICMP protocol.
57 static icmp v6() noexcept
58 {
59 return icmp(BOOST_ASIO_OS_DEF(IPPROTO_ICMPV6),
60 BOOST_ASIO_OS_DEF(AF_INET6));
61 }
62
63 /// Obtain an identifier for the type of the protocol.
64 int type() const noexcept
65 {
66 return BOOST_ASIO_OS_DEF(SOCK_RAW);
67 }
68
69 /// Obtain an identifier for the protocol.
70 int protocol() const noexcept
71 {
72 return protocol_;
73 }
74
75 /// Obtain an identifier for the protocol family.
76 int family() const noexcept
77 {
78 return family_;
79 }
80
81 /// The ICMP socket type.
82 typedef basic_raw_socket<icmp> socket;
83
84 /// The ICMP resolver type.
85 typedef basic_resolver<icmp> resolver;
86
87 /// Compare two protocols for equality.
88 friend bool operator==(const icmp& p1, const icmp& p2)
89 {
90 return p1.protocol_ == p2.protocol_ && p1.family_ == p2.family_;
91 }
92
93 /// Compare two protocols for inequality.
94 friend bool operator!=(const icmp& p1, const icmp& p2)
95 {
96 return p1.protocol_ != p2.protocol_ || p1.family_ != p2.family_;
97 }
98
99private:
100 // Construct with a specific family.
101 explicit icmp(int protocol_id, int protocol_family) noexcept
102 : protocol_(protocol_id),
103 family_(protocol_family)
104 {
105 }
106
107 int protocol_;
108 int family_;
109};
110
111} // namespace ip
112} // namespace asio
113} // namespace boost
114
115#include <boost/asio/detail/pop_options.hpp>
116
117#endif // BOOST_ASIO_IP_ICMP_HPP
118

source code of boost/libs/asio/include/boost/asio/ip/icmp.hpp