Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / ip / address_v4.hpp @ 2486

History | View | Annotate | Download (6.8 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// ip/address_v4.hpp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_IP_ADDRESS_V4_HPP
12 2486 sjacqu01
#define BOOST_ASIO_IP_ADDRESS_V4_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
#include <string>
20 2486 sjacqu01
#include <boost/asio/detail/array.hpp>
21 2486 sjacqu01
#include <boost/asio/detail/socket_types.hpp>
22 2486 sjacqu01
#include <boost/asio/detail/winsock_init.hpp>
23 2486 sjacqu01
#include <boost/system/error_code.hpp>
24 2486 sjacqu01
25 2486 sjacqu01
#if !defined(BOOST_ASIO_NO_IOSTREAM)
26 2486 sjacqu01
# include <iosfwd>
27 2486 sjacqu01
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
28 2486 sjacqu01
29 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
30 2486 sjacqu01
31 2486 sjacqu01
namespace boost {
32 2486 sjacqu01
namespace asio {
33 2486 sjacqu01
namespace ip {
34 2486 sjacqu01
35 2486 sjacqu01
/// Implements IP version 4 style addresses.
36 2486 sjacqu01
/**
37 2486 sjacqu01
 * The boost::asio::ip::address_v4 class provides the ability to use and
38 2486 sjacqu01
 * manipulate IP version 4 addresses.
39 2486 sjacqu01
 *
40 2486 sjacqu01
 * @par Thread Safety
41 2486 sjacqu01
 * @e Distinct @e objects: Safe.@n
42 2486 sjacqu01
 * @e Shared @e objects: Unsafe.
43 2486 sjacqu01
 */
44 2486 sjacqu01
class address_v4
45 2486 sjacqu01
{
46 2486 sjacqu01
public:
47 2486 sjacqu01
  /// The type used to represent an address as an array of bytes.
48 2486 sjacqu01
  /**
49 2486 sjacqu01
   * @note This type is defined in terms of the C++0x template @c std::array
50 2486 sjacqu01
   * when it is available. Otherwise, it uses @c boost:array.
51 2486 sjacqu01
   */
52 2486 sjacqu01
#if defined(GENERATING_DOCUMENTATION)
53 2486 sjacqu01
  typedef array<unsigned char, 4> bytes_type;
54 2486 sjacqu01
#else
55 2486 sjacqu01
  typedef boost::asio::detail::array<unsigned char, 4> bytes_type;
56 2486 sjacqu01
#endif
57 2486 sjacqu01
58 2486 sjacqu01
  /// Default constructor.
59 2486 sjacqu01
  address_v4()
60 2486 sjacqu01
  {
61 2486 sjacqu01
    addr_.s_addr = 0;
62 2486 sjacqu01
  }
63 2486 sjacqu01
64 2486 sjacqu01
  /// Construct an address from raw bytes.
65 2486 sjacqu01
  BOOST_ASIO_DECL explicit address_v4(const bytes_type& bytes);
66 2486 sjacqu01
67 2486 sjacqu01
  /// Construct an address from a unsigned long in host byte order.
68 2486 sjacqu01
  BOOST_ASIO_DECL explicit address_v4(unsigned long addr);
69 2486 sjacqu01
70 2486 sjacqu01
  /// Copy constructor.
71 2486 sjacqu01
  address_v4(const address_v4& other)
72 2486 sjacqu01
    : addr_(other.addr_)
73 2486 sjacqu01
  {
74 2486 sjacqu01
  }
75 2486 sjacqu01
76 2486 sjacqu01
#if defined(BOOST_ASIO_HAS_MOVE)
77 2486 sjacqu01
  /// Move constructor.
78 2486 sjacqu01
  address_v4(address_v4&& other)
79 2486 sjacqu01
    : addr_(other.addr_)
80 2486 sjacqu01
  {
81 2486 sjacqu01
  }
82 2486 sjacqu01
#endif // defined(BOOST_ASIO_HAS_MOVE)
83 2486 sjacqu01
84 2486 sjacqu01
  /// Assign from another address.
85 2486 sjacqu01
  address_v4& operator=(const address_v4& other)
86 2486 sjacqu01
  {
87 2486 sjacqu01
    addr_ = other.addr_;
88 2486 sjacqu01
    return *this;
89 2486 sjacqu01
  }
90 2486 sjacqu01
91 2486 sjacqu01
#if defined(BOOST_ASIO_HAS_MOVE)
92 2486 sjacqu01
  /// Move-assign from another address.
93 2486 sjacqu01
  address_v4& operator=(address_v4&& other)
94 2486 sjacqu01
  {
95 2486 sjacqu01
    addr_ = other.addr_;
96 2486 sjacqu01
    return *this;
97 2486 sjacqu01
  }
98 2486 sjacqu01
#endif // defined(BOOST_ASIO_HAS_MOVE)
99 2486 sjacqu01
100 2486 sjacqu01
  /// Get the address in bytes, in network byte order.
101 2486 sjacqu01
  BOOST_ASIO_DECL bytes_type to_bytes() const;
102 2486 sjacqu01
103 2486 sjacqu01
  /// Get the address as an unsigned long in host byte order
104 2486 sjacqu01
  BOOST_ASIO_DECL unsigned long to_ulong() const;
105 2486 sjacqu01
106 2486 sjacqu01
  /// Get the address as a string in dotted decimal format.
107 2486 sjacqu01
  BOOST_ASIO_DECL std::string to_string() const;
108 2486 sjacqu01
109 2486 sjacqu01
  /// Get the address as a string in dotted decimal format.
110 2486 sjacqu01
  BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
111 2486 sjacqu01
112 2486 sjacqu01
  /// Create an address from an IP address string in dotted decimal form.
113 2486 sjacqu01
  BOOST_ASIO_DECL static address_v4 from_string(const char* str);
114 2486 sjacqu01
115 2486 sjacqu01
  /// Create an address from an IP address string in dotted decimal form.
116 2486 sjacqu01
  BOOST_ASIO_DECL static address_v4 from_string(
117 2486 sjacqu01
      const char* str, boost::system::error_code& ec);
118 2486 sjacqu01
119 2486 sjacqu01
  /// Create an address from an IP address string in dotted decimal form.
120 2486 sjacqu01
  BOOST_ASIO_DECL static address_v4 from_string(const std::string& str);
121 2486 sjacqu01
122 2486 sjacqu01
  /// Create an address from an IP address string in dotted decimal form.
123 2486 sjacqu01
  BOOST_ASIO_DECL static address_v4 from_string(
124 2486 sjacqu01
      const std::string& str, boost::system::error_code& ec);
125 2486 sjacqu01
126 2486 sjacqu01
  /// Determine whether the address is a loopback address.
127 2486 sjacqu01
  BOOST_ASIO_DECL bool is_loopback() const;
128 2486 sjacqu01
129 2486 sjacqu01
  /// Determine whether the address is unspecified.
130 2486 sjacqu01
  BOOST_ASIO_DECL bool is_unspecified() const;
131 2486 sjacqu01
132 2486 sjacqu01
  /// Determine whether the address is a class A address.
133 2486 sjacqu01
  BOOST_ASIO_DECL bool is_class_a() const;
134 2486 sjacqu01
135 2486 sjacqu01
  /// Determine whether the address is a class B address.
136 2486 sjacqu01
  BOOST_ASIO_DECL bool is_class_b() const;
137 2486 sjacqu01
138 2486 sjacqu01
  /// Determine whether the address is a class C address.
139 2486 sjacqu01
  BOOST_ASIO_DECL bool is_class_c() const;
140 2486 sjacqu01
141 2486 sjacqu01
  /// Determine whether the address is a multicast address.
142 2486 sjacqu01
  BOOST_ASIO_DECL bool is_multicast() const;
143 2486 sjacqu01
144 2486 sjacqu01
  /// Compare two addresses for equality.
145 2486 sjacqu01
  friend bool operator==(const address_v4& a1, const address_v4& a2)
146 2486 sjacqu01
  {
147 2486 sjacqu01
    return a1.addr_.s_addr == a2.addr_.s_addr;
148 2486 sjacqu01
  }
149 2486 sjacqu01
150 2486 sjacqu01
  /// Compare two addresses for inequality.
151 2486 sjacqu01
  friend bool operator!=(const address_v4& a1, const address_v4& a2)
152 2486 sjacqu01
  {
153 2486 sjacqu01
    return a1.addr_.s_addr != a2.addr_.s_addr;
154 2486 sjacqu01
  }
155 2486 sjacqu01
156 2486 sjacqu01
  /// Compare addresses for ordering.
157 2486 sjacqu01
  friend bool operator<(const address_v4& a1, const address_v4& a2)
158 2486 sjacqu01
  {
159 2486 sjacqu01
    return a1.to_ulong() < a2.to_ulong();
160 2486 sjacqu01
  }
161 2486 sjacqu01
162 2486 sjacqu01
  /// Compare addresses for ordering.
163 2486 sjacqu01
  friend bool operator>(const address_v4& a1, const address_v4& a2)
164 2486 sjacqu01
  {
165 2486 sjacqu01
    return a1.to_ulong() > a2.to_ulong();
166 2486 sjacqu01
  }
167 2486 sjacqu01
168 2486 sjacqu01
  /// Compare addresses for ordering.
169 2486 sjacqu01
  friend bool operator<=(const address_v4& a1, const address_v4& a2)
170 2486 sjacqu01
  {
171 2486 sjacqu01
    return a1.to_ulong() <= a2.to_ulong();
172 2486 sjacqu01
  }
173 2486 sjacqu01
174 2486 sjacqu01
  /// Compare addresses for ordering.
175 2486 sjacqu01
  friend bool operator>=(const address_v4& a1, const address_v4& a2)
176 2486 sjacqu01
  {
177 2486 sjacqu01
    return a1.to_ulong() >= a2.to_ulong();
178 2486 sjacqu01
  }
179 2486 sjacqu01
180 2486 sjacqu01
  /// Obtain an address object that represents any address.
181 2486 sjacqu01
  static address_v4 any()
182 2486 sjacqu01
  {
183 2486 sjacqu01
    return address_v4();
184 2486 sjacqu01
  }
185 2486 sjacqu01
186 2486 sjacqu01
  /// Obtain an address object that represents the loopback address.
187 2486 sjacqu01
  static address_v4 loopback()
188 2486 sjacqu01
  {
189 2486 sjacqu01
    return address_v4(0x7F000001);
190 2486 sjacqu01
  }
191 2486 sjacqu01
192 2486 sjacqu01
  /// Obtain an address object that represents the broadcast address.
193 2486 sjacqu01
  static address_v4 broadcast()
194 2486 sjacqu01
  {
195 2486 sjacqu01
    return address_v4(0xFFFFFFFF);
196 2486 sjacqu01
  }
197 2486 sjacqu01
198 2486 sjacqu01
  /// Obtain an address object that represents the broadcast address that
199 2486 sjacqu01
  /// corresponds to the specified address and netmask.
200 2486 sjacqu01
  BOOST_ASIO_DECL static address_v4 broadcast(
201 2486 sjacqu01
      const address_v4& addr, const address_v4& mask);
202 2486 sjacqu01
203 2486 sjacqu01
  /// Obtain the netmask that corresponds to the address, based on its address
204 2486 sjacqu01
  /// class.
205 2486 sjacqu01
  BOOST_ASIO_DECL static address_v4 netmask(const address_v4& addr);
206 2486 sjacqu01
207 2486 sjacqu01
private:
208 2486 sjacqu01
  // The underlying IPv4 address.
209 2486 sjacqu01
  boost::asio::detail::in4_addr_type addr_;
210 2486 sjacqu01
};
211 2486 sjacqu01
212 2486 sjacqu01
#if !defined(BOOST_ASIO_NO_IOSTREAM)
213 2486 sjacqu01
214 2486 sjacqu01
/// Output an address as a string.
215 2486 sjacqu01
/**
216 2486 sjacqu01
 * Used to output a human-readable string for a specified address.
217 2486 sjacqu01
 *
218 2486 sjacqu01
 * @param os The output stream to which the string will be written.
219 2486 sjacqu01
 *
220 2486 sjacqu01
 * @param addr The address to be written.
221 2486 sjacqu01
 *
222 2486 sjacqu01
 * @return The output stream.
223 2486 sjacqu01
 *
224 2486 sjacqu01
 * @relates boost::asio::ip::address_v4
225 2486 sjacqu01
 */
226 2486 sjacqu01
template <typename Elem, typename Traits>
227 2486 sjacqu01
std::basic_ostream<Elem, Traits>& operator<<(
228 2486 sjacqu01
    std::basic_ostream<Elem, Traits>& os, const address_v4& addr);
229 2486 sjacqu01
230 2486 sjacqu01
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
231 2486 sjacqu01
232 2486 sjacqu01
} // namespace ip
233 2486 sjacqu01
} // namespace asio
234 2486 sjacqu01
} // namespace boost
235 2486 sjacqu01
236 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
237 2486 sjacqu01
238 2486 sjacqu01
#include <boost/asio/ip/impl/address_v4.hpp>
239 2486 sjacqu01
#if defined(BOOST_ASIO_HEADER_ONLY)
240 2486 sjacqu01
# include <boost/asio/ip/impl/address_v4.ipp>
241 2486 sjacqu01
#endif // defined(BOOST_ASIO_HEADER_ONLY)
242 2486 sjacqu01
243 2486 sjacqu01
#endif // BOOST_ASIO_IP_ADDRESS_V4_HPP