CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
SocketAddress Class Reference

Socket address More...

#include <cc/SocketAddress>

Inheritance diagram for SocketAddress:

Public Member Functions

 SocketAddress ()=default
 Create a null socket address.
 
 SocketAddress (New)
 Create a new socket address.
 
 SocketAddress (const String &address, int port=0)
 Create a socket address.
 
 SocketAddress (ProtocolFamily family, const String &address="", int port=0)
 Create a socket address.
 
 SocketAddress (int port)
 Create an IPv4 broadcast address.
 
 SocketAddress (const Socket &socket)
 Retrieve locally bound socket address of socket.
 
ProtocolFamily family () const
 Protocol family
 
SocketType socketType () const
 Socket type if this address is a result of name resolution
 
InternetProtocol protocol () const
 Socket protocol if this address is a result of name resolution
 
int port () const
 Service port
 
void setPort (int port)
 Change the service port
 
String networkAddress () const
 Convert the socket address to a string (sans port number)
 
String toString () const
 Convert the full address to a string (with port number)
 
int scope () const
 IPv6 scope of this address.
 
void setScope (int scope)
 Change the IPv6 scope.
 
String lookupHostName () const
 Lookup the host name of this address.
 
String lookupServiceName () const
 Lookup the service name of this address.
 
uint64_t networkPrefix () const
 Returns network prefix (the leading 64 bits of an IPv6 address).
 
int bitLength () const
 Size of the address in bits
 
struct sockaddr * addr ()
 Provide access to the underlying low-level address structure.
 
const struct sockaddr * addr () const
 Provide access to the underlying low-level address structure (read-only)
 
int addrLen () const
 Size of the underlying low-level address structure in bytes
 
int level () const
 Level parameter used to set socket options
 
bool operator== (const SocketAddress &other) const
 Equal to operator.
 
std::strong_ordering operator<=> (const SocketAddress &other) const
 Ordering operator.
 
- Public Member Functions inherited from Object
 Object ()=default
 Create a null object.
 
 operator bool () const
 Check if this is a non-null object.
 
bool isNull () const
 Check if this is a null object.
 
template<class T >
bool is () const
 Check if this object is of type T.
 
template<class T >
as () const
 Cast this object to type T.
 
bool isWeak () const
 Check if the underlying object reference is weak.
 
bool operator== (const Object &other) const
 Equality operator.
 
std::strong_ordering operator<=> (const Object &other) const
 Ordering operator.
 
long useCount () const
 Reference count.
 

Static Public Member Functions

static SocketAddress resolveHostName (const String &hostName, int port=0)
 Resolve Internet address of a host.
 
static SocketAddress resolveHostAndServiceName (const String &hostName, const String &serviceName)
 Resolve Internet address of a host.
 
static List< SocketAddressqueryConnectionInfo (const String &hostName, const String &serviceName="", ProtocolFamily family=ProtocolFamily::Unspec, SocketType socketType=SocketType::Unspec, Out< String > canonicalName=None{})
 Query the complete connection information for given host name, service name and protocol family.
 

Additional Inherited Members

- Protected Member Functions inherited from Object
template<class T >
weak () const
 
template<class T >
void initOnce ()
 Create the object state when called the first time.
 
template<class T >
void initOncePerThread ()
 Create a distinct object state for each thread when called the first time in that thread.
 
 Object (State *newState)
 Initialize object with newState.
 
 Object (State *state, Alias)
 
 Object (State *state, Weak)
 
Objectoperator= (std::nullptr_t)
 
- Static Protected Member Functions inherited from Object
template<class T >
static T alias (const State *state)
 Create an alias object for the given state.
 
template<class T >
static T weak (const State *state)
 
- Protected Attributes inherited from Object
Handle< Stateme
 Internal object state
 

Detailed Description

Socket address

See also
Uri

Constructor & Destructor Documentation

◆ SocketAddress() [1/6]

SocketAddress ( )
default

Create a null socket address.

◆ SocketAddress() [2/6]

SocketAddress ( New )
explicit

Create a new socket address.

◆ SocketAddress() [3/6]

SocketAddress ( const String & address,
int port = 0 )
explicit

Create a socket address.

