summaryrefslogtreecommitdiff
path: root/src/basic/in-addr-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-27 00:41:32 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-27 00:46:51 +0100
commitd830ebbdf67d8cb32d33d8fdd47cf467fd6d3815 (patch)
tree97152e692c31f5c578354736a3e0c8d514d25a81 /src/basic/in-addr-util.c
parent452b4e327d23b9e468d3198f4c91e8efd0b52a71 (diff)
resolved: never cache RRs originating from localhost
After all, this is likely a local DNS forwarder that caches anyway, hence there's no point in caching twice. Fixes #2038.
Diffstat (limited to 'src/basic/in-addr-util.c')
-rw-r--r--src/basic/in-addr-util.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c
index f4e24121e7..1f61b68efd 100644
--- a/src/basic/in-addr-util.c
+++ b/src/basic/in-addr-util.c
@@ -44,7 +44,7 @@ int in_addr_is_link_local(int family, const union in_addr_union *u) {
assert(u);
if (family == AF_INET)
- return (be32toh(u->in.s_addr) & 0xFFFF0000) == (169U << 24 | 254U << 16);
+ return (be32toh(u->in.s_addr) & UINT32_C(0xFFFF0000)) == (UINT32_C(169) << 24 | UINT32_C(254) << 16);
if (family == AF_INET6)
return IN6_IS_ADDR_LINKLOCAL(&u->in6);
@@ -52,6 +52,19 @@ int in_addr_is_link_local(int family, const union in_addr_union *u) {
return -EAFNOSUPPORT;
}
+int in_addr_is_localhost(int family, const union in_addr_union *u) {
+ assert(u);
+
+ if (family == AF_INET)
+ /* All of 127.x.x.x is localhost. */
+ return (be32toh(u->in.s_addr) & UINT32_C(0xFF000000)) == UINT32_C(127) << 24;
+
+ if (family == AF_INET)
+ return IN6_IS_ADDR_LOOPBACK(&u->in6);
+
+ return -EAFNOSUPPORT;
+}
+
int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b) {
assert(a);
assert(b);