senf::INet4Address Class Reference
[Addressing classes]

IPv4 Internet address. More...

#include <senf/Socket/Protocols/INet/INet4Address.hh>

Inheritance diagram for senf::INet4Address:
Inheritance graph
[legend]

List of all members.


Detailed Description

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

// Used to construct constant INet4 addresses
INet4Address(0xD3C2B1A0)

// Construct an INet4 address from it's string representation. All the standard address
// representations are supported
INet4Address::from_string("211.194.177.160")
INet4Address::from_string("211.12759456")

// Construct an INet4 address from raw data. 'from_data' takes an arbitrary iterator (e.g. a
// pointer) as argument. Here we use a fixed array but normally you will need this to build
// an INet4 address in a packet parser
char rawBytes[] = { 0xD3, 0xC2, 0xB1, 0xA0 };
INet4Address::from_data(rawBytes)

// Construct an INet4 address from the standard POSIX representation: a 32-bit integer in
// network byte oder. This is used to interface with POSIX routines
struct sockaddr_in saddr = ...;
INet4Address::from_inaddr(saddr.sin_addr.s_addr)

Since INet4Address is based on boost::array, you can access the raw data bytes of the address (in network byte order) using begin(), end() or operator[]

INet4Address ina = ...;
Packet::iterator i = ...;
std::copy(ina.begin(), ina.end(), i); // Copies 4 bytes
See also:
CheckINet4Network
INet4Network
Implementation note:
We awkwardly need to use static named constructors (from_ members) instead of ordinarily overloaded constructors for one simple reason: char * 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 88 of file INet4Address.hh.


Public Types

typedef uint32_t  address_type
  Address representation as number in host byte order.
typedef uint32_t  inaddr_type
  Legacy address representation in network byte order.

Static Public Attributes

static INet4Address const  None
  The empty (0) address.
static INet4Address const  Loopback
  The loopback (127.0.0.1) address.
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.
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.

Accessors

bool  local () const
  true, if address is locally administered
bool  loopback () const
  true, if address is within the loopback network
bool  multicast () const
  true, if address is a multicast address
bool  broadcast () const
  true, if address is 255.255.255.255
bool  boolean_test () const
  true, if address is non-empty (!= 0.0.0.0)
inaddr_type  inaddr () const
  Return the raw network byte order address.
address_type  address () const
  Return address represented as integer number.

Structors and default members

  INet4Address ()
  Construct an empty address.
  INet4Address (senf::NoInit_t)
  Construct uninitialized (!) address.
  INet4Address (address_type value)
  Construct an address constant.
static INet4Address  from_string (std::string const &s)
  Convert string to address.
template<class InputIterator >
static INet4Address  from_data (InputIterator i)
  Construct address from 4 bytes of raw data.
static INet4Address  from_inaddr (inaddr_type v)
  Construct address from integer in network byte order.

Member Typedef Documentation

typedef uint32_t senf::INet4Address::
address_type

Address representation as number in host byte order.

Definition at line 96 of file INet4Address.hh.

typedef uint32_t senf::INet4Address::
inaddr_type

Legacy address representation in network byte order.

Definition at line 97 of file INet4Address.hh.


Constructor & Destructor Documentation

senf::INet4Address::
INet4Address ()

Construct an empty address.

Definition at line 34 of file INet4Address.cci.

senf::INet4Address::
INet4Address ( senf::NoInit_t  )

Construct uninitialized (!) address.

Definition at line 39 of file INet4Address.cci.

senf::INet4Address::
INet4Address ( address_type  value )

Construct an address constant.

Definition at line 46 of file INet4Address.cc.


Member Function Documentation

senf::INet4Address::address_type senf::INet4Address::
address ()

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 116 of file INet4Address.cc.

bool senf::INet4Address::
boolean_test ()

true, if address is non-empty (!= 0.0.0.0)

Definition at line 75 of file INet4Address.cci.

bool senf::INet4Address::
broadcast ()

true, if address is 255.255.255.255

Definition at line 69 of file INet4Address.cci.

template<class InputIterator >
senf::INet4Address senf::INet4Address::
from_data ( InputIterator  i )

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.

Definition at line 37 of file INet4Address.ct.

senf::INet4Address senf::INet4Address::
from_inaddr ( inaddr_type  v )

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.

Definition at line 42 of file INet4Address.cci.

senf::INet4Address senf::INet4Address::
from_string ( std::string const &  s )

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.

Attention:
This call may block if s represents a hostname which must be looked up via some network protocol like DNS or NIS
Exceptions:
AddressSyntaxException  if the address cannot be converted for some reason
UnknownHostnameException  if the hostname cannot be resolved
Parameters:
[in]  s  Address literal or hostname

Definition at line 51 of file INet4Address.cc.

senf::INet4Address::inaddr_type senf::INet4Address::
inaddr ()

Return the raw network byte order address.

This member is used to interact with legacy code.

Returns:

Definition at line 58 of file INet4Address.cci.

bool senf::INet4Address::
local ()

true, if address is locally administered

This call checks, if the address is within one of the IANA private ranges.

Definition at line 93 of file INet4Address.cc.

bool senf::INet4Address::
loopback ()

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 104 of file INet4Address.cc.

bool senf::INet4Address::
multicast ()

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 110 of file INet4Address.cc.


Friends And Related Function Documentation

std::ostream &
operator<< ( std::ostream &  os,
INet4Address const &  addr )

Output INet4Address instance as it's string representation.

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.

See also:
INet4Address from_string()

Member Data Documentation

Definition at line 101 of file INet4Address.hh.

The loopback (127.0.0.1) address.

Definition at line 100 of file INet4Address.hh.

The empty (0) address.

Definition at line 99 of file INet4Address.hh.


The documentation for this class was generated from the following files: