diff --git a/lib/std/net.zig b/lib/std/net.zig index 1794f36c8..5b1037633 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -294,7 +294,7 @@ pub fn connectUnixSocket(path: []const u8) !fs.File { if (path.len > @typeOf(sock_addr.un.path).len) return error.NameTooLong; mem.copy(u8, sock_addr.un.path[0..], path); const size = @intCast(u32, @sizeOf(os.sa_family_t) + path.len); - try os.connect(sockfd, &sock_addr, size); + try os.connect(sockfd, sock_addr, size); return fs.File.openHandle(sockfd); } @@ -561,7 +561,7 @@ fn linuxLookupName( var prefixlen: i32 = 0; if (os.socket(addr.family, os.SOCK_DGRAM | os.SOCK_CLOEXEC, os.IPPROTO_UDP)) |fd| syscalls: { defer os.close(fd); - os.connect(fd, da, dalen) catch break :syscalls; + os.connect(fd, da.*, dalen) catch break :syscalls; key |= DAS_USABLE; os.getsockname(fd, sa, &salen) catch break :syscalls; if (addr.family == os.AF_INET) { diff --git a/lib/std/net/test.zig b/lib/std/net/test.zig index 47d85ce18..aced17f1b 100644 --- a/lib/std/net/test.zig +++ b/lib/std/net/test.zig @@ -29,6 +29,24 @@ test "std.net.parseIp6" { std.testing.expect(mem.eql(u8, "[ff01::fb]:80", printed)); } +test "resolve DNS" { + if (std.builtin.os == .windows) { + // DNS resolution not implemented on Windows yet. + return error.SkipZigTest; + } + var buf: [1000 * 10]u8 = undefined; + const a = &std.heap.FixedBufferAllocator.init(&buf).allocator; + + const address_list = net.getAddressList(a, "example.com", 80) catch |err| switch (err) { + // The tests are required to work even when there is no Internet connection, + // so some of these errors we must accept and skip the test. + error.UnknownHostName => return error.SkipZigTest, + error.TemporaryNameServerFailure => return error.SkipZigTest, + else => return err, + }; + address_list.deinit(); +} + test "listen on a port, send bytes, receive bytes" { if (std.builtin.os != .linux) { // TODO build abstractions for other operating systems