authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-27 18:26:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-27 18:26:50-07:00
logdf1f401cf0e997ed289e14f69ab1114e839b56ee
treec31efb1ef0e857ac7a61e27401db36763c798fc7
parent3c1daf951cf72e454de18e70f84b9a896aa17dd0

std.x.os.net: make error set consistent across targets


1 files changed, 17 insertions(+), 2 deletions(-)

lib/std/x/os/net.zig+17-2
......@@ -9,10 +9,25 @@ const testing = std.testing;
99const native_os = builtin.os;
1010const have_ifnamesize = @hasDecl(os.system, "IFNAMESIZE");
1111
12pub const ResolveScopeIdError = error{
13 NameTooLong,
14 PermissionDenied,
15 AddressFamilyNotSupported,
16 ProtocolFamilyNotAvailable,
17 ProcessFdQuotaExceeded,
18 SystemFdQuotaExceeded,
19 SystemResources,
20 ProtocolNotSupported,
21 SocketTypeNotSupported,
22 InterfaceNotFound,
23 FileSystem,
24 Unexpected,
25};
26
1227/// Resolves a network interface name into a scope/zone ID. It returns
1328/// an error if either resolution fails, or if the interface name is
1429/// too long.
15pub fn resolveScopeId(name: []const u8) !u32 {
30pub fn resolveScopeId(name: []const u8) ResolveScopeIdError!u32 {
1631 if (have_ifnamesize) {
1732 if (name.len >= os.IFNAMESIZE) return error.NameTooLong;
1833
......@@ -433,7 +448,7 @@ pub const IPv6 = extern struct {
433448 '0'...'9' => fmt.parseInt(u32, scope_id_slice, 10),
434449 else => resolveScopeId(scope_id_slice) catch |err| switch (err) {
435450 error.InterfaceNotFound => return error.InterfaceNotFound,
436 else => |e| return e,
451 else => err,
437452 },
438453 } catch return error.UnknownScopeId;
439454