Nebula
Loading...
Searching...
No Matches
Posix::PosixIpAddress Class Reference

#include <posixipaddress.h>

Detailed Description

Represents an IP address, consisting of a IPv4 host address and a port number.

Performs automatic name lookup on the host name. Can extract address information from an URI and
automatically converts host names to addresses, and offers the special hostnames "localhost", "any", "broadcast", "self" and "inetself" where:

  • "localhost" will translate to 127.0.0.1
  • "any" will translate to INADDR_ANY, which is 0.0.0.0
  • "broadcast" will translate to INADDR_BROADCAST, which is 255.255.255.255
  • "self" will translate to the first valid tcp/ip address for this host (there may be more then one address bound to the host)
  • "inetself" will translate to the first host address which is not a LAN address (which is not a class A, B, or C network) if none such exists the address will fall back to "self"

(C) 2006 Radon Labs GmbH (C) 2013-2018 Individual contributors, see AUTHORS file

Public Member Functions

 PosixIpAddress ()
 default constructor
 
 PosixIpAddress (const PosixIpAddress &rhs)
 copy constructor
 
 PosixIpAddress (const IO::URI &uri)
 construct from URI
 
 PosixIpAddress (const Util::String &hostName, ushort portNumber)
 construct from host name and port number
 
bool operator== (const PosixIpAddress &rhs) const
 equality operator
 
bool operator< (const PosixIpAddress &rhs) const
 less-then operator
 
bool operator> (const PosixIpAddress &rhs) const
 greater-then operator
 
void ExtractFromUri (const IO::URI &uri)
 extract host name and port number from URI
 
void SetHostName (const Util::String &hostName)
 set host name
 
const Util::StringGetHostName () const
 get host name
 
void SetPort (ushort port)
 set port number
 
ushort GetPort () const
 get port number
 
const Util::StringGetHostAddr () const
 get the ip address resulting from the host name as string
 

Protected Member Functions

void SetSockAddr (const sockaddr &addr)
 set sockaddr_in directly
 
const sockaddr & GetSockAddr () const
 get sockaddr_in field
 

Static Protected Member Functions

static bool GetHostByName (const Util::String &hostName, sockaddr &outAddr)
 perform address resolution, understands special host names
 
static bool IsInetAddr (const in_addr *addr)
 return true if an address is an internet address (not class A,B,C)
 

Protected Attributes

Util::String hostName
 
Util::String addrAsString
 
sockaddr addr
 

Friends

class PosixSocket
 

Constructor & Destructor Documentation

◆ PosixIpAddress() [1/4]

Posix::PosixIpAddress::PosixIpAddress ( )

default constructor

◆ PosixIpAddress() [2/4]

Posix::PosixIpAddress::PosixIpAddress ( const PosixIpAddress & rhs)

copy constructor

◆ PosixIpAddress() [3/4]

Posix::PosixIpAddress::PosixIpAddress ( const IO::URI & uri)

construct from URI

◆ PosixIpAddress() [4/4]

Posix::PosixIpAddress::PosixIpAddress ( const Util::String & hostName,
ushort portNumber )

construct from host name and port number

Member Function Documentation

◆ ExtractFromUri()

void Posix::PosixIpAddress::ExtractFromUri ( const IO::URI & uri)

extract host name and port number from URI

Extract the host name and optionally the port number from the provided URI.

If no port number is set in the URI, the current port number will be left as is. If the host name is empty, it will be set to "localhost".

◆ GetHostAddr()

const String & Posix::PosixIpAddress::GetHostAddr ( ) const

get the ip address resulting from the host name as string

Return the in address as string.

◆ GetHostByName()

bool Posix::PosixIpAddress::GetHostByName ( const Util::String & hostName,
sockaddr & outAddr )
staticprotected

perform address resolution, understands special host names

This resolves a host name into a IPv4 ip address.

The ip address is returned in network byte order in the hostAddress argument. The return value indicates whether the operation was successful. The following special hostnames can be defined:

  • "any" resolves to INADDR_ANY (0.0.0.0)
  • "broadcast" resolves to INADDR_BROADCAST (255.255.255.255)
  • "localhost" resolves to 127.0.0.1
  • "self" resolves to the first address of this host
  • "inetself" resolves to the first address which is not a LAN address

An empty host name is invalid. A hostname can also be an address string of the form xxx.yyy.zzz.www.

◆ GetHostName()

const String & Posix::PosixIpAddress::GetHostName ( ) const

get host name

Get the host name.

◆ GetPort()

ushort Posix::PosixIpAddress::GetPort ( ) const

get port number

Get the port number in host byte order.

◆ GetSockAddr()

const sockaddr & Posix::PosixIpAddress::GetSockAddr ( ) const
protected

get sockaddr_in field

Get the sockaddr_in struct, which has either been set directly with SetSockAddr() or indirectly through host name, port number or from an URI.

◆ IsInetAddr()

bool Posix::PosixIpAddress::IsInetAddr ( const in_addr * addr)
staticprotected

return true if an address is an internet address (not class A,B,C)

This method checks if the provided address is an "internet" address, not a LAN address (not a class A, B or C network address).

◆ operator<()

bool Posix::PosixIpAddress::operator< ( const PosixIpAddress & rhs) const
inline

less-then operator

◆ operator==()

bool Posix::PosixIpAddress::operator== ( const PosixIpAddress & rhs) const
inline

equality operator

◆ operator>()

bool Posix::PosixIpAddress::operator> ( const PosixIpAddress & rhs) const
inline

greater-then operator

◆ SetHostName()

void Posix::PosixIpAddress::SetHostName ( const Util::String & hostName)

set host name

Set the host name, and immediately convert it to an ip address.

This accepts the special hostnames "any", "broadcast", "localhost", "self" and "inetself". The result ip address can be returned in string form with the method GetAddrAsString().

◆ SetPort()

void Posix::PosixIpAddress::SetPort ( ushort port)

set port number

Set the port number.

Will be translated to network byte order internally.

◆ SetSockAddr()

void Posix::PosixIpAddress::SetSockAddr ( const sockaddr & sa)
protected

set sockaddr_in directly

Set the address directly from a sockaddr_in struct.

This will set the host name to the string representation of the host address.

Friends And Related Symbol Documentation

◆ PosixSocket

friend class PosixSocket
friend

Member Data Documentation

◆ addr

sockaddr Posix::PosixIpAddress::addr
protected

◆ addrAsString

Util::String Posix::PosixIpAddress::addrAsString
protected

◆ hostName

Util::String Posix::PosixIpAddress::hostName
protected

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