xtd 0.2.0
Loading...
Searching...
No Matches
xtd::net::ip_address Class Reference
Inheritance diagram for xtd::net::ip_address:
xtd::object xtd::iequatable< ip_address > xtd::interface xtd::equality_operators< type_t, equatable_t >

Definition

Provides an Internet Protocol (IP) address.

Header
#include <xtd/net/ip_address>
Namespace
xtd::net
Library
xtd.core
Examples
The following code example shows how to query a server to obtain the family addresses and the IP addresses it supports.
#include <xtd/net/sockets/socket>
#include <xtd/net/dns>
#include <xtd/net/ip_address>
#include <xtd/text/string_builder>
#include <xtd/console>
#include <xtd/startup>
#include <regex>
using namespace xtd;
using namespace xtd::collections::generic;
using namespace xtd::net;
using namespace xtd::net::sockets;
using namespace xtd::text;
class test_ip_address {
public:
static auto main(const list<string>& args) {
auto server = string_builder {};
// Define a regular expression to parse user's input.
// This is a security check. It allows only
// alphanumeric input string between 2 to 40 character long.
auto rex = std::regex {R"(^[a-zA-Z]\w{1,39}$)"};
if (args.size() < 1) {
// If no server name is passed as an argument to this program, use the current
// server name as default.
server = dns::get_host_name();
console::write_line("Using current host: {}", server);
} else {
server = args[0];
if (!regex_match(server.chars(), rex)) {
console::write_line("Input string format not allowed.");
return;
}
}
// Get the list of the addresses associated with the requested server.
ip_addresses(server.to_string());
// Get additional address information.
ip_address_additional_info();
}
private:
static void ip_addresses(const string& server) {
try {
// Get server related information.
auto heserver = dns::get_host_entry(server);
// Loop on the AddressList
for (auto cur_add : heserver.address_list()) {
// Display the type of address family supported by the server. If the
// server is IPv6-enabled this value is: InterNetworkV6. If the server
// is also IPv4-enabled there will be an additional value of InterNetwork.
console::write_line("address_family: {}", cur_add.address_family());
// Display the ScopeId property in case of IPV6 addresses.
if (cur_add.address_family() == address_family::inter_network_v6)
console::write_line("scope id: {}", cur_add.scope_id());
// Display the server IP address in the standard format. In
// IPv4 the format will be dotted-quad notation, in IPv6 it will be
// in in colon-hexadecimal notation.
console::write_line("address: {}", cur_add);
// Display the server IP address in byte format.
console::write("address_bytes: ");
auto bytes = cur_add.get_address_bytes();
for (size_t i = 0; i < bytes.size(); i++)
console::write(bytes[i]);
console::write_line("\r\n");
}
} catch (const system_exception& e) {
console::write_line("[do_resolve] exception: {}", e);
}
}
// This IPAddressAdditionalInfo displays additional server address information.
static void ip_address_additional_info() {
try {
// Display the flags that show if the server supports IPv4 or IPv6
// address schemas.
console::write_line("\r\nos_supports_ip_v4: {}", socket::os_supports_ip_v4());
console::write_line("os_supports_ip_v6: {}", socket::os_supports_ip_v6());
if (socket::os_supports_ip_v6()) {
// Display the server Any address. This IP address indicates that the server
// should listen for client activity on all network interfaces.
console::write_line("\r\nip_v6_any: {}", ip_address::ip_v6_any);
// Display the server loopback address.
console::write_line("ip_v6_loopback: {}", ip_address::ip_v6_loopback);
// Used during autoconfiguration first phase.
console::write_line("ip_v6_none: {}", ip_address::ip_v6_none);
console::write_line("is_loopback(ip_v6_loopback): {}", ip_address::is_loopback(ip_address::ip_v6_loopback));
}
console::write_line("is_loopback(loopback):{}", ip_address::is_loopback(ip_address::loopback));
} catch (const system_exception& e) {
console::write_line("[ip_addresses] exception: {}", e);
}
}
};
startup_(test_ip_address::main);
// This code produces the following output if no args:
//
// Using current host: !---OMITTED---!.local
// address_family: inter_network
// address: 192.168.1.37
// address_bytes: 192168137
//
//
// os_supports_ip_v4: true
// os_supports_ip_v6: true
//
// ip_v6_any: ::
// ip_v6_loopback: ::1
// ip_v6_none: ::
// is_loopback(ip_v6_loopback): true
// is_loopback(loopback):true
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.h:71
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::collections::generic::list::...
Definition list.h:364
The exception that is thrown when a method call is invalid for the object's current state.
Definition system_exception.h:18
Represents a mutable string of characters. This class cannot be inherited.
Definition basic_string_builder.h:35
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
@ i
The I key.
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.h:15
The xtd::net::sockets namespace provides a managed implementation of the Berkeley Sockets interface f...
Definition address_family.h:16
The xtd::net namespace provides a simple programming interface for many of the protocols used on netw...
Definition cookie_exception.h:11
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.h:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Remarks
The xtd::net::ip_address class contains the address of a computer on an IP network.