Parameters
addressNumerical host address, wildcard ("*", "::") or file path
portService port
Exceptions
InvalidAddressSyntax

◆ SocketAddress() [4/6]

SocketAddress ( ProtocolFamily family,
const String & address = "",
int port = 0 )
explicit

Create a socket address.

Parameters
familyProtocol family
addressNumerical host address, wildcard ("*", "::") or file path
portService port
Exceptions
InvalidAddressSyntax

◆ SocketAddress() [5/6]

SocketAddress ( int port)
explicit

Create an IPv4 broadcast address.

◆ SocketAddress() [6/6]

SocketAddress ( const Socket & socket)
explicit

Retrieve locally bound socket address of socket.

Member Function Documentation

◆ resolveHostName()

SocketAddress resolveHostName ( const String & hostName,
int port = 0 )
static

Resolve Internet address of a host.

Parameters
hostNameHost or domain name to resolve
portPort number to set
Exceptions
HostNameResolutionError

◆ resolveHostAndServiceName()

SocketAddress resolveHostAndServiceName ( const String & hostName,
const String & serviceName )
static

Resolve Internet address of a host.

Parameters
hostNameHost or domain name to resolve
serviceNameService name to resolve (e.g. "http")
Exceptions
HostNameResolutionError

◆ queryConnectionInfo()

List< SocketAddress > queryConnectionInfo ( const String & hostName,
const String & serviceName = "",
ProtocolFamily family = ProtocolFamily::Unspec,
SocketType socketType = SocketType::Unspec,
Out< String > canonicalName = None{} )
static

Query the complete connection information for given host name, service name and protocol family.

The call blocks until the local resolver has resolved the host name. This may take several seconds. Depending on supported protocol stacks and service availability in different protocols (UDP/TCP) and number of network addresses of the queried host multiple SocketAddress objects will be returned. An empty list is returned, if the host name is unknown, service is not available or protocol family is not supported by the host. The host name can be a short name relative to the local domain. The fully qualified domain name (aka canonical name) can be optionally retrieved.

Parameters
hostNameHost or domain name to resolve
serviceNameService name (e.g. "http")
familyProtocol family
socketTypeSocket type.
canonicalNameOptionally return the fully qualified domain name
Exceptions
HostNameResolutionError

◆ family()

ProtocolFamily family ( ) const

Protocol family

◆ socketType()

SocketType socketType ( ) const

Socket type if this address is a result of name resolution

◆ protocol()

InternetProtocol protocol ( ) const

Socket protocol if this address is a result of name resolution

◆ port()

int port ( ) const

Service port

◆ setPort()

void setPort ( int port)

Change the service port

◆ networkAddress()

String networkAddress ( ) const

Convert the socket address to a string (sans port number)

◆ toString()

String toString ( ) const

Convert the full address to a string (with port number)

◆ scope()

int scope ( ) const

IPv6 scope of this address.

◆ setScope()

void setScope ( int scope)

Change the IPv6 scope.

◆ lookupHostName()

String lookupHostName ( ) const

Lookup the host name of this address.

Usually a reverse DNS lookup will be issued, which may take several seconds.

Exceptions
HostNameLookupError

◆ lookupServiceName()

String lookupServiceName ( ) const

Lookup the service name of this address.

In most setups the service name will be looked up in a local file (/etc/services) and therefore the call returns almost immediately.

Exceptions
ServiceNameLookupError

◆ networkPrefix()

uint64_t networkPrefix ( ) const

Returns network prefix (the leading 64 bits of an IPv6 address).

For an IPv4 address the entire address is returned.

◆ bitLength()

int bitLength ( ) const

Size of the address in bits

◆ addr() [1/2]

struct sockaddr * addr ( )

Provide access to the underlying low-level address structure.

◆ addr() [2/2]

const struct sockaddr * addr ( ) const

Provide access to the underlying low-level address structure (read-only)

◆ addrLen()

int addrLen ( ) const

Size of the underlying low-level address structure in bytes

◆ level()

int level ( ) const

Level parameter used to set socket options

◆ operator==()

bool operator== ( const SocketAddress & other) const

Equal to operator.

◆ operator<=>()

std::strong_ordering operator<=> ( const SocketAddress & other) const

Ordering operator.