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