senf::BSDSocketAddress Class Reference
[Addressing classes]

Socket addressing, BSD style. More...

#include <senf/Socket/Protocols/BSDSocketAddress.hh>

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

List of all members.


Detailed Description

Socket addressing, BSD style.

BSDSocketAddress is the base class of all BSD sockaddr based addressing classes. The sockaddr addressing interface is split into several parts

It is not possible to create or store BSDSocketAddress instances: You must either store an address in one of the specifically typed subclasses or using GenericBSDSocketAddress.

A BSDSocketAddress or GenericBSDSocketAddress can be cast (like a downcast) to (the correct) type specific cast using sockaddr_cast:

void foo(senf::BSDSOcketAddress const & addr)
{
    if (addr.family() == senf::INet4SocketAddress::addressFamily) {
        senf::INet4SocketAddress i4addr (
            senf::sockaddr_cast<senf::INet4SocketAddress>(addr) );
        ...
    }
}

All these classes provide a generic sockaddr API to interface with legacy sockaddr based code (e.g. the BSD socket API). In this base-class, this interface is read-only, the derived classes however provide a read-write interface.

Definition at line 76 of file BSDSocketAddress.hh.


Public Member Functions

bool  operator== (BSDSocketAddress const &other) const
  Compare two arbitrary addresses.
bool  operator< (BSDSocketAddress const &other) const
  Compare two arbitrary addresses.
bool  boolean_test () const
  Return true, if address is not empty.
short  family () const
  Return the address family.

Related Functions

(Note that these are not member functions.)

template<class Target >
Target sockaddr_cast (BSDSocketAddress &source)
  Safe socket address down-cast.
template<class Target >
Target const &  sockaddr_cast (BSDSocketAddress const &source)
  Safe socket address down-cast (const).
std::ostream &  operator<< (std::ostream &os, BSDSocketAddress const &addr)
  Output generic socket address.

Generic sockaddr interface

struct sockaddr const *  sockaddr_p () const
socklen_t  socklen () const
socklen_t const *  socklen_p () const

Protected Member Functions

  BSDSocketAddress (socklen_t len, short family)
  BSDSocketAddress (BSDSocketAddress const &other)
BSDSocketAddress operator= (BSDSocketAddress const &other)
struct sockaddr *  sockaddr_p ()
socklen_t *  socklen_p ()
void  socklen (socklen_t len)

Constructor & Destructor Documentation

senf::BSDSocketAddress::
BSDSocketAddress ( socklen_t  len,
short  family )

Definition at line 94 of file BSDSocketAddress.cci.

senf::BSDSocketAddress::
BSDSocketAddress ( BSDSocketAddress const &  other )

Definition at line 113 of file BSDSocketAddress.cci.


Member Function Documentation

bool senf::BSDSocketAddress::
boolean_test ()

Return true, if address is not empty.

An address is considered empty if

  • the family is AF_UNSPEC
  • or the size is 0
  • or all data bytes are 0

Definition at line 82 of file BSDSocketAddress.cci.

short senf::BSDSocketAddress::
family ()

Return the address family.

This value is found in the addressFamily member of each typed derived class (e.g. INet4Address::addressFamily)

Definition at line 45 of file BSDSocketAddress.cci.

bool senf::BSDSocketAddress::
operator< ( BSDSocketAddress const &  other )

Compare two arbitrary addresses.

Ordering is based on the in-memory representation. It is primarily useful to use addresses as keys in a map or set.

Definition at line 74 of file BSDSocketAddress.cci.

senf::BSDSocketAddress & senf::BSDSocketAddress::
operator= ( BSDSocketAddress const &  other )

Reimplemented in senf::GenericBSDSocketAddress.

Definition at line 120 of file BSDSocketAddress.cci.

bool senf::BSDSocketAddress::
operator== ( BSDSocketAddress const &  other )

Compare two arbitrary addresses.

For addresses to be considered equal, they must have the same family, length and the data must be identical.

Definition at line 68 of file BSDSocketAddress.cci.

struct sockaddr * senf::BSDSocketAddress::
sockaddr_p ()

Reimplemented in senf::GenericBSDSocketAddress.

Definition at line 128 of file BSDSocketAddress.cci.

struct sockaddr const * senf::BSDSocketAddress::
sockaddr_p ()

Reimplemented in senf::GenericBSDSocketAddress.

Definition at line 39 of file BSDSocketAddress.cci.

void senf::BSDSocketAddress::
socklen ( socklen_t  len )

Definition at line 63 of file BSDSocketAddress.cci.

socklen_t senf::BSDSocketAddress::
socklen ()

Definition at line 51 of file BSDSocketAddress.cci.

socklen_t * senf::BSDSocketAddress::
socklen_p ()

Definition at line 133 of file BSDSocketAddress.cci.

socklen_t const * senf::BSDSocketAddress::
socklen_p ()

Definition at line 57 of file BSDSocketAddress.cci.


Friends And Related Function Documentation

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

Output generic socket address.

This stream operator will output a generic BSDSocketAddress in a family depending format.

template<class Target >
Target const &
sockaddr_cast ( BSDSocketAddress const &  source )

Safe socket address down-cast (const).

See also:
sockaddr_cast()

template<class Target >
Target &
sockaddr_cast ( BSDSocketAddress source )

Safe socket address down-cast.

sockaddr_cast allows to safely cast a socket address to it's derived type. Only the family specific derived addressing classes are permissible for Target.

This cast is especially useful to cast a GenericBSDSocketAddress to it's concrete type.


Member Data Documentation

char senf::BSDSocketAddress::_b[boost::alignment_of< struct sockaddr_storage >::
value]

Definition at line 130 of file BSDSocketAddress.hh.

boost::type_with_alignment<boost::alignment_of<struct sockaddr_storage>::value> senf::BSDSocketAddress::
a_

Definition at line 129 of file BSDSocketAddress.hh.

socklen_t senf::BSDSocketAddress::
len_

Definition at line 128 of file BSDSocketAddress.hh.


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