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