Public Fields

static const ip_address any
 Provides an IP address that indicates that the server must listen for client activity on all network interfaces. This field is constant.
 
static const ip_address broadcast
 Provides the IP broadcast address. This field is constant.
 
static const ip_address ip_v6_any
 The Socket::Bind method uses the cIPv6Any field to indicate that a Socket must listen for client activity on all network interfaces. This field is constant.
 
static const ip_address ip_v6_loopback
 Provides the IP loopback address. This field is constant.
 
static const ip_address ip_v6_none
 Provides an IP address that indicates that no network interface should be used. This field is constant.
 
static const ip_address loopback
 Provides the IP loopback address. This field is constant.
 
static const ip_address none
 Provides an IP address that indicates that no network interface should be used. This field is constant.
 

Public Constructors

 ip_address ()=default
 Initializes a new instance of the xtd::net::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 (const std::vector< xtd::byte > &address)
 Initializes a new instance of the xtd::net::ip_address class with the address specified as a byte array.
 
 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 array.
 
 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 Bytes.
 

Public Properties

sockets::address_family address_family () const noexcept
 Gets the address family of the IP address.
 
bool is_ip_v4_mapped_to_ip_v6 () const noexcept
 Gets whether the IP address is an IPv4-mapped IPv6 address.
 
bool is_ip_v6_link_local () const noexcept
 Gets whether the address is an IPv6 link local address.
 
bool is_ip_v6_multicast () const noexcept
 Gets whether the address is an IPv6 multicast global address.
 
bool is_ip_v6_site_local () const noexcept
 Gets whether the address is an IPv6 site local address.
 
bool is_ip_v6_teredo () const noexcept
 Gets whether the address is an IPv6 Teredo address.
 
uint32 scope_id () const
 Gets the IPv6 address scope identifier.
 
ip_addressscope_id (uint32 value)
 Sets the IPv6 address scope identifier.
 

Public Methods

bool equals (const ip_address &other) const noexcept override
 
std::vector< xtd::byteget_address_bytes () const
 Provides a copy of the IPAddress as an array of bytes.
 
ip_address map_to_ip_v4 () const noexcept
 Maps the xtd::net::ip_address object to an IPv4 address.
 
ip_address map_to_ip_v6 () const noexcept
 Maps the xtd::net::ip_address object to an IPv6 address.
 
string to_string () const noexcept override
 Converts an Internet address to its standard notation.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 

Public Static Methods

static double host_to_network_order (double host)
 Converts a Double value from host byte order to network byte order.
 
static int16 host_to_network_order (int16 host)
 Converts a short value from host byte order to network byte order.
 
static int32 host_to_network_order (int32 host)
 Converts a integer value from host byte order to network byte order.
 
static int64 host_to_network_order (int64 host)
 Converts a long value from host byte order to network byte order.
 
static float host_to_network_order (float host)
 Converts a Single value from host byte order to network byte order.
 
static uint16 host_to_network_order (uint16 host)
 Converts a short value from host byte order to network byte order.
 
