-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Implement if_nametoindex
for windows
#22555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks! |
CI failures look related to me. |
I'd be happy to merge any changes or fixes, if that is something that would be beneficial. Anything else I can contribute to this? |
Well one of the tests you enabled to run on Windows is failing there:
So that needs to be resolved. |
I also saw that. What I didn't get: To me it seems like the codepath where the |
Seems that this condition doesn't trigger: Lines 530 to 532 in 0679358
Because when running on Windows with libc Lines 5783 to 5790 in 0679358
So I'd suggest making that test string 12 characters longer ( "ff01::fb%wlp3s0s0s0s0s0s0s0s0s0s0s0s0s0s0" |
I was also looking at that piece of code, but didn't make the |
Windows has a different max length for their interface names, leading to test cases not having the expected result
0679358
to
f954764
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems that the "ff01::fb%12345678901234" test string, since its scope id was only 14 characters long, was triggering one of the different error.Overflow
s that happen later on:
Lines 584 to 597 in f954764
} else { | |
const digit = try std.fmt.charToDigit(c, 16); | |
{ | |
const ov = @mulWithOverflow(x, 16); | |
if (ov[1] != 0) return error.Overflow; | |
x = ov[0]; | |
} | |
{ | |
const ov = @addWithOverflow(x, digit); | |
if (ov[1] != 0) return error.Overflow; | |
x = ov[0]; | |
} | |
saw_any_digits = true; | |
} |
Revert a change, as that was supposed to target a different test case
worked for me in latest master build 0.15.0-dev.79+9f235a105 please merge 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if_nametoindex
docs say:
The if_nametoindex function is implemented for portability of applications with Unix environments, but the ConvertInterface functions are preferred. The if_nametoindex function can be replaced by a call to the ConvertInterfaceNameToLuidA function to convert the ANSI interface name to a NET_LUID followed by a call to the ConvertInterfaceLuidToIndex to convert the NET_LUID to the local interface index.
Not sure it's worth worrying about for now, though. At some point I assume it'd be better to swap things over to that (or ConvertInterfaceNameToLuidW
but I'm unsure if interface names can be non-ASCII?) and also use GetAddrInfoW
instead of getaddrinfo
(unrelated to this PR, was just looking at other ws2_32
calls)
(or lower-level equivalents if they exist, I didn't see any ntdll calls when running if_nametoindex
with NtTrace
[note, though, that it doesn't capture Rtl function calls])
Does this actually fix #20530? |
Yes, it fixes the compile error in that issue.
The tests that call |
Are those CI failures related? I saw some similar ones in different PR's, and I don't think that the string concatenation in the test cast should cause a OOM during comptime |
Nope, those aren't your fault. The PR should be good to go; I'll merge it once we resolve those CI issues. |
Alright. Thanks everyone for working through this with me :D |
This implements the
if_nametoindex
function for windows.I noticed zig threw a compile error when trying to compile the zigdig example code for windows.
If I read the code correctly, and looking at issue #20530, this seems also hinder all IP resolution on windows, even though
if_nametoindex
is only called in the ipv4 codepath.I pieced this code together from looking at the darwin implementation and the old std.x namespace, which also contained an implementation for windows.
This seems to pass all test, except for this one
zig/lib/std/net/test.zig
Line 79 in d5db027
error.Overflow
case should be handled beforeif_nametoindex
is even called. If someone can help me fix this case, I'd be happy for any pointers.I'm also happy about any other pointers and things I should fix.
Fixes #20530.