ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.37k stars 2.51k forks source link

Trying to call std.net.Address.resolveIp fails on windows with a compiler error #20530

Open rupakhetibinit opened 3 months ago

rupakhetibinit commented 3 months ago

Zig Version

0.14.0-dev.185+c40708a2c

Steps to Reproduce and Observed Behavior

const std = @import("std");

pub fn main() !void {
    const stdout = std.io.getStdOut().writer();
    const address = try std.net.Address.resolveIp("127.0.0.1", 4221);
    var listener = try address.listen(.{
        .reuse_address = false,
    });
    try stdout.print("Started http server on port 4221", .{});

    defer listener.deinit();
}

The exact error I run into is this.

❯ zig build run
run
└─ run http-server
   └─ install
      └─ install http-server
         └─ zig build-exe http-server Debug native 1 errors
C:\Users\BINIT\scoop\persist\zigup\zig\0.14.0-dev.185+c40708a2c\files\lib\std\net.zig:756:5: error: std.net.if_nametoindex unimplemented for this OS
    @compileError("std.net.if_nametoindex unimplemented for this OS");
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    resolve: C:\Users\BINIT\scoop\persist\zigup\zig\0.14.0-dev.185+c40708a2c\files\lib\std\net.zig:614:46
    resolveIp6: C:\Users\BINIT\scoop\persist\zigup\zig\0.14.0-dev.185+c40708a2c\files\lib\std\net.zig:103:48
    4 reference(s) hidden; use '-freference-trace=6' to see all references

For some reason it's still calling resolveip6 even after calling and supposedly returning ip4 at least that's what I could figure out which seems like it shouldn't be happening because ipv4 should be already resolved before it reaches resolveip6 https://github.com/ziglang/zig/blob/c40708a2ce4f6ed1adcc1de39fc7b4fc27db32f8/lib/std/net.zig#L66-L87

Expected Behavior

Not get compiler error.

vhorvath2010 commented 4 weeks ago

I am also seeing this issue

Wolfleader101 commented 2 days ago

I'm also getting this issue, not sure why its resolving ipv6