static uint32 host_to_network_order (uint32 host)
 Converts a integer value from host byte order to network byte order.
 
static uint64 host_to_network_order (uint64 host)
 Converts a long value from host byte order to network byte order.
 
static bool is_loopback (const ip_address &address)
 Indicates whether the specified IP address is the loopback address.
 
static double network_to_host_order (double network)
 Converts a Double value from network byte order to host byte order.
 
static int16 network_to_host_order (int16 network)
 Converts a short value from network byte order to host byte order.
 
static int32 network_to_host_order (int32 host)
 Converts a integer value from network byte order to host byte order.
 
static int64 network_to_host_order (int64 network)
 Converts a long value from network byte order to host byte order.
 
static float network_to_host_order (float network)
 Converts a Single value from network byte order to host byte order.
 
static uint16 network_to_host_order (uint16 network)
 Converts a short value from network byte order to host byte order.
 
static uint32 network_to_host_order (uint32 network)
 Converts a integer value from network byte order to host byte order.
 
static uint64 network_to_host_order (uint64 network)
 Converts a long value from network byte order to host byte order.
 
static ip_address parse (const string &str)
 Converts an IP address string to an xtd::net::ip_address instance.
 
static bool try_parse (const string &str, ip_address &address) noexcept
 Determines whether a string is a valid IP address.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Public Member Functions inherited from xtd::iequatable< ip_address >
