diff options
| author | Luna <git@l4.pm> | 2020-04-20 16:34:37 -0300 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-06-02 14:56:19 -0400 |
| commit | c8468bed42db773cc0622c6ea2e18d5e17808f2b (patch) | |
| tree | 83be6e3ed804ab505a3a280bba5941a8a474a61d /lib/std/net.zig | |
| parent | c7b790ded685cb3bcb17fe7a27de7ae054133250 (diff) | |
| download | zig-c8468bed42db773cc0622c6ea2e18d5e17808f2b.tar.gz zig-c8468bed42db773cc0622c6ea2e18d5e17808f2b.zip | |
Add std.os.ioctl
Diffstat (limited to 'lib/std/net.zig')
| -rw-r--r-- | lib/std/net.zig | 24 |
1 files changed, 6 insertions, 18 deletions
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); } |
