class RNET::Address

This class defines a network address. More...

#include <RNETAddress.h>

Inherits: Object.

Public functions:

Address ( )
Address ( const RED::String & iString )
Address ( unsigned int iIPv4, unsigned short iPort = 0 )
~Address ( )
unsigned intIPv4 ( ) const
boolIsValid ( ) const
boolIsWeb ( ) const
booloperator!= ( const Address & other ) const
booloperator< ( const Address & other ) const
booloperator== ( const Address & other ) const
unsigned shortPort ( ) const
voidReset ( )
const RED::String &ToString ( ) const
voidToString ( RED::String & oAddress, RED::String & oPort ) const

Public static functions:

static RNET::AddressBroadcast ( unsigned int iPort )
static RNET::AddressHost ( unsigned short iPort )
static RNET::AddressLocalHost ( unsigned short iPort )

Protected variables:

unsigned int_ip [4]
bool_is_web
unsigned short_port
RED::String_string
RED::String_string_address
RED::String_string_port
bool_valid

Detailed description:

This class defines a network address.

A network address can be either a single IP address (only v4 is supported right now) or an IP address and a port.

This class offers several helpers to access to the address under various forms.

Note:

The numerical values are always returned in network byte order! The setting of numerical values can be in hardware or network byte order depending on the method called; check the corresponding documentation!

Functions documentation

Default constructor.

While no address has been set manually, this object stays invalid.

public RNET::Address::Address(const RED::String &iString)

Constructs an address from a string.

The string must follow:

a.b.c.d

or a.b.c.d:port

where a.b.c.d is a valid IP v4 address and port is an optional port value.

Parameters:

iStringthe address as a string.
public RNET::Address::Address(unsigned intiIPv4,
unsigned shortiPort = 0
)

Constructs an address from an IP v4 address in network byte order.

Parameters:

iIPv4IP v4 address in network byte order.
iPortoptional port in network byte order.

Destructor.

public unsigned int RNET::Address::IPv4() const

Returns:

the address in IP v4 format in network byte order.
public bool RNET::Address::IsValid() const

Returns:

true if a valid IP address has been set,
false otherwise.
public bool RNET::Address::IsWeb() const

Returns:

true if the address starts with "www.", false otherwise.
public bool RNET::Address::operator!=(const Address &other) const

Inequality comparison operator.

public bool RNET::Address::operator<(const Address &other) const

Less than comparison operator.

public bool RNET::Address::operator==(const Address &other) const

Equality comparison operator.

public unsigned short RNET::Address::Port() const

Returns:

the optional port of the address in network byte order.
public void RNET::Address::Reset()

Resets the address content and set it back to invalid.

public const RED::String & RNET::Address::ToString() const

Returns a string version of the address.

If the address contains a port, the output will have the following format: a.b.c.d:port, otherwise, it will look like: a.b.c.d.

Returns:

a string version of the address.
public void RNET::Address::ToString(RED::String &oAddress,
RED::String &oPort
)const

Returns both address and port strings from the address.

Parameters:

oAddressreference to the returned IP string.
oPortreference to the returned port string.
public static RNET::Address RNET::Address::Broadcast(unsigned intiPort)

Returns the broadcast address including the given port.

Parameters:

iPortthe port to use in hardware byte order (not in network byte order!).

Returns:

the broadcast address including the given port.
public static RNET::Address RNET::Address::Host(unsigned shortiPort)

Returns the network address of the host machine including the given port.

Parameters:

iPortthe port to use in hardware byte order (not in network byte order!).

Returns:

the network address of the host machine including the given port.
public static RNET::Address RNET::Address::LocalHost(unsigned shortiPort)

Returns the network address of the loopback interface (most of the time 127.0.0.1) including the given port.

Parameters:

iPortthe port to use in hardware byte order (not in network byte order!).

Returns:

the network address of the local machine including the given port.

Variables documentation

protected unsigned int RNET::Address::_ip[4]

IP address (v4 only).

protected bool RNET::Address::_is_web

true if the address was created with a WWW URL, false otherwise.

protected unsigned short RNET::Address::_port

optional port.

string version of the full IP address (including port).

string version of the IP address only.

string version of the port only.

protected bool RNET::Address::_valid

true if the address is valid, false otherwise.