2019-03-12 04:11:20 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-04-02 19:54:38 +02:00
|
|
|
#include <Kernel/Net/MACAddress.h>
|
|
|
|
#include <Kernel/Net/IPv4.h>
|
2019-03-12 04:11:20 +01:00
|
|
|
|
|
|
|
struct ICMPType {
|
|
|
|
enum {
|
|
|
|
EchoReply = 0,
|
|
|
|
EchoRequest = 8,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
class [[gnu::packed]] ICMPHeader {
|
|
|
|
public:
|
|
|
|
ICMPHeader() { }
|
|
|
|
~ICMPHeader() { }
|
|
|
|
|
|
|
|
byte type() const { return m_type; }
|
|
|
|
void set_type(byte b) { m_type = b; }
|
|
|
|
|
|
|
|
byte code() const { return m_code; }
|
|
|
|
void set_code(byte b) { m_code = b; }
|
|
|
|
|
2019-03-12 12:43:30 +01:00
|
|
|
word checksum() const { return m_checksum; }
|
2019-03-12 11:44:38 +01:00
|
|
|
void set_checksum(word w) { m_checksum = w; }
|
2019-03-12 04:11:20 +01:00
|
|
|
|
2019-03-12 04:39:50 +01:00
|
|
|
const void* payload() const { return this + 1; }
|
|
|
|
void* payload() { return this + 1; }
|
2019-03-12 04:11:20 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
byte m_type { 0 };
|
|
|
|
byte m_code { 0 };
|
2019-03-12 11:44:38 +01:00
|
|
|
NetworkOrdered<word> m_checksum { 0 };
|
2019-03-12 04:39:50 +01:00
|
|
|
// NOTE: The rest of the header is 4 bytes
|
2019-03-12 04:11:20 +01:00
|
|
|
};
|
|
|
|
|
2019-03-12 04:39:50 +01:00
|
|
|
static_assert(sizeof(ICMPHeader) == 4);
|
2019-03-12 04:11:20 +01:00
|
|
|
|
|
|
|
struct [[gnu::packed]] ICMPEchoPacket {
|
|
|
|
ICMPHeader header;
|
|
|
|
NetworkOrdered<word> identifier;
|
|
|
|
NetworkOrdered<word> sequence_number;
|
2019-03-12 04:39:50 +01:00
|
|
|
void* payload() { return this + 1; }
|
|
|
|
const void* payload() const { return this + 1; }
|
2019-03-12 04:11:20 +01:00
|
|
|
};
|