virtual bool equals (const ip_address &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ ip_address() [1/5]

xtd::net::ip_address::ip_address ( )
default

Initializes a new instance of the xtd::net::ip_address.

Remarks
ip_address is initialized by default value xtd::net::ip_address::none.

◆ ip_address() [2/5]

xtd::net::ip_address::ip_address ( uint32  address)
explicit

Initializes a new instance of the xtd::net::ip_address class with the address specified as an uint32.

Parameters
addressThe value of the IP address. For example, the value 0x2414188F in big-endian format would be the IP address "143.24.20.36".

◆ ip_address() [3/5]

xtd::net::ip_address::ip_address ( const std::vector< xtd::byte > &  address)
explicit

Initializes a new instance of the xtd::net::ip_address class with the address specified as a byte array.

Parameters
addressThe byte array value of the IP address.

◆ ip_address() [4/5]

xtd::net::ip_address::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 array.

Parameters
addressThe byte array value of the IP address.
scope_idThe long value of the scope identifier.
Exceptions
xtd::argument_out_of_range_exceptionscope_id < 0 or scope_id > 0x00000000FFFFFFFF.
Remarks
This constructor instantiates an IPv6 address. The scope_dd identifies a network interface in the case of a link-local address.
The scope is valid only for link-local and site-local addresses.
The byte array is assumed to be in network byte order with the most significant byte first in index position 0.

◆ ip_address() [5/5]

xtd::net::ip_address::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 Bytes.

Parameters
quad_part_address1The first quad part of the IP address.
quad_part_address2The second quad part of the IP address.
quad_part_address3The third quad part of the IP address.
quad_part_address4The fourth quad part of the IP address.

Member Function Documentation

◆ address_family()

sockets::address_family xtd::net::ip_address::address_family ( ) const
noexcept

Gets the address family of the IP address.

Returns
Returns sockets::address_family::inter_network for IPv4 or sockets::address_family::inter_network_v6 for IPv6.

◆ is_ip_v4_mapped_to_ip_v6()

bool xtd::net::ip_address::is_ip_v4_mapped_to_ip_v6 ( ) const
noexcept

Gets whether the IP address is an IPv4-mapped IPv6 address.

Returns
true if the IP address is an IPv4-mapped IPv6 address; otherwise, false.
Remarks
Dual-stack sockets always require IPv6 addresses. The ability to interact with an IPv4 address requires the use of the IPv4-mapped IPv6 address format. Any IPv4 addresses must be represented in the IPv4-mapped IPv6 address format which enables an IPv6 only application to communicate with an IPv4 node. The IPv4-mapped IPv6 address format allows the IPv4 address of an IPv4 node to be represented as an IPv6 address. The IPv4 address is encoded into the low-order 32 bits of the IPv6 address, and the high-order 96 bits hold the fixed prefix 0:0:0:0:0:FFFF. The IPv4-mapped IPv6 address format is specified in RFC 4291. For more information, see www.ietf.org/rfc/rfc4291.txt.

◆ is_ip_v6_link_local()

bool xtd::net::ip_address::is_ip_v6_link_local ( ) const
noexcept

Gets whether the address is an IPv6 link local address.

Returns
bool true if the IP address is an IPv6 link local address; otherwise, false.

◆ is_ip_v6_multicast()

bool xtd::net::ip_address::is_ip_v6_multicast ( ) const
noexcept

Gets whether the address is an IPv6 multicast global address.

Returns
bool true if the IP address is an IPv6 multicast global address; otherwise, false.

◆ is_ip_v6_site_local()

bool xtd::net::ip_address::is_ip_v6_site_local ( ) const
noexcept

Gets whether the address is an IPv6 site local address.

Returns
bool true if the IP address is an IPv6 site local address; otherwise, false.

◆ is_ip_v6_teredo()

bool xtd::net::ip_address::is_ip_v6_teredo ( ) const
noexcept

Gets whether the address is an IPv6 Teredo address.

Returns
true if the IP address is an IPv6 Teredo address; otherwise, false.
Remarks
A Teredo address is an IPv6 address with the prefix of 2001::/32. Teredo addresses can be returned through normal DNS name resolution or enumerated as an IPv6 address assigned to a local interface.

◆ scope_id() [1/2]

uint32 xtd::net::ip_address::scope_id ( ) const

Gets the IPv6 address scope identifier.

Returns
A uint32 that specifies the scope of the address.
Exceptions
xtd::net::sockets::socket_exceptionif address_family = sockets::address_family::inter_network

◆ scope_id() [2/2]

ip_address & xtd::net::ip_address::scope_id ( uint32  value)

Sets the IPv6 address scope identifier.

Parameters
valueA uint32 that specifies the scope of the address.
Exceptions
xtd::net::sockets::socket_exceptionif address_family = sockets::address_family::inter_network

◆ get_address_bytes()

std::vector< xtd::byte > xtd::net::ip_address::get_address_bytes ( ) const

Provides a copy of the IPAddress as an array of bytes.

Returns
A byte array.

◆ map_to_ip_v4()

ip_address xtd::net::ip_address::map_to_ip_v4 ( ) const
noexcept

Maps the xtd::net::ip_address object to an IPv4 address.

Returns
An IPv4 address.
Remarks
Dual-stack sockets always require IPv6 addresses. The ability to interact with an IPv4 address requires the use of the IPv4-mapped IPv6 address format. Any IPv4 addresses must be represented in the IPv4-mapped IPv6 address format which enables an IPv6 only application to communicate with an IPv4 node. The IPv4-mapped IPv6 address format allows the IPv4 address of an IPv4 node to be represented as an IPv6 address. The IPv4 address is encoded into the low-order 32 bits of the IPv6 address, and the high-order 96 bits hold the fixed prefix 0:0:0:0:0:FFFF. The IPv4-mapped IPv6 address format is specified in RFC 4291. For more information, see www.ietf.org/rfc/rfc4291.txt.

◆ map_to_ip_v6()

ip_address xtd::net::ip_address::map_to_ip_v6 ( ) const
noexcept

Maps the xtd::net::ip_address object to an IPv6 address.

Returns
An IPv6 address.
Remarks
Dual-stack sockets always require IPv6 addresses. The ability to interact with an IPv4 address requires the use of the IPv4-mapped IPv6 address format. Any IPv4 addresses must be represented in the IPv4-mapped IPv6 address format which enables an IPv6 only application to communicate with an IPv4 node. The IPv4-mapped IPv6 address format allows the IPv4 address of an IPv4 node to be represented as an IPv6 address. The IPv4 address is encoded into the low-order 32 bits of the IPv6 address, and the high-order 96 bits hold the fixed prefix 0:0:0:0:0:FFFF. The IPv4-mapped IPv6 address format is specified in RFC 4291. For more information, see www.ietf.org/rfc/rfc4291.txt.

◆ to_string()

string xtd::net::ip_address::to_string ( ) const
overridevirtualnoexcept

Converts an Internet address to its standard notation.

Returns
A string that contains the IP address in either IPv4 dotted-quad or in IPv6 colon-hexadecimal notation.

Reimplemented from xtd::object.

◆ host_to_network_order() [1/8]

static double xtd::net::ip_address::host_to_network_order ( double  host)
static

Converts a Double value from host byte order to network byte order.

Parameters
hostThe number to convert, expressed in host byte order.
Returns
A Double value, expressed in network byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values.Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::host_to_network_order method converts multibyte integer values that are stored on the host system from the byte order used by the host to the byte order used by the network.

◆ host_to_network_order() [2/8]

static int16 xtd::net::ip_address::host_to_network_order ( int16  host)
static

Converts a short value from host byte order to network byte order.

Parameters
hostThe number to convert, expressed in host byte order.
Returns
A short value, expressed in network byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values.Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::host_to_network_order method converts multibyte integer values that are stored on the host system from the byte order used by the host to the byte order used by the network.

◆ host_to_network_order() [3/8]

static int32 xtd::net::ip_address::host_to_network_order ( int32  host)
static

Converts a integer value from host byte order to network byte order.

Parameters
hostThe number to convert, expressed in host byte order.
Returns
A integer value, expressed in network byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values.Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::host_to_network_order method converts multibyte integer values that are stored on the host system from the byte order used by the host to the byte order used by the network.

◆ host_to_network_order() [4/8]

static int64 xtd::net::ip_address::host_to_network_order ( int64  host)
static

Converts a long value from host byte order to network byte order.

Parameters
hostThe number to convert, expressed in host byte order.
Returns
A long value, expressed in network byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values.Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::host_to_network_order method converts multibyte integer values that are stored on the host system from the byte order used by the host to the byte order used by the network.

◆ host_to_network_order() [5/8]

static float xtd::net::ip_address::host_to_network_order ( float  host)
static

Converts a Single value from host byte order to network byte order.

Parameters
hostThe number to convert, expressed in host byte order.
Returns
A Single value, expressed in network byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values.Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::host_to_network_order method converts multibyte integer values that are stored on the host system from the byte order used by the host to the byte order used by the network.

◆ host_to_network_order() [6/8]

static uint16 xtd::net::ip_address::host_to_network_order ( uint16  host)
static

Converts a short value from host byte order to network byte order.

Parameters
hostThe number to convert, expressed in host byte order.
Returns
A unsigned short value, expressed in network byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values.Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::host_to_network_order method converts multibyte integer values that are stored on the host system from the byte order used by the host to the byte order used by the network.

◆ host_to_network_order() [7/8]

static uint32 xtd::net::ip_address::host_to_network_order ( uint32  host)
static

Converts a integer value from host byte order to network byte order.

Parameters
hostThe number to convert, expressed in host byte order.
Returns
A unsigned integer value, expressed in network byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values.Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::host_to_network_order method converts multibyte integer values that are stored on the host system from the byte order used by the host to the byte order used by the network.

◆ host_to_network_order() [8/8]

static uint64 xtd::net::ip_address::host_to_network_order ( uint64  host)
static

Converts a long value from host byte order to network byte order.

Parameters
hostThe number to convert, expressed in host byte order.
Returns
A unsigned long value, expressed in network byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values.Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::host_to_network_order method converts multibyte integer values that are stored on the host system from the byte order used by the host to the byte order used by the network.

◆ is_loopback()

static bool xtd::net::ip_address::is_loopback ( const ip_address address)
static

Indicates whether the specified IP address is the loopback address.

Parameters
addressAn IP address.
Returns
bool true if address is the loopback address; otherwise, false.

◆ network_to_host_order() [1/8]

static double xtd::net::ip_address::network_to_host_order ( double  network)
static

Converts a Double value from network byte order to host byte order.

Parameters
networkThe number to convert, expressed in network byte order.
Returns
A Double value, expressed in host byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::network_to_host_order method converts multibyte integer values that are stored on the host system from the byte order used by the network to the byte order used by the host.

◆ network_to_host_order() [2/8]

static int16 xtd::net::ip_address::network_to_host_order ( int16  network)
static

Converts a short value from network byte order to host byte order.

Parameters
networkThe number to convert, expressed in network byte order.
Returns
A short value, expressed in host byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::network_to_host_order method converts multibyte integer values that are stored on the host system from the byte order used by the network to the byte order used by the host.

◆ network_to_host_order() [3/8]

static int32 xtd::net::ip_address::network_to_host_order ( int32  host)
static

Converts a integer value from network byte order to host byte order.

Parameters
hostThe number to convert, expressed in network byte order.
Returns
A integer value, expressed in host byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::network_to_host_order method converts multibyte integer values that are stored on the host system from the byte order used by the network to the byte order used by the host.

◆ network_to_host_order() [4/8]

static int64 xtd::net::ip_address::network_to_host_order ( int64  network)
static

Converts a long value from network byte order to host byte order.

Parameters
networkThe number to convert, expressed in network byte order.
Returns
A long value, expressed in host byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::network_to_host_order method converts multibyte integer values that are stored on the host system from the byte order used by the network to the byte order used by the host.

◆ network_to_host_order() [5/8]

static float xtd::net::ip_address::network_to_host_order ( float  network)
static

Converts a Single value from network byte order to host byte order.

Parameters
networkThe number to convert, expressed in host byte order.
Returns
A Single value, expressed in host byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::network_to_host_order method converts multibyte integer values that are stored on the host system from the byte order used by the network to the byte order used by the host.

◆ network_to_host_order() [6/8]

static uint16 xtd::net::ip_address::network_to_host_order ( uint16  network)
static

Converts a short value from network byte order to host byte order.

Parameters
networkThe number to convert, expressed in network byte order.
Returns
A unsigned short value, expressed in host byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::network_to_host_order method converts multibyte integer values that are stored on the host system from the byte order used by the network to the byte order used by the host.

◆ network_to_host_order() [7/8]

static uint32 xtd::net::ip_address::network_to_host_order ( uint32  network)
static

Converts a integer value from network byte order to host byte order.

Parameters
networkThe number to convert, expressed in network byte order.
Returns
A unsigned integer value, expressed in host byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::network_to_host_order method converts multibyte integer values that are stored on the host system from the byte order used by the network to the byte order used by the host.

◆ network_to_host_order() [8/8]

static uint64 xtd::net::ip_address::network_to_host_order ( uint64  network)
static

Converts a long value from network byte order to host byte order.

Parameters
networkThe number to convert, expressed in network byte order.
Returns
A unsigned long value, expressed in host byte order.
Remarks
Different computers use different conventions for ordering the bytes within multibyte integer values. Some computers put the most significant byte first (known as big-endian order) and others put the least-significant byte first (known as little-endian order). To work with computers that use different byte ordering, all integer values that are sent over the network are sent in network byte order which has the most significant byte first.
The xtd::net::sockets::socket::network_to_host_order method converts multibyte integer values that are stored on the host system from the byte order used by the network to the byte order used by the host.

◆ parse()

static ip_address xtd::net::ip_address::parse ( const string str)
static

Converts an IP address string to an xtd::net::ip_address instance.

Parameters
strA string that contains an IP address in dotted-quad notation for IPv4 and in colon-hexadecimal notation for IPv6.
Returns
An xtd::net::ip_address instance.
Exceptions
xtd::format_exceptionstr is not a valid IP address.
Remarks
The static xtd::net::ip_address::parse method creates an xtd::net::ip_address instance from an IP address expressed in dotted-quad notation for IPv4 and in colon-hexadecimal notation for IPv6.
The number of parts (each part is separated by a period) in str determines how the IP address is constructed. A one part address is stored directly in the network address. A two part address, convenient for specifying a class A address, puts the leading part in the first byte and the trailing part in the right-most three bytes of the network address. A three part address, convenient for specifying a class B address, puts the first part in the first byte, the second part in the second byte, and the final part in the right-most two bytes of the network address.

◆ try_parse()

static bool xtd::net::ip_address::try_parse ( const string str,
ip_address address 
)
staticnoexcept

Determines whether a string is a valid IP address.

Parameters
strThe string to validate.
addressThe xtd::net::ip_address version of the string.
Returns
bool true if str is a valid IP address; otherwise, false.

◆ equals() [1/2]

virtual bool xtd::object::equals ( const object obj) const
virtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.
Examples
The following code example compares the current instance with another object.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto object1 = new_ptr<object>();
auto object2 = new_ptr<object>();
auto object3 = object2;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
object3 = object1;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
}
// This code produces the following output :
//
// false
// false
// true
// true
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...

