| ... | @@ -447,7 +447,9 @@ pub const Ip6Address = struct { | ... | @@ -447,7 +447,9 @@ pub const Ip6Address = struct { |
| 447 | pub const Unresolved = struct { | 447 | pub const Unresolved = struct { |
| 448 | /// Big endian | 448 | /// Big endian |
| 449 | bytes: [16]u8, | 449 | bytes: [16]u8, |
| 450 | interface_name: ?Interface.Name, | 450 | /// Has not been checked to be a valid native interface name. |
| | 451 | /// Externally managed memory. |
| | 452 | interface_name: ?[]const u8, |
| 451 | | 453 | |
| 452 | pub const Parsed = union(enum) { | 454 | pub const Parsed = union(enum) { |
| 453 | success: Unresolved, | 455 | success: Unresolved, |
| ... | @@ -536,7 +538,6 @@ pub const Ip6Address = struct { | ... | @@ -536,7 +538,6 @@ pub const Ip6Address = struct { |
| 536 | parts_i += 1; | 538 | parts_i += 1; |
| 537 | text_i += 1; | 539 | text_i += 1; |
| 538 | const name = text[text_i..]; | 540 | const name = text[text_i..]; |
| 539 | if (name.len > Interface.Name.max_len) return .{ .interface_name_oversized = text_i }; | | |
| 540 | if (name.len == 0) return .incomplete; | 541 | if (name.len == 0) return .incomplete; |
| 541 | interface_name_text = name; | 542 | interface_name_text = name; |
| 542 | text_i = @intCast(text.len); | 543 | text_i = @intCast(text.len); |
| ... | @@ -563,7 +564,7 @@ pub const Ip6Address = struct { | ... | @@ -563,7 +564,7 @@ pub const Ip6Address = struct { |
| 563 | | 564 | |
| 564 | return .{ .success = .{ | 565 | return .{ .success = .{ |
| 565 | .bytes = @bitCast(parts), | 566 | .bytes = @bitCast(parts), |
| 566 | .interface_name = if (interface_name_text) |t| .fromSliceUnchecked(t) else null, | 567 | .interface_name = interface_name_text, |
| 567 | } }; | 568 | } }; |
| 568 | }, | 569 | }, |
| 569 | } | 570 | } |
| ... | @@ -646,7 +647,7 @@ pub const Ip6Address = struct { | ... | @@ -646,7 +647,7 @@ pub const Ip6Address = struct { |
| 646 | } | 647 | } |
| 647 | } | 648 | } |
| 648 | } | 649 | } |
| 649 | if (u.interface_name) |n| try w.print("%{s}", .{n.toSlice()}); | 650 | if (u.interface_name) |n| try w.print("%{s}", .{n}); |
| 650 | } | 651 | } |
| 651 | }; | 652 | }; |
| 652 | | 653 | |
| ... | @@ -678,6 +679,8 @@ pub const Ip6Address = struct { | ... | @@ -678,6 +679,8 @@ pub const Ip6Address = struct { |
| 678 | /// If this is returned, more detailed diagnostics can be obtained by | 679 | /// If this is returned, more detailed diagnostics can be obtained by |
| 679 | /// calling the `Parsed.init` function. | 680 | /// calling the `Parsed.init` function. |
| 680 | ParseFailed, | 681 | ParseFailed, |
| | 682 | /// The interface name is longer than the host operating system supports. |
| | 683 | NameTooLong, |
| 681 | } || Interface.Name.ResolveError; | 684 | } || Interface.Name.ResolveError; |
| 682 | | 685 | |
| 683 | /// This function requires an `Io` parameter because it must query the operating | 686 | /// This function requires an `Io` parameter because it must query the operating |
| ... | @@ -689,7 +692,11 @@ pub const Ip6Address = struct { | ... | @@ -689,7 +692,11 @@ pub const Ip6Address = struct { |
| 689 | .success => |p| return .{ | 692 | .success => |p| return .{ |
| 690 | .bytes = p.bytes, | 693 | .bytes = p.bytes, |
| 691 | .port = port, | 694 | .port = port, |
| 692 | .interface = if (p.interface_name) |n| try n.resolve(io) else .none, | 695 | .interface = i: { |
| | 696 | const text = p.interface_name orelse break :i .none; |
| | 697 | const name: Interface.Name = try .fromSlice(text); |
| | 698 | break :i try name.resolve(io); |
| | 699 | }, |
| 693 | }, | 700 | }, |
| 694 | else => return error.ParseFailed, | 701 | else => return error.ParseFailed, |
| 695 | }; | 702 | }; |
| ... | @@ -946,7 +953,7 @@ pub const Interface = struct { | ... | @@ -946,7 +953,7 @@ pub const Interface = struct { |
| 946 | pub const Name = struct { | 953 | pub const Name = struct { |
| 947 | bytes: [max_len:0]u8, | 954 | bytes: [max_len:0]u8, |
| 948 | | 955 | |
| 949 | pub const max_len = std.posix.IFNAMESIZE - 1; | 956 | pub const max_len = if (@TypeOf(std.posix.IFNAMESIZE) == void) 0 else std.posix.IFNAMESIZE - 1; |
| 950 | | 957 | |
| 951 | pub fn toSlice(n: *const Name) []const u8 { | 958 | pub fn toSlice(n: *const Name) []const u8 { |
| 952 | return std.mem.sliceTo(&n.bytes, 0); | 959 | return std.mem.sliceTo(&n.bytes, 0); |