xtd - Reference Guide 0.2.0
ip_address.h
Go to the documentation of this file.
1 #pragma once
5 
6 #include <vector>
7 #include "../core_export.h"
8 #include "../iequatable.h"
9 #include "../object.h"
10 #include "../types.h"
11 #include "../ustring.h"
12 #include "sockets/address_family.h"
13 
15 namespace xtd {
17  namespace net {
19  namespace sockets {
20  class socket;
21  }
23 
34  class core_export_ ip_address : public xtd::object, public xtd::iequatable<ip_address> {
35  public:
37 
41  static ip_address any;
60  static ip_address none;
62 
64 
68  ip_address() = default;
71  explicit ip_address(uint32_t address);
74  explicit ip_address(const std::vector<byte_t>& address);
82  ip_address(const std::vector<byte_t>& address, uint32_t scope_id);
88  ip_address(byte_t quad_part_address1, byte_t quad_part_address2, byte_t quad_part_address3, byte_t quad_part_address4);
90 
92  ip_address(ip_address&& ip_address) = default;
93  ip_address(const ip_address& ip_address) = default;
94  ip_address& operator=(const ip_address&) = default;
95  friend std::ostream& operator <<(std::ostream& os, const ip_address& address) noexcept {return os << address.to_string();}
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_t scope_id() const;
134  ip_address& scope_id(uint32_t value);
136 
138 
140  bool equals(const object& other) const noexcept override;
141  bool equals(const ip_address& other) const noexcept override;
142 
145  std::vector<byte_t> get_address_bytes() const;
146 
152  static double host_to_network_order(double host);
153 
159  static int16_t host_to_network_order(int16_t host);
160 
166  static int32_t host_to_network_order(int32_t host);
167 
173  static int64_t host_to_network_order(int64_t host);
174 
180  static float host_to_network_order(float host);
181 
187  static uint16_t host_to_network_order(uint16_t host);
188 
194  static uint32_t host_to_network_order(uint32_t host);
195 
201  static uint64_t host_to_network_order(uint64_t host);
202 
206  static bool is_loopback(const ip_address& address);
207 
211  ip_address map_to_ip_v4() const noexcept;
212 
216  ip_address map_to_ip_v6() const noexcept;
217 
223  static double network_to_host_order(double network);
224 
230  static int16_t network_to_host_order(int16_t network);
231 
237  static int32_t network_to_host_order(int32_t host);
238 
244  static int64_t network_to_host_order(int64_t network);
245 
251  static float network_to_host_order(float network);
252 
258  static uint16_t network_to_host_order(uint16_t network);
259 
265  static uint32_t network_to_host_order(uint32_t network);
266 
272  static uint64 network_to_host_order(uint64 network);
273 
280  static ip_address parse(const ustring& str);
281 
284  ustring to_string() const noexcept override;
285 
290  static bool try_parse(const ustring& str, ip_address& address);
292 
293  private:
294  friend xtd::net::sockets::socket;
295  static constexpr const size_t number_of_numbers_ = 8;
296  ip_address(const std::vector<uint16_t>& numbers, uint32_t scope_id);
297  uint32_t address_ = 0xFFFFFFFF;
298  std::vector<uint16_t> numbers_ = std::vector<uint16_t>(number_of_numbers_);
299  uint32_t scope_id_ = 0;
300  sockets::address_family address_family_ = sockets::address_family::inter_network;
301  };
302  }
303 }
Provides an Internet Protocol (IP) address.
Definition: ip_address.h:34
value_t parse(const std::string &str)
Convert a string into a type.
Definition: parse.h:22
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
bool try_parse(const std::basic_string< char_t > &str, value_t &value)
Convert a string into a type.
Definition: parse.h:399
static ip_address ip_v6_loopback
Provides the IP loopback address. This field is constant.
Definition: ip_address.h:50
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:50
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:1110
uint64_t uint64
Represents a 64-bit unsigned integer.
Definition: types.h:211
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:19
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:41
Socket options apply to all sockets.
static ip_address loopback
Provides the IP loopback address. This field is constant.
Definition: ip_address.h:57
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:30
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:54
Contains xtd::net::sockets::address_family enum.
ustring to_string() const noexcept override
Converts an Internet address to its standard notation.
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:47
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:60
static ip_address broadcast
Provides the IP broadcast address. This field is constant.
Definition: ip_address.h:44
address_family
Specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use...
Definition: address_family.h:27