xaizek / tos (License: GPLv3 only) (since 2018-12-07)
This is an alternative version of sources presented as part of Write Your Own OS video tutorial by Viktor Engelmann.
<root> / src / net / icmp.hpp (4b56c9674fc93dd9b122fc1f1fa870c7dbc342a2) (973B) (mode 100644) [raw]
#ifndef TOS__NET__ICMP_HPP__
#define TOS__NET__ICMP_HPP__

#include <cstdint>

#include "net/ipv4.hpp"
#include "utils/struct.hpp"

namespace net {

struct ICMPMsg
{
    NetField<+0, 1, std::uint8_t> type;
    NetField<+1, 1, std::uint8_t> code;

    NetField<+2, 2, std::uint16_t> checksum;
    NetField<+4, 4, std::uint32_t> data;

    explicit ICMPMsg(std::uint8_t data[])
        : type(data), code(data), checksum(data), data(data)
    {
    }

    static constexpr std::ptrdiff_t size()
    {
        using lastField = decltype(data);
        return lastField::offset + lastField::size;
    }
};

class ICMP : private IPHandler
{
public:
    ICMP(IPProvider &backend);

public:
    void requestEchoReply(NetOrder<std::uint32_t> ip);

private:
    virtual bool onIPReceived(NetOrder<std::uint32_t> srcIP,
                              NetOrder<std::uint32_t> dstIP,
                              span<std::uint8_t> msg) override;
};

}

#endif // TOS__NET__ICMP_HPP__
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/tos

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/tos

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master