Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
SC::SocketIPAddress Struct Reference

Native representation of an IP Address. More...

#include <SocketDescriptor.h>

Public Types

using AsciiBuffer = char[MAX_ASCII_STRING_LENGTH]
 Buffer for storing the ASCII representation of an IP Address.
 

Public Member Functions

 SocketIPAddress (SocketFlags::AddressFamily addressFamily=SocketFlags::AddressFamilyIPV4)
 Constructs an ip address from a given family (IPV4 or IPV6)
 
SocketFlags::AddressFamily getAddressFamily () const
 Get Address family of this ip address (IPV4 or IPV6)
 
uint16_t getPort () const
 Get port of this ip address.
 
Result fromAddressPort (StringViewData interfaceAddress, uint16_t port)
 Builds this SocketIPAddress parsing given address string and port.
 
uint32_t sizeOfHandle () const
 Size of the native IP Address representation.
 
bool isValid () const
 Checks if this is a valid IPV4 or IPV6 address.
 
template<size_t N>
StringViewData toString (char(&buffer)[N]) const
 Returns the text representation of this SocketIPAddress.
 

Public Attributes

AlignedStorage< 28 > handle = {}
 Handle to native OS representation of the IP Address.
 

Static Public Attributes

static constexpr int MAX_ASCII_STRING_LENGTH = 46
 Maximum length of the ASCII representation of an IP Address.
 

Friends

struct SocketServer
 
struct SocketClient
 

Detailed Description

Native representation of an IP Address.

Example:

SocketIPAddress address;
SC_TEST_EXPECT(not address.fromAddressPort("1223.22.44.1", 6666));
SC_TEST_EXPECT(address.fromAddressPort("127.0.0.1", 123));
SC_TEST_EXPECT(address.fromAddressPort("::1", 123));

Member Typedef Documentation

◆ AsciiBuffer

Buffer for storing the ASCII representation of an IP Address.

Constructor & Destructor Documentation

◆ SocketIPAddress()

SC::SocketIPAddress::SocketIPAddress ( SocketFlags::AddressFamily addressFamily = SocketFlags::AddressFamilyIPV4)

Constructs an ip address from a given family (IPV4 or IPV6)

Parameters
addressFamilyThe address family

Member Function Documentation

◆ fromAddressPort()

Result SC::SocketIPAddress::fromAddressPort ( StringViewData interfaceAddress,
uint16_t port )
nodiscard

Builds this SocketIPAddress parsing given address string and port.

Parameters
interfaceAddressA valid IPV4 or IPV6 address expressed as an ASCII string
portThe port to connect to
Returns
A valid Result if the address has been parsed successfully

◆ getAddressFamily()

SocketFlags::AddressFamily SC::SocketIPAddress::getAddressFamily ( ) const
nodiscard

Get Address family of this ip address (IPV4 or IPV6)

Returns
The Ip Address Family of the given SocketDescriptor

◆ getPort()

uint16_t SC::SocketIPAddress::getPort ( ) const
nodiscard

Get port of this ip address.

Returns
The port of the given SocketIPAddress

◆ isValid()

bool SC::SocketIPAddress::isValid ( ) const
nodiscard

Checks if this is a valid IPV4 or IPV6 address.

◆ sizeOfHandle()

uint32_t SC::SocketIPAddress::sizeOfHandle ( ) const
nodiscard

Size of the native IP Address representation.

◆ toString()

template<size_t N>
StringViewData SC::SocketIPAddress::toString ( char(&) buffer[N]) const
inlinenodiscard

Returns the text representation of this SocketIPAddress.

Parameters
bufferBuffer to store the ASCII representation of the IP Address
Returns
A sub-Span of buffer that has the length of actually written bytes
Note
The buffer must be at least MAX_ASCII_STRING_LENGTH bytes long

Member Data Documentation

◆ handle

AlignedStorage<28> SC::SocketIPAddress::handle = {}

Handle to native OS representation of the IP Address.

◆ MAX_ASCII_STRING_LENGTH

int SC::SocketIPAddress::MAX_ASCII_STRING_LENGTH = 46
staticconstexpr

Maximum length of the ASCII representation of an IP Address.


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