mirror of
https://git.robbyzambito.me/zaprus/
synced 2026-02-04 03:34:48 +00:00
Write relay message to the network
This commit is contained in:
10
src/main.zig
10
src/main.zig
@@ -189,6 +189,10 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
std.debug.print("full message = {any}\n", .{full_msg});
|
std.debug.print("full message = {any}\n", .{full_msg});
|
||||||
|
|
||||||
|
var socket: RawSocket = try .init("enp7s0");
|
||||||
|
defer socket.deinit();
|
||||||
|
try socket.send(full_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parseDest(in: ?[]const u8) [4]u8 {
|
fn parseDest(in: ?[]const u8) [4]u8 {
|
||||||
@@ -222,7 +226,7 @@ const RawSocket = struct {
|
|||||||
fd: i32,
|
fd: i32,
|
||||||
sockaddr_ll: std.posix.sockaddr.ll,
|
sockaddr_ll: std.posix.sockaddr.ll,
|
||||||
|
|
||||||
fn init(ifname: []const u8) RawSocket {
|
fn init(ifname: []const u8) !RawSocket {
|
||||||
const socket: i32 = @intCast(std.os.linux.socket(AF.PACKET, SOCK.RAW, 0));
|
const socket: i32 = @intCast(std.os.linux.socket(AF.PACKET, SOCK.RAW, 0));
|
||||||
|
|
||||||
var ifr: std.posix.ifreq = std.mem.zeroInit(std.posix.ifreq, .{});
|
var ifr: std.posix.ifreq = std.mem.zeroInit(std.posix.ifreq, .{});
|
||||||
@@ -265,7 +269,9 @@ const RawSocket = struct {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deinit() void {}
|
fn deinit(self: *RawSocket) void {
|
||||||
|
_ = self;
|
||||||
|
}
|
||||||
|
|
||||||
fn send(self: RawSocket, payload: []const u8) !void {
|
fn send(self: RawSocket, payload: []const u8) !void {
|
||||||
const sent_bytes = std.os.linux.sendto(
|
const sent_bytes = std.os.linux.sendto(
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ const Relay = struct {
|
|||||||
pub fn toBytes(self: Relay, buf: []u8) []u8 {
|
pub fn toBytes(self: Relay, buf: []u8) []u8 {
|
||||||
var out: Writer = .fixed(buf);
|
var out: Writer = .fixed(buf);
|
||||||
out.writeInt(u16, @intFromEnum(PacketType.relay), .big) catch unreachable;
|
out.writeInt(u16, @intFromEnum(PacketType.relay), .big) catch unreachable;
|
||||||
out.writeInt(u16, undefined, .big) catch unreachable; // Length field, but unread. Will switch to checksum
|
out.writeInt(u16, @intCast(self.payload.len), .big) catch unreachable; // Length field, but unread. Will switch to checksum
|
||||||
out.writeAll(&self.dest.bytes) catch unreachable;
|
out.writeAll(&self.dest.bytes) catch unreachable;
|
||||||
out.writeAll(self.payload) catch unreachable;
|
out.writeAll(self.payload) catch unreachable;
|
||||||
return out.buffered();
|
return out.buffered();
|
||||||
|
|||||||
Reference in New Issue
Block a user