# class SocketAddr | A socket address holder. More...
Full name | `TelEngine::SocketAddr`
Definition | `#include <yateclass.h>`
Inherits | TelEngine::GenObject [public ]
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Types

- enum Family { Unknown = AF_UNSPEC, IPv4 = AF_INET, AfMax = AF_MAX, AfUnsupported = AfMax, IPv6 = AF_INET6, IPv6 = AfUnsupported + 1, Unix = AF_UNIX, Unix = AfUnsupported + 2, }

#### Public Methods

- inline SocketAddr ()
- inline SocketAddr (const SocketAddr& value)
- explicit SocketAddr (int family, const void* raw = 0)
- SocketAddr (const struct sockaddr* addr, socklen_t len = 0)
- virtual ~SocketAddr ()
- inline SocketAddr& operator= (const SocketAddr& value)
- bool operator== (const SocketAddr& other) const
- inline bool operator!= (const SocketAddr& other) const
- void clear ()
- bool assign (int family)
- void assign (const struct sockaddr* addr, socklen_t len = 0)
- bool assign (const DataBlock& addr)
- bool local (const SocketAddr& remote)
- inline bool valid () const
- inline bool null () const
- inline int family () const
- inline const char* familyName ()
- inline unsigned int scopeId () const
- inline bool scopeId (unsigned int val)
- inline const String& host () const
- inline const String& addr () const
- virtual bool host (const String& name)
- int port () const
- bool port (int newport)
- inline struct sockaddr* address () const
- inline socklen_t length () const
- inline bool isNullAddr () const
- int copyAddr (DataBlock& addr) const

#### Public Static Methods

- static bool supports (int family)
- static int family (const String& addr)
- static bool stringify (String& buf, struct sockaddr* addr)
- static inline int unStringify (uint8_t* buf, const String& host, int family = Unknown)
- static int copyAddr (uint8_t* buf, struct sockaddr* addr)
- static inline unsigned int scopeId (struct sockaddr* addr)
- static inline bool scopeId (struct sockaddr* addr, unsigned int val)
- static String& appendAddr (String& buf, const String& addr, int family = Unknown)
- static inline String& appendTo (String& buf, const String& addr, int port, int family = Unknown)
- static inline String appendTo (const String& addr, int port, int family = Unknown)
- static bool isNullAddr (const String& addr, int family = Unknown)
- static void splitIface (const String& buf, String& addr, String* iface = 0)
- static void split (const String& buf, String& addr, int& port, bool portPresent = false)
- static inline const char* lookupFamily (int family)
- static const String& ipv4NullAddr ()
- static const String& ipv6NullAddr ()
- static const TokenDict* dictFamilyName ()

#### Protected Methods

- virtual void stringify ()
- virtual void updateAddr () const

#### Protected Members

- struct sockaddr* m_address
- socklen_t m_length
- String m_host
- mutable String m_addr

## Detailed Description

Wrapper class to keep a socket address

enum Family { Unknown = AF_UNSPEC, IPv4 = AF_INET, AfMax = AF_MAX, AfUnsupported = AfMax, IPv6 = AF_INET6, IPv6 = AfUnsupported + 1, Unix = AF_UNIX, Unix = AfUnsupported + 2, } | ### Family

Known address families

inline SocketAddr () | ### SocketAddr

Default constructor of an empty address

inline SocketAddr (const SocketAddr& value) | ### SocketAddr

Copy constructor

Parameters:

value | Address to copy

explicit SocketAddr (int family, const void* raw = 0) | ### SocketAddr

Constructor of a null address

Parameters:

family | Family of the address to create
raw | Raw address data

SocketAddr (const struct sockaddr* addr, socklen_t len = 0) | ### SocketAddr

Constructor that stores a copy of an address

Parameters:

addr | Pointer to the address to store
len | Length of the stored address, zero to use default

~SocketAddr () | ### ~SocketAddr

[virtual]

Destructor that frees and zeroes out everything

