summaryrefslogtreecommitdiffstats
path: root/src/common/address_helper.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/common/address_helper.cc
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/common/address_helper.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/common/address_helper.cc b/src/common/address_helper.cc
new file mode 100644
index 00000000..cdb8591f
--- /dev/null
+++ b/src/common/address_helper.cc
@@ -0,0 +1,39 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * address_helper.cc
+ *
+ * Created on: Oct 27, 2013
+ * Author: matt
+ */
+
+#include <netdb.h>
+#include <regex>
+
+#include "common/address_helper.h"
+
+// decode strings like "tcp://<host>:<port>"
+int entity_addr_from_url(entity_addr_t *addr /* out */, const char *url)
+{
+ std::regex expr("(tcp|rdma)://([^:]*):([\\d]+)");
+ std::cmatch m;
+
+ if (std::regex_match(url, m, expr)) {
+ string host(m[2].first, m[2].second);
+ string port(m[3].first, m[3].second);
+ addrinfo hints;
+ // FIPS zeroization audit 20191115: this memset is fine.
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ addrinfo *res;
+ if (!getaddrinfo(host.c_str(), nullptr, &hints, &res)) {
+ addr->set_sockaddr((sockaddr*)res->ai_addr);
+ addr->set_port(std::atoi(port.c_str()));
+ freeaddrinfo(res);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+