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