File indexing completed on 2025-01-18 09:28:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_IP_ADDRESS_V6_HPP
0012 #define BOOST_ASIO_IP_ADDRESS_V6_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <functional>
0020 #include <string>
0021 #include <boost/asio/detail/array.hpp>
0022 #include <boost/asio/detail/cstdint.hpp>
0023 #include <boost/asio/detail/socket_types.hpp>
0024 #include <boost/asio/detail/string_view.hpp>
0025 #include <boost/asio/detail/winsock_init.hpp>
0026 #include <boost/system/error_code.hpp>
0027 #include <boost/asio/ip/address_v4.hpp>
0028
0029 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0030 # include <iosfwd>
0031 #endif
0032
0033 #include <boost/asio/detail/push_options.hpp>
0034
0035 namespace boost {
0036 namespace asio {
0037 namespace ip {
0038
0039 template <typename> class basic_address_iterator;
0040
0041
0042 typedef uint_least32_t scope_id_type;
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 class address_v6
0054 {
0055 public:
0056
0057
0058
0059
0060
0061 #if defined(GENERATING_DOCUMENTATION)
0062 typedef array<unsigned char, 16> bytes_type;
0063 #else
0064 typedef boost::asio::detail::array<unsigned char, 16> bytes_type;
0065 #endif
0066
0067
0068
0069
0070
0071
0072
0073 BOOST_ASIO_DECL address_v6() noexcept;
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 BOOST_ASIO_DECL explicit address_v6(const bytes_type& bytes,
0086 scope_id_type scope_id = 0);
0087
0088
0089 BOOST_ASIO_DECL address_v6(const address_v6& other) noexcept;
0090
0091
0092 BOOST_ASIO_DECL address_v6(address_v6&& other) noexcept;
0093
0094
0095 BOOST_ASIO_DECL address_v6& operator=(
0096 const address_v6& other) noexcept;
0097
0098
0099 BOOST_ASIO_DECL address_v6& operator=(address_v6&& other) noexcept;
0100
0101
0102
0103
0104
0105 scope_id_type scope_id() const noexcept
0106 {
0107 return scope_id_;
0108 }
0109
0110
0111
0112
0113
0114
0115
0116 void scope_id(scope_id_type id) noexcept
0117 {
0118 scope_id_ = id;
0119 }
0120
0121
0122 BOOST_ASIO_DECL bytes_type to_bytes() const noexcept;
0123
0124
0125 BOOST_ASIO_DECL std::string to_string() const;
0126
0127 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0128
0129 BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
0130
0131
0132
0133 static address_v6 from_string(const char* str);
0134
0135
0136
0137 static address_v6 from_string(
0138 const char* str, boost::system::error_code& ec);
0139
0140
0141
0142 static address_v6 from_string(const std::string& str);
0143
0144
0145
0146 static address_v6 from_string(
0147 const std::string& str, boost::system::error_code& ec);
0148
0149
0150
0151 BOOST_ASIO_DECL address_v4 to_v4() const;
0152 #endif
0153
0154
0155
0156
0157
0158
0159 BOOST_ASIO_DECL bool is_loopback() const noexcept;
0160
0161
0162
0163
0164
0165
0166 BOOST_ASIO_DECL bool is_unspecified() const noexcept;
0167
0168
0169 BOOST_ASIO_DECL bool is_link_local() const noexcept;
0170
0171
0172 BOOST_ASIO_DECL bool is_site_local() const noexcept;
0173
0174
0175 BOOST_ASIO_DECL bool is_v4_mapped() const noexcept;
0176
0177 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0178
0179
0180 BOOST_ASIO_DECL bool is_v4_compatible() const;
0181 #endif
0182
0183
0184 BOOST_ASIO_DECL bool is_multicast() const noexcept;
0185
0186
0187 BOOST_ASIO_DECL bool is_multicast_global() const noexcept;
0188
0189
0190 BOOST_ASIO_DECL bool is_multicast_link_local() const noexcept;
0191
0192
0193 BOOST_ASIO_DECL bool is_multicast_node_local() const noexcept;
0194
0195
0196 BOOST_ASIO_DECL bool is_multicast_org_local() const noexcept;
0197
0198
0199 BOOST_ASIO_DECL bool is_multicast_site_local() const noexcept;
0200
0201
0202 BOOST_ASIO_DECL friend bool operator==(const address_v6& a1,
0203 const address_v6& a2) noexcept;
0204
0205
0206 friend bool operator!=(const address_v6& a1,
0207 const address_v6& a2) noexcept
0208 {
0209 return !(a1 == a2);
0210 }
0211
0212
0213 BOOST_ASIO_DECL friend bool operator<(const address_v6& a1,
0214 const address_v6& a2) noexcept;
0215
0216
0217 friend bool operator>(const address_v6& a1,
0218 const address_v6& a2) noexcept
0219 {
0220 return a2 < a1;
0221 }
0222
0223
0224 friend bool operator<=(const address_v6& a1,
0225 const address_v6& a2) noexcept
0226 {
0227 return !(a2 < a1);
0228 }
0229
0230
0231 friend bool operator>=(const address_v6& a1,
0232 const address_v6& a2) noexcept
0233 {
0234 return !(a1 < a2);
0235 }
0236
0237
0238
0239
0240
0241
0242
0243
0244 static address_v6 any() noexcept
0245 {
0246 return address_v6();
0247 }
0248
0249
0250
0251
0252
0253
0254 BOOST_ASIO_DECL static address_v6 loopback() noexcept;
0255
0256 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0257
0258 BOOST_ASIO_DECL static address_v6 v4_mapped(const address_v4& addr);
0259
0260
0261 BOOST_ASIO_DECL static address_v6 v4_compatible(const address_v4& addr);
0262 #endif
0263
0264 private:
0265 friend class basic_address_iterator<address_v6>;
0266
0267
0268 boost::asio::detail::in6_addr_type addr_;
0269
0270
0271 scope_id_type scope_id_;
0272 };
0273
0274
0275
0276
0277
0278 inline address_v6 make_address_v6(const address_v6::bytes_type& bytes,
0279 scope_id_type scope_id = 0)
0280 {
0281 return address_v6(bytes, scope_id);
0282 }
0283
0284
0285
0286
0287
0288 BOOST_ASIO_DECL address_v6 make_address_v6(const char* str);
0289
0290
0291
0292
0293
0294 BOOST_ASIO_DECL address_v6 make_address_v6(const char* str,
0295 boost::system::error_code& ec) noexcept;
0296
0297
0298
0299
0300
0301 BOOST_ASIO_DECL address_v6 make_address_v6(const std::string& str);
0302
0303
0304
0305
0306
0307 BOOST_ASIO_DECL address_v6 make_address_v6(const std::string& str,
0308 boost::system::error_code& ec) noexcept;
0309
0310 #if defined(BOOST_ASIO_HAS_STRING_VIEW) \
0311 || defined(GENERATING_DOCUMENTATION)
0312
0313
0314
0315
0316
0317 BOOST_ASIO_DECL address_v6 make_address_v6(string_view str);
0318
0319
0320
0321
0322
0323 BOOST_ASIO_DECL address_v6 make_address_v6(string_view str,
0324 boost::system::error_code& ec) noexcept;
0325
0326 #endif
0327
0328
0329
0330
0331 enum v4_mapped_t { v4_mapped };
0332
0333
0334
0335
0336
0337 BOOST_ASIO_DECL address_v4 make_address_v4(
0338 v4_mapped_t, const address_v6& v6_addr);
0339
0340
0341
0342
0343
0344 BOOST_ASIO_DECL address_v6 make_address_v6(
0345 v4_mapped_t, const address_v4& v4_addr);
0346
0347 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361 template <typename Elem, typename Traits>
0362 std::basic_ostream<Elem, Traits>& operator<<(
0363 std::basic_ostream<Elem, Traits>& os, const address_v6& addr);
0364
0365 #endif
0366
0367 }
0368 }
0369 }
0370
0371 namespace std {
0372
0373 template <>
0374 struct hash<boost::asio::ip::address_v6>
0375 {
0376 std::size_t operator()(const boost::asio::ip::address_v6& addr)
0377 const noexcept
0378 {
0379 const boost::asio::ip::address_v6::bytes_type bytes = addr.to_bytes();
0380 std::size_t result = static_cast<std::size_t>(addr.scope_id());
0381 combine_4_bytes(result, &bytes[0]);
0382 combine_4_bytes(result, &bytes[4]);
0383 combine_4_bytes(result, &bytes[8]);
0384 combine_4_bytes(result, &bytes[12]);
0385 return result;
0386 }
0387
0388 private:
0389 static void combine_4_bytes(std::size_t& seed, const unsigned char* bytes)
0390 {
0391 const std::size_t bytes_hash =
0392 (static_cast<std::size_t>(bytes[0]) << 24) |
0393 (static_cast<std::size_t>(bytes[1]) << 16) |
0394 (static_cast<std::size_t>(bytes[2]) << 8) |
0395 (static_cast<std::size_t>(bytes[3]));
0396 seed ^= bytes_hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
0397 }
0398 };
0399
0400 }
0401
0402 #include <boost/asio/detail/pop_options.hpp>
0403
0404 #include <boost/asio/ip/impl/address_v6.hpp>
0405 #if defined(BOOST_ASIO_HEADER_ONLY)
0406 # include <boost/asio/ip/impl/address_v6.ipp>
0407 #endif
0408
0409 #endif