xtd 0.2.0
ip_address.h
Go to the documentation of this file.
1 #pragma once
6 #include "../core_export.h"
7 #include "../iequatable.h"
8 #include "../object.h"
9 #include "../types.h"
10 #include "../ustring.h"
11 #include <vector>
12 
14 namespace xtd {
16  namespace net {
18  namespace sockets {
19  class socket;
20  }
22 
35  class core_export_ ip_address : public xtd::object, public xtd::iequatable<ip_address> {
36  public:
38 
42  static ip_address any;
61  static ip_address none;
63 
65 
69  ip_address() = default;
72  explicit ip_address(uint32 address);
75  explicit ip_address(const std::vector<xtd::byte>& address);
83  ip_address(const std::vector<xtd::byte>& address, uint32 scope_id);
89  ip_address(xtd::byte quad_part_address1, xtd::byte quad_part_address2, xtd::byte quad_part_address3, xtd::byte quad_part_address4);
91 
93  ip_address(ip_address&& ip_address) = default;
94  ip_address(const ip_address& ip_address) = default;
95  ip_address& operator =(const ip_address&) = default;
97 
99 
103  sockets::address_family address_family() const noexcept;
104 
108  bool is_ip_v4_mapped_to_ip_v6() const noexcept;
109 
112  bool is_ip_v6_link_local() const noexcept;
113 
116  bool is_ip_v6_multicast() const noexcept;
117 
120  bool is_ip_v6_site_local() const noexcept;
121 
125  bool is_ip_v6_teredo() const noexcept;
126 
130  uint32 scope_id() const;
134  ip_address& scope_id(uint32 value);
136 
138 
140  bool equals(const ip_address& other) const noexcept override;
141 
144  std::vector<xtd::byte> get_address_bytes() const;
145 
151  static double host_to_network_order(double host);
152 
158  static int16 host_to_network_order(int16 host);
159 
165  static int32 host_to_network_order(int32 host);
166 
172  static int64 host_to_network_order(int64 host);
173 
179  static float host_to_network_order(float host);
180 
186  static uint16 host_to_network_order(uint16 host);
187 
193  static uint32 host_to_network_order(uint32 host);
194 
200  static uint64 host_to_network_order(uint64 host);
201 
205  static bool is_loopback(const ip_address& address);
206 
210  ip_address map_to_ip_v4() const noexcept;
211 
215  ip_address map_to_ip_v6() const noexcept;
216 
222  static double network_to_host_order(double network);
223 
229  static int16 network_to_host_order(int16 network);
230 
236  static int32 network_to_host_order(int32 host);
237 
243  static int64 network_to_host_order(int64 network);
244 
250  static float network_to_host_order(float network);
251 
257  static uint16 network_to_host_order(uint16 network);
258 
264  static uint32 network_to_host_order(uint32 network);
265 
271  static uint64 network_to_host_order(uint64 network);
272 
279  static ip_address parse(const ustring& str);
280 
283  ustring to_string() const noexcept override;
284 
289  static bool try_parse(const ustring& str, ip_address& address) noexcept;
291 
292  private:
293  friend xtd::net::sockets::socket;
294  static constexpr size_t number_of_numbers_ = 8;
295  ip_address(const std::vector<uint16>& numbers, uint32 scope_id);
296  uint32 address_ = 0xFFFFFFFF;
297  std::vector<uint16> numbers_ = std::vector<uint16>(number_of_numbers_);
298  uint32 scope_id_ = 0;
299  sockets::address_family address_family_ = sockets::address_family::inter_network;
300  };
301  }
302 }
Provides an Internet Protocol (IP) address.
Definition: ip_address.h:35
value_t parse(const std::string &str)
Convert a string into a type.
Definition: parse.h:23
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
static ip_address ip_v6_loopback
Provides the IP loopback address. This field is constant.
Definition: ip_address.h:51
uint_least16_t uint16
Represents a 16-bit unsigned integer.
Definition: types.h:228
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
std::string to_string(const date_time &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: date_time.h:1063
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:18
static ip_address any
Provides an IP address that indicates that the server must listen for client activity on all network ...
Definition: ip_address.h:42
Socket options apply to all sockets.
static ip_address loopback
Provides the IP loopback address. This field is constant.
Definition: ip_address.h:58
int_least16_t int16
Represents a 16-bit signed integer.
Definition: types.h:118
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
static ip_address ip_v6_none
Provides an IP address that indicates that no network interface should be used. This field is constan...
Definition: ip_address.h:55
Contains xtd::net::sockets::address_family enum.
static ip_address ip_v6_any
The Socket::Bind method uses the cIPv6Any field to indicate that a Socket must listen for client acti...
Definition: ip_address.h:48
bool try_parse(const std::basic_string< char_t > &str, value_t &value) noexcept
Convert a string into a type.
Definition: parse.h:406
uint_least64_t uint64
Represents a 64-bit unsigned integer.
Definition: types.h:250
int_least64_t int64
Represents a 64-bit signed integer.
Definition: types.h:140
uint_least8_t byte
Represents a 8-bit unsigned integer.
Definition: types.h:39
static ip_address none
Provides an IP address that indicates that no network interface should be used. This field is constan...
Definition: ip_address.h:61
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition: types.h:239
static ip_address broadcast
Provides the IP broadcast address. This field is constant.
Definition: ip_address.h:45
address_family
Specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use...
Definition: address_family.h:28