Nebula
|
#include <posixipaddress.h>
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:
(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::String & | GetHostName () const |
get host name | |
void | SetPort (ushort port) |
set port number | |
ushort | GetPort () const |
get port number | |
const Util::String & | GetHostAddr () 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 |
Posix::PosixIpAddress::PosixIpAddress | ( | ) |
default constructor
Posix::PosixIpAddress::PosixIpAddress | ( | const PosixIpAddress & | rhs | ) |
copy constructor
Posix::PosixIpAddress::PosixIpAddress | ( | const IO::URI & | uri | ) |
construct from URI
Posix::PosixIpAddress::PosixIpAddress | ( | const Util::String & | hostName, |
ushort | portNumber ) |
construct from host name and port number
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".
const String & Posix::PosixIpAddress::GetHostAddr | ( | ) | const |
get the ip address resulting from the host name as string
Return the in address as string.
|
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:
An empty host name is invalid. A hostname can also be an address string of the form xxx.yyy.zzz.www.
const String & Posix::PosixIpAddress::GetHostName | ( | ) | const |
get host name
Get the host name.
ushort Posix::PosixIpAddress::GetPort | ( | ) | const |
get port number
Get the port number in host byte order.
|
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.
|
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).
|
inline |
less-then operator
|
inline |
equality operator
|
inline |
greater-then operator
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().
void Posix::PosixIpAddress::SetPort | ( | ushort | port | ) |
set port number
Set the port number.
Will be translated to network byte order internally.
|
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.
|
friend |
|
protected |
|
protected |
|
protected |