Reimplemented from xtd::object.

◆ equals() [2/2]

template<typename object_a_t , typename object_b_t >
static bool xtd::object::equals ( const object_a_t &  object_a,
const object_b_t &  object_b 
)
inlinestaticnoexcept

Determines whether the specified object instances are considered equal.

Parameters
object_aThe first object to compare.
object_bThe second object to compare.
Returns
true if object_a is the same instance as object_b or if both are null references or if object_a(object_b) returns true. otherwise, false.
Examples
The following code example compares different objects.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
string s1 = "Tom";
string s2 = "Carol";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "Tom";
s2 = "Tom";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "";
s2 = "Tom";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "Carol";
s2 = "";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "";
s2 = "";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
}
// This code produces the following output :
//
// object::equals("Tom", "Carol") => false
// object::equals("Tom", "Tom") => true
// object::equals("", "Tom") => false
// object::equals("Carol", "") => false
// object::equals("", "") => true
virtual bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.

Member Data Documentation

◆ any

const ip_address xtd::net::ip_address::any
static

Provides an IP address that indicates that the server must listen for client activity on all network interfaces. This field is constant.

Remarks
The xtd::net::ip_address::any field is equivalent to 0.0.0.0 in dotted-quad notation

◆ broadcast

const ip_address xtd::net::ip_address::broadcast
static

