0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
Hypertable::InetAddr Class Reference

Encapsulate an internet address. More...

#include <InetAddr.h>

Inheritance diagram for Hypertable::InetAddr:
Inheritance graph
[legend]
Collaboration diagram for Hypertable::InetAddr:
Collaboration graph
[legend]

Public Member Functions

 InetAddr ()
 Constructor creates an empty internet address. More...
 
 InetAddr (const String &host, uint16_t port)
 Constructor creates an internet address from an endpoint; resolves the hostname to an IP address. More...
 
 InetAddr (const String &endpoint)
 Constructor creates an internet address from an endpoint encoded as "hostname:port". More...
 
 InetAddr (uint32_t ip32, uint16_t port)
 Constructor creates an internet address from a 32bit IP address. More...
 
 InetAddr (const sockaddr_in &addr)
 Constructor creates an internet address from a unix sockaddr_in structure. More...
 
InetAddroperator= (const sockaddr_in &addr)
 Assigns a unix sockaddr_in address structure to this object. More...
 
bool operator== (const InetAddr &other) const
 
bool operator!= (const InetAddr &other) const
 
bool operator< (const InetAddr &other) const
 
String format (int sep= ':') const
 Returns a string with a dotted notation ("127.0.0.1:8080") including the port. More...
 
String format_ipaddress ()
 Returns a string with a dotted notation ("127.0.0.1") without! the port. More...
 
String hex (int sep= ':')
 Returns a compact String representation ("0x2387646:80") including the port. More...
 
size_t encoded_length () const
 Returns serialized object length. More...
 
void encode (uint8_t **bufp) const
 Writes serialized representation of object to a buffer. More...
 
void decode (const uint8_t **bufp, size_t *remainp)
 Reads serialized representation of object from a buffer. More...
 
void legacy_decode (const uint8_t **bufp, size_t *remainp)
 Deserializes object from legacy serialization format. More...
 

Static Public Member Functions

static bool initialize (sockaddr_in *addr, const char *host, uint16_t port)
 Initialize a sockaddr_in structure from host:port. More...
 
static bool initialize (sockaddr_in *addr, const char *addr_str)
 Initialize addr from an endpoint string (host:port) More...
 
static bool initialize (sockaddr_in *addr, uint32_t haddr, uint16_t port)
 Initializes addr from an integer ip address and port. More...
 
static Endpoint parse_endpoint (const char *endpoint, int defport=0)
 Parse an endpoint string in (host:port) format. More...
 
static Endpoint parse_endpoint (const String &endpoint, int defport=0)
 Parse an endpoint string in (host:port) format. More...
 
static bool parse_ipv4 (const char *ip, uint16_t port, sockaddr_in &addr, int base=0)
 Parses an ipv4 address string in dotted notiation ("n.n.n.n") or as a number and initializes a sockaddr_in structure with the address. More...
 
static bool is_ipv4 (const char *ip)
 Tests whether the input string in n.n.n.n format (base 10) More...
 
static String format (const sockaddr_in &addr, int sep= ':')
 Formats a socket address. More...
 
static String format_ipaddress (const sockaddr_in &addr)
 Formats a socket address without the port. More...
 
static String hex (const sockaddr_in &addr, int sep= ':')
 Returns a compact String representation ("0x2387646:80") including the port. More...
 

Private Member Functions

uint8_t encoding_version () const
 Returns encoding version. More...
 
size_t encoded_length_internal () const
 Returns internal serialized length. More...
 
void encode_internal (uint8_t **bufp) const
 Writes serialized representation of object to a buffer. More...
 
void decode_internal (uint8_t version, const uint8_t **bufp, size_t *remainp)
 Reads serialized representation of object from a buffer. More...
 

Detailed Description

Encapsulate an internet address.

Note, deriving from sockaddr_in is just a path of least resistance and should ,e changed to aggregation if we decide to support ipv6

Definition at line 66 of file InetAddr.h.

Constructor & Destructor Documentation

Hypertable::InetAddr::InetAddr ( )

Constructor creates an empty internet address.

Definition at line 48 of file InetAddr.cc.

Hypertable::InetAddr::InetAddr ( const String host,
uint16_t  port 
)

Constructor creates an internet address from an endpoint; resolves the hostname to an IP address.

Parameters
hostThe hostname
portThe port of the remote service
Exceptions
Error::BAD_DOMAIN_NAMEif the host cannot be resolved

Definition at line 53 of file InetAddr.cc.

