xtd 0.2.0
Loading...
Searching...
No Matches
ip_address.hpp
Go to the documentation of this file.
1
4#pragma once
6#include "../core_export.hpp"
7#include "../iequatable.hpp"
8#include "../object.hpp"
9#include "../types.hpp"
10#include "../string.hpp"
11#include <vector>
12
14namespace xtd {
16 namespace net {
18 namespace sockets {
19 class socket;
20 }
22
37 class core_export_ ip_address : public xtd::object, public xtd::iequatable<ip_address> {
38 public:
40
44 static const ip_address any;
47 static const ip_address broadcast;
50 static const ip_address ip_v6_any;
57 static const ip_address ip_v6_none;
60 static const ip_address loopback;
63 static const ip_address none;
65
67
71 ip_address() = default;
74 explicit ip_address(uint32 address);
77 explicit ip_address(const std::vector<xtd::byte>& address);
85 ip_address(const std::vector<xtd::byte>& address, uint32 scope_id);
91 ip_address(xtd::byte quad_part_address1, xtd::byte quad_part_address2, xtd::byte quad_part_address3, xtd::byte quad_part_address4);
93
95 ip_address(ip_address&& ip_address) = default;
96 ip_address(const ip_address& ip_address) = default;
97 ip_address& operator =(const ip_address&) = default;
99
101
106
110 bool is_ip_v4_mapped_to_ip_v6() const noexcept;
111
114 bool is_ip_v6_link_local() const noexcept;
115
118 bool is_ip_v6_multicast() const noexcept;
119
122 bool is_ip_v6_site_local() const noexcept;
123
127 bool is_ip_v6_teredo() const noexcept;
128
132 uint32 scope_id() const;
136 ip_address& scope_id(uint32 value);
138
140
142 using object::equals;
143 bool equals(const ip_address& other) const noexcept override;
144
147 std::vector<xtd::byte> get_address_bytes() const;
148
152 ip_address map_to_ip_v4() const noexcept;
153
157 ip_address map_to_ip_v6() const noexcept;
158
161 string to_string() const noexcept override;
163
165
172 static double host_to_network_order(double host);
173
179 static int16 host_to_network_order(int16 host);
180
186 static int32 host_to_network_order(int32 host);
187
193 static int64 host_to_network_order(int64 host);
194
200 static float host_to_network_order(float host);
201
207 static uint16 host_to_network_order(uint16 host);
208
214 static uint32 host_to_network_order(uint32 host);
215
221 static uint64 host_to_network_order(uint64 host);
222
226 static bool is_loopback(const ip_address& address);
227
233 static double network_to_host_order(double network);
234
240 static int16 network_to_host_order(int16 network);
241
247 static int32 network_to_host_order(int32 host);
248
254 static int64 network_to_host_order(int64 network);
255
261 static float network_to_host_order(float network);
262
268 static uint16 network_to_host_order(uint16 network);
269
275 static uint32 network_to_host_order(uint32 network);
276
282 static uint64 network_to_host_order(uint64 network);
283
290 static ip_address parse(const string& str);
291
296 static bool try_parse(const string& str, ip_address& address) noexcept;
298
299 private:
300 friend xtd::net::sockets::socket;
301 static constexpr size_t number_of_numbers_ = 8;
302 ip_address(const std::vector<uint16>& numbers, uint32 scope_id);
303 uint32 address_ = 0xFFFFFFFF;
304 std::vector<uint16> numbers_ = std::vector<uint16>(number_of_numbers_);
305 uint32 scope_id_ = 0;
306 sockets::address_family address_family_ = sockets::address_family::inter_network;
307 };
308 }
309}
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.hpp:22
Provides an Internet Protocol (IP) address.
Definition ip_address.hpp:37
static const 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.hpp:57
ip_address()=default
Initializes a new instance of the xtd::net::ip_address.
static const ip_address any
Provides an IP address that indicates that the server must listen for client activity on all network ...
Definition ip_address.hpp:44
static const ip_address loopback
Provides the IP loopback address. This field is constant.
Definition ip_address.hpp:60
sockets::address_family address_family() const noexcept
Gets the address family of the IP address.
ip_address(uint32 address)
Initializes a new instance of the xtd::net::ip_address class with the address specified as an uint32.
ip_address(xtd::byte quad_part_address1, xtd::byte quad_part_address2, xtd::byte quad_part_address3, xtd::byte quad_part_address4)
Initializes a new instance of the xtd::net::ip_address class with the address specified as a four Byt...
static const ip_address ip_v6_loopback
Provides the IP loopback address. This field is constant.
Definition ip_address.hpp:53
static const ip_address broadcast
Provides the IP broadcast address. This field is constant.
Definition ip_address.hpp:47
static const 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.hpp:50
ip_address(const std::vector< xtd::byte > &address)
Initializes a new instance of the xtd::net::ip_address class with the address specified as a byte arr...
ip_address(const std::vector< xtd::byte > &address, uint32 scope_id)
Initializes a new instance of the xtd::net::ip_address class with the address specified as a byte arr...
static const ip_address none
Provides an IP address that indicates that no network interface should be used. This field is constan...
Definition ip_address.hpp:63
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
#define core_export_
Define shared library export.
Definition core_export.hpp:13
int16_t int16
Represents a 16-bit signed integer.
Definition int16.hpp:23
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.hpp:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
address_family
Specifies the addressing scheme that an instance of the xtd::net::sockets::socket class can use.
Definition address_family.hpp:30
@ socket
Socket options apply to all sockets.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10