From c8468bed42db773cc0622c6ea2e18d5e17808f2b Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 20 Apr 2020 16:34:37 -0300 Subject: Add std.os.ioctl --- lib/std/net.zig | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'lib/std/net.zig') diff --git a/lib/std/net.zig b/lib/std/net.zig index 866a7b0cca..22c3d6d895 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -545,24 +545,12 @@ fn if_nametoindex(name: []const u8) !u32 { std.mem.copy(u8, &ifr.ifr_ifrn.name, name); ifr.ifr_ifrn.name[name.len] = 0; - const rc = os.system.syscall3( - os.linux.SYS_ioctl, - @bitCast(usize, @as(isize, sockfd)), - os.linux.SIOCGIFINDEX, - @ptrToInt(&ifr), - ); - - switch (os.errno(rc)) { - os.EBADF => return error.BadFile, - os.EINTR => return error.CaughtSignal, - os.EIO => return error.FileSystem, - os.EINVAL => unreachable, - os.ENOTTY => unreachable, - os.ENXIO => unreachable, - // ioctl() sends ENODEV for an unknown scope id. - os.ENODEV => return error.InterfaceNotFound, - else => {}, - } + std.os.ioctl(sockfd, os.linux.SIOCGIFINDEX, @ptrToInt(&ifr)) catch |err| { + switch (err) { + error.NoDevice => return error.InterfaceNotFound, + else => return err, + } + }; return @bitCast(u32, ifr.ifr_ifru.ifru_ivalue); } -- cgit v1.2.3