28 #ifndef Hypertable_Common_InetAddr_h
29 #define Hypertable_Common_InetAddr_h
36 #include <netinet/in.h>
46 : host(host), port(port) {
96 InetAddr(uint32_t ip32, uint16_t port);
109 memcpy(
this, &addr,
sizeof(sockaddr_in));
115 return (
bool)!memcmp(
this, &other,
sizeof(
InetAddr));
119 return !(*
this == other);
123 if (sin_family != other.sin_family)
124 return sin_family < other.sin_family;
125 if (sin_addr.s_addr != other.sin_addr.s_addr)
126 return sin_addr.s_addr < other.sin_addr.s_addr;
127 return sin_port < other.sin_port;
150 static bool initialize(sockaddr_in *addr,
const char *host, uint16_t port);
158 static bool initialize(sockaddr_in *addr,
const char *addr_str);
167 static bool initialize(sockaddr_in *addr, uint32_t haddr, uint16_t port);
198 static bool parse_ipv4(
const char *ip, uint16_t port, sockaddr_in &addr,
206 static bool is_ipv4(
const char *ip);
214 static String format(
const sockaddr_in &addr,
int sep =
':');
230 static String hex(
const sockaddr_in &addr,
int sep =
':');
244 void encode(uint8_t **bufp)
const;
252 void decode(
const uint8_t **bufp,
size_t *remainp);
283 void decode_internal(uint8_t version,
const uint8_t **bufp,
size_t *remainp);
290 std::ostream &
operator<<(std::ostream &,
const sockaddr_in &);
296 #endif // Hypertable_Common_InetAddr_h
String format_ipaddress()
Returns a string with a dotted notation ("127.0.0.1") without! the port.
std::string String
A String is simply a typedef to std::string.
static Endpoint parse_endpoint(const char *endpoint, int defport=0)
Parse an endpoint string in (host:port) format.
void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
bool operator<(const InetAddr &other) const
static Endpoint parse_endpoint(const String &endpoint, int defport=0)
Parse an endpoint string in (host:port) format.
String hex(int sep= ':')
Returns a compact String representation ("0x2387646:80") including the port.
uint8_t encoding_version() const
Returns encoding version.
Encapsulate an internet address.
static bool is_ipv4(const char *ip)
Tests whether the input string in n.n.n.n format (base 10)
InetAddr()
Constructor creates an empty internet address.
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
void encode(uint8_t **bufp) const
Writes serialized representation of object to a buffer.
String format(int sep= ':') const
Returns a string with a dotted notation ("127.0.0.1:8080") including the port.
bool operator==(const InetAddr &other) const
static bool initialize(sockaddr_in *addr, const char *host, uint16_t port)
Initialize a sockaddr_in structure from host:port.
Endpoint(const String &host, uint16_t port)
InetAddr & operator=(const sockaddr_in &addr)
Assigns a unix sockaddr_in address structure to this object.
size_t encoded_length_internal() const
Returns internal serialized length.
size_t encoded_length() const
Returns serialized object length.
void legacy_decode(const uint8_t **bufp, size_t *remainp)
Deserializes object from legacy serialization format.
void encode_internal(uint8_t **bufp) const
Writes serialized representation of object to a buffer.
A String class based on std::string.
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 sockad...
InetAddr(const sockaddr_in &addr)
Constructor creates an internet address from a unix sockaddr_in structure.
bool operator!=(const InetAddr &other) const
High-level entry point to a service; wraps a host:port pair.