diff options
| author | Stephen Gregoratto <dev@sgregoratto.me> | 2021-09-18 23:26:55 +1000 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-09-24 13:50:18 -0400 |
| commit | a032fd01e88be2c6e8d0cfb0ccd3d9859c9dffdc (patch) | |
| tree | 56a13b671117c0d3c815c5b2c7c0b55f8c4dbec4 /lib/std | |
| parent | 1e7009a9d982faa466517063452ed7d299b66966 (diff) | |
| download | zig-a032fd01e88be2c6e8d0cfb0ccd3d9859c9dffdc.tar.gz zig-a032fd01e88be2c6e8d0cfb0ccd3d9859c9dffdc.zip | |
Resolve scope IDs using IPv6 sockets
On certain systems (Solaris), resolving the scope id from an interface
name can only be done on AF_INET-domain sockets. While we're here,
simplify the test while we're here, since there's only one address.
Also note that the loopback interface name is not stable across OSs.
BSDs and Solaris use `lo0` whilst Linux uses `l0`.
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/x/os/net.zig | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/lib/std/x/os/net.zig b/lib/std/x/os/net.zig index 5b06d492a5..a529396c3c 100644 --- a/lib/std/x/os/net.zig +++ b/lib/std/x/os/net.zig @@ -27,7 +27,7 @@ pub fn resolveScopeId(name: []const u8) !u32 { return rc; } - const fd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM, 0); + const fd = try os.socket(os.AF.INET, os.SOCK.DGRAM, 0); defer os.closeSocket(fd); var f: os.ifreq = undefined; @@ -566,21 +566,17 @@ test "ipv6: parse & format" { test "ipv6: parse & format addresses with scope ids" { if (!have_ifnamesize) return error.SkipZigTest; - - const inputs = [_][]const u8{ - "FF01::FB%lo", - }; - - const outputs = [_][]const u8{ - "ff01::fb%1", + const iface = if (native_os.tag == .linux) + "lo" + else + "lo0"; + const input = "FF01::FB%" ++ iface; + const output = "ff01::fb%1"; + + const parsed = IPv6.parse(input) catch |err| switch (err) { + error.InterfaceNotFound => return, + else => return err, }; - for (inputs) |input, i| { - const parsed = IPv6.parse(input) catch |err| switch (err) { - error.InterfaceNotFound => continue, - else => return err, - }; - - try testing.expectFmt(outputs[i], "{}", .{parsed}); - } + try testing.expectFmt(output, "{}", .{parsed}); } |
