libcommonc++  0.7
SocketAddress Class Reference

A socket endpoint network address. More...

#include <SocketAddress.h++>

Public Member Functions

 SocketAddress ()
 Construct a new, null SocketAddress. More...
 
 SocketAddress (const InetAddress &address, uint16_t port)
 Construct a new SocketAddress for a given IP address and port number. More...
 
 SocketAddress (const struct sockaddr &other)
 Construct a new SocketAddress for a given sockaddr structure. More...
 
 SocketAddress (const struct sockaddr_in &other)
 Construct a new SocketAddress for a given sockaddr_in structure. More...
 
 SocketAddress (const SocketAddress &other)
 Copy constructor. More...
 
 ~SocketAddress ()
 Destructor. More...
 
SocketAddressoperator= (const struct sockaddr &other)
 Assignment operator. More...
 
SocketAddressoperator= (const struct sockaddr_in &other)
 Assignment operator. More...
 
SocketAddressoperator= (const SocketAddress &other)
 Assignment operator. More...
 
InetAddress getAddress () const
 Get the IP address for this address. More...
 
void setAddress (const InetAddress &address)
 Set the IP address for this address. More...
 
void setHost (const String &host)
 Set the hostname for this address. More...
 
uint16_t getPort () const
 Get the port number for this address. More...
 
void setPort (uint16_t port)
 Set the port number for this address. More...
 
void setSocketAddress (const struct sockaddr &addr)
 Set the address from a sockaddr structure. More...
 
sockaddr getSocketAddress () const
 Get the address as a sockaddr structure. More...
 
void reset ()
 Reset the address to a null address. More...
 
 operator sockaddr * ()
 Cast operator. More...
 
 operator sockaddr_in * ()
 Cast operator. More...
 
String toString () const
 Get a String representation for this address. More...
 
bool operator== (const SocketAddress &other) const
 Equality operator. More...
 
bool operator!= (const SocketAddress &other) const
 Inequality operator. More...
 

Detailed Description

A socket endpoint network address.

The address consists of an IP address and a port number.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ SocketAddress() [1/5]

Construct a new, null SocketAddress.

◆ SocketAddress() [2/5]

SocketAddress ( const InetAddress address,
uint16_t  port 
)

Construct a new SocketAddress for a given IP address and port number.

Parameters
addressThe IP address.
portThe port number.

◆ SocketAddress() [3/5]

SocketAddress ( const struct sockaddr &  other)
explicit

Construct a new SocketAddress for a given sockaddr structure.

◆ SocketAddress() [4/5]

SocketAddress ( const struct sockaddr_in &  other)
explicit

Construct a new SocketAddress for a given sockaddr_in structure.

◆ SocketAddress() [5/5]

SocketAddress ( const SocketAddress other)

Copy constructor.

◆ ~SocketAddress()

Destructor.

Member Function Documentation

◆ getAddress()

InetAddress getAddress ( ) const

Get the IP address for this address.

◆ getPort()

uint16_t getPort ( ) const
inline

Get the port number for this address.

◆ getSocketAddress()

sockaddr getSocketAddress ( ) const
inline

Get the address as a sockaddr structure.

◆ operator sockaddr *()

operator sockaddr * ( )
inline

Cast operator.

◆ operator sockaddr_in *()

operator sockaddr_in * ( )
inline

Cast operator.

◆ operator!=()

bool operator!= ( const SocketAddress other) const
inline

Inequality operator.

◆ operator=() [1/3]

SocketAddress & operator= ( const struct sockaddr &  other)

Assignment operator.

◆ operator=() [2/3]

SocketAddress & operator= ( const struct sockaddr_in &  other)

Assignment operator.

◆ operator=() [3/3]

SocketAddress & operator= ( const SocketAddress other)

Assignment operator.

◆ operator==()

bool operator== ( const SocketAddress other) const

Equality operator.

◆ reset()

void reset ( )

Reset the address to a null address.

◆ setAddress()

void setAddress ( const InetAddress address)

Set the IP address for this address.

◆ setHost()

void setHost ( const String host)

Set the hostname for this address.

Parameters
hostThe host, as a dot-separated IP address or DNS name.
Exceptions
HostNotFoundExceptionIf the hostname could not be resolved.

◆ setPort()

void setPort ( uint16_t  port)
inline

Set the port number for this address.

◆ setSocketAddress()

void setSocketAddress ( const struct sockaddr &  addr)
inline

Set the address from a sockaddr structure.

◆ toString()

String toString ( ) const

Get a String representation for this address.

Member Data Documentation

◆ _insaddr

struct sockaddr_in _insaddr

◆ _saddr

struct sockaddr _saddr

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