Hypertable::InetAddr::InetAddr ( const String endpoint)

Constructor creates an internet address from an endpoint encoded as "hostname:port".

Parameters
endpointThe remote addres ("hostname:port")
Exceptions
Error::BAD_DOMAIN_NAMEif the host cannot be resolved

Definition at line 58 of file InetAddr.cc.

Hypertable::InetAddr::InetAddr ( uint32_t  ip32,
uint16_t  port 
)

Constructor creates an internet address from a 32bit IP address.

Parameters
ip32The 32bit IP address
portThe port of the remote service
Exceptions
Error::BAD_DOMAIN_NAMEif the host cannot be resolved

Definition at line 63 of file InetAddr.cc.

Hypertable::InetAddr::InetAddr ( const sockaddr_in &  addr)
inline

Constructor creates an internet address from a unix sockaddr_in structure.

Parameters
addrThe unix sockaddr_in structure
Exceptions
Error::BAD_DOMAIN_NAMEif the host cannot be resolved

Definition at line 104 of file InetAddr.h.

Member Function Documentation

void Hypertable::InetAddr::decode ( const uint8_t **  bufp,
size_t *  remainp 
)

Reads serialized representation of object from a buffer.

Parameters
bufpAddress of destination buffer pointer (advanced by call)
remainpAddress of integer holding amount of remaining buffer
See also
encode() for encoding format
Exceptions
Exceptionwith code Error::PROTOCOL_ERROR if version being decoded is greater than that returned by encoding_version().

Definition at line 261 of file InetAddr.cc.

void Hypertable::InetAddr::decode_internal ( uint8_t  version,
const uint8_t **  bufp,
size_t *  remainp 
)
private

Reads serialized representation of object from a buffer.

This function is to be overridden by derived classes and should decode the object per-se as encoded with encode_internal().

Parameters
versionEncoding version
bufpAddress of destination buffer pointer (advanced by call)
remainpAddress of integer holding amount of serialized encoding remaining
See also
encode_internal() for encoding format

Definition at line 311 of file InetAddr.cc.

void Hypertable::InetAddr::encode ( uint8_t **  bufp) const

Writes serialized representation of object to a buffer.

This function encodes a serialized representation of the object, starting with a header that includes the encoding version and the serialized length of the object. After the header, the object per-se is encoded with encode_internal().

Parameters
bufpAddress of destination buffer pointer (advanced by call)

Encoding is as follows:

Encoding Description
1 byte Encoding version as returned by encoding_version()
vint Length of encoded object as returned by encoded_length_internal()
variable Object encoded with encode_internal()

Definition at line 255 of file InetAddr.cc.

void Hypertable::InetAddr::encode_internal ( uint8_t **  bufp) const
private

Writes serialized representation of object to a buffer.

This function is to be overridden by derived classes and should encode the object per-se.

Parameters
bufpAddress of destination buffer pointer (advanced by call)

Encoding is as follows:

Encoding Description
i8sizeof(sockaddr_in)
i8Address family (sin_family)
i16Port
i16Address (sin_addr.s_addr)

Definition at line 304 of file InetAddr.cc.

size_t Hypertable::InetAddr::encoded_length ( ) const

Returns serialized object length.

Returns the serialized length of the object as encoded by encode().

See also
encode() for encoding format
Returns
Overall serialized object length

Definition at line 228 of file InetAddr.cc.

size_t Hypertable::InetAddr::encoded_length_internal ( ) const
private

Returns internal serialized length.

This function is to be overridden by derived classes and should return the length of the the serialized object per-se.

Returns
Internal serialized length
See also
encode_internal() for encoding format

Definition at line 288 of file InetAddr.cc.

uint8_t Hypertable::InetAddr::encoding_version ( ) const
private

Returns encoding version.

Returns
Encoding version

Definition at line 284 of file InetAddr.cc.

String Hypertable::InetAddr::format ( int  sep = ':') const
inline

Returns a string with a dotted notation ("127.0.0.1:8080") including the port.

Definition at line 132 of file InetAddr.h.

String Hypertable::InetAddr::format ( const sockaddr_in &  addr,
int  sep = ':' 
)
static

Formats a socket address.

Parameters
addrThe address structure
sepThe separator character between hostname and port
Returns
A string with the formatted "hostname:port" tuple

Definition at line 208 of file InetAddr.cc.

String Hypertable::InetAddr::format_ipaddress ( )
inline

