#include <conexus/ipv4_address.h>
Inheritance diagram for Conexus::IPv4::Address:
This class represents an IPv4 address and includes support for accessing the address as a traditional sockaddr_in (a BSD socket API IPv4 network address C structure).
Host byte order and network byte order: all methods expect parameters and return values in host byte order with the following exception; if you request a sockaddr_in representation of this address, the sockaddr_in C structure will be filled with values that are already in network byte order and ready for use with raw BSD API socket calls.
Public Types | |
typedef boost::shared_ptr< Address > | pointer |
Public Member Functions | |
Address (uint32_t address=INADDR_ANY, uint16_t port=0) | |
Default constructor, or if parameters are used constructs an address from a numeric address and an optional port number. | |
Address (const struct sockaddr_in &addr) | |
Address (const struct sockaddr_storage &addr) | |
Address (const struct sockaddr &addr) | |
Address (const IPv6::Address &addr) | |
uint32_t | address () const |
Returns the IPv4 address. | |
std::string | address_string () const |
Returns the IPv4 address as a string. | |
uint32_t | subnet_mask () const |
Returns the subnet mask associated with this address. | |
std::string | subnet_mask_string () const |
Returns the netmask associated with this address as a string. | |
unsigned | prefix_length () const |
Returns the prefix length of the subnet mask associated with this address. | |
std::string | prefix_length_string () const |
Returns the prefix length of the subnet mask associated with this address as a string. | |
std::string | address_subnet_mask_string () const |
Returns the IPv4 address as an address/subnetmask string. | |
std::string | cidr_address_string () const |
Returns the IPv4 address as a CIDR address/prefixlen string. | |
uint32_t | prefix () const |
Returns the prefix part of this address. | |
std::string | prefix_string () const |
Returns the prefix part of this address as a string. | |
uint32_t | broadcast_address () const |
Returns the broadcast address for this address. | |
std::string | broadcast_address_string () const |
Returns the broadcast address for this address as a string. | |
uint32_t | local_address () const |
Returns the local part of this address. | |
std::string | local_address_string () const |
Returns the local part of this address as a string. | |
uint16_t | port () const |
Returns the port number associated with this address. | |
std::string | port_string () const |
Returns the port number associated with this address as a string. | |
void | set_address (uint32_t address) |
Set the address to the specified value. | |
void | set_address (std::string address) |
Sets the address to the specified value. | |
virtual void | set_address (std::string address, uint16_t port) |
Sets the address and port to the specified value. | |
void | set_address_subnet_mask (uint32_t address, uint32_t subnet_mask) |
Sets the address to an absolute value with a specified subnet mask. | |
void | set_address_prefix_length (uint32_t address, unsigned prefix_length) |
Sets the address to an absolute value with a specified CIDR prefix length. | |
void | set_subnet_mask (uint32_t subnet_mask) |
Sets the subnet mask to the specified value. | |
void | set_subnet_mask (std::string subnet_mask) |
Sets the subnet mask to the specified value. | |
void | set_prefix_length (unsigned prefix_length) |
Sets the prefix length to the specified value. | |
void | set_prefix_length (std::string prefix_length) |
Sets the prefix length to the specified value. | |
void | set_port (uint16_t port) |
Sets the port portion of this address. | |
void | set_port (std::string port) |
Sets the port to the specified value. | |
bool | is_valid_hostname (const std::string) const |
Determine whether the provided string is a valid hostname by performing a DNS query. | |
std::string | hostname () const |
Performs a DNS query on the currently set address and returns the hostname string. | |
std::string | servicename () const |
Performs a service name lookup on the currently set port and returns the servicename string. | |
bool | is_private () const |
True if this address specifies a private network. | |
bool | is_reserved () const |
True if this address is a reserved address specified as either 0.0.0.0/16 or class E (11110). | |
bool | is_loopback () const |
True of this address is the loopback address with prefix 127.0.0.1/24. | |
bool | is_broadcast () const |
True if this is a valid broadcast address. | |
bool | is_multicast () const |
True if this is a valid multicast address. | |
bool | is_any () const |
True if this is the any address. | |
socklen_t | sockaddr_size () const |
Overrides the virtual parent method and provides the size in bytes of the underlying sockaddr_in structure. | |
sockaddr_in & | sockaddr_in () |
Provides a non-constant reference to the underlying sockaddr_in structure. | |
sockaddr_in * | sockaddr_in_ptr () |
Provides a non-constant pointer to the underlying sockaddr_in structure. | |
Address & | operator= (const Address &other) |
virtual const std::string & | object_type () |
virtual bool | is_ipv4 () |
virtual bool | is_ipv6 () |
Static Public Member Functions | |
static Address::pointer | create (uint32_t address=INADDR_ANY, uint16_t port=0) |
static Address::pointer | create (const struct sockaddr_in &addr) |
static Address::pointer | create (const struct sockaddr_storage &addr) |
static Address::pointer | create (const struct sockaddr &addr) |
static Address::pointer | create (const IPv6::Address &ipv6addr) |
Protected Attributes | |
sockaddr_in * | m_psockaddr_in |
unsigned | m_prefix_length |
|
Default constructor, or if parameters are used constructs an address from a numeric address and an optional port number. Sets default family to AF_INET.
|
|
True if this address specifies a private network. For reference, private networks are defined as:
|
|
Sets the address to the specified value. If this is not a numeric specification, a DNS query will be performed. Accepts addresses of the following forms: # aaa.aaa.aaa.aaa[/nnn.nnn.nnn.nnn | /bb][:ppppp | :servicename] # hostname[/nnn.nnn.nnn.nnn | /bb][:ppppp | :servicename] Where:
Implements Conexus::IPBase::AddressBase. |