Compare commits
No commits in common. "dcfcccda560e94d68e8528b720a44233541b3c2f" and "952253104e884b747cef675b35740baa5e149543" have entirely different histories.
dcfcccda56
...
952253104e
2 changed files with 10 additions and 14 deletions
12
src/mdns.zig
12
src/mdns.zig
|
@ -8,7 +8,6 @@ const MDNSError = error{
|
|||
NotResponse,
|
||||
NoMatchingAddress,
|
||||
AddressBadFormat,
|
||||
SocketBindFail,
|
||||
};
|
||||
|
||||
pub fn get_mdns(domain: util.Domain, ip_info: util.IPInfo) !util.IP {
|
||||
|
@ -44,9 +43,6 @@ fn get_mdns_socket(ip_info: util.IPInfo) !socket {
|
|||
if (std.c.setsockopt(sock, std.c.SOL.SOCKET, std.c.SO.RCVTIMEO, &timeout, @intCast(@sizeOf(std.c.timeval))) == -1) {
|
||||
return MDNSError.SocketInitFail;
|
||||
}
|
||||
if (std.c.setsockopt(sock, std.c.SOL.SOCKET, std.c.SO.BINDTOIFINDEX, &ip_info.interface, @sizeOf(c_int)) == -1) {
|
||||
return MDNSError.SocketBindFail;
|
||||
}
|
||||
return sock;
|
||||
}
|
||||
|
||||
|
@ -85,7 +81,13 @@ fn construct_mdns_query(domain: util.Domain, ip_info: util.IPInfo, buff: []u8) !
|
|||
fn get_target_address(ip_info: util.IPInfo) !std.net.Address {
|
||||
const target_addr: []const u8 = switch (ip_info.version) {
|
||||
.IPv4 => "224.0.0.251",
|
||||
.IPv6 => "ff02::fb",
|
||||
.IPv6 => blk: {
|
||||
var buf: [50]u8 = undefined;
|
||||
var byte_buf = std.io.fixedBufferStream(&buf);
|
||||
const writer = byte_buf.writer();
|
||||
try std.fmt.format(writer, "ff02::fb%{d}", .{ip_info.interface});
|
||||
break :blk buf[0..writer.context.pos];
|
||||
},
|
||||
else => unreachable,
|
||||
};
|
||||
return std.net.Address.resolveIp(target_addr, 5353);
|
||||
|
|
12
src/util.zig
12
src/util.zig
|
@ -64,15 +64,9 @@ 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;
|
||||
|
||||
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;
|
||||
const iface = try std.fmt.parseInt(c_int, args.next() orelse return ArgError.NotEnoughArgs, 10);
|
||||
if (iface < 0) {
|
||||
return ArgError.InvalidInterface;
|
||||
}
|
||||
return .{ domain, IPInfo{ .version = ip_ver, .interface = iface } };
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue