mirror of
https://github.com/ziglang/zig.git
synced 2025-12-16 03:03:09 +00:00
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.
This commit is contained in:
parent
c8a7dc22b1
commit
0a03d68594
@ -869,21 +869,21 @@ fn linuxLookupName(
|
|||||||
} else {
|
} else {
|
||||||
try linuxLookupNameFromHosts(addrs, canon, name, family, port);
|
try linuxLookupNameFromHosts(addrs, canon, name, family, port);
|
||||||
if (addrs.items.len == 0) {
|
if (addrs.items.len == 0) {
|
||||||
try linuxLookupNameFromDnsSearch(addrs, canon, name, family, port);
|
// RFC 6761 Section 6.3.3
|
||||||
}
|
|
||||||
if (addrs.items.len == 0) {
|
|
||||||
// RFC 6761 Section 6.3
|
|
||||||
// Name resolution APIs and libraries SHOULD recognize localhost
|
// Name resolution APIs and libraries SHOULD recognize localhost
|
||||||
// names as special and SHOULD always return the IP loopback address
|
// names as special and SHOULD always return the IP loopback address
|
||||||
// for address queries and negative responses for all other query
|
// for address queries and negative responses for all other query
|
||||||
// types.
|
// types.
|
||||||
|
|
||||||
// Check for equal to "localhost" or ends in ".localhost"
|
// 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] == '.')) {
|
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 = .{ .in = Ip4Address.parse("127.0.0.1", port) catch unreachable } });
|
||||||
try addrs.append(LookupAddr{ .addr = .{ .in6 = Ip6Address.parse("::1", port) catch unreachable } });
|
try addrs.append(LookupAddr{ .addr = .{ .in6 = Ip6Address.parse("::1", port) catch unreachable } });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try linuxLookupNameFromDnsSearch(addrs, canon, name, family, port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user