| ... | @@ -184,7 +184,6 @@ pub const Address = extern union { | ... | @@ -184,7 +184,6 @@ pub const Address = extern union { |
| 184 | } | 184 | } |
| 185 | | 185 | |
| 186 | pub fn resolveIp6(buf: []const u8, port: u16) !Address { | 186 | pub fn resolveIp6(buf: []const u8, port: u16) !Address { |
| 187 | // FIXME: implement if_nametoindex | | |
| 188 | // FIXME: this is a very bad implementation, since it's only a copy | 187 | // FIXME: this is a very bad implementation, since it's only a copy |
| 189 | // of parseIp6 with alphanumerical scope id support | 188 | // of parseIp6 with alphanumerical scope id support |
| 190 | var result = Address{ | 189 | var result = Address{ |
| ... | @@ -205,7 +204,7 @@ pub const Address = extern union { | ... | @@ -205,7 +204,7 @@ pub const Address = extern union { |
| 205 | var abbrv = false; | 204 | var abbrv = false; |
| 206 | | 205 | |
| 207 | var scope_id = false; | 206 | var scope_id = false; |
| 208 | var scope_id_value: [32]u8 = undefined; | 207 | var scope_id_value: [16]u8 = undefined; |
| 209 | var scope_id_index: usize = 0; | 208 | var scope_id_index: usize = 0; |
| 210 | | 209 | |
| 211 | for (buf) |c, i| { | 210 | for (buf) |c, i| { |
| ... | @@ -273,10 +272,13 @@ pub const Address = extern union { | ... | @@ -273,10 +272,13 @@ pub const Address = extern union { |
| 273 | return error.Incomplete; | 272 | return error.Incomplete; |
| 274 | } | 273 | } |
| 275 | | 274 | |
| 276 | const resolved_scope_id = std.fmt.parseInt(u32, scope_id_value, 10) catch |err| blk: { | 275 | var resolved_scope_id: u32 = 0; |
| 277 | if (err != err.InvalidCharacter) return err; | 276 | if (std.mem.len(scope_id_value) > 0) { |
| 278 | break :blk if_nametoindex(scope_id_value); | 277 | resolved_scope_id = std.fmt.parseInt(u32, &scope_id_value, 10) catch |err| blk: { |
| 279 | }; | 278 | if (err != error.InvalidCharacter) return err; |
| | 279 | break :blk try if_nametoindex(&scope_id_value); |
| | 280 | }; |
| | 281 | } |
| 280 | | 282 | |
| 281 | result.in6.scope_id = resolved_scope_id; | 283 | result.in6.scope_id = resolved_scope_id; |
| 282 | | 284 | |
| ... | @@ -522,7 +524,7 @@ fn if_nametoindex(name: []const u8) !u32 { | ... | @@ -522,7 +524,7 @@ fn if_nametoindex(name: []const u8) !u32 { |
| 522 | var sockfd = try os.socket(os.AF_UNIX, os.SOCK_DGRAM | os.SOCK_CLOEXEC, 0); | 524 | var sockfd = try os.socket(os.AF_UNIX, os.SOCK_DGRAM | os.SOCK_CLOEXEC, 0); |
| 523 | defer os.close(sockfd); | 525 | defer os.close(sockfd); |
| 524 | | 526 | |
| 525 | std.mem.copy(u8, ifr.ifr_ifrn.name, &name); | 527 | std.mem.copy(u8, &ifr.ifr_ifrn.name, name); |
| 526 | | 528 | |
| 527 | const rc = os.system.syscall3( | 529 | const rc = os.system.syscall3( |
| 528 | os.linux.SYS_ioctl, | 530 | os.linux.SYS_ioctl, |