Encapsulate an internet address. More...
#include <InetAddr.h>
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... | |
InetAddr & | operator= (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... | |
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.
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.
host | The hostname |
port | The port of the remote service |
Error::BAD_DOMAIN_NAME | if 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".
endpoint | The remote addres ("hostname:port") |
Error::BAD_DOMAIN_NAME | if 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.
ip32 | The 32bit IP address |
port | The port of the remote service |
Error::BAD_DOMAIN_NAME | if the host cannot be resolved |
Definition at line 63 of file InetAddr.cc.
|
inline |
Constructor creates an internet address from a unix sockaddr_in structure.
addr | The unix sockaddr_in structure |
Error::BAD_DOMAIN_NAME | if the host cannot be resolved |
Definition at line 104 of file InetAddr.h.
void Hypertable::InetAddr::decode | ( | const uint8_t ** | bufp, |
size_t * | remainp | ||
) |
Reads serialized representation of object from a buffer.
bufp | Address of destination buffer pointer (advanced by call) |
remainp | Address of integer holding amount of remaining buffer |
Exception | with code Error::PROTOCOL_ERROR if version being decoded is greater than that returned by encoding_version(). |
Definition at line 261 of file InetAddr.cc.
|
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().
version | Encoding version |
bufp | Address of destination buffer pointer (advanced by call) |
remainp | Address of integer holding amount of serialized encoding remaining |
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().
bufp | Address 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.
|
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.
bufp | Address of destination buffer pointer (advanced by call) |
Encoding is as follows:
Encoding | Description |
---|---|
i8 | sizeof(sockaddr_in) |
i8 | Address family (sin_family) |
i16 | Port |
i16 | Address (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().
Definition at line 228 of file InetAddr.cc.
|
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.
Definition at line 288 of file InetAddr.cc.
|
private |
|
inline |
Returns a string with a dotted notation ("127.0.0.1:8080") including the port.
Definition at line 132 of file InetAddr.h.
|
static |
Formats a socket address.
addr | The address structure |
sep | The separator character between hostname and port |
Definition at line 208 of file InetAddr.cc.
|
inline |
Returns a string with a dotted notation ("127.0.0.1") without! the port.
Definition at line 136 of file InetAddr.h.
|
static |
Formats a socket address without the port.
addr | The address structure |
Definition at line 215 of file InetAddr.cc.
|
inline |
Returns a compact String representation ("0x2387646:80") including the port.
Definition at line 140 of file InetAddr.h.
|
static |
Returns a compact String representation ("0x2387646:80") including the port.
addr | The address structure |
sep | The separator character between hostname and port |
Definition at line 222 of file InetAddr.cc.
|
static |
Initialize a sockaddr_in structure from host:port.
addr | The sockaddr_in structure (or a pointer to an InetAddr) |
host | The hostname of the remote service |
port | The port of the remote service |
Definition at line 68 of file InetAddr.cc.
|
static |
Initialize addr from an endpoint string (host:port)
addr | The sockaddr_in structure (or a pointer to an InetAddr) |
addr_str | A string with the remote address |
Definition at line 191 of file InetAddr.cc.
|
static |
Initializes addr from an integer ip address and port.
addr | The sockaddr_in structure (or a pointer to an InetAddr) |
haddr | The remote host's address (IPv4) |
port | The remote host's port |
Definition at line 200 of file InetAddr.cc.
|
static |
Tests whether the input string in n.n.n.n format (base 10)
ip | - ipv4 string |
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.
|
inline |
Definition at line 118 of file InetAddr.h.
|
inline |
Definition at line 122 of file InetAddr.h.
|
inline |
Assigns a unix sockaddr_in address structure to this object.
Definition at line 107 of file InetAddr.h.
|
inline |
Definition at line 114 of file InetAddr.h.
|
static |
Parse an endpoint string in (host:port) format.
endpoint | Hostname or hostname:port of the endpoint |
defport | Default port if the hostname does not include a port |
Definition at line 181 of file InetAddr.cc.
|
inlinestatic |
Parse an endpoint string in (host:port) format.
endpoint | Hostname or hostname:port of the endpoint |
defport | Default port if the hostname does not include a port |
Definition at line 185 of file InetAddr.h.
|
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.
ip | The ipv4 string in dotted notiation or the number |
port | The port of the address |
addr | Returns the parsed address |
base | Base of the integer representation (default: 0, handle 0x) |
Definition at line 135 of file InetAddr.cc.