summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c15
-rw-r--r--src/shared/util.h2
2 files changed, 17 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index a1c8baf237..ceafa019a8 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -6732,3 +6732,18 @@ char *tempfn_random(const char *p) {
return t;
}
+
+/* make sure the hostname is not "localhost" */
+bool is_localhost(const char *hostname) {
+ assert(hostname);
+
+ /* This tries to identify local hostnames described in RFC6761
+ * plus the redhatism of .localdomain */
+
+ return streq(hostname, "localhost") ||
+ streq(hostname, "localhost.") ||
+ endswith(hostname, ".localhost") ||
+ endswith(hostname, ".localhost.") ||
+ endswith(hostname, ".localdomain") ||
+ endswith(hostname, ".localdomain.");
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 6ad43cd274..6d3791be7f 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -959,3 +959,5 @@ int fflush_and_check(FILE *f);
char *tempfn_xxxxxx(const char *p);
char *tempfn_random(const char *p);
+
+bool is_localhost(const char *hostname);