clan::SocketName Class Reference - ClanLib SDK
Description: clan::SocketName Class Reference

Public Member Functions | List of all members
clan::SocketName Class Reference
clanNetwork Socket

Socket name; container class for an IP address and port. More...

`#include <socket_name.h>`

## Public Member Functions
| SocketName ()
| Constructs a new socket name.
| SocketName (const std::string &address, const std::string &port)
| Constructs a SocketName.
| SocketName (const std::string &port)
| Constructs a SocketName.
void | from_sockaddr (int domain, sockaddr *addr, int len)
| Get the socket name from a C sockets sockaddr structure.
std::string | get_address () const
| Returns the address part of the socket name.
std::string | get_port () const
| Returns the port part of the socket name.
std::string | lookup_hostname () const
| Perform a DNS lookup, if needed, for the hostname.
std::string | lookup_ipv4 () const
| Perform a DNS lookup, if needed, for the IP v4 address.
bool | operator< (const SocketName &other_instance) const
| Returns true if the other address is less.
bool | operator== (const SocketName &other_instance) const
| Returns true if objects are the same.
bool | operator> (const SocketName &other_instance) const
| Returns true if the other address is greater.
void | set_address (const std::string &address)
| Set the IP address.
void | set_name (const std::string &hostname, const std::string &port)
| Set the socket name using a hostname and port.
void | set_port (const std::string &port)
| Set the IP port.
SocketName | to_hostname ()
| Create socket name that uses the hostname as its address.
SocketName | to_ipv4 ()
| Create socket name that uses the IP v4 address as its address.
void | to_sockaddr (int domain, sockaddr *addr, int len) const
| Fill the socket name into a C sockets sockaddr structure.

## Detailed Description

Socket name; container class for an IP address and port.

## Constructor & Destructor Documentation

## ◆ SocketName() [1/3]

clan::SocketName::SocketName | ( |  | ) |

Constructs a new socket name.

If no address is specified, the socket address will default to INADDR_ANY. If no port is specified, it will default to port 0.

Referenced by operator<(), operator==(), operator>(), to_hostname(), and to_ipv4().

## ◆ SocketName() [2/3]

clan::SocketName::SocketName | ( | const std::string & | port | ) |

Constructs a SocketName.

Parameters

  port | = String

## ◆ SocketName() [3/3]

clan::SocketName::SocketName | ( | const std::string & | address,
|  | const std::string & | port )

Constructs a SocketName.

Parameters

  address | = String
  port | = String

## Member Function Documentation

## ◆ from_sockaddr()

void clan::SocketName::from_sockaddr | ( | int | domain,
|  | sockaddr * | addr,
|  | int | len )

Get the socket name from a C sockets sockaddr structure.

## ◆ get_address()

std::string clan::SocketName::get_address | ( |  | ) | const

Returns the address part of the socket name.

## ◆ get_port()

std::string clan::SocketName::get_port | ( |  | ) | const

Returns the port part of the socket name.

## ◆ lookup_hostname()

std::string clan::SocketName::lookup_hostname | ( |  | ) | const

Perform a DNS lookup, if needed, for the hostname.

## ◆ lookup_ipv4()

std::string clan::SocketName::lookup_ipv4 | ( |  | ) | const

Perform a DNS lookup, if needed, for the IP v4 address.

## ◆ operator<()

bool clan::SocketName::operator< | ( | const SocketName & | other_instance | ) | const

Returns true if the other address is less.

This is used for sorting purposes (eg. if you use a std::map<SocketName, Socket>), and sorts the address based on lowest IP number address.

References SocketName().

## ◆ operator==()

bool clan::SocketName::operator== | ( | const SocketName & | other_instance | ) | const

Returns true if objects are the same.

References SocketName().

## ◆ operator>()

bool clan::SocketName::operator> | ( | const SocketName & | other_instance | ) | const

Returns true if the other address is greater.

This is used for sorting purposes (eg. if you use a std::map<SocketName, Socket>), and sorts the address based on lowest IP number address.

References SocketName().

## ◆ set_address()

void clan::SocketName::set_address | ( | const std::string & | address | ) |

Set the IP address.

## ◆ set_name()

void clan::SocketName::set_name | ( | const std::string & | hostname,
|  | const std::string & | port )

Set the socket name using a hostname and port.

Parameters

  hostname | Can be an IPv4 dotted-quad, hostname or a valid IPv6 address.
  port | Port number.

## ◆ set_port()

void clan::SocketName::set_port | ( | const std::string & | port | ) |

Set the IP port.

## ◆ to_hostname()

SocketName clan::SocketName::to_hostname | ( |  | ) |

Create socket name that uses the hostname as its address.

References SocketName().

## ◆ to_ipv4()

SocketName clan::SocketName::to_ipv4 | ( |  | ) |

Create socket name that uses the IP v4 address as its address.

References SocketName().

## ◆ to_sockaddr()

void clan::SocketName::to_sockaddr | ( | int | domain,
|  | sockaddr * | addr,
|  | int | len ) const

Fill the socket name into a C sockets sockaddr structure.

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

- socket_name.h