Conexus::IPv4::Address Class Reference
[Classes for communicating via IP version 4 sockets]

#include <conexus/ipv4_address.h>

Inheritance diagram for Conexus::IPv4::Address:

Inheritance graph
[legend]
List of all members.

Detailed Description

IPv4 network 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.

Author:
Rick L Vinyard Jr <rvinyard@cs.nmsu.edu>


Public Types

typedef boost::shared_ptr<
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 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.
Addressoperator= (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 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

sockaddr_in * m_psockaddr_in
 typedef'ed pointer to IPv4 address type.
unsigned m_prefix_length
 Netmask prefix length.


Constructor & Destructor Documentation

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.

Parameters:
address Numeric address in local host byte order.
port Port number in local host byte order.


Member Function Documentation

bool Conexus::IPv4::Address::is_private  )  const
 

True if this address specifies a private network.

For reference, private networks are defined as:

  • 10.0.0.0 to 10.255.255.255 (10/8 prefix)
  • 172.16.0.0 to 172.31.255.255 (172.16/12 prefix)
  • 192.168.0.0 to 192.168.255.255 (192.168/16 prefix)

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:

  • aaa.aaa.aaa.aaa is an address in dotted decimal form
  • hostname is a host name
  • nnn.nnn.nnn.nnn is an optional subnet mask in dotted decimal form
  • bb is an optional prefix length
  • ppppp is an optional port specification
  • servicename is an optional service name specification

Implements Conexus::IPBase::AddressBase.


Member Data Documentation

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.


The documentation for this class was generated from the following files:
Generated on Sat Aug 26 17:35:24 2006 by  doxygen 1.4.6