summaryrefslogtreecommitdiffstats
path: root/util/system/hostname.cpp
diff options
context:
space:
mode:
authorstanly <[email protected]>2022-02-10 16:46:49 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:46:49 +0300
commit6170310e8721e225f64ddabf7a7358253d7a1249 (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /util/system/hostname.cpp
parentcde218e65dfef5ce03a48d641fd8f7913cf17b2d (diff)
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'util/system/hostname.cpp')
-rw-r--r--util/system/hostname.cpp82
1 files changed, 41 insertions, 41 deletions
diff --git a/util/system/hostname.cpp b/util/system/hostname.cpp
index 56a322a790c..386f646d6bd 100644
--- a/util/system/hostname.cpp
+++ b/util/system/hostname.cpp
@@ -1,7 +1,7 @@
#include <util/memory/tempbuf.h>
#include <util/generic/singleton.h>
#include <util/generic/yexception.h>
-#include <util/network/ip.h>
+#include <util/network/ip.h>
#if defined(_unix_)
#include <unistd.h>
@@ -31,24 +31,24 @@ namespace {
TString HostName;
};
-
- struct TFQDNHostNameHolder {
- inline TFQDNHostNameHolder() {
- struct addrinfo hints;
- struct addrinfo* ais{nullptr};
- char buf[1024];
-
- memset(buf, 0, sizeof(buf));
- int res = gethostname(buf, sizeof(buf) - 1);
- if (res) {
- ythrow TSystemError() << "can not get hostname";
- }
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_UNSPEC;
- hints.ai_flags = AI_CANONNAME;
- res = getaddrinfo(buf, nullptr, &hints, &ais);
- if (res) {
+
+ struct TFQDNHostNameHolder {
+ inline TFQDNHostNameHolder() {
+ struct addrinfo hints;
+ struct addrinfo* ais{nullptr};
+ char buf[1024];
+
+ memset(buf, 0, sizeof(buf));
+ int res = gethostname(buf, sizeof(buf) - 1);
+ if (res) {
+ ythrow TSystemError() << "can not get hostname";
+ }
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_flags = AI_CANONNAME;
+ res = getaddrinfo(buf, nullptr, &hints, &ais);
+ if (res) {
if (res != EAI_NONAME) {
ythrow TSystemError() << "can not get FQDN (return code is " << res << ", hostname is \"" << buf << "\")";
}
@@ -56,12 +56,12 @@ namespace {
} else {
FQDNHostName = ais->ai_canonname;
freeaddrinfo(ais);
- }
- FQDNHostName.to_lower();
- }
-
+ }
+ FQDNHostName.to_lower();
+ }
+
TString FQDNHostName;
- };
+ };
}
const TString& HostName() {
@@ -71,26 +71,26 @@ const TString& HostName() {
const char* GetHostName() {
return HostName().data();
}
-
+
const TString& FQDNHostName() {
- return (Singleton<TFQDNHostNameHolder>())->FQDNHostName;
-}
-
-const char* GetFQDNHostName() {
+ return (Singleton<TFQDNHostNameHolder>())->FQDNHostName;
+}
+
+const char* GetFQDNHostName() {
return FQDNHostName().data();
-}
-
+}
+
bool IsFQDN(const TString& name) {
TString absName = name;
if (!absName.EndsWith('.')) {
- absName.append(".");
- }
-
- try {
- // ResolveHost() can't be used since it is ipv4-only, port is not important
- TNetworkAddress addr(absName, 0);
+ absName.append(".");
+ }
+
+ try {
+ // ResolveHost() can't be used since it is ipv4-only, port is not important
+ TNetworkAddress addr(absName, 0);
} catch (const TNetworkResolutionError&) {
- return false;
- }
- return true;
-}
+ return false;
+ }
+ return true;
+}