]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * address_helper.cc | |
5 | * | |
6 | * Created on: Oct 27, 2013 | |
7 | * Author: matt | |
8 | */ | |
9 | ||
10 | #include <netdb.h> | |
11 | #include <regex> | |
12 | ||
13 | #include "common/address_helper.h" | |
14 | ||
15 | // decode strings like "tcp://<host>:<port>" | |
16 | int entity_addr_from_url(entity_addr_t *addr /* out */, const char *url) | |
17 | { | |
18 | std::regex expr("(tcp|rdma)://([^:]*):([\\d]+)"); | |
19 | std::cmatch m; | |
20 | ||
21 | if (std::regex_match(url, m, expr)) { | |
22 | string host(m[2].first, m[2].second); | |
23 | string port(m[3].first, m[3].second); | |
24 | addrinfo hints; | |
25 | // FIPS zeroization audit 20191115: this memset is fine. | |
26 | memset(&hints, 0, sizeof(hints)); | |
27 | hints.ai_family = PF_UNSPEC; | |
28 | addrinfo *res; | |
29 | if (!getaddrinfo(host.c_str(), nullptr, &hints, &res)) { | |
30 | addr->set_sockaddr((sockaddr*)res->ai_addr); | |
31 | addr->set_port(std::atoi(port.c_str())); | |
32 | freeaddrinfo(res); | |
33 | return 0; | |
34 | } | |
35 | } | |
36 | ||
37 | return 1; | |
38 | } | |
39 |