| ... | @@ -9,10 +9,25 @@ const testing = std.testing; | ... | @@ -9,10 +9,25 @@ const testing = std.testing; |
| 9 | const native_os = builtin.os; | 9 | const native_os = builtin.os; |
| 10 | const have_ifnamesize = @hasDecl(os.system, "IFNAMESIZE"); | 10 | const have_ifnamesize = @hasDecl(os.system, "IFNAMESIZE"); |
| 11 | | 11 | |
| | 12 | pub 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 | |
| 12 | /// Resolves a network interface name into a scope/zone ID. It returns | 27 | /// Resolves a network interface name into a scope/zone ID. It returns |
| 13 | /// an error if either resolution fails, or if the interface name is | 28 | /// an error if either resolution fails, or if the interface name is |
| 14 | /// too long. | 29 | /// too long. |
| 15 | pub fn resolveScopeId(name: []const u8) !u32 { | 30 | pub fn resolveScopeId(name: []const u8) ResolveScopeIdError!u32 { |
| 16 | if (have_ifnamesize) { | 31 | if (have_ifnamesize) { |
| 17 | if (name.len >= os.IFNAMESIZE) return error.NameTooLong; | 32 | if (name.len >= os.IFNAMESIZE) return error.NameTooLong; |
| 18 | | 33 | |
| ... | @@ -433,7 +448,7 @@ pub const IPv6 = extern struct { | ... | @@ -433,7 +448,7 @@ pub const IPv6 = extern struct { |
| 433 | '0'...'9' => fmt.parseInt(u32, scope_id_slice, 10), | 448 | '0'...'9' => fmt.parseInt(u32, scope_id_slice, 10), |
| 434 | else => resolveScopeId(scope_id_slice) catch |err| switch (err) { | 449 | else => resolveScopeId(scope_id_slice) catch |err| switch (err) { |
| 435 | error.InterfaceNotFound => return error.InterfaceNotFound, | 450 | error.InterfaceNotFound => return error.InterfaceNotFound, |
| 436 | else => |e| return e, | 451 | else => err, |
| 437 | }, | 452 | }, |
| 438 | } catch return error.UnknownScopeId; | 453 | } catch return error.UnknownScopeId; |
| 439 | | 454 | |