From dcfcccda560e94d68e8528b720a44233541b3c2f Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Sat, 18 May 2024 13:53:50 +0500 Subject: [PATCH] Allow either a valid scope_id or the device name as valid input for the interface --- src/util.zig | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/util.zig b/src/util.zig index dd2b437..1193ca5 100644 --- a/src/util.zig +++ b/src/util.zig @@ -64,9 +64,15 @@ pub fn get_input() !struct { const ip_ver_str = args.next() orelse return ArgError.NotEnoughArgs; const ip_ver = std.meta.intToEnum(IP_VER_ENUM, std.fmt.parseInt(u3, ip_ver_str, 10) catch return ArgError.InvalidAddressVer) catch return ArgError.InvalidAddressVer; - const iface = try std.fmt.parseInt(c_int, args.next() orelse return ArgError.NotEnoughArgs, 10); - if (iface < 0) { - return ArgError.InvalidInterface; + var iface: c_int = undefined; + if (args.next()) |iface_str| { + iface = std.fmt.parseInt(c_int, iface_str, 10) catch |err| blk: { + if (err == std.fmt.ParseIntError.Overflow) return err; + break :blk std.c.if_nametoindex(iface_str); + }; + if (iface <= 0) return ArgError.InvalidInterface; + } else { + return ArgError.NotEnoughArgs; } return .{ domain, IPInfo{ .version = ip_ver, .interface = iface } }; }