inline SocketAddr& operator= (const SocketAddr& value) | ### operator=

Assignment operator

Parameters:

value | Address to copy

bool operator== (const SocketAddr& other) | ### operator==

[const]

Equality comparation operator

Parameters:

other | Address to compare to

Returns: True if the addresses are equal

inline bool operator!= (const SocketAddr& other) | ### operator!=

[const]

Inequality comparation operator

Parameters:

other | Address to compare to

Returns: True if the addresses are different

void clear () | ### clear

Clears up the address, frees the memory

bool assign (int family) | ### assign

Assigns an empty address of a specific type

Parameters:

family | Family of the address to create

Returns: True if the address family is supported

void assign (const struct sockaddr* addr, socklen_t len = 0) | ### assign

Assigns a new address

Parameters:

addr | Pointer to the address to store
len | Length of the stored address, zero to use default

bool assign (const DataBlock& addr) | ### assign

Assigns a new address

Parameters:

addr | Packed binary address to store

Returns: True if the address family is supported

bool local (const SocketAddr& remote) | ### local

Attempt to guess a local address that will be used to reach a remote one

Parameters:

remote | Remote address to reach

Returns: True if guessed an address, false if failed

inline bool valid () | ### valid

[const]

Check if a non-null address is held

Returns: True if a valid address is held, false if null

inline bool null () | ### null

[const]

Check if a null address is held

Returns: True if a null address is held

inline int family () | ### family

[const]

Get the family of the stored address

Returns: Address family of the stored address or zero (AF_UNSPEC)

inline const char* familyName () | ### familyName

Retrieve address family name

Returns: Address family name

inline unsigned int scopeId () | ### scopeId

[const]

Retrieve the sin6_scope_id value of an IPv6 address

Returns: The requested value (it may be 0), 0 if not available

inline bool scopeId (unsigned int val) | ### scopeId

Set the sin6_scope_id value of an IPv6 address

Parameters:

val | Value to set

Returns: True on success, false if not available

inline const String& host () | ### host

[const]

Get the host of this address

Returns: Host name as String

inline const String& addr () | ### addr

[const]

Get the host and port of this address

Returns: Address String (host:port)

bool host (const String& name) | ### host

[virtual]

Set the hostname of this address. Guess address family if not initialized

Parameters:

name | Host to set

Returns: True if new host set, false if name could not be parsed

int port () | ### port

[const]

Get the port of the stored address (if supported)

Returns: Port number of the socket address or zero

bool port (int newport) | ### port

Set the port of the stored address (if supported)

Parameters:

newport | Port number to set in the socket address

Returns: True if new port set, false if not supported

inline struct sockaddr* address () | ### address

[const]

Get the contained socket address

Returns: A pointer to the socket address

inline socklen_t length () | ### length

[const]

Get the length of the address

Returns: Length of the stored address

inline bool isNullAddr () | ### isNullAddr

[const]

Check if this address is empty or null

Returns: True if the address is empty or '0.0.0.0' (IPv4) or '::' IPv6

int copyAddr (DataBlock& addr) | ### copyAddr

[const]

Copy the host address to a buffer

Parameters:

addr | Buffer to put the packed address into

Returns: Address family, Unknown on failure

bool supports (int family) | ### supports

[static]

Check if an address family is supported by the library

Parameters:

family | Family of the address to check

Returns: True if the address family is supported

int family (const String& addr) | ### family

[static]

Retrieve the family of an address

Parameters:

addr | The address to check

Returns: Address family

bool stringify (String& buf, struct sockaddr* addr) | ### stringify

[static]

Convert the host address to a String

Parameters:

buf | Destination buffer
addr | Socket address

Returns: True on success, false if address family is not supported

inline int unStringify (uint8_t* buf, const String& host, int family = Unknown) | ### unStringify

[static]

Put a host address to a buffer

Parameters:

buf | Destination buffer. It must be large enough to keep the address (4 bytes for IPv4, 16 bytes for IPv6)
host | The host address
family | Address family, set it to Unknown to detect

