]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: introduce common macro for 127.0.0.2 IP address 25530/head
authorLennart Poettering <lennart@poettering.net>
Fri, 25 Nov 2022 13:50:59 +0000 (14:50 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 25 Nov 2022 16:41:55 +0000 (17:41 +0100)
src/nss-myhostname/nss-myhostname.c
src/resolve/resolved-dns-synthesize.c
src/shared/resolve-util.h

index 120e76be45c013f7fe46d4cfc62cd7751e3888cc..3af1d2f0c13fbac994ab6d233b33392e18ae6db7 100644 (file)
@@ -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);
index 0a78078b7d970051840037e51bcf539c3c7878cb..51e06bb91ea0debd50730915687b1ec1de47f613 100644 (file)
@@ -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": */
 
index e58173d864dad8976d2b4d4e66b6f6fded29b381..7c9008c7053f80b1f8b5d839cce59b9d8de3bcdb 100644 (file)
@@ -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 {