zig
zig copied to clipboard
std.net.getAddressList may return TemporaryNameServerFailure
Zig Version
0.11.0-dev.1783+436e99d13
Steps to Reproduce and Observed Behavior
test "resolve address" {
const allocator = std.testing.allocator;
const port = 3478;
_ = try std.net.getAddressList(allocator, "ziglang.org", port);
}
/usr/lib/zig/lib/std/net.zig:45:9: 0x21e7ca in parseIp (test)
return error.InvalidIPAddressFormat;
^
/usr/lib/zig/lib/std/net.zig:75:29: 0x21e3b9 in parseExpectingFamily (test)
os.AF.UNSPEC => return parseIp(name, port),
^
/usr/lib/zig/lib/std/net.zig:1392:48: 0x22a6ef in linuxLookupNameFromDns (test)
if (ap[0].len < 4 or (ap[0][3] & 15) == 2) return error.TemporaryNameServerFailure;
^
/usr/lib/zig/lib/std/net.zig:1336:5: 0x22ba4c in linuxLookupNameFromDnsSearch (test)
return linuxLookupNameFromDns(addrs, canon, name, family, rc, port);
^
/usr/lib/zig/lib/std/net.zig:974:17: 0x22c807 in linuxLookupName (test)
try linuxLookupNameFromDnsSearch(addrs, canon, name, family, port);
^
/usr/lib/zig/lib/std/net.zig:911:9: 0x2369f1 in getAddressList (test)
try linuxLookupName(&lookup_addrs, &canon, name, family, flags, port);
^
/home/hequn/router/zig/ztun/src/packet.zig:439:9: 0x2373ff in test.resolve address (test)
_ = try std.net.getAddressList(allocator, "ziglang.org", port);
^
# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 223.5.5.5
nameserver fe80::ca47:8cff:fe00:6%enp3s0
# ip -6 addr
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
inet6 fe80::f949:b3aa:9aa:f548/64 scope link noprefixroute
valid_lft forever preferred_lft forever
If i add a debug print in address eql funtion, it print result of
net eql a 223.5.5.5:53 b [::ffff:223.5.5.5]:53
net eql a [fe80::ca47:8cff:fe00:6]:53 b [::ffff:223.5.5.5]:53
net eql a 223.5.5.5:53 b [::ffff:223.5.5.5]:53
net eql a [fe80::ca47:8cff:fe00:6]:53 b [::ffff:223.5.5.5]:53
net eql a 223.5.5.5:53 b [::ffff:223.5.5.5]:53
net eql a [fe80::ca47:8cff:fe00:6]:53 b [::ffff:223.5.5.5]:53
net eql a 223.5.5.5:53 b [::ffff:223.5.5.5]:53
net eql a [fe80::ca47:8cff:fe00:6]:53 b [::ffff:223.5.5.5]:53
Test [4/5] test.resolve address... FAIL (TemporaryNameServerFailure)
If i add the following check, test passed.
pub fn eql(a: Address, b: Address) bool {
const a_bytes = @ptrCast([*]const u8, &a.any)[0..a.getOsSockLen()];
const b_bytes = @ptrCast([*]const u8, &b.any)[0..b.getOsSockLen()];
+ if (a.any.family == os.AF.INET6 and b.any.family == os.AF.INET) {
+ return mem.eql(u8, a.in6.sa.addr[12..16], @ptrCast(*const [4]u8, &b.in.sa.addr));
+ } else if (a.any.family == os.AF.INET and b.any.family == os.AF.INET6 ) {
+ return mem.eql(u8, b.in6.sa.addr[12..16], @ptrCast(*const [4]u8, &a.in.sa.addr));
+ }
return mem.eql(u8, a_bytes, b_bytes);
}
Expected Behavior
test pass.