The Micro C++ Library
|
An InetAddress represents a BSD socket API compliant Internet Protocol (IPv4) specific SocketAddress. More...
#include <micxx.hxx>
Inherits micxx::SocketAddress.
Inherited by micxx::MulticastAddress.
Public Member Functions | |
InetAddress (unsigned short port=0) | |
Construct an InetAddress for the constant INADDR_ANY with the specified port. | |
InetAddress (const std::string &hostname, unsigned short port=0) | |
Construct an InetAddress for the specified hostname and the specified port. | |
virtual SocketAddress * | clone () const |
Return an exact copy of this InetAddress allocated by new . | |
virtual std::string | getHost () const |
Returns the IPv4 standard dotted-decimal string representation of this InetAddress IP address. | |
virtual std::string | getHostname () const |
Uses gethostbyaddr(const char*,int,int) to lookup the hostname. | |
virtual struct in_addr & | getInetAddr () |
The internal BSD socket API compatible structure of this InetAddress. | |
virtual struct in_addr & | getInetAddr () const |
The const version of getInetAddr(). | |
virtual unsigned short | getPort () const |
The port of this InetAddress. | |
virtual void | increment (unsigned n=1) |
Increment the numeric IPv4 address representation by n. | |
virtual bool | isInAddrAny () const |
Check if this InetAddress IPv4 address represents the BSD socket API constant INADDR_ANY . | |
virtual void | setAddress (const struct sockaddr *aaddress, socklen_t asize) |
(Re)set the stored address to aaddress with size asize. | |
virtual void | setHostname (const std::string &hostname) |
Set either the IPv4 address part or the port or both from the specified hostname. | |
virtual void | setPort (unsigned short port=0) |
Set the port to the specified port. | |
virtual std::string | toString () const |
A default string representation of this InetAddress like n.n.n.n[:port] using the standard dotted format. | |
Static Public Member Functions | |
static std::string | inetNtoA (struct in_addr &addr) |
Calls the Posix inet_ntoa(addr) synchronized by System::getMutex(). | |
Static Public Attributes | |
static const InetAddress | InAddrAny |
This InetAddress represents the BSD socket API constant INADDR_ANY . |
An InetAddress represents a BSD socket API compliant Internet Protocol (IPv4) specific SocketAddress.
An InetAddress stores an IPv4 address (Layer 3) and a port number (Layer 4).
The IPv4 address could either be specified as a hostname, or as a numeric string representation like n.n.n.n known as the standard dotted format.
Internally IPv4 addresses are always stored in a numeric integral format.
A hostname argument for an InetAddress may either be specified like hostname[:port] or like n.n.n.n[:port], where [ ] are not part of the string, but are used to note that :port is an optional part.
micxx::InetAddress::InetAddress | ( | unsigned short | port = 0 | ) |
Construct an InetAddress for the constant INADDR_ANY
with the specified port.
port | The port to be used. |
micxx::InetAddress::InetAddress | ( | const std::string & | hostname, |
unsigned short | port = 0 |
||
) |
Construct an InetAddress for the specified hostname and the specified port.
hostname | a hostname or an IPv4 address in standard dotted format or a combination like host[:port] or n.n.n.n[:port] |
port | a port number between 0 and 65535 |
virtual SocketAddress* micxx::InetAddress::clone | ( | ) | const [virtual] |
Return an exact copy of this InetAddress allocated by new
.
Implements micxx::SocketAddress.
Reimplemented in micxx::MulticastAddress.
virtual std::string micxx::InetAddress::getHost | ( | ) | const [virtual] |
Returns the IPv4 standard dotted-decimal string representation of this InetAddress IP address.
virtual std::string micxx::InetAddress::getHostname | ( | ) | const [virtual] |
Uses gethostbyaddr(const char*,int,int) to lookup the hostname.
virtual struct in_addr& micxx::InetAddress::getInetAddr | ( | ) | [read, virtual] |
The internal BSD socket API compatible structure of this InetAddress.
virtual struct in_addr& micxx::InetAddress::getInetAddr | ( | ) | const [read, virtual] |
The const
version of getInetAddr().
virtual unsigned short micxx::InetAddress::getPort | ( | ) | const [virtual] |
The port of this InetAddress.
virtual void micxx::InetAddress::increment | ( | unsigned | n = 1 | ) | [virtual] |
Increment the numeric IPv4 address representation by n.
static std::string micxx::InetAddress::inetNtoA | ( | struct in_addr & | addr | ) | [static] |
Calls the Posix inet_ntoa(addr) synchronized by System::getMutex().
virtual bool micxx::InetAddress::isInAddrAny | ( | ) | const [virtual] |
Check if this InetAddress IPv4 address represents the BSD socket API constant INADDR_ANY
.
true
if getInetAddr().s_addr is equal to INADDR_ANY
,false
otherwise. virtual void micxx::InetAddress::setAddress | ( | const struct sockaddr * | aaddress, |
socklen_t | asize | ||
) | [virtual] |
(Re)set the stored address to aaddress with size asize.
In addition to SocketAddress::setAddress, this implementation also checks, if the size of aaddress is equal to size of struct sockaddr_in.
Reimplemented from micxx::SocketAddress.
virtual void micxx::InetAddress::setHostname | ( | const std::string & | hostname | ) | [virtual] |
Set either the IPv4 address part or the port or both from the specified hostname.
hostname | a hostname or an IPv4 address in standard dotted format or a combination like host[:port] or n.n.n.n[:port] |
Reimplemented in micxx::MulticastAddress.
virtual void micxx::InetAddress::setPort | ( | unsigned short | port = 0 | ) | [virtual] |
Set the port to the specified port.
virtual std::string micxx::InetAddress::toString | ( | ) | const [virtual] |
A default string representation of this InetAddress like n.n.n.n[:port] using the standard dotted format.
Reimplemented from micxx::SocketAddress.
Reimplemented in micxx::MulticastAddress.
const InetAddress micxx::InetAddress::InAddrAny [static] |
This InetAddress represents the BSD socket API constant INADDR_ANY
.