| ... | @@ -869,21 +869,21 @@ fn linuxLookupName( | ... | @@ -869,21 +869,21 @@ fn linuxLookupName( |
| 869 | } else { | 869 | } else { |
| 870 | try linuxLookupNameFromHosts(addrs, canon, name, family, port); | 870 | try linuxLookupNameFromHosts(addrs, canon, name, family, port); |
| 871 | if (addrs.items.len == 0) { | 871 | if (addrs.items.len == 0) { |
| 872 | try linuxLookupNameFromDnsSearch(addrs, canon, name, family, port); | 872 | // RFC 6761 Section 6.3.3 |
| 873 | } | | |
| 874 | if (addrs.items.len == 0) { | | |
| 875 | // RFC 6761 Section 6.3 | | |
| 876 | // Name resolution APIs and libraries SHOULD recognize localhost | 873 | // Name resolution APIs and libraries SHOULD recognize localhost |
| 877 | // names as special and SHOULD always return the IP loopback address | 874 | // names as special and SHOULD always return the IP loopback address |
| 878 | // for address queries and negative responses for all other query | 875 | // for address queries and negative responses for all other query |
| 879 | // types. | 876 | // types. |
| 880 | | 877 | |
| 881 | // Check for equal to "localhost" or ends in ".localhost" | 878 | // Check for equal to "localhost(.)" or ends in ".localhost(.)" |
| 882 | if (mem.endsWith(u8, name, "localhost") and (name.len == "localhost".len or name[name.len - "localhost".len] == '.')) { | 879 | const localhost = if (name[name.len - 1] == '.') "localhost." else "localhost"; |
| | 880 | if (mem.endsWith(u8, name, localhost) and (name.len == localhost.len or name[name.len - localhost.len] == '.')) { |
| 883 | try addrs.append(LookupAddr{ .addr = .{ .in = Ip4Address.parse("127.0.0.1", port) catch unreachable } }); | 881 | try addrs.append(LookupAddr{ .addr = .{ .in = Ip4Address.parse("127.0.0.1", port) catch unreachable } }); |
| 884 | try addrs.append(LookupAddr{ .addr = .{ .in6 = Ip6Address.parse("::1", port) catch unreachable } }); | 882 | try addrs.append(LookupAddr{ .addr = .{ .in6 = Ip6Address.parse("::1", port) catch unreachable } }); |
| 885 | return; | 883 | return; |
| 886 | } | 884 | } |
| | 885 | |
| | 886 | try linuxLookupNameFromDnsSearch(addrs, canon, name, family, port); |
| 887 | } | 887 | } |
| 888 | } | 888 | } |
| 889 | } else { | 889 | } else { |