Returns: Address family, Unknown on failure

int copyAddr (uint8_t* buf, struct sockaddr* addr) | ### copyAddr

[static]

Copy a host address to a buffer

Parameters:

buf | Destination buffer. It must be large enough to keep the address (4 bytes for IPv4, 16 bytes for IPv6)
addr | The host address

Returns: Address family, Unknown on failure

inline unsigned int scopeId (struct sockaddr* addr) | ### scopeId

[static]

Retrieve the scope id value of an IPv6 address

Parameters:

addr | The address

Returns: The requested value (it may be 0), 0 if not available

inline bool scopeId (struct sockaddr* addr, unsigned int val) | ### scopeId

[static]

Set the scope id value of an IPv6 address

Parameters:

addr | Address to set
val | Value to set

Returns: True on success, false if not available

String& appendAddr (String& buf, const String& addr, int family = Unknown) | ### appendAddr

[static]

Append an address to a buffer

Parameters:

buf | Destination buffer
addr | Address to append
family | Address family, set it to Unknown to detect

Returns: Buffer address

inline String& appendTo (String& buf, const String& addr, int port, int family = Unknown) | ### appendTo

[static]

Append an address to a buffer in the form addr:port

Parameters:

buf | Destination buffer
addr | Address to append
port | Port to append
family | Address family, set it to Unknown to detect

Returns: Buffer address

inline String appendTo (const String& addr, int port, int family = Unknown) | ### appendTo

[static]

Append an address to a buffer in the form addr:port

Parameters:

addr | Address to append
port | Port to append
family | Address family, set it to Unknown to detect

Returns: A String with concatenated address and port

bool isNullAddr (const String& addr, int family = Unknown) | ### isNullAddr

[static]

Check if an address is empty or null

Parameters:

addr | Address to check
family | Address family, set it to Unknown to detect

Returns: True if the address is empty or '0.0.0.0' (IPv4) or '::' IPv6

void splitIface (const String& buf, String& addr, String* iface = 0) | ### splitIface

[static]

Split an interface from address An interface may be present in addr after a percent char (e.g. fe80::23%eth0) It is safe call this method with the same destination and source string

Parameters:

buf | Source buffer
addr | Destination buffer for address
iface | Optional pointer to be filled with interface name

void split (const String& buf, String& addr, int& port, bool portPresent = false) | ### split

[static]

Split an address into ip/port. Handled formats: addr, addr:port, [addr], [addr]:port It is safe call this method with the same destination and source string

Parameters:

buf | Source buffer
addr | Destination buffer for address
port | Destination port
portPresent | Set it to true if the port is always present after the last ':'. This will handle IPv6 addresses without square brackets and port present (e.g. fe80::23:5060 will split into addr=fe80::23 and port=5060)

inline const char* lookupFamily (int family) | ### lookupFamily

[static]

Retrieve address family name

Parameters:

family | Address family to retrieve

Returns: Address family name

const String& ipv4NullAddr () | ### ipv4NullAddr

[static]

Retrieve IPv4 null address

Returns: IPv4 null address (0.0.0.0)

const String& ipv6NullAddr () | ### ipv6NullAddr

[static]

Retrieve IPv6 null address

Returns: IPv6 null address (::)

const TokenDict* dictFamilyName () | ### dictFamilyName

[static]

Retrieve the family name dictionary

Returns: Pointer to family name dictionary

void stringify () | ### stringify

[protected virtual]

Convert the host address to a String stored in m_host

void updateAddr () | ### updateAddr

[protected const virtual]

Store host:port in m_addr

struct sockaddr* m_address | ### m_address

[protected]

socklen_t m_length | ### m_length

[protected]

String m_host | ### m_host

[protected]

mutable String m_addr | ### m_addr

[protected]

Generated by: paulc on bussard on Fri May 8 12:37:22 2015, using kdoc 2.0a54.