From 056c398bdacb11775f163cbf51268bc79b6b612b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 25 Nov 2022 14:50:59 +0100 Subject: [PATCH] resolved: introduce common macro for 127.0.0.2 IP address --- src/nss-myhostname/nss-myhostname.c | 3 ++- src/resolve/resolved-dns-synthesize.c | 4 ++-- src/shared/resolve-util.h | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c index 120e76be45c..3af1d2f0c13 100644 --- a/src/nss-myhostname/nss-myhostname.c +++ b/src/nss-myhostname/nss-myhostname.c @@ -12,6 +12,7 @@ #include "local-addresses.h" #include "macro.h" #include "nss-util.h" +#include "resolve-util.h" #include "signal-util.h" #include "socket-util.h" #include "string-util.h" @@ -21,7 +22,7 @@ * IPv6 we use ::1 which unfortunately will not translate back to the * hostname but instead something like "localhost" or so. */ -#define LOCALADDRESS_IPV4 (htobe32(0x7F000002)) +#define LOCALADDRESS_IPV4 (htobe32(INADDR_LOCALADDRESS)) #define LOCALADDRESS_IPV6 &in6addr_loopback NSS_GETHOSTBYNAME_PROTOTYPES(myhostname); diff --git a/src/resolve/resolved-dns-synthesize.c b/src/resolve/resolved-dns-synthesize.c index 0a78078b7d9..51e06bb91ea 100644 --- a/src/resolve/resolved-dns-synthesize.c +++ b/src/resolve/resolved-dns-synthesize.c @@ -217,7 +217,7 @@ static int synthesize_system_hostname_rr(Manager *m, const DnsResourceKey *key, buffer[n++] = (struct local_address) { .family = AF_INET, .ifindex = LOOPBACK_IFINDEX, - .address.in.s_addr = htobe32(0x7F000002), + .address.in.s_addr = htobe32(INADDR_LOCALADDRESS), }; if (IN_SET(af, AF_INET6, AF_UNSPEC) && socket_ipv6_is_enabled()) @@ -245,7 +245,7 @@ static int synthesize_system_hostname_ptr(Manager *m, int af, const union in_add assert(address); assert(answer); - if (af == AF_INET && address->in.s_addr == htobe32(0x7F000002)) { + if (af == AF_INET && address->in.s_addr == htobe32(INADDR_LOCALADDRESS)) { /* Always map the IPv4 address 127.0.0.2 to the local hostname, in addition to "localhost": */ diff --git a/src/shared/resolve-util.h b/src/shared/resolve-util.h index e58173d864d..7c9008c7053 100644 --- a/src/shared/resolve-util.h +++ b/src/shared/resolve-util.h @@ -11,6 +11,9 @@ /* 127.0.0.54 in native endian (The IP address we listen on we only implement "proxy" mode) */ #define INADDR_DNS_PROXY_STUB ((in_addr_t) 0x7f000036U) +/* 127.0.0.2 is an address we always map to the local hostname. This is different from 127.0.0.1 which maps to "localhost" */ +#define INADDR_LOCALADDRESS ((in_addr_t) 0x7f000002U) + typedef enum DnsCacheMode DnsCacheMode; enum DnsCacheMode { -- 2.47.3