xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
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 
30  class core_export_ ip_address : public xtd::object, public xtd::iequatable<ip_address> {
31  public:
34  static ip_address any;
53  static ip_address none;
54 
57  ip_address() = default;
60  explicit ip_address(uint32_t address);
63  explicit ip_address(const std::vector<byte_t>& address);
71  ip_address(const std::vector<byte_t>& address, uint32_t scope_id);
77  ip_address(byte_t quad_part_address1, byte_t quad_part_address2, byte_t quad_part_address3, byte_t quad_part_address4);
78 
80  ip_address(ip_address&& ip_address) = default;
81  ip_address(const ip_address& ip_address) = default;
82  ip_address& operator=(const ip_address&) = default;
83  friend std::ostream& operator <<(std::ostream& os, const ip_address& address) noexcept {return os << address.to_string();}
85 
89 
93  bool is_ip_v4_mapped_to_ip_v6() const noexcept;
94 
97  bool is_ip_v6_link_local() const noexcept;
98 
101  bool is_ip_v6_multicast() const noexcept;
102 
105  bool is_ip_v6_site_local() const noexcept;
106 
110  bool is_ip_v6_teredo() const noexcept;
111 
115  uint32_t scope_id() const;
119  ip_address& scope_id(uint32_t value);
120 
121  bool equals(const object& other) const noexcept override;
122  bool equals(const ip_address& other) const noexcept override;
123 
126  std::vector<byte_t> get_address_bytes() const;
127 
133  static double host_to_network_order(double host);
134 
140  static int16_t host_to_network_order(int16_t host);
141 
147  static int32_t host_to_network_order(int32_t host);
148 
154  static int64_t host_to_network_order(int64_t host);
155 
161  static float host_to_network_order(float host);
162 
168  static uint16_t host_to_network_order(uint16_t host);
169 
175  static uint32_t host_to_network_order(uint32_t host);
176 
182  static uint64_t host_to_network_order(uint64_t host);
183 
187  static bool is_loopback(const ip_address& address);
188 
192  ip_address map_to_ip_v4() const noexcept;
193 
197  ip_address map_to_ip_v6() const noexcept;
198 
204  static double network_to_host_order(double network);
205 
211  static int16_t network_to_host_order(int16_t network);
212 
218  static int32_t network_to_host_order(int32_t host);
219 
225  static int64_t network_to_host_order(int64_t network);
226 
232  static float network_to_host_order(float network);
233 
239  static uint16_t network_to_host_order(uint16_t network);
240 
246  static uint32_t network_to_host_order(uint32_t network);
247 
253  static uint64 network_to_host_order(uint64 network);
254 
261  static ip_address parse(const ustring& str);
262 
265  ustring to_string() const noexcept override;
266 
271  static bool try_parse(const ustring& str, ip_address& address);
272 
273  private:
274  friend xtd::net::sockets::socket;
275  static constexpr const size_t number_of_numbers_ = 8;
276  ip_address(const std::vector<uint16_t>& numbers, uint32_t scope_id);
277  uint32_t address_ = 0xFFFFFFFF;
278  std::vector<uint16_t> numbers_ = std::vector<uint16_t>(number_of_numbers_);
279  uint32_t scope_id_ = 0;
280  sockets::address_family address_family_ = sockets::address_family::inter_network;
281  };
282  }
283 }
Contains xtd::net::sockets::address_family enum.
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:19
Provides an Internet Protocol (IP) address.
Definition: ip_address.h:30
static ip_address broadcast
Provides the IP broadcast address. This field is constant.
Definition: ip_address.h:37
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:40
ip_address(const std::vector< byte_t > &address)
Initializes a new instance of the xtd::net::ip_address class with the address specified as a byte arr...
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:47
ip_address(const std::vector< byte_t > &address, uint32_t scope_id)
Initializes a new instance of the xtd::net::ip_address class with the address specified as a byte arr...
ip_address()=default
Initializes a new instance of the xtd::net::ip_address.
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:34
sockets::address_family address_family() const noexcept
Gets the address family of the IP address.
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:53
ip_address(byte_t quad_part_address1, byte_t quad_part_address2, byte_t quad_part_address3, byte_t quad_part_address4)
Initializes a new instance of the xtd::net::ip_address class with the address specified as a four Byt...
ustring to_string() const noexcept override
Converts an Internet address to its standard notation.
static ip_address ip_v6_loopback
Provides the IP loopback address. This field is constant.
Definition: ip_address.h:43
ip_address(uint32_t address)
Initializes a new instance of the xtd::net::ip_address class with the address specified as an int64_t...
static ip_address loopback
Provides the IP loopback address. This field is constant.
Definition: ip_address.h:50
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition: object.h:26
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
#define core_export_
Define shared library export.
Definition: core_export.h:13
uint64_t uint64
Represents a 64-bit unsigned integer.
Definition: types.h:219
address_family
Specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use.
Definition: address_family.h:24
bool try_parse(const std::basic_string< char_t > &str, value_t &value)
Convert a type into a string.
Definition: parse.h:354
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: to_string.h:37
value_t parse(const std::string &str)
Convert a type into a string.
Definition: parse.h:22
@ socket
Socket options apply to all sockets.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17