3 #include "hmbdc/Exception.hpp" 10 #include <netinet/in.h> 11 #include <arpa/inet.h> 14 #include <sys/socket.h> 16 namespace hmbdc {
namespace comm {
namespace inet {
20 explicit Endpoint(std::string
const& ipPort) {
24 std::replace(std::begin(s), std::end(s),
':',
' ');
26 if (2 != sscanf(s.c_str(),
"%s %" SCNu16, ip, &port)) {
27 HMBDC_THROW(std::runtime_error,
"incorrect address " << ipPort);
29 memset(&v, 0,
sizeof(v));
30 v.sin_family = AF_INET;
31 v.sin_addr.s_addr = inet_addr(ip);
32 v.sin_port = htons(port);
36 Endpoint(std::string
const& ip, uint16_t port) {
37 memset(&v, 0,
sizeof(v));
38 v.sin_family = AF_INET;
39 v.sin_addr.s_addr = inet_addr(ip.c_str());
40 v.sin_port = htons(port);
43 bool operator == (
Endpoint const& other)
const {
44 return memcmp(&v, &other.v,
sizeof(v)) == 0;
47 std::istream& operator >> (std::istream& is,
Endpoint& ep) {
Definition: Endpoint.hpp:17