AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::network::Address Class Reference

Socket address (IPv4 or IPv6 address and port). More...

#include <address.hpp>

Collaboration diagram for anch::network::Address:

Public Member Functions

 Address () noexcept
 Address (const sockaddr *address, socklen_t length)
int getFamily () const noexcept
std::string getHost () const
uint16_t getPort () const noexcept
std::string toString () const
const sockaddr * data () const noexcept
socklen_t size () const noexcept
bool operator== (const Address &other) const noexcept

Static Public Member Functions

static std::vector< Address > resolve (const std::string &host, uint16_t port, SocketType type, bool passive=false, int family=AF_UNSPEC)

Friends

class Socket

Detailed Description

Socket address (IPv4 or IPv6 address and port).

The address is copied in a sockaddr_storage : it does not depend on getaddrinfo result lifetime.

Author
Vincent Lachenal
Since
0.2

Constructor & Destructor Documentation

◆ Address() [1/2]

anch::network::Address::Address ( )
noexcept

Address default constructor (address is not set)

◆ Address() [2/2]

anch::network::Address::Address ( const sockaddr * address,
socklen_t length )

Address constructor

Parameters
addressthe address to copy
lengththe address length
Exceptions
std::invalid_argumentlength is greater than sockaddr_storage
Here is the call graph for this function:

Member Function Documentation

◆ data()

const sockaddr * anch::network::Address::data ( ) const
noexcept

Raw address getter

Returns
the address
Here is the call graph for this function:

◆ getFamily()

int anch::network::Address::getFamily ( ) const
noexcept

Address family getter

Returns
AF_INET , AF_INET6 (or AF_UNSPEC when address is not set)
Here is the call graph for this function:

◆ getHost()

std::string anch::network::Address::getHost ( ) const

Numeric host getter

Returns
the numeric host (127.0.0.1 or ::1 for example)
Here is the call graph for this function:

◆ getPort()

uint16_t anch::network::Address::getPort ( ) const
noexcept

Port getter

Returns
the port
Here is the call graph for this function:

◆ operator==()

bool anch::network::Address::operator== ( const Address & other) const
noexcept

Check if addresses are equals (same bytes)

Parameters
otherthe address to compare to
Returns
true when addresses are equals, false otherwise
Here is the call graph for this function:

◆ resolve()

std::vector< Address > anch::network::Address::resolve ( const std::string & host,
uint16_t port,
SocketType type,
bool passive = false,
int family = AF_UNSPEC )
static

Resolve host name (with getaddrinfo )

Parameters
hostthe host name or numeric address ; empty for loopback address (or any address when passive )
portthe port
typethe socket type
passivetrue for addresses to bind, false for addresses to connect to
familythe address family (AF_UNSPEC , AF_INET or AF_INET6 ; IPv4 addresses are mapped for AF_INET6 )
Returns
the addresses (at least one)
Exceptions
anch::network::IOExceptionresolution error
Here is the call graph for this function:

◆ size()

socklen_t anch::network::Address::size ( ) const
noexcept

Raw address length getter

Returns
the length
Here is the call graph for this function:

◆ toString()

std::string anch::network::Address::toString ( ) const

String representation: host:port ([host]:port for IPv6)

Returns
the string representation
Here is the call graph for this function:

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