Allow either a valid scope_id or the device name as valid input for the interface
This commit is contained in:
parent
69bfc60261
commit
dcfcccda56
1 changed files with 9 additions and 3 deletions
12
src/util.zig
12
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 } };
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue