From fecc80c1ba2eed9dadb9a10c15508c356bcc5fc1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 2 Jul 2014 13:41:31 +0200 Subject: util: generalize is_localhost() and use it everywhere where applicable --- src/shared/util.c | 15 +++++++++++++++ src/shared/util.h | 2 ++ 2 files changed, 17 insertions(+) (limited to 'src/shared') 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); -- cgit v1.2.3-54-g00ecf