Address

Functions

Address

Address

Address

~Address

void

Reset

bool

IsValid

unsigned int

IPv4

unsigned short

Port

bool

IsWeb

const String &

ToString

void

ToString

bool

operator==

bool

operator

bool

operator!=

Address

LocalHost

Address

Host

Address

Broadcast

Detailed Description

class Address : public RED::Object

This class defines a network address.

@related class RNET::System

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!

Note

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

Public Functions

Address()

Default constructor.

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

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

iString – the address as a string.

Address(unsigned int iIPv4, unsigned short iPort = 0)

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

Parameters
  • iIPv4 – IP v4 address in network byte order.

  • iPort – optional port in network byte order.

~Address()

Destructor.

void Reset()

Resets the address content and set it back to invalid.

inline bool IsValid() const
Returns

true if a valid IP address has been set,false otherwise.

inline unsigned int IPv4() const
Returns

the address in IP v4 format in network byte order.

inline unsigned short Port() const
Returns

the optional port of the address in network byte order.

inline bool IsWeb() const
Returns

true if the address starts with “www.”, false otherwise.

inline const RED::String &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.

inline void ToString(RED::String &oAddress, RED::String &oPort) const

Returns both address and port strings from the address.

Parameters
  • oAddress – reference to the returned IP string.

  • oPort – reference to the returned port string.

inline bool operator==(const Address &other) const

Equality comparison operator.

inline bool operator<(const Address &other) const

Less than comparison operator.

inline bool operator!=(const Address &other) const

Inequality comparison operator.

Public Static Functions

static RNET::Address LocalHost(unsigned short iPort)

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

Parameters

iPort – the port to use in hardware byte order (not in network byte order!).

Returns

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

static RNET::Address Host(unsigned short iPort)

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

Parameters

iPort – the port to use in hardware byte order (not in network byte order!).

Returns

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

static RNET::Address Broadcast(unsigned int iPort)

Returns the broadcast address including the given port.

Parameters

iPort – the port to use in hardware byte order (not in network byte order!).

Returns

the broadcast address including the given port.