A generic socket address class. More...
#include <socket.h>
Public Member Functions | |
address (int family, const char *address, int type=SOCK_STREAM, int protocol=0) | |
Construct a socket address. | |
address (Socket &socket, const char *hostname, const char *service=((void *) 0)) | |
Construct a socket address for an existing socket. | |
address (socket_t socket, const char *hostname, const char *service=((void *) 0)) | |
Construct a socket address for a socket descriptor. | |
address (const char *hostname, unsigned service=0, int family=0) | |
Construct a socket address from host and service. | |
address () | |
Construct an empty address. | |
address (const address &reference) | |
Copy constructor. | |
~address () | |
Destroy address. | |
struct sockaddr * | getAddr (void) |
Get the first socket address in our address list. | |
struct sockaddr * | get (int family) |
Get the first socket address of specified family from our list. | |
int | getfamily (void) |
Get the family of a socket address by first entry. | |
struct sockaddr * | find (struct sockaddr *addr) |
Find a specific socket address in our address list. | |
struct addrinfo * | getList (void) |
Get the full socket address list from the object. | |
operator struct addrinfo * () | |
Get the full socket address list by casted reference. | |
struct addrinfo * | operator* () |
Return the full socket address list by pointer reference. | |
operator bool () | |
Test if the address list is valid. | |
bool | operator! () |
Test if we have no address list. | |
operator struct sockaddr * () | |
Get the first socket address by casted reference. | |
void | clear (void) |
Clear current object. | |
void | set (const char *hostname, const char *service=((void *) 0), int family=0, int type=SOCK_STREAM) |
Set the host addresses to form a new list. | |
void | add (const char *hostname, const char *service=((void *) 0), int family=0, int type=SOCK_STREAM) |
Append additional host addresses to our list. | |
void | set (int family, const char *address, int type=SOCK_STREAM, int protocol=0) |
Set an entry for host binding. | |
void | add (sockaddr *address) |
Add an individual socket address to our address list. | |
bool | remove (struct sockaddr *address) |
Remove an individual socket address from our address list. | |
bool | insert (struct sockaddr *address) |
Insert an individual socket address to our address list only if unique. | |
unsigned | insert (struct addrinfo *address, int family=0) |
Insert unique members from another socket address list to ours. | |
unsigned | remove (struct addrinfo *address, int family=0) |
Remove members from another socket address list from ours. | |
void | copy (const struct addrinfo *address) |
Copy an existing addrinfo into our object. | |
void | set (struct sockaddr *address) |
Set an individual socket address for our address list. | |
void | set (const char *hostname, unsigned service=0, int family=0) |
Set a socket address from host and service. | |
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 307 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 = ((void *) 0) | |||
) |
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 = ((void *) 0) | |||
) |
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 = 0 | |||
) |
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 | ( | sockaddr * | address | ) |
Add an individual socket address to our address list.
address | to add. |
void ucc::Socket::address::add | ( | const char * | hostname, | |
const char * | service = ((void *) 0) , |
|||
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::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 | ) | [read] |
Find a specific socket address in our address list.
struct sockaddr* ucc::Socket::address::get | ( | int | family | ) | [read] |
Get the first socket address of specified family from our list.
family | to seek. |
struct sockaddr* ucc::Socket::address::getAddr | ( | void | ) | [read] |
Get the first socket address in our address list.
int ucc::Socket::address::getfamily | ( | void | ) |
Get the family of a socket address by first entry.
struct addrinfo* ucc::Socket::address::getList | ( | void | ) | [inline, read] |
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. |
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. |
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 | ( | ) | [inline] |
ucc::Socket::address::operator struct addrinfo * | ( | ) | [inline] |
ucc::Socket::address::operator struct sockaddr * | ( | ) | [inline] |
bool ucc::Socket::address::operator! | ( | ) | [inline] |
struct addrinfo* ucc::Socket::address::operator* | ( | ) | [inline, read] |
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. |
bool ucc::Socket::address::remove | ( | struct sockaddr * | address | ) |
Remove an individual socket address from our address list.
address | to remove. |
void ucc::Socket::address::set | ( | const char * | hostname, | |
unsigned | service = 0 , |
|||
int | family = 0 | |||
) |
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. |
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 = ((void *) 0) , |
|||
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. |