Home
Net module

Address

Represents an IPv4 or IPv6 socket address with host and port.

Address

#include <icy/net/address.h>
class Address

Defined in src/net/include/icy/net/address.h:28

Represents an IPv4 or IPv6 socket address with host and port.

List of all members

NameKindOwner
operator<<friendDeclared here
AddressfunctionDeclared here
AddressfunctionDeclared here
AddressfunctionDeclared here
AddressfunctionDeclared here
AddressfunctionDeclared here
AddressfunctionDeclared here
~AddressfunctionDeclared here
operator=functionDeclared here
swapfunctionDeclared here
hostfunctionDeclared here
portfunctionDeclared here
lengthfunctionDeclared here
addrfunctionDeclared here
affunctionDeclared here
toStringfunctionDeclared here
familyfunctionDeclared here
validfunctionDeclared here
operator<functionDeclared here
operator==functionDeclared here
operator!=functionDeclared here
resolveServicefunctionDeclared here
validateIPfunctionDeclared here
initfunctionDeclared here
FamilyenumDeclared here
_basevariableDeclared here

Friends

NameDescription
operator<< inline

operator<<

inline

friend inline std::ostream & operator<<(std::ostream & stream, const Address & addr)

Defined in src/net/include/icy/net/address.h:131

Public Methods

ReturnNameDescription
AddressCreates a wildcard (all zero) IPv4 Address.
AddressCreates an Address from an IP address and a port number.
AddressCreates an Address by copying another one.
AddressCreates an Address from a native socket address.
AddressCreates an Address from an IP address and a service name or port number.
Address explicitCreates an Address from an IP address or host name and a port number/service name. Host name/address and port number must be separated by a colon. In case of an IPv6 address, the address part must be enclosed in brackets.
~Address noexceptDestroys the Address.
Address &operator=Assigns another Address.
voidswapSwaps the Address with another one.
std::stringhost constReturns the host IP address.
uint16_tport constReturns the port number.
socklen_tlength constReturns the length of the internal native socket address.
const struct sockaddr *addr constReturns a pointer to the internal native socket address.
intaf constReturns the address family (AF_INET or AF_INET6) of the address.
std::stringtoString constReturns a string representation of the address.
Address::Familyfamily constReturns the address family of the host's address.
boolvalid constReturns true when the port is set and the address is valid ie. not wildcard.
booloperator< constCompares two addresses for ordering (by family then port).
booloperator== constReturns true if the host and port of both addresses are equal.
booloperator!= constReturns true if the host or port of the addresses differ.

Address

Address()

Defined in src/net/include/icy/net/address.h:39

Creates a wildcard (all zero) IPv4 Address.


Address

Address(const std::string & host, uint16_t port)

Defined in src/net/include/icy/net/address.h:45

Creates an Address from an IP address and a port number.

The IP address must either be a domain name, or it must be in dotted decimal (IPv4) or hex string (IPv6) format.


Address

Address(const Address & addr)

Defined in src/net/include/icy/net/address.h:48

Creates an Address by copying another one.


Address

Address(const struct sockaddr * addr, socklen_t length)

Defined in src/net/include/icy/net/address.h:51

Creates an Address from a native socket address.


Address

Address(const std::string & host, const std::string & port)

Defined in src/net/include/icy/net/address.h:61

Creates an Address from an IP address and a service name or port number.

The IP address must either be a domain name, or it must be in dotted decimal (IPv4) or hex string (IPv6) format.

The given port must either be a decimal port number, or a service name.


Address

explicit

explicit Address(const std::string & hostAndPort)

Defined in src/net/include/icy/net/address.h:72

Creates an Address from an IP address or host name and a port number/service name. Host name/address and port number must be separated by a colon. In case of an IPv6 address, the address part must be enclosed in brackets.

Examples: 192.168.1.10:80

0state.com:8080


~Address

noexcept

~Address() noexcept

Defined in src/net/include/icy/net/address.h:75

Destroys the Address.


operator=

Address & operator=(const Address & addr)

Defined in src/net/include/icy/net/address.h:78

Assigns another Address.


swap

void swap(Address & addr)

Defined in src/net/include/icy/net/address.h:81

Swaps the Address with another one.


host

const

std::string host() const

Defined in src/net/include/icy/net/address.h:84

Returns the host IP address.


port

const

uint16_t port() const

Defined in src/net/include/icy/net/address.h:87

Returns the port number.


length

const

socklen_t length() const

Defined in src/net/include/icy/net/address.h:90

Returns the length of the internal native socket address.


addr

const

const struct sockaddr * addr() const

Defined in src/net/include/icy/net/address.h:93

Returns a pointer to the internal native socket address.


af

const

int af() const

Defined in src/net/include/icy/net/address.h:96

Returns the address family (AF_INET or AF_INET6) of the address.


toString

const

std::string toString() const

Defined in src/net/include/icy/net/address.h:99

Returns a string representation of the address.


family

const

Address::Family family() const

Defined in src/net/include/icy/net/address.h:102

Returns the address family of the host's address.


valid

const

bool valid() const

Defined in src/net/include/icy/net/address.h:106

Returns true when the port is set and the address is valid ie. not wildcard.


operator<

const

bool operator<(const Address & addr) const

Defined in src/net/include/icy/net/address.h:121

Compares two addresses for ordering (by family then port).

Parameters

  • addr The address to compare against.

Returns

true if this address is less than addr.


operator==

const

bool operator==(const Address & addr) const

Defined in src/net/include/icy/net/address.h:125

Returns true if the host and port of both addresses are equal.

Parameters

  • addr The address to compare against.

operator!=

const

bool operator!=(const Address & addr) const

Defined in src/net/include/icy/net/address.h:129

Returns true if the host or port of the addresses differ.

Parameters

  • addr The address to compare against.

Public Static Methods

ReturnNameDescription
uint16_tresolveService staticResolves a service name or decimal port string to a port number.
boolvalidateIP staticReturns true if the given string is a valid IPv4 or IPv6 address.

resolveService

static

static uint16_t resolveService(const std::string & service)

Defined in src/net/include/icy/net/address.h:111

Resolves a service name or decimal port string to a port number.

Parameters

  • service Service name (e.g. "http") or decimal port string (e.g. "80").

Returns

The resolved port number in host byte order.


validateIP

static

static bool validateIP(std::string_view address)

Defined in src/net/include/icy/net/address.h:116

Returns true if the given string is a valid IPv4 or IPv6 address.

Parameters

  • address The string to validate.

Returns

true if the address parses as a valid IP address, false otherwise.

Protected Methods

ReturnNameDescription
voidinit

init

void init(const std::string & host, uint16_t port)

Defined in src/net/include/icy/net/address.h:138

Public Types

NameDescription
FamilyPossible address families for IP addresses.

Family

enum Family

Defined in src/net/include/icy/net/address.h:32

Possible address families for IP addresses.

ValueDescription
IPv4
IPv6

Private Attributes

ReturnNameDescription
std::shared_ptr< AddressBase >_base

_base

std::shared_ptr< AddressBase > _base

Defined in src/net/include/icy/net/address.h:141