# SocketAddr Class Reference

A socket address holder. More...

`#include <yateclass.h>`

Inheritance diagram for SocketAddr:

List of all members.

## Public Member Functions

| SocketAddr ()
| SocketAddr (const SocketAddr &value)
| SocketAddr (int family)
| SocketAddr (const struct sockaddr *addr, socklen_t len=0)
virtual | ~SocketAddr ()
SocketAddr & | operator= (const SocketAddr &value)
bool | operator== (const SocketAddr &other) const
bool | operator!= (const SocketAddr &other) const
void | clear ()
bool | assign (int family)
void | assign (const struct sockaddr *addr, socklen_t len=0)
bool | local (const SocketAddr &remote)
bool | valid () const
bool | null () const
int | family () const
const String & | host () const
virtual bool | host (const String &name)
int | port () const
bool | port (int newport)
sockaddr * | address () const
socklen_t | length () const

## Static Public Member Functions

static bool | supports (int family)

## Protected Member Functions

virtual void | stringify ()

## Protected Attributes

sockaddr * | m_address
socklen_t | m_length
String | m_host

## Detailed Description

A socket address holder.

Wrapper class to keep a socket address

## Constructor & Destructor Documentation

SocketAddr | ( |  | ) | `[inline]`

Default constructor of an empty address

SocketAddr | ( | const SocketAddr & | value | ) | `[inline]`

Copy constructor

Parameters:

  | value | Address to copy

SocketAddr | ( | int | family | ) |

Constructor of a null address

Parameters:

  | family | Family of the address to create

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

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

virtual ~SocketAddr | ( |  | ) | `[virtual]`

Destructor that frees and zeroes out everything

## Member Function Documentation

SocketAddr& operator= | ( | const SocketAddr & | value | ) | `[inline]`

Assignment operator

Parameters:

  | value | Address to copy

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

Equality comparation operator

Parameters:

  | other | Address to compare to

Returns:
  True if the addresses are equal

bool operator!= | ( | const SocketAddr & | other | ) | const`[inline]`

Inequality comparation operator

Parameters:

  | other | Address to compare to

Returns:
  True if the addresses are different

void clear | ( |  | ) |

Clears up the address, frees the memory

bool assign | ( | int | family | ) |

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` |
| ) |  |  |

Assigns a new address

Parameters:

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

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

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

bool valid | ( |  | ) | const`[inline]`

Check if a non-null address is held

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

bool null | ( |  | ) | const`[inline]`

Check if a null address is held

Returns:
  True if a null address is held

int family | ( |  | ) | const`[inline]`

Get the family of the stored address

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

const String& host | ( |  | ) | const`[inline]`

Get the host of this address

Returns:
  Host name as String

virtual bool host | ( | const String & | name | ) | `[virtual]`

Set the hostname of this address

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

int port | ( |  | ) | const

Get the port of the stored address (if supported)

Returns:
  Port number of the socket address or zero

bool port | ( | int | newport | ) |

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

struct sockaddr* address | ( |  | ) | const`[inline, read]`

Get the contained socket address

Returns:
  A pointer to the socket address

socklen_t length | ( |  | ) | const`[inline]`

Get the length of the address

Returns:
  Length of the stored address

static bool supports | ( | int | family | ) | `[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

virtual void stringify | ( |  | ) | `[protected, virtual]`

Convert the host address to a String stored in m_host

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

- yateclass.h