aboutsummaryrefslogtreecommitdiff
path: root/lib/std/net.zig
diff options
context:
space:
mode:
authorpraschke <stel@comfy.monster>2023-01-10 15:26:01 +0000
committerAndrew Kelley <andrew@ziglang.org>2023-01-10 18:09:07 -0500
commit3ab43988c1cc5e22c84faccd1816df6e8094d9a3 (patch)
treea18a20aa1c5f1896918c580853b1c5dde7215521 /lib/std/net.zig
parent9b807f9c171e9e5998447ab3846d29de921cf8dd (diff)
downloadzig-3ab43988c1cc5e22c84faccd1816df6e8094d9a3.tar.gz
zig-3ab43988c1cc5e22c84faccd1816df6e8094d9a3.zip
std.net: check for localhost names before asking DNS
the old implementation asks DNS before checking if it shouldn't. additionally, it did not catch absolute 'localhost.' names.
Diffstat (limited to 'lib/std/net.zig')
-rw-r--r--lib/std/net.zig12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/std/net.zig b/lib/std/net.zig
index aa51176184..da4cf30046 100644
--- a/lib/std/net.zig
+++ b/lib/std/net.zig
@@ -882,21 +882,21 @@ fn linuxLookupName(
} else {
try linuxLookupNameFromHosts(addrs, canon, name, family, port);
if (addrs.items.len == 0) {
- try linuxLookupNameFromDnsSearch(addrs, canon, name, family, port);
- }
- if (addrs.items.len == 0) {
- // RFC 6761 Section 6.3
+ // RFC 6761 Section 6.3.3
// Name resolution APIs and libraries SHOULD recognize localhost
// names as special and SHOULD always return the IP loopback address
// for address queries and negative responses for all other query
// types.
- // Check for equal to "localhost" or ends in ".localhost"
- if (mem.endsWith(u8, name, "localhost") and (name.len == "localhost".len or name[name.len - "localhost".len] == '.')) {
+ // Check for equal to "localhost(.)" or ends in ".localhost(.)"
+ const localhost = if (name[name.len - 1] == '.') "localhost." else "localhost";
+ if (mem.endsWith(u8, name, localhost) and (name.len == localhost.len or name[name.len - localhost.len] == '.')) {
try addrs.append(LookupAddr{ .addr = .{ .in = Ip4Address.parse("127.0.0.1", port) catch unreachable } });
try addrs.append(LookupAddr{ .addr = .{ .in6 = Ip6Address.parse("::1", port) catch unreachable } });
return;
}
+
+ try linuxLookupNameFromDnsSearch(addrs, canon, name, family, port);
}
}
} else {