mirror of
https://git.robbyzambito.me/zaprus/
synced 2026-02-04 03:34:48 +00:00
Fix checksum issue
This commit is contained in:
@@ -95,12 +95,15 @@ pub fn connect(self: Client, io: Io, payload: []const u8) !SaprusConnection {
|
||||
},
|
||||
};
|
||||
|
||||
log.debug("Setting bpf filter to port {}", .{connection.connection.src});
|
||||
try self.socket.attachSaprusPortFilter(connection.connection.src);
|
||||
log.debug("bpf set", .{});
|
||||
|
||||
var connection_buf: [2048]u8 = undefined;
|
||||
var connection_bytes = connection.toBytes(&connection_buf);
|
||||
headers.setPayloadLen(connection_bytes.len);
|
||||
|
||||
log.debug("Building full message", .{});
|
||||
var full_msg = blk: {
|
||||
var msg_buf: [2048]u8 = undefined;
|
||||
var msg_w: Writer = .fixed(&msg_buf);
|
||||
@@ -108,17 +111,21 @@ pub fn connect(self: Client, io: Io, payload: []const u8) !SaprusConnection {
|
||||
msg_w.writeAll(connection_bytes) catch unreachable;
|
||||
break :blk msg_w.buffered();
|
||||
};
|
||||
log.debug("Built full message. Sending message", .{});
|
||||
|
||||
try self.socket.send(full_msg);
|
||||
var res_buf: [4096]u8 = undefined;
|
||||
|
||||
// Ignore response from sentinel, just accept that we got one.
|
||||
log.debug("Awaiting handshake response", .{});
|
||||
_ = try self.socket.receive(&res_buf);
|
||||
try io.sleep(.fromMilliseconds(40), .real);
|
||||
|
||||
headers.udp.dst_port = udp_dest_port;
|
||||
headers.ip.id = rand.int(u16);
|
||||
headers.setPayloadLen(connection_bytes.len);
|
||||
|
||||
log.debug("Building final handshake message", .{});
|
||||
full_msg = blk: {
|
||||
var msg_buf: [2048]u8 = undefined;
|
||||
var msg_w: Writer = .fixed(&msg_buf);
|
||||
@@ -140,3 +147,4 @@ const EthIpUdp = @import("./EthIpUdp.zig").EthIpUdp;
|
||||
const std = @import("std");
|
||||
const Io = std.Io;
|
||||
const Writer = std.Io.Writer;
|
||||
const log = std.log;
|
||||
|
||||
@@ -14,12 +14,16 @@ pub fn init(socket: RawSocket, headers: EthIpUdp, connection: SaprusMessage) Con
|
||||
|
||||
pub fn next(self: Connection, io: Io, buf: []u8) ![]const u8 {
|
||||
_ = io;
|
||||
log.debug("Awaiting connection message", .{});
|
||||
const res = try self.socket.receive(buf);
|
||||
log.debug("Received {} byte connection message", .{res.len});
|
||||
const connection_res = blk: {
|
||||
const msg: SaprusMessage = try .parse(res[42..]);
|
||||
break :blk msg.connection;
|
||||
};
|
||||
|
||||
log.debug("Payload was {s}", .{connection_res.payload});
|
||||
|
||||
return connection_res.payload;
|
||||
}
|
||||
|
||||
@@ -29,14 +33,16 @@ pub fn send(self: *Connection, io: Io, buf: []const u8) !void {
|
||||
break :blk io_source.interface();
|
||||
};
|
||||
|
||||
log.debug("Sending connection message", .{});
|
||||
|
||||
self.connection.connection.payload = buf;
|
||||
const connection_bytes = blk: {
|
||||
var connection_bytes: [2048]u8 = undefined;
|
||||
break :blk self.connection.toBytes(&connection_bytes);
|
||||
};
|
||||
|
||||
self.headers.setPayloadLen(connection_bytes.len);
|
||||
self.headers.ip.id = rand.int(u16);
|
||||
self.headers.setPayloadLen(connection_bytes.len);
|
||||
|
||||
const full_msg = blk: {
|
||||
var msg_buf: [2048]u8 = undefined;
|
||||
@@ -47,12 +53,16 @@ pub fn send(self: *Connection, io: Io, buf: []const u8) !void {
|
||||
};
|
||||
|
||||
try self.socket.send(full_msg);
|
||||
|
||||
log.debug("Sent {} byte connection message", .{full_msg.len});
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const Io = std.Io;
|
||||
const Writer = std.Io.Writer;
|
||||
|
||||
const log = std.log;
|
||||
|
||||
const SaprusMessage = @import("./message.zig").Message;
|
||||
|
||||
const EthIpUdp = @import("./EthIpUdp.zig").EthIpUdp;
|
||||
|
||||
@@ -100,7 +100,9 @@ pub fn main(init: std.process.Init) !void {
|
||||
|
||||
if (flags.connect != null) {
|
||||
reconnect: while (true) {
|
||||
log.debug("Starting connection", .{});
|
||||
var connection = try client.connect(init.io, flags.connect.?);
|
||||
log.debug("Connection started", .{});
|
||||
|
||||
while (true) {
|
||||
var res_buf: [2048]u8 = undefined;
|
||||
@@ -156,6 +158,7 @@ fn parseDest(in: ?[]const u8) [4]u8 {
|
||||
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("std");
|
||||
const log = std.log;
|
||||
const ArrayList = std.ArrayList;
|
||||
const StaticStringMap = std.StaticStringMap;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user