const std = @import("std");
pub fn main() anyerror!void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = &arena.allocator;
const list = try std.net.getAddressList(allocator, "ziglang.org", 443);
std.log.info("{}", .{list.addrs[0]});
}
This program crashes with the error error.Unexpected: GetLastError(10093): Either the application has not called WSAStartup, or WSAStartup failed.. To get this to work you need to add a call to WSAStartup as follows:
const std = @import("std");
pub fn main() anyerror!void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = &arena.allocator;
_ = try std.os.windows.WSAStartup(2, 2);
const list = try std.net.getAddressList(allocator, "google.com", 443);
std.log.info("{}", .{list.addrs[0]});
try std.os.windows.WSACleanup();
}
The os.socket API abstracts this call away from user-code through the WSASocketW in os/windows.zig, which initializes WSA if needed. It seems right to me that the std.net APIs should do the same.
This program crashes with the error
error.Unexpected: GetLastError(10093): Either the application has not called WSAStartup, or WSAStartup failed.. To get this to work you need to add a call toWSAStartupas follows:The
os.socketAPI abstracts this call away from user-code through theWSASocketWinos/windows.zig, which initializes WSA if needed. It seems right to me that thestd.netAPIs should do the same.