sockpp
Modern C++ socket library wrapper
Public Member Functions | Static Public Attributes | List of all members
sockpp::unix_address Class Reference

Class that represents a UNIX domain address. More...

#include <unix_address.h>

Inheritance diagram for sockpp::unix_address:
sockpp::sock_address

Public Member Functions

 unix_address ()
 Constructs an empty address. More...
 
 unix_address (const std::string &path)
 Constructs an address for the specified path. More...
 
 unix_address (const sockaddr &addr)
 Constructs the address by copying the specified structure. More...
 
 unix_address (const sock_address &addr)
 Constructs the address by copying the specified structure. More...
 
 unix_address (const sockaddr_un &addr)
 Constructs the address by copying the specified structure. More...
 
 unix_address (const unix_address &addr)
 Constructs the address by copying the specified address. More...
 
bool is_set () const
 Checks if the address is set to some value. More...
 
std::string path () const
 Gets the path to which this address refers. More...
 
socklen_t size () const override
 Gets the size of the address structure. More...
 
const sockaddr * sockaddr_ptr () const override
 Gets a pointer to this object cast to a const sockaddr. More...
 
sockaddr * sockaddr_ptr () override
 Gets a pointer to this object cast to a sockaddr. More...
 
const sockaddr_un * sockaddr_un_ptr () const
 Gets a const pointer to this object cast to a sockaddr_un. More...
 
sockaddr_un * sockaddr_un_ptr ()
 Gets a pointer to this object cast to a sockaddr_un. More...
 
std::string to_string () const
 Gets a printable string for the address. More...
 
- Public Member Functions inherited from sockpp::sock_address
virtual ~sock_address ()
 Virtual destructor.
 
virtual sa_family_t family () const
 Gets the network family of the address. More...
 

Static Public Attributes

static constexpr sa_family_t ADDRESS_FAMILY = AF_UNIX
 The address family for this type of address.
 
static constexpr size_t MAX_PATH_NAME = 108
 

Detailed Description

Class that represents a UNIX domain address.

This inherits from the UNIX form of a socket address, sockaddr_un.

Constructor & Destructor Documentation

◆ unix_address() [1/6]

sockpp::unix_address::unix_address ( )
inline

Constructs an empty address.

The address is initialized to all zeroes.

◆ unix_address() [2/6]

sockpp::unix_address::unix_address ( const std::string &  path)

Constructs an address for the specified path.

Parameters
pathThe

◆ unix_address() [3/6]

sockpp::unix_address::unix_address ( const sockaddr &  addr)
explicit

Constructs the address by copying the specified structure.

Parameters
addrThe generic address
Exceptions
std::invalid_argumentif the address is not a UNIX-domain address (i.e. family is not AF_UNIX)

◆ unix_address() [4/6]

sockpp::unix_address::unix_address ( const sock_address addr)
inline

Constructs the address by copying the specified structure.

Parameters
addrThe other address

◆ unix_address() [5/6]

sockpp::unix_address::unix_address ( const sockaddr_un &  addr)
inline

Constructs the address by copying the specified structure.

Parameters
addrThe other address
Exceptions
std::invalid_argumentif the address is not properly initialized as a UNIX-domain address (i.e. family is not AF_UNIX)

◆ unix_address() [6/6]

sockpp::unix_address::unix_address ( const unix_address addr)
inline

Constructs the address by copying the specified address.

Parameters
addrThe other address

Member Function Documentation

◆ is_set()

bool sockpp::unix_address::is_set ( ) const
inline

Checks if the address is set to some value.

This doesn't attempt to determine if the address is valid, simply that it's not all zero.

Returns
true if the address has been set, false otherwise.

◆ path()

std::string sockpp::unix_address::path ( ) const
inline

Gets the path to which this address refers.

Returns
The path to which this address refers.

◆ size()

socklen_t sockpp::unix_address::size ( ) const
inlineoverridevirtual

Gets the size of the address structure.

Note: In this implementation, this should return sizeof(this) but more convenient in some places, and the implementation might change in the future, so it might be more compatible with future revisions to use this call.

Returns
The size of the address structure.

Implements sockpp::sock_address.

◆ sockaddr_ptr() [1/2]

const sockaddr* sockpp::unix_address::sockaddr_ptr ( ) const
inlineoverridevirtual

Gets a pointer to this object cast to a const sockaddr.

Returns
A pointer to this object cast to a const sockaddr.

Implements sockpp::sock_address.

◆ sockaddr_ptr() [2/2]

sockaddr* sockpp::unix_address::sockaddr_ptr ( )
inlineoverridevirtual

Gets a pointer to this object cast to a sockaddr.

Returns
A pointer to this object cast to a sockaddr.

Implements sockpp::sock_address.

◆ sockaddr_un_ptr() [1/2]

const sockaddr_un* sockpp::unix_address::sockaddr_un_ptr ( ) const
inline

Gets a const pointer to this object cast to a sockaddr_un.

Returns
const sockaddr_un pointer to this object.

◆ sockaddr_un_ptr() [2/2]

sockaddr_un* sockpp::unix_address::sockaddr_un_ptr ( )
inline

Gets a pointer to this object cast to a sockaddr_un.

Returns
sockaddr_un pointer to this object.

◆ to_string()

std::string sockpp::unix_address::to_string ( ) const
inline

Gets a printable string for the address.

Returns
A string representation of the address in the form "unix:<path>"

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