Skip to content

Commit 9a5ba5e

Browse files
std.net: implement if_nametoindex for windows
1 parent d5db027 commit 9a5ba5e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/std/net.zig

+13
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,19 @@ fn if_nametoindex(name: []const u8) IPv6InterfaceError!u32 {
752752
return @as(u32, @bitCast(index));
753753
}
754754

755+
if (native_os == .windows) {
756+
if (name.len >= posix.IFNAMESIZE)
757+
return error.NameTooLong;
758+
759+
var interface_name: [posix.IFNAMESIZE:0]u8 = undefined;
760+
@memcpy(interface_name[0..name.len], name);
761+
interface_name[name.len] = 0;
762+
const index = std.os.windows.ws2_32.if_nametoindex(@as([*:0]const u8, &interface_name));
763+
if (index == 0)
764+
return error.InterfaceNotFound;
765+
return index;
766+
}
767+
755768
@compileError("std.net.if_nametoindex unimplemented for this OS");
756769
}
757770

0 commit comments

Comments
 (0)