| ... | ... | @@ -19,9 +19,6 @@ pub const Address = extern union { |
| 19 | 19 | in6: Ip6Address, |
| 20 | 20 | un: if (has_unix_sockets) os.sockaddr_un else void, |
| 21 | 21 | |
| 22 | | // TODO this crashed the compiler. https://github.com/ziglang/zig/issues/3512 |
| 23 | | //pub const localhost = initIp4(parseIp4("127.0.0.1") catch unreachable, 0); |
| 24 | | |
| 25 | 22 | /// Parse the given IP address string into an Address value. |
| 26 | 23 | /// It is recommended to use `resolveIp` instead, to handle |
| 27 | 24 | /// IPv6 link-local unix addresses. |
| ... | ... | @@ -839,6 +836,20 @@ fn linuxLookupName( |
| 839 | 836 | if (addrs.items.len == 0) { |
| 840 | 837 | try linuxLookupNameFromDnsSearch(addrs, canon, name, family, port); |
| 841 | 838 | } |
| 839 | if (addrs.items.len == 0) { |
| 840 | // RFC 6761 Section 6.3 |
| 841 | // Name resolution APIs and libraries SHOULD recognize localhost |
| 842 | // names as special and SHOULD always return the IP loopback address |
| 843 | // for address queries and negative responses for all other query |
| 844 | // types. |
| 845 | |
| 846 | // Check for equal to "localhost" or ends in ".localhost" |
| 847 | if (mem.endsWith(u8, name, "localhost") and (name.len == "localhost".len or name[name.len - "localhost".len] == '.')) { |
| 848 | try addrs.append(LookupAddr{ .addr = .{ .in = Ip4Address.parse("127.0.0.1", port) catch unreachable } }); |
| 849 | try addrs.append(LookupAddr{ .addr = .{ .in6 = Ip6Address.parse("::1", port) catch unreachable } }); |
| 850 | return; |
| 851 | } |
| 852 | } |
| 842 | 853 | } |
| 843 | 854 | } else { |
| 844 | 855 | try canon.resize(0); |