Remove interfaces since not needed for sockets and android requires root access for validation
This commit is contained in:
parent
6e89c63eca
commit
f505f50888
1 changed files with 4 additions and 19 deletions
23
src/util.zig
23
src/util.zig
|
@ -6,13 +6,11 @@ const ArgError = error{
|
||||||
NotEnoughArgs,
|
NotEnoughArgs,
|
||||||
BadDomain,
|
BadDomain,
|
||||||
InvalidAddressVer,
|
InvalidAddressVer,
|
||||||
InterfaceRequired,
|
|
||||||
InvalidInterface,
|
|
||||||
EnvVarNotSet,
|
EnvVarNotSet,
|
||||||
InvalidOldHostsPath,
|
InvalidOldHostsPath,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const IP_VER_ENUM = enum(u3) {
|
pub const IP_VER = enum(u3) {
|
||||||
Both = 0,
|
Both = 0,
|
||||||
IPv4 = 4,
|
IPv4 = 4,
|
||||||
IPv6 = 6,
|
IPv6 = 6,
|
||||||
|
@ -30,11 +28,6 @@ pub fn merge_addrs(v4: IP, v6: IP) IP {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const IPInfo = struct {
|
|
||||||
version: IP_VER_ENUM,
|
|
||||||
interface: ?[:0]const u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Domain = struct {
|
pub const Domain = struct {
|
||||||
name: [:0]const u8,
|
name: [:0]const u8,
|
||||||
labels: [5][]const u8,
|
labels: [5][]const u8,
|
||||||
|
@ -53,7 +46,7 @@ pub const cwd = std.fs.cwd();
|
||||||
|
|
||||||
pub fn get_input() !struct {
|
pub fn get_input() !struct {
|
||||||
Domain,
|
Domain,
|
||||||
IPInfo,
|
IP_VER,
|
||||||
} {
|
} {
|
||||||
var args = std.process.args();
|
var args = std.process.args();
|
||||||
_ = args.next(); // consume calling binary arg
|
_ = args.next(); // consume calling binary arg
|
||||||
|
@ -62,17 +55,9 @@ pub fn get_input() !struct {
|
||||||
const domain = try check_domain(domain_str);
|
const domain = try check_domain(domain_str);
|
||||||
|
|
||||||
const ip_ver_str = args.next() orelse return ArgError.NotEnoughArgs;
|
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 ip_ver = std.meta.intToEnum(IP_VER, std.fmt.parseInt(u3, ip_ver_str, 10) catch return ArgError.InvalidAddressVer) catch return ArgError.InvalidAddressVer;
|
||||||
|
|
||||||
var iface: ?[:0]const u8 = null;
|
return .{ domain, ip_ver };
|
||||||
if (ip_ver != IP_VER_ENUM.IPv4) {
|
|
||||||
iface = args.next() orelse return ArgError.InterfaceRequired;
|
|
||||||
if (std.c.if_nametoindex(iface.?) == 0) {
|
|
||||||
return ArgError.InvalidInterface;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return .{ domain, IPInfo{ .version = ip_ver, .interface = iface } };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_domain(domain_str: [:0]const u8) !Domain {
|
fn check_domain(domain_str: [:0]const u8) !Domain {
|
||||||
|
|
Loading…
Reference in a new issue