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

Class that represents an internet (IPv6) address. More...

#include <inet6_address.h>

Inheritance diagram for sockpp::inet6_address:
sockpp::sock_address

Public Member Functions

 inet6_address ()
 Constructs an empty address. More...
 
 inet6_address (in_port_t port)
 Constructs an address for any iface using the specified port. More...
 
 inet6_address (const std::string &saddr, in_port_t port)
 Constructs an address using the name of the host and the specified port. More...
 
 inet6_address (const sockaddr_storage &addr)
 Constructs the address by copying the specified structure. More...
 
 inet6_address (const sock_address &addr)
 Constructs the address by copying the specified structure. More...
 
 inet6_address (const sockaddr_in6 &addr)
 Constructs the address by copying the specified structure. More...
 
 inet6_address (const inet6_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...
 
void create (const in6_addr &addr, in_port_t port)
 Creates the socket address using the specified host address and port number. More...
 
void create (const std::string &saddr, in_port_t port)
 Creates the socket address using the specified host name and port number. More...
 
in6_addr address () const
 Gets 128-bit IPv6 address. More...
 
uint8_t operator[] (int i) const
 Gets a byte of the 128-bit IPv6 Address. More...
 
in_port_t port () const
 Gets the port number. More...
 
socklen_t size () const override
 Gets the size of this structure. More...
 
const sockaddr * sockaddr_ptr () const override
 Gets a pointer to this object cast to a sockaddr. More...
 
sockaddr * sockaddr_ptr () override
 Gets a pointer to this object cast to a sockaddr. More...
 
const sockaddr_in6 * sockaddr_in6_ptr () const
 Gets a const pointer to this object cast to a sockaddr_in6. More...
 
sockaddr_in6 * sockaddr_in6_ptr ()
 Gets a pointer to this object cast to a sockaddr_in6. 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 Member Functions

static inet6_address loopback (in_port_t port)
 Creates an address on the loopback (localhost) interface. More...
 
static in6_addr resolve_name (const std::string &saddr)
 Attempts to resolve the host name into a 32-bit internet address. More...
 

Static Public Attributes

static constexpr sa_family_t ADDRESS_FAMILY = AF_INET6
 The address family for this type of address.
 

Detailed Description

Class that represents an internet (IPv6) address.

This inherits from the IP-specific form of a socket address, sockaddr_in.

Constructor & Destructor Documentation

◆ inet6_address() [1/7]

sockpp::inet6_address::inet6_address ( )
inline

Constructs an empty address.

The address is initialized to all zeroes.

◆ inet6_address() [2/7]

sockpp::inet6_address::inet6_address ( in_port_t  port)
inlineexplicit

Constructs an address for any iface using the specified port.

This is a convenient way for a server to specify an address that will bind to all interfaces.

Parameters
portThe port number in native/host byte order.

◆ inet6_address() [3/7]

sockpp::inet6_address::inet6_address ( const std::string &  saddr,
in_port_t  port 
)
inline

Constructs an address using the name of the host and the specified port.

This attempts to resolve the host name to an address.

Parameters
saddrThe name of the host.
portThe port number in native/host byte order.

◆ inet6_address() [4/7]

sockpp::inet6_address::inet6_address ( const sockaddr_storage &  addr)
inline

Constructs the address by copying the specified structure.

TODO: Do we actually need a conversion from something that's cast to a sockaddr, but is really a sockaddr_in6?

Parameters
addrThe other address

◆ inet6_address() [5/7]

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

Constructs the address by copying the specified structure.

Parameters
addrThe other address

◆ inet6_address() [6/7]

sockpp::inet6_address::inet6_address ( const sockaddr_in6 &  addr)
inline

Constructs the address by copying the specified structure.

Parameters
addrThe other address

◆ inet6_address() [7/7]

sockpp::inet6_address::inet6_address ( const inet6_address addr)
inline

Constructs the address by copying the specified address.

Parameters
addrThe other address

Member Function Documentation

◆ address()

in6_addr sockpp::inet6_address::address ( ) const
inline

Gets 128-bit IPv6 address.

The address is usually stored in network byte order.

Returns
The IPv6 address.

◆ create() [1/2]

void sockpp::inet6_address::create ( const in6_addr &  addr,
in_port_t  port 
)

Creates the socket address using the specified host address and port number.

Parameters
addrThe host address (16-byte IPv6 address).
portThe host port number.

◆ create() [2/2]

void sockpp::inet6_address::create ( const std::string &  saddr,
in_port_t  port 
)

Creates the socket address using the specified host name and port number.

Parameters
saddrThe string host name.
portThe port number in native/host byte order.

◆ is_set()

bool sockpp::inet6_address::is_set ( ) const

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
bool

◆ loopback()

static inet6_address sockpp::inet6_address::loopback ( in_port_t  port)
inlinestatic

Creates an address on the loopback (localhost) interface.

Parameters
portThe port number (in native/host byte order).
Returns
The full address on the loopback interface.

◆ operator[]()

uint8_t sockpp::inet6_address::operator[] ( int  i) const
inline

Gets a byte of the 128-bit IPv6 Address.

Note that the address is normally stored in network byte order.

Parameters
iThe byte to read (0-7) { return addr_ != sockaddr_in6{};
Returns
The specified byte in the 128-bit IPv6 Address

◆ port()

in_port_t sockpp::inet6_address::port ( ) const
inline

Gets the port number.

Returns
The port number in native/host byte order.

◆ resolve_name()

static in6_addr sockpp::inet6_address::resolve_name ( const std::string &  saddr)
static

Attempts to resolve the host name into a 32-bit internet address.

Parameters
saddrThe string host name.
Returns
The internet address in network byte order.

◆ size()

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

Gets the size of this structure.

This is equivalent to sizeof(this) but more convenient in some places.

Returns
The size of this structure.

Implements sockpp::sock_address.

◆ sockaddr_in6_ptr() [1/2]

const sockaddr_in6* sockpp::inet6_address::sockaddr_in6_ptr ( ) const
inline

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

Returns
const sockaddr_in6 pointer to this object.

◆ sockaddr_in6_ptr() [2/2]

sockaddr_in6* sockpp::inet6_address::sockaddr_in6_ptr ( )
inline

Gets a pointer to this object cast to a sockaddr_in6.

Returns
sockaddr_in6 pointer to this object.

◆ sockaddr_ptr() [1/2]

const sockaddr* sockpp::inet6_address::sockaddr_ptr ( ) const
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_ptr() [2/2]

sockaddr* sockpp::inet6_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.

◆ to_string()

std::string sockpp::inet6_address::to_string ( ) const

Gets a printable string for the address.

This gets the address in the printable form "[addr]:port" using inet_ntop(). It does not attempt to find the host name using a lookup.

Returns
A string representation of the address in the form '[address]:port'

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