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_V4_HPP
0012 #define BOOST_ASIO_IP_ADDRESS_V4_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
0028 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0029 # include <iosfwd>
0030 #endif
0031
0032 #include <boost/asio/detail/push_options.hpp>
0033
0034 namespace boost {
0035 namespace asio {
0036 namespace ip {
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 class address_v4
0048 {
0049 public:
0050
0051 typedef uint_least32_t uint_type;
0052
0053
0054
0055
0056
0057
0058 #if defined(GENERATING_DOCUMENTATION)
0059 typedef array<unsigned char, 4> bytes_type;
0060 #else
0061 typedef boost::asio::detail::array<unsigned char, 4> bytes_type;
0062 #endif
0063
0064
0065
0066
0067
0068
0069
0070 address_v4() noexcept
0071 {
0072 addr_.s_addr = 0;
0073 }
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 BOOST_ASIO_DECL explicit address_v4(const bytes_type& bytes);
0085
0086
0087
0088
0089
0090 BOOST_ASIO_DECL explicit address_v4(uint_type addr);
0091
0092
0093 address_v4(const address_v4& other) noexcept
0094 : addr_(other.addr_)
0095 {
0096 }
0097
0098
0099 address_v4(address_v4&& other) noexcept
0100 : addr_(other.addr_)
0101 {
0102 }
0103
0104
0105 address_v4& operator=(const address_v4& other) noexcept
0106 {
0107 addr_ = other.addr_;
0108 return *this;
0109 }
0110
0111
0112 address_v4& operator=(address_v4&& other) noexcept
0113 {
0114 addr_ = other.addr_;
0115 return *this;
0116 }
0117
0118
0119 BOOST_ASIO_DECL bytes_type to_bytes() const noexcept;
0120
0121
0122 BOOST_ASIO_DECL uint_type to_uint() const noexcept;
0123
0124 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0125
0126
0127 BOOST_ASIO_DECL unsigned long to_ulong() const;
0128 #endif
0129
0130
0131 BOOST_ASIO_DECL std::string to_string() const;
0132
0133 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0134
0135
0136 BOOST_ASIO_DECL std::string to_string(boost::system::error_code& ec) const;
0137
0138
0139
0140 static address_v4 from_string(const char* str);
0141
0142
0143
0144 static address_v4 from_string(
0145 const char* str, boost::system::error_code& ec);
0146
0147
0148
0149 static address_v4 from_string(const std::string& str);
0150
0151
0152
0153 static address_v4 from_string(
0154 const std::string& str, boost::system::error_code& ec);
0155 #endif
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 BOOST_ASIO_DECL bool is_loopback() const noexcept;
0166
0167
0168
0169
0170
0171
0172
0173
0174 BOOST_ASIO_DECL bool is_unspecified() const noexcept;
0175
0176 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0177
0178
0179 BOOST_ASIO_DECL bool is_class_a() const;
0180
0181
0182
0183 BOOST_ASIO_DECL bool is_class_b() const;
0184
0185
0186
0187 BOOST_ASIO_DECL bool is_class_c() const;
0188 #endif
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198 BOOST_ASIO_DECL bool is_multicast() const noexcept;
0199
0200
0201 friend bool operator==(const address_v4& a1,
0202 const address_v4& a2) noexcept
0203 {
0204 return a1.addr_.s_addr == a2.addr_.s_addr;
0205 }
0206
0207
0208 friend bool operator!=(const address_v4& a1,
0209 const address_v4& a2) noexcept
0210 {
0211 return a1.addr_.s_addr != a2.addr_.s_addr;
0212 }
0213
0214
0215
0216
0217
0218
0219
0220 friend bool operator<(const address_v4& a1,
0221 const address_v4& a2) noexcept
0222 {
0223 return a1.to_uint() < a2.to_uint();
0224 }
0225
0226
0227
0228
0229
0230
0231
0232 friend bool operator>(const address_v4& a1,
0233 const address_v4& a2) noexcept
0234 {
0235 return a1.to_uint() > a2.to_uint();
0236 }
0237
0238
0239
0240
0241
0242
0243
0244 friend bool operator<=(const address_v4& a1,
0245 const address_v4& a2) noexcept
0246 {
0247 return a1.to_uint() <= a2.to_uint();
0248 }
0249
0250
0251
0252
0253
0254
0255
0256 friend bool operator>=(const address_v4& a1,
0257 const address_v4& a2) noexcept
0258 {
0259 return a1.to_uint() >= a2.to_uint();
0260 }
0261
0262
0263
0264
0265
0266
0267
0268
0269 static address_v4 any() noexcept
0270 {
0271 return address_v4();
0272 }
0273
0274
0275
0276
0277
0278
0279
0280
0281 static address_v4 loopback() noexcept
0282 {
0283 return address_v4(0x7F000001);
0284 }
0285
0286
0287
0288
0289
0290
0291
0292
0293 static address_v4 broadcast() noexcept
0294 {
0295 return address_v4(0xFFFFFFFF);
0296 }
0297
0298 #if !defined(BOOST_ASIO_NO_DEPRECATED)
0299
0300
0301
0302 BOOST_ASIO_DECL static address_v4 broadcast(
0303 const address_v4& addr, const address_v4& mask);
0304
0305
0306
0307 BOOST_ASIO_DECL static address_v4 netmask(const address_v4& addr);
0308 #endif
0309
0310 private:
0311
0312 boost::asio::detail::in4_addr_type addr_;
0313 };
0314
0315
0316
0317
0318
0319 inline address_v4 make_address_v4(const address_v4::bytes_type& bytes)
0320 {
0321 return address_v4(bytes);
0322 }
0323
0324
0325
0326
0327
0328 inline address_v4 make_address_v4(address_v4::uint_type addr)
0329 {
0330 return address_v4(addr);
0331 }
0332
0333
0334
0335
0336
0337 BOOST_ASIO_DECL address_v4 make_address_v4(const char* str);
0338
0339
0340
0341
0342
0343 BOOST_ASIO_DECL address_v4 make_address_v4(const char* str,
0344 boost::system::error_code& ec) noexcept;
0345
0346
0347
0348
0349
0350 BOOST_ASIO_DECL address_v4 make_address_v4(const std::string& str);
0351
0352
0353
0354
0355
0356 BOOST_ASIO_DECL address_v4 make_address_v4(const std::string& str,
0357 boost::system::error_code& ec) noexcept;
0358
0359 #if defined(BOOST_ASIO_HAS_STRING_VIEW) \
0360 || defined(GENERATING_DOCUMENTATION)
0361
0362
0363
0364
0365
0366 BOOST_ASIO_DECL address_v4 make_address_v4(string_view str);
0367
0368
0369
0370
0371
0372 BOOST_ASIO_DECL address_v4 make_address_v4(string_view str,
0373 boost::system::error_code& ec) noexcept;
0374
0375 #endif
0376
0377
0378 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392 template <typename Elem, typename Traits>
0393 std::basic_ostream<Elem, Traits>& operator<<(
0394 std::basic_ostream<Elem, Traits>& os, const address_v4& addr);
0395
0396 #endif
0397
0398 }
0399 }
0400 }
0401
0402 namespace std {
0403
0404 template <>
0405 struct hash<boost::asio::ip::address_v4>
0406 {
0407 std::size_t operator()(const boost::asio::ip::address_v4& addr)
0408 const noexcept
0409 {
0410 return std::hash<unsigned int>()(addr.to_uint());
0411 }
0412 };
0413
0414 }
0415
0416 #include <boost/asio/detail/pop_options.hpp>
0417
0418 #include <boost/asio/ip/impl/address_v4.hpp>
0419 #if defined(BOOST_ASIO_HEADER_ONLY)
0420 # include <boost/asio/ip/impl/address_v4.ipp>
0421 #endif
0422
0423 #endif