Provides the IP broadcast address. This field is constant.

Remarks
The xtd::net::ip_address::broadcast field is equivalent to 255.255.255.255 in dotted-quad notation.

◆ ip_v6_any

const ip_address xtd::net::ip_address::ip_v6_any
static

The Socket::Bind method uses the cIPv6Any field to indicate that a Socket must listen for client activity on all network interfaces. This field is constant.

Remarks
The xtd::net::ip_address::ip_v6_any field is equivalent to 0:0:0:0:0:0:0:0 in colon-hexadecimal notation, or to :: in compact notation.

◆ ip_v6_loopback

const ip_address xtd::net::ip_address::ip_v6_loopback
static

Provides the IP loopback address. This field is constant.

Remarks
The xtd::net::ip_address::ip_v6_loopback field is equivalent to 0:0:0:0:0:0:0:1 in colon-hexadecimal notation, or to ::1 in compact notation.

◆ ip_v6_none

const ip_address xtd::net::ip_address::ip_v6_none
static

Provides an IP address that indicates that no network interface should be used. This field is constant.

Remarks
The Socket::Bind method uses the cIPv6None field to indicate that a Socket must not listen for client activity.
The xtd::net::ip_address::ip_v6_none field is equivalent to 0:0:0:0:0:0:0:0 in colon-hexadecimal notation, or to ::0 in compact notation.

◆ loopback

const ip_address xtd::net::ip_address::loopback
static

Provides the IP loopback address. This field is constant.

Remarks
The xtd::net::ip_address::loopback field is equivalent to 127.0.0.1 in dotted-quad notation.

◆ none

const ip_address xtd::net::ip_address::none
static

Provides an IP address that indicates that no network interface should be used. This field is constant.

Remarks
The xtd::net::ip_address::none field is equivalent to 255.255.255.255 in dotted-quad notation.

The documentation for this class was generated from the following file: