4 * Created on: Oct 27, 2013
10 #include "common/address_helper.h"
11 #include "boost/regex.hpp"
15 // decode strings like "tcp://<host>:<port>"
16 int entity_addr_from_url(entity_addr_t *addr /* out */, const char *url)
18 using namespace boost;
21 regex expr("(tcp|rdma)://([^:]*):([\\d]+)");
24 if (regex_match(url, m, expr)) {
25 string host(m[2].first, m[2].second);
26 string port(m[3].first, m[3].second);
28 memset(&hints, 0, sizeof(hints));
29 hints.ai_family = PF_UNSPEC;
31 int error = getaddrinfo(host.c_str(), NULL, &hints, &res);
33 addr->set_sockaddr((sockaddr*)res->ai_addr);
34 addr->set_port(std::atoi(port.c_str()));