Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::IpAddress Class Reference

Network class that represents an IP address. More...

Public Types

using IPv4 = std::array< UInt8, 4 >
 
using IPv6 = std::array< UInt16, 8 >
 

Public Member Functions

 IpAddress ()
 Constructs a IpAddress object by default.
 
 IpAddress (const IPv4 &ip, UInt16 port=0)
 Constructs a IpAddress object with an IP and a port. More...
 
 IpAddress (const IPv6 &ip, UInt16 port=0)
 Constructs a IpAddress object with an IP and a port. More...
 
 IpAddress (const UInt8 &a, const UInt8 &b, const UInt8 &c, const UInt8 &d, UInt16 port=0)
 Constructs a IpAddress object with an IP and a port. More...
 
 IpAddress (const UInt16 &a, const UInt16 &b, const UInt16 &c, const UInt16 &d, const UInt16 &e, const UInt16 &f, const UInt16 &g, const UInt16 &h, UInt16 port=0)
 Constructs a IpAddress object with an IP and a port. More...
 
 IpAddress (const char *address)
 
 IpAddress (const String &address)
 
 IpAddress (const IpAddress &)=default
 
 IpAddress (IpAddress &&)=default
 
bool BuildFromAddress (const char *address)
 Builds the IP from a hostname. More...
 
UInt16 GetPort () const
 Gets the port. More...
 
NetProtocol GetProtocol () const
 Gets the net protocol. More...
 
bool IsLoopback () const
 Checks whether the IP address is loopback. More...
 
bool IsValid () const
 Checks whether the IP address is valid. More...
 
void SetPort (UInt16 port)
 Sets the port. More...
 
IPv4 ToIPv4 () const
 Converts IpAddress to IPv4. More...
 
IPv6 ToIPv6 () const
 Converts IpAddress to IPv6. More...
 
String ToString () const
 Gives a string representation. More...
 
UInt32 ToUInt32 () const
 Converts IpAddress to UInt32. More...
 
 operator bool () const
 Converts IpAddress to boolean. More...
 
IpAddressoperator= (const IpAddress &)=default
 
IpAddressoperator= (IpAddress &&)=default
 

Static Public Member Functions

static String ResolveAddress (const IpAddress &address, String *service=nullptr, ResolveError *error=nullptr)
 Resolves the address based on the IP. More...
 
static std::vector< HostnameInfo > ResolveHostname (NetProtocol procol, const String &hostname, const String &protocol="http", ResolveError *error=nullptr)
 Resolves the address based on the hostname. More...
 

Static Public Attributes

static IpAddress AnyIpV4
 
static IpAddress AnyIpV6
 
static IpAddress BroadcastIpV4
 
static IpAddress Invalid
 
static IpAddress LoopbackIpV4
 
static IpAddress LoopbackIpV6
 

Friends

std::ostream & operator<< (std::ostream &out, const IpAddress &address)
 Output operator. More...
 
bool operator== (const IpAddress &first, const IpAddress &second)
 Compares the IpAddress to other one. More...
 
bool operator!= (const IpAddress &first, const IpAddress &second)
 Compares the IpAddress to other one. More...
 
bool operator< (const IpAddress &first, const IpAddress &second)
 Compares the IpAddress to other one. More...
 
bool operator<= (const IpAddress &first, const IpAddress &second)
 Compares the IpAddress to other one. More...
 
bool operator> (const IpAddress &first, const IpAddress &second)
 Compares the IpAddress to other one. More...
 
bool operator>= (const IpAddress &first, const IpAddress &second)
 Compares the IpAddress to other one. More...
 

Detailed Description

Network class that represents an IP address.

Constructor & Destructor Documentation

◆ IpAddress() [1/6]

Nz::IpAddress::IpAddress ( const IPv4 &  ip,
UInt16  port = 0 
)
inline

Constructs a IpAddress object with an IP and a port.

Parameters
ipIPv4 address
portPort of the IP

◆ IpAddress() [2/6]

Nz::IpAddress::IpAddress ( const IPv6 &  ip,
UInt16  port = 0 
)
inline

Constructs a IpAddress object with an IP and a port.

Parameters
ipIPv6 address
portPort of the IP

◆ IpAddress() [3/6]

Nz::IpAddress::IpAddress ( const UInt8 &  a,
const UInt8 &  b,
const UInt8 &  c,
const UInt8 &  d,
UInt16  port = 0 
)
inline

Constructs a IpAddress object with an IP and a port.

Parameters
ipIPv4 address (a.b.c.d)
portPort of the IP

◆ IpAddress() [4/6]

Nz::IpAddress::IpAddress ( const UInt16 &  a,
const UInt16 &  b,
const UInt16 &  c,
const UInt16 &  d,
const UInt16 &  e,
const UInt16 &  f,
const UInt16 &  g,
const UInt16 &  h,
UInt16  port = 0 
)
inline

Constructs a IpAddress object with an IP and a port.

Parameters
ipIPv6 address (a.b.c.d.e.f.g.h)
portPort of the IP

◆ IpAddress() [5/6]

Nz::IpAddress::IpAddress ( const char *  address)
inlineexplicit

