Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Public Types | Public Member Functions | Public Attributes | List of all members
gf::SocketAddress Class Reference

A socket address. More...

#include <gf/SocketAddress.h>

Public Types

using StorageLengthType = implementation-defined
 The type to handle the storage length. More...
 

Public Member Functions

 SocketAddress ()=default
 Default constructor. More...
 
SocketFamily getFamily () const
 Get the family of the socket address. More...
 
std::string getHostname (SocketAddressFormat format=SocketAddressFormat::Unrestricted) const
 Get the hostname associated to the address. More...
 
std::string getService (SocketAddressFormat format=SocketAddressFormat::Unrestricted) const
 Get the service associated to the address. More...
 
 SocketAddress (sockaddr *a_storage, StorageLengthType a_length)
 Constructor with a raw sockaddr and a length. More...
 
const sockaddr * asSockAddr () const
 Get the storage as a sockaddr address. More...
 

Public Attributes

sockaddr_storage storage
 The storage for the address. More...
 
StorageLengthType length
 The length of the address. More...
 

Detailed Description

A socket address.

A socket address is composed of an IP address (representing an hostname) and a port number (representing a service).

You can not create a socket address directly.

In other libraries, it can also be called "endpoint".

Member Typedef Documentation

◆ StorageLengthType

using gf::SocketAddress::StorageLengthType = implementation-defined

The type to handle the storage length.

Constructor & Destructor Documentation

◆ SocketAddress() [1/2]

gf::SocketAddress::SocketAddress ( )
default

Default constructor.

◆ SocketAddress() [2/2]

gf::SocketAddress::SocketAddress ( sockaddr *  a_storage,
StorageLengthType  a_length 
)

Constructor with a raw sockaddr and a length.

Member Function Documentation

◆ asSockAddr()

const sockaddr * gf::SocketAddress::asSockAddr ( ) const
inline

Get the storage as a sockaddr address.

◆ getFamily()

SocketFamily gf::SocketAddress::getFamily ( ) const

Get the family of the socket address.

◆ getHostname()

std::string gf::SocketAddress::getHostname ( SocketAddressFormat  format = SocketAddressFormat::Unrestricted) const

Get the hostname associated to the address.

Parameters
formatThe format of the socket address
Returns
The hostname part of the address as a string
See also
getService()

◆ getService()

std::string gf::SocketAddress::getService ( SocketAddressFormat  format = SocketAddressFormat::Unrestricted) const

Get the service associated to the address.

Parameters
formatThe format of the socket address
Returns
The service part of the address as a string
See also
getHostname()

Member Data Documentation

◆ length

StorageLengthType gf::SocketAddress::length

The length of the address.

◆ storage

sockaddr_storage gf::SocketAddress::storage

The storage for the address.