Returns a string with a dotted notation ("127.0.0.1") without! the port.

Definition at line 136 of file InetAddr.h.

String Hypertable::InetAddr::format_ipaddress ( const sockaddr_in &  addr)
static

Formats a socket address without the port.

Parameters
addrThe address structure
Returns
A string with the formatted "hostname:port" tuple

Definition at line 215 of file InetAddr.cc.

String Hypertable::InetAddr::hex ( int  sep = ':')
inline

Returns a compact String representation ("0x2387646:80") including the port.

Definition at line 140 of file InetAddr.h.

String Hypertable::InetAddr::hex ( const sockaddr_in &  addr,
int  sep = ':' 
)
static

Returns a compact String representation ("0x2387646:80") including the port.

Parameters
addrThe address structure
sepThe separator character between hostname and port
Returns
A string with the formatted tuple

Definition at line 222 of file InetAddr.cc.

bool Hypertable::InetAddr::initialize ( sockaddr_in *  addr,
const char *  host,
uint16_t  port 
)
static

Initialize a sockaddr_in structure from host:port.

Parameters
addrThe sockaddr_in structure (or a pointer to an InetAddr)
hostThe hostname of the remote service
portThe port of the remote service
Returns
true on success, otherwise false

Definition at line 68 of file InetAddr.cc.

bool Hypertable::InetAddr::initialize ( sockaddr_in *  addr,
const char *  addr_str 
)
static

Initialize addr from an endpoint string (host:port)

Parameters
addrThe sockaddr_in structure (or a pointer to an InetAddr)
addr_strA string with the remote address
Returns
true on success, otherwise false

Definition at line 191 of file InetAddr.cc.

bool Hypertable::InetAddr::initialize ( sockaddr_in *  addr,
uint32_t  haddr,
uint16_t  port 
)
static

Initializes addr from an integer ip address and port.

Parameters
addrThe sockaddr_in structure (or a pointer to an InetAddr)
haddrThe remote host's address (IPv4)
portThe remote host's port
Returns
true on success, otherwise false

Definition at line 200 of file InetAddr.cc.

bool Hypertable::InetAddr::is_ipv4 ( const char *  ip)
static

Tests whether the input string in n.n.n.n format (base 10)

Parameters
ip- ipv4 string
Returns
true if it's an address in dotted notation, otherwise false

Definition at line 113 of file InetAddr.cc.

void Hypertable::InetAddr::legacy_decode ( const uint8_t **  bufp,
size_t *  remainp 
)

Deserializes object from legacy serialization format.

Definition at line 277 of file InetAddr.cc.

bool Hypertable::InetAddr::operator!= ( const InetAddr other) const
inline

Definition at line 118 of file InetAddr.h.

bool Hypertable::InetAddr::operator< ( const InetAddr other) const
inline

Definition at line 122 of file InetAddr.h.

InetAddr& Hypertable::InetAddr::operator= ( const sockaddr_in &  addr)
inline

Assigns a unix sockaddr_in address structure to this object.

Definition at line 107 of file InetAddr.h.

bool Hypertable::InetAddr::operator== ( const InetAddr other) const
inline

Definition at line 114 of file InetAddr.h.

Endpoint Hypertable::InetAddr::parse_endpoint ( const char *  endpoint,
int  defport = 0 
)
static

Parse an endpoint string in (host:port) format.

Parameters
endpointHostname or hostname:port of the endpoint
defportDefault port if the hostname does not include a port
Returns
Endpoint tuple

Definition at line 181 of file InetAddr.cc.

static Endpoint Hypertable::InetAddr::parse_endpoint ( const String endpoint,
int  defport = 0 
)
inlinestatic

Parse an endpoint string in (host:port) format.

Parameters
endpointHostname or hostname:port of the endpoint
defportDefault port if the hostname does not include a port
Returns
Endpoint tuple

Definition at line 185 of file InetAddr.h.

bool Hypertable::InetAddr::parse_ipv4 ( const char *  ip,
uint16_t  port,
sockaddr_in &  addr,
int  base = 0 
)
static

Parses an ipv4 address string in dotted notiation ("n.n.n.n") or as a number and initializes a sockaddr_in structure with the address.

Parameters
ipThe ipv4 string in dotted notiation or the number
portThe port of the address
addrReturns the parsed address
baseBase of the integer representation (default: 0, handle 0x)
Returns
true on success, otherwise false

Definition at line 135 of file InetAddr.cc.


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