A generic socket address class. More...
#include <socket.h>
Public Member Functions | |
void | add (sockaddr *address) |
Add an individual socket address to our address list. | |
void | add (const char *hostname, const char *service=NULL, int type=SOCK_STREAM) |
Append additional host addresses to our list. | |
address (const address &reference) | |
Copy constructor. | |
address () | |
Construct an empty address. | |
address (const char *hostname, unsigned service=0) | |
Construct a socket address from host and service. | |
address (const char *host, const char *service, int type=SOCK_STREAM) | |
Construct a socket address list for a service. | |
address (int family, const char *hostname, const char *service=NULL) | |
Construct a socket address for an existing socket. | |
address (int family, const char *address, int type=SOCK_STREAM, int protocol=0) | |
Construct a socket address. | |
void | clear (void) |
Clear current object. | |
void | copy (const struct addrinfo *address) |
Copy an existing addrinfo into our object. | |
int | family (void) const |
Get the family of the first member in a list of services. | |
struct sockaddr * | find (const struct sockaddr *addr) const |
Find a specific socket address in our address list. | |
struct sockaddr * | get (int family) const |
Get the first socket address of specified family from our list. | |
struct sockaddr * | get (void) const |
Get the first socket address in our address list. | |
struct sockaddr * | getAddr (void) const |
struct addrinfo * | getList (void) const |
Get the full socket address list from the object. | |
bool | insert (struct sockaddr *address) |
Insert an individual socket address to our address list only if unique. | |
unsigned | insert (struct addrinfo *address) |
Insert unique members from another socket address list to ours. | |
operator bool () const | |
Test if the address list is valid. | |
operator struct addrinfo * () const | |
Get the full socket address list by casted reference. | |
operator struct sockaddr * () const | |
Get the first socket address by casted reference. | |
operator struct sockaddr_in * () const | |
operator struct sockaddr_in6 * () const | |
bool | operator! () const |
Test if we have no address list. | |
struct sockaddr * | operator() (int family) const |
struct sockaddr * | operator() (void) const |
struct addrinfo * | operator* () const |
Return the full socket address list by pointer reference. | |
bool | remove (struct sockaddr *address) |
Remove an individual socket address from our address list. | |
unsigned | remove (struct addrinfo *address) |
Remove members from another socket address list from ours. | |
void | set (const char *hostname, unsigned service=0) |
Set a socket address from host and service. | |
void | set (struct sockaddr *address) |
Set an individual socket address for our address list. | |
void | set (int family, const char *address, int type=SOCK_STREAM, int protocol=0) |
Set an entry for host binding. | |
void | set (const char *hostname, const char *service=NULL, int type=SOCK_STREAM) |
Set the host addresses to form a new list. | |
~address () | |
Destroy address. | |
Static Public Member Functions | |
static struct sockaddr * | dup (struct sockaddr *address) |
Duplicate a socket address. | |
static struct sockaddr_in * | ipv4 (struct sockaddr *address) |
Convert address object into ipv4 address. | |
static struct sockaddr_in6 * | ipv6 (struct sockaddr *address) |
Convert address object into ipv6 address. | |
Protected Attributes | |
struct addrinfo * | list |
A generic socket address class.
This class uses the addrinfo list to store socket multiple addresses in a protocol and family independent manner. Hence, this address class can be used for ipv4 and ipv6 sockets, for assigning connections to multiple hosts, etc. The address class will call the resolver when passed host names.
Definition at line 343 of file socket.h.
ucommon::Socket::address::address | ( | int | family, | |
const char * | address, | |||
int | type = SOCK_STREAM , |
|||
int | protocol = 0 | |||
) |
ucommon::Socket::address::address | ( | int | family, | |
const char * | hostname, | |||
const char * | service = NULL | |||
) |
Construct a socket address for an existing socket.
This can be the name of a host or to perform a lookup in a domain for a service. Family can be used to restrict the set of results returned, however since things like connecto() already filter by family and create will use family from the addrinfo, in most cases AF_UNSPEC can be used. This may be depreciated in favor of the constructor that matches a set() method.
family | of hosts to filter by or AF_UNSPEC. | |
hostname | or ip address. The socket family is used for hostnames. | |
service | port or name we are referencing or NULL. |
ucommon::Socket::address::address | ( | const char * | host, | |
const char * | service, | |||
int | type = SOCK_STREAM | |||
) |
ucommon::Socket::address::address | ( | const char * | hostname, | |
unsigned | service = 0 | |||
) |
ucommon::Socket::address::address | ( | const address & | reference | ) |
Copy constructor.
reference | to object to copy from. |
ucommon::Socket::address::~address | ( | ) |
Destroy address.
Deallocate addrinfo structure.
void ucommon::Socket::address::add | ( | sockaddr * | address | ) |
void ucommon::Socket::address::add | ( | const char * | hostname, | |
const char * | service = NULL , |
|||
int | type = SOCK_STREAM | |||
) |
Append additional host addresses to our list.
hostname | or address to resolve. | |
service | name or port number, or NULL if not used. | |
type | of socket (stream or dgram). |
void ucommon::Socket::address::copy | ( | const struct addrinfo * | address | ) |
Copy an existing addrinfo into our object.
This is also used to support the copy constructor.
address | list to copy from. |
static struct sockaddr* ucommon::Socket::address::dup | ( | struct sockaddr * | address | ) | [static, read] |
int ucommon::Socket::address::family | ( | void | ) | const |
Get the family of the first member in a list of services.
struct sockaddr* ucommon::Socket::address::find | ( | const struct sockaddr * | addr | ) | const [read] |
struct sockaddr* ucommon::Socket::address::get | ( | int | family | ) | const [read] |
struct sockaddr* ucommon::Socket::address::get | ( | void | ) | const [read] |
struct addrinfo* ucommon::Socket::address::getList | ( | void | ) | const [inline, read] |
bool ucommon::Socket::address::insert | ( | struct sockaddr * | address | ) |
unsigned ucommon::Socket::address::insert | ( | struct addrinfo * | address | ) |
static struct sockaddr_in* ucommon::Socket::address::ipv4 | ( | struct sockaddr * | address | ) | [static, read] |
static struct sockaddr_in6* ucommon::Socket::address::ipv6 | ( | struct sockaddr * | address | ) | [static, read] |
ucommon::Socket::address::operator bool | ( | ) | const [inline] |
ucommon::Socket::address::operator struct addrinfo * | ( | ) | const [inline] |
ucommon::Socket::address::operator struct sockaddr * | ( | ) | const [inline] |
bool ucommon::Socket::address::operator! | ( | ) | const [inline] |
struct addrinfo* ucommon::Socket::address::operator* | ( | ) | const [inline, read] |
bool ucommon::Socket::address::remove | ( | struct sockaddr * | address | ) |
unsigned ucommon::Socket::address::remove | ( | struct addrinfo * | address | ) |
void ucommon::Socket::address::set | ( | const char * | hostname, | |
unsigned | service = 0 | |||
) |
void ucommon::Socket::address::set | ( | struct sockaddr * | address | ) |
void ucommon::Socket::address::set | ( | int | family, | |
const char * | address, | |||
int | type = SOCK_STREAM , |
|||
int | protocol = 0 | |||
) |
void ucommon::Socket::address::set | ( | const char * | hostname, | |
const char * | service = NULL , |
|||
int | type = SOCK_STREAM | |||
) |
Set the host addresses to form a new list.
hostname | or address to resolve. | |
service | name or port number, or NULL if not used. | |
type | of socket (stream or dgram) to filter list by. |