#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 ConexusPointer< Address > | pointer |
Class scope smart pointer typedef. | |
typedef ConexusPointer< Address > | pointer |
Class scope smart pointer typedef. | |
typedef ConexusPointer< Address > | pointer |
Class scope smart pointer typedef. | |
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 std::string &host, uint16_t port=0) | |
Address (const struct sockaddr_in &addr) | |
Constructs from an IPv4 sockaddr. | |
Address (const struct sockaddr_storage &addr) | |
Constructs from a generic sockaddr_storage. | |
Address (const struct sockaddr &addr) | |
Constructs from a generic sockaddr. | |
Address (const IPv6::Address &addr) | |
Constructs from an IPv6 address if the IPv6 address is IPv4 compatible. | |
virtual | ~Address () |
Destructor. | |
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 (const std::string &address) |
Sets the address to the specified value. | |
virtual void | set_address (const 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 (const 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 (const 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 (const 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. | |
operator struct sockaddr_in * () | |
Address & | operator= (const Address &other) |
Address & | operator= (const Conexus::Address &other) |
bool | operator== (const Address &other) const |
True if the port and address are the same. | |
virtual sigc::signal< void > | signal_changed () |
virtual sigc::signal< void > | signal_address_changed () |
virtual sigc::signal< void > | signal_port_changed () |
virtual sigc::signal< void > | signal_prefix_changed () |
virtual bool | is_ipv4 () |
Always true for IPv4::Address. | |
virtual bool | is_ipv6 () |
Never true. | |
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) | |
Constructs from an IPv4 sockaddr. | |
Address (const struct sockaddr_storage &addr) | |
Constructs from a generic sockaddr_storage. | |
Address (const struct sockaddr &addr) | |
Constructs from a generic sockaddr. | |
Address (const IPv6::Address &addr) | |
Constructs from an IPv6 address if the IPv6 address is IPv4 compatible. | |
virtual | ~Address () |
Destructor. | |
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. | |
operator struct sockaddr_in * () | |
Address & | operator= (const Address &other) |
bool | operator== (const Address &other) const |
True if the port and address are the same. | |
virtual const std::string & | object_type () |
String identifier of this class. | |
virtual bool | is_ipv4 () |
Always true for IPv4::Address. | |
virtual bool | is_ipv6 () |
Never true. | |
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) | |
Constructs from an IPv4 sockaddr. | |
Address (const struct sockaddr_storage &addr) | |
Constructs from a generic sockaddr_storage. | |
Address (const struct sockaddr &addr) | |
Constructs from a generic sockaddr. | |
Address (const IPv6::Address &addr) | |
Constructs from an IPv6 address if the IPv6 address is IPv4 compatible. | |
virtual | ~Address () |
Destructor. | |
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. | |
operator struct sockaddr_in * () | |
Address & | operator= (const Address &other) |
bool | operator== (const Address &other) const |
True if the port and address are the same. | |
virtual const std::string & | object_type () |
String identifier of this class. | |
virtual bool | is_ipv4 () |
Always true for IPv4::Address. | |
virtual bool | is_ipv6 () |
Never true. | |
Static Public Member Functions | |
static pointer | create (uint32_t address=INADDR_ANY, uint16_t port=0) |
Creates a smart pointer from an address and port number. | |
static pointer | create (const std::string &host, uint16_t port) |
static pointer | create (const struct sockaddr_in &addr) |
Creates a smart pointer from an IPv4 sockaddr_in. | |
static pointer | create (const struct sockaddr_storage &addr) |
Creates a smart pointer from a generic sockaddr_storage. | |
static pointer | create (const struct sockaddr &addr) |
Creates a smart pointer from a generic sockaddr. | |
static pointer | create (const IPv6::Address &ipv6addr) |
Creates a smart pointer from an IPv6 address if the IPv6 address is IPv4 compatible. | |
static Address::pointer | create (uint32_t address=INADDR_ANY, uint16_t port=0) |
Creates a smart pointer from an address and port number. | |
static Address::pointer | create (const struct sockaddr_in &addr) |
Creates a smart pointer from an IPv4 sockaddr_in. | |
static Address::pointer | create (const struct sockaddr_storage &addr) |
Creates a smart pointer from a generic sockaddr_storage. | |
static Address::pointer | create (const struct sockaddr &addr) |
Creates a smart pointer from a generic sockaddr. | |
static Address::pointer | create (const IPv6::Address &ipv6addr) |
Creates a smart pointer from an IPv6 address if the IPv6 address is IPv4 compatible. | |
static Address::pointer | create (uint32_t address=INADDR_ANY, uint16_t port=0) |
Creates a smart pointer from an address and port number. | |
static Address::pointer | create (const struct sockaddr_in &addr) |
Creates a smart pointer from an IPv4 sockaddr_in. | |
static Address::pointer | create (const struct sockaddr_storage &addr) |
Creates a smart pointer from a generic sockaddr_storage. | |
static Address::pointer | create (const struct sockaddr &addr) |
Creates a smart pointer from a generic sockaddr. | |
static Address::pointer | create (const IPv6::Address &ipv6addr) |
Creates a smart pointer from an IPv6 address if the IPv6 address is IPv4 compatible. | |
Protected Attributes | |
uint32_t | m_address |
uint16_t | m_port |
unsigned | m_prefix_length |
Netmask prefix length. | |
sigc::signal< void > | m_signal_address_changed |
sigc::signal< void > | m_signal_port_changed |
sigc::signal< void > | m_signal_prefix_changed |
sigc::signal< void > | m_signal_changed |
sockaddr_in * | m_psockaddr_in |
typedef'ed pointer to IPv4 address type. | |
sockaddr_in * | m_psockaddr_in |
typedef'ed pointer to IPv4 address type. |
Conexus::IPv4::Address::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.
Sets default family to AF_INET.
address | Numeric address in local host byte order. | |
port | Port number in local host byte order. |
Conexus::IPv4::Address::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.
Sets default family to AF_INET.
address | Numeric address in local host byte order. | |
port | Port number in local host byte order. |
Conexus::IPv4::Address::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.
Sets default family to AF_INET.
address | Numeric address in local host byte order. | |
port | Port number in local host byte order. |
void Conexus::IPv4::Address::set_address | ( | const std::string & | address | ) | [virtual] |
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::IPAddress.
bool Conexus::IPv4::Address::is_private | ( | ) | const |
True if this address specifies a private network.
For reference, private networks are defined as:
void Conexus::IPv4::Address::set_address | ( | std::string | address | ) | [virtual] |
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::IPAddress.
bool Conexus::IPv4::Address::is_private | ( | ) | const |
True if this address specifies a private network.
For reference, private networks are defined as:
void Conexus::IPv4::Address::set_address | ( | std::string | address | ) | [virtual] |
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::IPAddress.
bool Conexus::IPv4::Address::is_private | ( | ) | const |
True if this address specifies a private network.
For reference, private networks are defined as:
struct sockaddr_in* Conexus::IPv4::Address::m_psockaddr_in [protected] |
typedef'ed pointer to IPv4 address type.
Actually points to underlying storage of type sockaddr_storage.
struct sockaddr_in* Conexus::IPv4::Address::m_psockaddr_in [protected] |
typedef'ed pointer to IPv4 address type.
Actually points to underlying storage of type sockaddr_storage.