chiark / gitweb /
nss-myhostname: introduce is_gateway() similar to the existing is_hostname()
authorLennart Poettering <lennart@poettering.net>
Thu, 18 Dec 2014 00:44:34 +0000 (01:44 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 19 Dec 2014 01:07:42 +0000 (02:07 +0100)
src/nss-myhostname/nss-myhostname.c

index 2f76860..dcf7c1f 100644 (file)
 NSS_GETHOSTBYNAME_PROTOTYPES(myhostname);
 NSS_GETHOSTBYADDR_PROTOTYPES(myhostname);
 
+static bool is_gateway(const char *hostname) {
+        assert(hostname);
+
+        return streq(hostname, "gateway") ||
+               streq(hostname, "gateway.");
+}
+
 enum nss_status _nss_myhostname_gethostbyname4_r(
                 const char *name,
                 struct gaih_addrtuple **pat,
@@ -78,7 +85,7 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
                 canonical = "localhost";
                 local_address_ipv4 = htonl(INADDR_LOOPBACK);
 
-        } else if (streq(name, "gateway") || streq(name, "gateway.")) {
+        } else if (is_gateway(name)) {
 
                 n_addresses = local_gateways(NULL, 0, AF_UNSPEC, &addresses);
                 if (n_addresses <= 0) {
@@ -348,7 +355,7 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
                 canonical = "localhost";
                 local_address_ipv4 = htonl(INADDR_LOOPBACK);
 
-        } else if (streq(name, "gateway") || streq(name, "gateway.")) {
+        } else if (is_gateway(name)) {
 
                 n_addresses = local_gateways(NULL, 0, af, &addresses);
                 if (n_addresses <= 0) {