~blainsmith/hare-icmp

f875e0c3214583536f5eafb915b24aa516da0123 — Blain Smith 1 year, 3 months ago ee75a4c
encoding a message

Signed-off-by: Blain Smith <rebelgeek@blainsmith.com>
2 files changed, 28 insertions(+), 2 deletions(-)

M net/icmp/+test.ha
M net/icmp/message.ha
M net/icmp/+test.ha => net/icmp/+test.ha +5 -1
@@ 1,3 1,7 @@
@test fn message() void = {
@test fn encode() void = {
    assert(1 == 1);
};

@test fn decode() void = {
    assert(1 == 1);
};
\ No newline at end of file

M net/icmp/message.ha => net/icmp/message.ha +23 -1
@@ 53,7 53,29 @@ export type parameter_problem = struct {

// Encodes a [[message]] into a slice of bytes ready to be transmitted over the wire
export fn encode(in: *message, out: []u8) void = {
    return;
    out[1] = in.code: u8;
    endian::beputu16(out[2..4], in.checksum: u16);

    match (in.body) {
    case let m: echo =>
        out[0] = V4_ECHO: u8;
        endian::beputu16(out[4..6], m.id: u16);
        endian::beputu16(out[6..8], m.seq: u16);
        out[8..] = m.data;
    case let m: reply =>
        out[0] = V4_ECHO_REPLY: u8;
        endian::beputu16(out[4..6], m.id: u16);
        endian::beputu16(out[6..8], m.seq: u16);
        out[8..] = m.data;
    case let m: destination_unreachable =>
        out[0] = V4_DESTINATION_UNREACHABLE: u8;
    case let m: time_exeeded =>
        out[0] = V4_TIME_EXCEEDED: u8;
    case let m: parameter_problem =>
        out[0] = V4_PARAMETER_PROBLEM: u8;
        out[4] = m.pointer: u8;
        out[5..] = m.data;
    };
};

// Decodes a slice of bytes from the wire into a [[message]]