Constructs a IpAddress object with a C-string

Parameters
addressHostname or textual IP address

◆ IpAddress() [6/6]

Nz::IpAddress::IpAddress ( const String address)
inlineexplicit

Constructs a IpAddress object with a string

Parameters
addressHostname or textual IP address

Member Function Documentation

◆ BuildFromAddress()

bool Nz::IpAddress::BuildFromAddress ( const char *  address)

Builds the IP from a hostname.

Returns
true If successful
Remarks
address C-string symbolizing the IP address or hostname

◆ GetPort()

UInt16 Nz::IpAddress::GetPort ( ) const
inline

Gets the port.

Returns
Port attached to the IP address

◆ GetProtocol()

NetProtocol Nz::IpAddress::GetProtocol ( ) const
inline

Gets the net protocol.

Returns
Protocol attached to the IP address

◆ IsLoopback()

bool Nz::IpAddress::IsLoopback ( ) const

Checks whether the IP address is loopback.

Returns
true If it is the case
Remarks
Produces a NazaraAssert if internal protocol is invalid (should never happen)

◆ IsValid()

bool Nz::IpAddress::IsValid ( ) const
inline

Checks whether the IP address is valid.

Returns
true If successful

◆ operator bool()

Nz::IpAddress::operator bool ( ) const
inlineexplicit

Converts IpAddress to boolean.

Returns
true If IpAddress is valid
See also
IsValid

◆ ResolveAddress()

String Nz::IpAddress::ResolveAddress ( const IpAddress address,
String service = nullptr,
ResolveError *  error = nullptr 
)
static

Resolves the address based on the IP.

Returns
Hostname of the address
Parameters
addressIP address to resolve
serviceOptional argument to specify the protocol used
errorOptional argument to get the error
Remarks
Produces a NazaraAssert if address is invalid

◆ ResolveHostname()

std::vector< HostnameInfo > Nz::IpAddress::ResolveHostname ( NetProtocol  protocol,
const String hostname,
const String service = "http",
ResolveError *  error = nullptr 
)
static

Resolves the address based on the hostname.

Returns
Informations about the host: IP(s) of the address, names, ...
Parameters
protocolNet protocol to use
hostnameHostname to resolve
serviceSpecify the service used (http, ...)
errorOptional argument to get the error
Remarks
Produces a NazaraAssert if net protocol is set to unknown

◆ SetPort()

void Nz::IpAddress::SetPort ( UInt16  port)
inline

Sets the port.

Parameters
portPort attached to the IP address

◆ ToIPv4()

IpAddress::IPv4 Nz::IpAddress::ToIPv4 ( ) const
inline

Converts IpAddress to IPv4.

Returns
Corresponding IPv4
Remarks
Produces a NazaraAssert if net protocol is not IPv4

◆ ToIPv6()

IpAddress::IPv6 Nz::IpAddress::ToIPv6 ( ) const
inline

Converts IpAddress to IPv6.

Returns
Corresponding IPv6
Remarks
Produces a NazaraAssert if net protocol is not IPv6

◆ ToString()

String Nz::IpAddress::ToString ( ) const

Gives a string representation.

Returns
A string representation of the object
Remarks
Produces a NazaraAssert if internal protocol is invalid (should never happen)

◆ ToUInt32()

UInt32 Nz::IpAddress::ToUInt32 ( ) const
inline

Converts IpAddress to UInt32.

Returns
Corresponding UInt32
Remarks
Produces a NazaraAssert if net protocol is not IPv4

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const IpAddress first,
const IpAddress second 
)
friend

Compares the IpAddress to other one.

Returns
false if the ip addresses are the same
Parameters
firstFirst ip address to compare
secondSecond ip address to compare with

◆ operator<

bool operator< ( const IpAddress first,
const IpAddress second 
)
friend

Compares the IpAddress to other one.

Returns
true if this ip address is inferior to the other one
Parameters
firstFirst ip address to compare
secondSecond ip address to compare with

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const IpAddress address 
)
friend

Output operator.

Returns
The stream
Parameters
outThe stream
addressThe address to output

◆ operator<=

bool operator<= ( const IpAddress first,
const IpAddress second 
)
friend

Compares the IpAddress to other one.

Returns
true if this ip address is inferior or equal to the other one
Parameters
firstFirst ip address to compare
secondSecond ip address to compare with

◆ operator==

bool operator== ( const IpAddress first,
const IpAddress second 
)
friend

Compares the IpAddress to other one.

Returns
true if the ip addresses are the same
Parameters
firstFirst ip address to compare
secondSecond ip address to compare with

◆ operator>

bool operator> ( const IpAddress first,
const IpAddress second 
)
friend

Compares the IpAddress to other one.

Returns
true if this ip address is greather to the other one
Parameters
firstFirst ip address to compare
secondSecond ip address to compare with

◆ operator>=

bool operator>= ( const IpAddress first,
const IpAddress second 
)
friend

Compares the IpAddress to other one.

Returns
true if this ip address is greather or equal to the other one
Parameters
firstFirst ip address to compare
secondSecond ip address to compare with

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