IPv4 Internet address. More...
#include <senf/Socket/Protocols/INet/INet4Address.hh>
Public Types | |
typedef uint32_t | address_type |
Address representation as number in host byte order. More... | |
typedef uint32_t | inaddr_type |
Legacy address representation in network byte order. More... | |
Static Public Attributes | |
static INet4Address const | None |
The empty (0) address. More... | |
static INet4Address const | Loopback |
The loopback (127.0.0.1) address. More... | |
static INet4Address const | Broadcast |
Related Functions | |
(Note that these are not member functions.) | |
std::ostream & | operator<< (std::ostream &os, INet4Address const &addr) |
Output INet4Address instance as it's string representation. More... | |
std::istream & | operator>> (std::istream &os, INet4Address &addr) |
Initialize INet4Address instance from a string representation sets std::ios::failbit on the stream if an error occurred. More... | |
Structors and default members | |
INet4Address () | |
Construct an empty address. More... | |
INet4Address (senf::NoInit_t) | |
Construct uninitialized (!) address. More... | |
INet4Address (address_type value) | |
Construct an address constant. More... | |
static INet4Address | from_string (std::string const &s) |
Convert string to address. More... | |
template<class InputIterator > | |
static INet4Address | from_data (InputIterator i) |
Construct address from 4 bytes of raw data. More... | |
static INet4Address | from_inaddr (inaddr_type v) |
Construct address from integer in network byte order. More... | |
Accessors | |
bool | local () const |
true , if address is locally administered More... | |
bool | loopback () const |
true , if address is within the loopback network More... | |
bool | multicast () const |
true , if address is a multicast address More... | |
bool | broadcast () const |
true , if address is 255.255.255.255 More... | |
bool | boolean_test () const |
true , if address is non-empty (!= 0.0.0.0) More... | |
inaddr_type | inaddr () const |
Return the raw network byte order address. More... | |
address_type | address () const |
Return address represented as integer number. More... | |
Additional Inherited Members | |
Public Member Functions inherited from senf::comparable_safe_bool< INet4Address > | |
operator bool_type () const | |
bool | operator! () const |
Protected Types inherited from senf::safe_bool_base | |
typedef void(safe_bool_base::* | bool_type) () const |
Protected Member Functions inherited from senf::comparable_safe_bool< INet4Address > | |
~comparable_safe_bool () | |
Protected Member Functions inherited from senf::safe_bool_base | |
void | this_type_does_not_support_comparisons () const |
safe_bool_base () | |
safe_bool_base (const safe_bool_base &) | |
safe_bool_base & | operator= (const safe_bool_base &) |
~safe_bool_base () | |
IPv4 Internet address.
INet4Address represents a simple IP address. It is modelled as a fixed-size container/sequence of 4 bytes.
The following statements all create the same INet4 address 211.194.177.160
Since INet4Address is based on \c boost::array, you can access the raw data bytes of the address (in network byte order) using \c begin(), \c end() or \c operator[]
\see CheckINet4Network \n INet4Network \par "Implementation note:" We awkwardly need to use static named constructors (<tt>from_</tt> members) instead of ordinarily overloaded constructors for one simple reason: <tt>char *</tt> doubles as string literal and as arbitrary data iterator. The iterator constructor can therefore not be distinguished from initialization with a string literal. Therefore we need to disambiguate using the named constructors.
Definition at line 78 of file INet4Address.hh.
typedef uint32_t senf::INet4Address::address_type |
Address representation as number in host byte order.
Definition at line 86 of file INet4Address.hh.
typedef uint32_t senf::INet4Address::inaddr_type |
Legacy address representation in network byte order.
Definition at line 87 of file INet4Address.hh.
senf::INet4Address::INet4Address | ( | ) |
Construct an empty address.
|
explicit |
Construct uninitialized (!) address.
|
explicit |
Construct an address constant.
Definition at line 36 of file INet4Address.cc.
senf::INet4Address::address_type senf::INet4Address::address | ( | ) | const |
Return address represented as integer number.
This member returns the address as an integer number in host byte order. This representation allows simple network math operations.
Definition at line 103 of file INet4Address.cc.
bool senf::INet4Address::boolean_test | ( | ) | const |
true
, if address is non-empty (!= 0.0.0.0)
bool senf::INet4Address::broadcast | ( | ) | const |
true
, if address is 255.255.255.255
|
static |
Construct address from 4 bytes of raw data.
from_data will build an address from 4 bytes of raw data as accessed by the iterator. The data must be in network byte order.
|
static |
Construct address from integer in network byte order.
This call is used when interfacing with other legacy code to convert a network byte order address in an integer number into an INet4Address.
|
static |
Convert string to address.
This member will try to convert the given string into an IP address. from_string() supports all standard IP literal representations as well as hostnames.
AddressSyntaxException | if the address cannot be converted for some reason |
UnknownHostnameException | if the hostname cannot be resolved |
[in] | s | Address literal or hostname |
Definition at line 41 of file INet4Address.cc.
inaddr_type senf::INet4Address::inaddr | ( | ) | const |
Return the raw network byte order address.
This member is used to interact with legacy code.
bool senf::INet4Address::local | ( | ) | const |
true
, if address is locally administered
This call checks, if the address is within one of the IANA private ranges.
Definition at line 80 of file INet4Address.cc.
bool senf::INet4Address::loopback | ( | ) | const |
true
, if address is within the loopback network
Checks, whether the address is in the IANA loopback network 10.0.0.0/8
Definition at line 91 of file INet4Address.cc.
bool senf::INet4Address::multicast | ( | ) | const |
true
, if address is a multicast address
Checks, whether the address is in the 224.0.0.0/4 network reserved for multicast addresses by the IANA.
Definition at line 97 of file INet4Address.cc.
|
related |
Output INet4Address instance as it's string representation.
|
related |
Initialize INet4Address instance from a string representation sets std::ios::failbit on the stream if an error occurred.
|
static |
Definition at line 91 of file INet4Address.hh.
|
static |
The loopback (127.0.0.1) address.
Definition at line 90 of file INet4Address.hh.
|
static |
The empty (0) address.
Definition at line 89 of file INet4Address.hh.