A generic socket address class. More...
#include <socket.h>
Public Member Functions | |
void | add (const char *hostname, const char *service=NULL, int family=0, int type=SOCK_STREAM) |
Append additional host addresses to our list. | |
void | add (sockaddr *address) |
Add an individual socket address to our address list. | |
address (const char *hostname, unsigned service=0, int family=AF_INET) | |
Construct a socket address from host and service. | |
address (int family, const char *address, int type=SOCK_STREAM, int protocol=0) | |
Construct a socket address. | |
address () | |
Construct an empty address. | |
address (Socket &socket, const char *hostname, const char *service=NULL) | |
Construct a socket address for an existing socket. | |
address (socket_t socket, const char *hostname, const char *service=NULL) | |
Construct a socket address for a socket descriptor. | |
address (const address &reference) | |
Copy constructor. | |
void | clear (void) |
Clear current object. | |
void | copy (const struct addrinfo *address) |
Copy an existing addrinfo into our object. | |
struct sockaddr * | find (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 * | getAddr (void) const |
Get the first socket address in our address list. | |
int | getfamily (void) const |
Get the family of a socket address by first entry. | |
struct addrinfo * | getList (void) const |
Get the full socket address list from the object. | |
unsigned | insert (struct addrinfo *address, int family=0) |
Insert unique members from another socket address list to ours. | |
bool | insert (struct sockaddr *address) |
Insert an individual socket address to our address list only if unique. | |
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. | |
bool | operator! () const |
Test if we have no address list. | |
struct addrinfo * | operator* () const |
Return the full socket address list by pointer reference. | |
unsigned | remove (struct addrinfo *address, int family=0) |
Remove members from another socket address list from ours. | |
bool | remove (struct sockaddr *address) |
Remove an individual socket address from 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 family=0, int type=SOCK_STREAM) |
Set the host addresses to form a new list. | |
void | set (const char *hostname, unsigned service=0, int family=AF_INET) |
Set a socket address from host and service. | |
void | set (struct sockaddr *address) |
Set an individual socket address for our address 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 335 of file socket.h.
ucc::Socket::address::address | ( | int | family, | |
const char * | address, | |||
int | type = SOCK_STREAM , |
|||
int | protocol = 0 | |||
) |
Construct a socket address.
address | or hostname. | |
family | of socket address. Needed when hostnames are used. | |
type | of socket (stream, dgram, etc). | |
protocol | number of socket. |
ucc::Socket::address::address | ( | Socket & | socket, | |
const char * | hostname, | |||
const char * | service = NULL | |||
) |
Construct a socket address for an existing socket.
socket | to use for family of socket address. | |
hostname | or ip address. The socket family is used for hostnames. | |
service | port or name we are referencing or NULL. |
ucc::Socket::address::address | ( | socket_t | socket, | |
const char * | hostname, | |||
const char * | service = NULL | |||
) |
Construct a socket address for a socket descriptor.
socket | descriptor to use for family. | |
hostname | or address to use. | |
service | port or name we are referencing or NULL. |
ucc::Socket::address::address | ( | const char * | hostname, | |
unsigned | service = 0 , |
|||
int | family = AF_INET | |||
) |
Construct a socket address from host and service.
hostname | or address to use. | |
service | port or 0. | |
family | of socket address. |
ucc::Socket::address::address | ( | const address & | reference | ) |
Copy constructor.
reference | to object to copy from. |
ucc::Socket::address::~address | ( | ) |
Destroy address.
Deallocate addrinfo structure.
void ucc::Socket::address::add | ( | const char * | hostname, | |
const char * | service = NULL , |
|||
int | family = 0 , |
|||
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. | |
family | of hostname. | |
type | of socket. |
void ucc::Socket::address::add | ( | sockaddr * | address | ) |
Add an individual socket address to our address list.
address | to add. |
void ucc::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* ucc::Socket::address::dup | ( | struct sockaddr * | address | ) | [static, read] |
Duplicate a socket address.
address | to duplicate. |
struct sockaddr* ucc::Socket::address::find | ( | struct sockaddr * | addr | ) | const [read] |
Find a specific socket address in our address list.
struct sockaddr* ucc::Socket::address::get | ( | int | family | ) | const [read] |
Get the first socket address of specified family from our list.
family | to seek. |
struct sockaddr* ucc::Socket::address::getAddr | ( | void | ) | const [read] |
Get the first socket address in our address list.
int ucc::Socket::address::getfamily | ( | void | ) | const |
Get the family of a socket address by first entry.
struct addrinfo* ucc::Socket::address::getList | ( | void | ) | const [inline, read] |
bool ucc::Socket::address::insert | ( | struct sockaddr * | address | ) |
Insert an individual socket address to our address list only if unique.
address | to insert into list. |
unsigned ucc::Socket::address::insert | ( | struct addrinfo * | address, | |
int | family = 0 | |||
) |
Insert unique members from another socket address list to ours.
address | list to insert into list. | |
family | to scan for or 0 for all. |
static struct sockaddr_in* ucc::Socket::address::ipv4 | ( | struct sockaddr * | address | ) | [static, read] |
Convert address object into ipv4 address.
address | to convert. |
static struct sockaddr_in6* ucc::Socket::address::ipv6 | ( | struct sockaddr * | address | ) | [static, read] |
Convert address object into ipv6 address.
address | to convert. |
ucc::Socket::address::operator bool | ( | ) | const [inline] |
ucc::Socket::address::operator struct addrinfo * | ( | ) | const [inline] |
ucc::Socket::address::operator struct sockaddr * | ( | ) | const [inline] |
bool ucc::Socket::address::operator! | ( | ) | const [inline] |
struct addrinfo* ucc::Socket::address::operator* | ( | ) | const [inline, read] |
bool ucc::Socket::address::remove | ( | struct sockaddr * | address | ) |
Remove an individual socket address from our address list.
address | to remove. |
unsigned ucc::Socket::address::remove | ( | struct addrinfo * | address, | |
int | family = 0 | |||
) |
Remove members from another socket address list from ours.
address | list to remove from list. | |
family | to scan for or 0 for all. |
void ucc::Socket::address::set | ( | int | family, | |
const char * | address, | |||
int | type = SOCK_STREAM , |
|||
int | protocol = 0 | |||
) |
Set an entry for host binding.
address | or hostname. | |
family | of socket address. Needed when hostnames are used. | |
type | of socket (stream, dgram, etc). | |
protocol | number of socket. |
void ucc::Socket::address::set | ( | const char * | hostname, | |
const char * | service = NULL , |
|||
int | family = 0 , |
|||
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. | |
family | of hostname. | |
type | of socket. |
void ucc::Socket::address::set | ( | const char * | hostname, | |
unsigned | service = 0 , |
|||
int | family = AF_INET | |||
) |
Set a socket address from host and service.
hostname | or address to use. | |
service | port or 0. | |
family | of socket address. |
void ucc::Socket::address::set | ( | struct sockaddr * | address | ) |
Set an individual socket address for our address list.
address | to add. |