ucommon
Public Member Functions | Static Public Member Functions | Protected Attributes
ucommon::Socket::address Class Reference

A generic socket address class. More...

#include <socket.h>

Public Member Functions

void add (char *hostname, char *service=((void *) 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 (int family, char *address, int type=SOCK_STREAM, int protocol=0)
 Construct a socket address.
 address (int family, char *hostname, char *service=((void *) 0))
 Construct a socket address for an existing socket.
 address (char *host, char *service, int type=SOCK_STREAM)
 Construct a socket address list for a service.
 address (char *hostname, unsigned service=0)
 Construct a socket address from host and service.
 address ()
 Construct an empty address.
 address (address &reference)
 Copy constructor.
void clear (void)
 Clear current object.
void copy (struct addrinfo *address)
 Copy an existing addrinfo into our object.
struct sockaddr * find (struct sockaddr *addr)
 Find a specific socket address in our address list.
struct sockaddr * get (int family)
 Get the first socket address of specified family from our list.
struct sockaddr * getAddr (void)
 Get the first socket address in our address list.
int getfamily (void)
 Get the family of the first member in a list of services.
struct addrinfogetList (void)
 Get the full socket address list from the object.
unsigned insert (struct addrinfo *address)
 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 ()
 Test if the address list is valid.
 operator struct addrinfo * ()
 Get the full socket address list by casted reference.
 operator struct sockaddr * ()
 Get the first socket address by casted reference.
bool operator! ()
 Test if we have no address list.
struct addrinfooperator* ()
 Return the full socket address list by pointer reference.
unsigned remove (struct addrinfo *address)
 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 (char *hostname, char *service=((void *) 0), int type=SOCK_STREAM)
 Set the host addresses to form a new list.
void set (int family, char *address, int type=SOCK_STREAM, int protocol=0)
 Set an entry for host binding.
void set (struct sockaddr *address)
 Set an individual socket address for our address list.
void set (char *hostname, unsigned service=0)
 Set a socket address from host and service.
 ~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 addrinfolist

Detailed Description

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.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 343 of file socket.h.

Constructor & Destructor Documentation

ucommon::Socket::address::address ( int  family,
char *  address,
int  type = SOCK_STREAM,
int  protocol = 0 
)

Construct a socket address.

This is used to get an address to bind a socket interface to. The address can be specified as the ip address of the interface or as a "hostname". If a hostname is used, then family should be specified for clarity.

Parameters
familyof socket address. Needed when host names are used.
addressor hostname.
typeof socket (stream, dgram, etc).
protocolnumber of socket.
ucommon::Socket::address::address ( int  family,
char *  hostname,
char *  service = ((void *) 0) 
)

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.

Parameters
familyof hosts to filter by or AF_UNSPEC.
hostnameor ip address. The socket family is used for hostnames.
serviceport or name we are referencing or NULL.
ucommon::Socket::address::address ( char *  host,
char *  service,
int  type = SOCK_STREAM 
)

Construct a socket address list for a service.

Parameters
hostaddress for service.
servicename or port number.
typeof service, stream, dgram, etc.
ucommon::Socket::address::address ( char *  hostname,
unsigned  service = 0 
)

Construct a socket address from host and service.

This is primarily used to construct a list of potential service connections by pure port numbers or for host lookup only.

Parameters
hostnameor address to use.
serviceport or 0.
ucommon::Socket::address::address ( address reference)

Copy constructor.

Parameters
referenceto object to copy from.
ucommon::Socket::address::~address ( )

Destroy address.

Deallocate addrinfo structure.

Member Function Documentation

void ucommon::Socket::address::add ( char *  hostname,
char *  service = ((void *) 0),
int  type = SOCK_STREAM 
)

Append additional host addresses to our list.

Parameters
hostnameor address to resolve.
servicename or port number, or NULL if not used.
typeof socket (stream or dgram).
void ucommon::Socket::address::add ( sockaddr *  address)

Add an individual socket address to our address list.

Parameters
addressto add.
void ucommon::Socket::address::copy ( struct addrinfo address)

Copy an existing addrinfo into our object.

This is also used to support the copy constructor.

Parameters
addresslist to copy from.
static struct sockaddr* ucommon::Socket::address::dup ( struct sockaddr *  address)
staticread

Duplicate a socket address.

Parameters
addressto duplicate.
Returns
duplicate address object.
struct sockaddr* ucommon::Socket::address::find ( struct sockaddr *  addr)
read

Find a specific socket address in our address list.

Returns
matching address from list or NULL if not found.
struct sockaddr* ucommon::Socket::address::get ( int  family)
read

Get the first socket address of specified family from our list.

Parameters
familyto seek.
Returns
first socket address of family or NULL if none.
struct sockaddr* ucommon::Socket::address::getAddr ( void  )
read

Get the first socket address in our address list.

Returns
first socket address or NULL if none.
int ucommon::Socket::address::getfamily ( void  )

Get the family of the first member in a list of services.

Returns
family of first socket address or 0 if none.
struct addrinfo* ucommon::Socket::address::getList ( void  )
inlineread

Get the full socket address list from the object.

Returns
addrinfo list we resolved or NULL if none.

Definition at line 437 of file socket.h.

unsigned ucommon::Socket::address::insert ( struct addrinfo address)

Insert unique members from another socket address list to ours.

Parameters
addresslist to insert into list.
Returns
count of addresses added.
bool ucommon::Socket::address::insert ( struct sockaddr *  address)

Insert an individual socket address to our address list only if unique.

Parameters
addressto insert into list.
Returns
true if inserted, false if duplicate.
static struct sockaddr_in* ucommon::Socket::address::ipv4 ( struct sockaddr *  address)
staticread

Convert address object into ipv4 address.

Parameters
addressto convert.
Returns
new ipv4 address or NULL if not ipv4.
static struct sockaddr_in6* ucommon::Socket::address::ipv6 ( struct sockaddr *  address)
staticread

Convert address object into ipv6 address.

Parameters
addressto convert.
Returns
new ipv6 address or NULL if not ipv6.
ucommon::Socket::address::operator bool ( )
inline

Test if the address list is valid.

Returns
true if we have an address list.

Definition at line 458 of file socket.h.

ucommon::Socket::address::operator struct addrinfo * ( )
inline

Get the full socket address list by casted reference.

Returns
addrinfo list we resolved or NULL if none.

Definition at line 444 of file socket.h.

ucommon::Socket::address::operator struct sockaddr * ( )
inline

Get the first socket address by casted reference.

Returns
first socket address we resolved or NULL if none.

Definition at line 472 of file socket.h.

bool ucommon::Socket::address::operator! ( )
inline

Test if we have no address list.

Returns
true if we have no address list.

Definition at line 465 of file socket.h.

struct addrinfo* ucommon::Socket::address::operator* ( )
inlineread

Return the full socket address list by pointer reference.

Returns
addrinfo list we resolved or NULL if none.

Definition at line 451 of file socket.h.

unsigned ucommon::Socket::address::remove ( struct addrinfo address)

Remove members from another socket address list from ours.

Parameters
addresslist to remove from list.
Returns
count of addresses removed.
bool ucommon::Socket::address::remove ( struct sockaddr *  address)

Remove an individual socket address from our address list.

Parameters
addressto remove.
Returns
true if found and removed, false if not found.
void ucommon::Socket::address::set ( char *  hostname,
char *  service = ((void *) 0),
int  type = SOCK_STREAM 
)

Set the host addresses to form a new list.

Parameters
hostnameor address to resolve.
servicename or port number, or NULL if not used.
typeof socket (stream or dgram) to filter list by.
void ucommon::Socket::address::set ( int  family,
char *  address,
int  type = SOCK_STREAM,
int  protocol = 0 
)

Set an entry for host binding.

Parameters
familyof socket address. Needed when hostnames are used.
addressor hostname.
typeof socket (stream, dgram, etc).
protocolnumber of socket.
void ucommon::Socket::address::set ( struct sockaddr *  address)

Set an individual socket address for our address list.

Parameters
addressto add.
void ucommon::Socket::address::set ( char *  hostname,
unsigned  service = 0 
)

Set a socket address from host and service.

Parameters
hostnameor address to use.
serviceport or 0.

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