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