Socket addressing, BSD style. More...

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

Inheritance diagram for senf::BSDSocketAddress:

Public Member Functions

bool operator== (BSDSocketAddress const &other) const
 Compare two arbitrary addresses. More...
 
bool operator< (BSDSocketAddress const &other) const
 Compare two arbitrary addresses. More...
 
bool boolean_test () const
 Return true, if address is not empty. More...
 
short family () const
 Return the address family. More...
 
- Public Member Functions inherited from senf::comparable_safe_bool< BSDSocketAddress >
 operator bool_type () const
 
bool operator! () const
 

Protected Member Functions

 BSDSocketAddress (socklen_t len, short family)
 
 BSDSocketAddress (BSDSocketAddress const &other)
 
BSDSocketAddressoperator= (BSDSocketAddress const &other)
 
struct sockaddr * sockaddr_p ()
 
socklen_t * socklen_p ()
 
void socklen (socklen_t len)
 
- Protected Member Functions inherited from senf::comparable_safe_bool< BSDSocketAddress >
 ~comparable_safe_bool ()
 
- Protected Member Functions inherited from senf::safe_bool_base
void this_type_does_not_support_comparisons () const
 
 safe_bool_base ()
 
 safe_bool_base (const safe_bool_base &)
 
safe_bool_baseoperator= (const safe_bool_base &)
 
 ~safe_bool_base ()
 

Related Functions

(Note that these are not member functions.)

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

Generic sockaddr interface

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

Additional Inherited Members

- Protected Types inherited from senf::safe_bool_base
typedef void(safe_bool_base::* bool_type) () const
 

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)
{
senf::sockaddr_cast<senf::INet4SocketAddress>(addr) );
...
}
}
    All these classes provide a generic \c sockaddr API to interface with legacy \c 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 67 of file BSDSocketAddress.hh.

Constructor & Destructor Documentation

◆ BSDSocketAddress() [1/2]

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

◆ BSDSocketAddress() [2/2]

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

Member Function Documentation

◆ boolean_test()

bool senf::BSDSocketAddress::boolean_test ( ) const

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

◆ family()

short senf::BSDSocketAddress::family ( ) const

Return the address family.

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

◆ operator<()

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

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.

◆ operator=()

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

◆ operator==()

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

Compare two arbitrary addresses.

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

◆ sockaddr_p() [1/2]

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

◆ sockaddr_p() [2/2]

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

◆ socklen() [1/2]

socklen_t senf::BSDSocketAddress::socklen ( ) const

◆ socklen() [2/2]

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

◆ socklen_p() [1/2]

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

◆ socklen_p() [2/2]

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

Friends And Related Function Documentation

◆ operator<<()

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

Output generic socket address.

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

◆ sockaddr_cast() [1/2]

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

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.

◆ sockaddr_cast() [2/2]

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

Safe socket address down-cast (const)

See also
sockaddr_cast()

Member Data Documentation

◆ _b

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

Definition at line 121 of file BSDSocketAddress.hh.

◆ a_

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

Definition at line 120 of file BSDSocketAddress.hh.

◆ len_

socklen_t senf::BSDSocketAddress::len_

Definition at line 119 of file BSDSocketAddress.hh.


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