summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-07-02 13:41:31 +0200
committerLennart Poettering <lennart@poettering.net>2014-07-02 13:41:31 +0200
commitfecc80c1ba2eed9dadb9a10c15508c356bcc5fc1 (patch)
tree8db82ae690416827c910683432c9746f365acf2e /src/shared
parent9a00f57a5ba7ed431e6bac8d8b36518708503b4e (diff)
util: generalize is_localhost() and use it everywhere where applicable
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);