Allow either a valid scope_id or the device name as valid input for the interface

This commit is contained in:
Muaz Ahmad 2024-05-18 13:53:50 +05:00
parent 69bfc60261
commit dcfcccda56

View file

@ -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 } };
}