xtd 0.2.0
Loading...
Searching...
No Matches
ip_address.hpp
Go to the documentation of this file.
1
4#pragma once
6#include "../array.hpp"
7#include "../core_export.hpp"
8#include "../iequatable.hpp"
9#include "../object.hpp"
10#include "../types.hpp"
11#include "../string.hpp"
12#include <vector>
13
15namespace xtd {
17 namespace net {
19 namespace sockets {
20 class socket;
21 }
23
42 class core_export_ ip_address : public xtd::object, public xtd::iequatable<xtd::net::ip_address> {
43 public:
45
49 static const ip_address any;
52 static const ip_address broadcast;
55 static const ip_address ip_v6_any;
62 static const ip_address ip_v6_none;
65 static const ip_address loopback;
68 static const ip_address none;
70
72
79 explicit ip_address(xtd::uint32 address);
82 explicit ip_address(const xtd::array<xtd::byte>& address);
96 ip_address(xtd::byte quad_part_address1, xtd::byte quad_part_address2, xtd::byte quad_part_address3, xtd::byte quad_part_address4);
98
100 ip_address(ip_address&& ip_address) = default;
101 ip_address(const ip_address& ip_address) = default;
102 auto operator =(ip_address&&) -> ip_address& = default;
103 auto operator =(const ip_address&) -> ip_address& = default;
105
107
111 [[nodiscard]] auto address_family() const noexcept -> xtd::net::sockets::address_family;
112
116 [[nodiscard]] auto is_ip_v4_mapped_to_ip_v6() const noexcept -> bool;
117
120 [[nodiscard]] auto is_ip_v6_link_local() const noexcept -> bool;
121
124 [[nodiscard]] auto is_ip_v6_multicast() const noexcept -> bool;
125
128 [[nodiscard]] auto is_ip_v6_site_local() const noexcept -> bool;
129
133 [[nodiscard]] auto is_ip_v6_teredo() const noexcept -> bool;
134
138 [[nodiscard]] auto scope_id() const -> xtd::uint32;
142 auto scope_id(xtd::uint32 value) -> ip_address&;
144
146
151 [[nodiscard]] auto equals(const object& obj) const noexcept -> bool override;
155 [[nodiscard]] auto equals(const ip_address& other) const noexcept -> bool override;
156
159 [[nodiscard]] auto get_address_bytes() const -> xtd::array<xtd::byte>;
160
163 [[nodiscard]] auto get_hash_code() const noexcept -> xtd::size override;
164
168 [[nodiscard]] auto map_to_ip_v4() const noexcept -> ip_address;
169
173 [[nodiscard]] auto map_to_ip_v6() const noexcept -> ip_address;
174
177 [[nodiscard]] auto to_string() const noexcept -> xtd::string override;
179
181
188 [[nodiscard]] static auto host_to_network_order(double host) -> double;
189
195 [[nodiscard]] static auto host_to_network_order(xtd::int16 host) -> xtd::int16;
196
202 [[nodiscard]] static auto host_to_network_order(xtd::int32 host) -> xtd::int32;
203
209 [[nodiscard]] static auto host_to_network_order(xtd::int64 host) -> xtd::int64;
210
216 [[nodiscard]] static auto host_to_network_order(float host) -> float;
217
223 [[nodiscard]] static auto host_to_network_order(xtd::uint16 host) -> xtd::uint16;
224
230 [[nodiscard]] static auto host_to_network_order(xtd::uint32 host) -> xtd::uint32;
231
237 [[nodiscard]] static auto host_to_network_order(xtd::uint64 host) -> xtd::uint64;
238
242 [[nodiscard]] static auto is_loopback(const ip_address& address) -> bool;
243
249 [[nodiscard]] static auto network_to_host_order(double network) -> double;
250
256 [[nodiscard]] static auto network_to_host_order(xtd::int16 network) -> xtd::int16;
257
263 [[nodiscard]] static auto network_to_host_order(xtd::int32 host) -> xtd::int32;
264
270 [[nodiscard]] static auto network_to_host_order(xtd::int64 network) -> xtd::int64;
271
277 [[nodiscard]] static auto network_to_host_order(float network) -> float;
278
284 [[nodiscard]] static auto network_to_host_order(xtd::uint16 network) -> xtd::uint16;
285
291 [[nodiscard]] static auto network_to_host_order(xtd::uint32 network) -> xtd::uint32;
292
298 [[nodiscard]] static auto network_to_host_order(xtd::uint64 network) -> xtd::uint64;
299
306 [[nodiscard]] static auto parse(const xtd::string& str) -> ip_address;
307
312 static auto try_parse(const xtd::string& str, ip_address& address) noexcept -> bool;
314
315 private:
316 friend xtd::net::sockets::socket;
317 static constexpr xtd::size number_of_numbers_ = 8;
318 ip_address(const xtd::array<xtd::uint16>& numbers, xtd::uint32 scope_id);
319 xtd::uint32 address_or_scope_id_ = 0;
320 xtd::array<xtd::uint16> numbers_ = xtd::array<xtd::uint16>(number_of_numbers_);
321 sockets::address_family address_family_ = sockets::address_family::inter_network;
322 };
323 }
324}
325
326#include "../literals/ip_address.hpp"
Contains xtd::net::sockets::address_family enum.
Contains xtd::array class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:23
auto is_ip_v6_multicast() const noexcept -> bool
Gets whether the address is an IPv6 multicast global address.
auto is_ip_v6_teredo() const noexcept -> bool
Gets whether the address is an IPv6 Teredo address.
ip_address(xtd::uint32 address)
Initializes a new instance of the xtd::net::ip_address class with the address specified as an uint32.
auto is_ip_v4_mapped_to_ip_v6() const noexcept -> bool
Gets whether the IP address is an IPv4-mapped IPv6 address.
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:62
auto get_hash_code() const noexcept -> xtd::size override
Serves as a hash function for a particular type.
static auto is_loopback(const ip_address &address) -> bool
Indicates whether the specified IP address is the loopback address.
auto map_to_ip_v4() const noexcept -> ip_address
Maps the xtd::net::ip_address object to an IPv4 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:49
auto address_family() const noexcept -> xtd::net::sockets::address_family
Gets the address family of the IP address.
static auto parse(const xtd::string &str) -> ip_address
Converts an IP address string to an xtd::net::ip_address instance.
static const ip_address loopback
Provides the IP loopback address. This field is constant.
Definition ip_address.hpp:65
static auto network_to_host_order(double network) -> double
Converts a Double value from network byte order to host byte order.
ip_address(const xtd::array< xtd::byte > &address, xtd::uint32 scope_id)
Initializes a new instance of the xtd::net::ip_address class with the address specified as a byte arr...
static auto try_parse(const xtd::string &str, ip_address &address) noexcept -> bool
Determines whether a string is a valid IP address.
static auto host_to_network_order(double host) -> double
Converts a Double value from host byte order to network byte order.
ip_address()
Initializes a new instance of the xtd::net::ip_address.
auto map_to_ip_v6() const noexcept -> ip_address
Maps the xtd::net::ip_address object to an IPv6 address.
auto is_ip_v6_site_local() const noexcept -> bool
Gets whether the address is an IPv6 site local address.
auto get_address_bytes() const -> xtd::array< xtd::byte >
Provides a copy of the IPAddress as an array of bytes.
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:58
auto scope_id() const -> xtd::uint32
Gets the IPv6 address scope identifier.
ip_address(const xtd::array< xtd::byte > &address)
Initializes a new instance of the xtd::net::ip_address class with the address specified as a byte arr...
static const ip_address broadcast
Provides the IP broadcast address. This field is constant.
Definition ip_address.hpp:52
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:55
auto to_string() const noexcept -> xtd::string override
Converts an Internet address to its standard notation.
auto equals(const object &obj) const noexcept -> bool override
Determines whether the specified object is equal to the current object.
auto is_ip_v6_link_local() const noexcept -> bool
Gets whether the address is an IPv6 link local address.
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:68
Implements the Berkeley sockets interface.
Definition socket.hpp:77
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
Contains core_export_ keyword.
#define core_export_
Define shared library export.
Definition core_export.hpp:13
std::int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
std::uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
std::uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
std::int16_t int16
Represents a 16-bit signed integer.
Definition int16.hpp:23
std::uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.hpp:23
std::uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
@ host
The xtd::uri::host data.
Definition uri_components.hpp:23
@ other
The operating system is other.
Definition platform_id.hpp:60
Contains xtd::iequatable interface.
The xtd::net::sockets namespace provides a managed implementation of the Berkeley Sockets interface f...
Definition address_family.hpp:16
The xtd::net namespace provides a simple programming interface for many of the protocols used on netw...
Definition cookie_exception.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::object class.
Contains xtd::string alias.
Contains xtd fundamental types.