From af8a516fc22865abd80d6e26f1541fa3d6bebfdc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 9 May 2024 00:42:44 +0200 Subject: MHR-23: :boom:, refactors. - Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss --- Kernel/NetworkKit/IP.hpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Kernel/NetworkKit/IP.hpp (limited to 'Kernel/NetworkKit/IP.hpp') diff --git a/Kernel/NetworkKit/IP.hpp b/Kernel/NetworkKit/IP.hpp new file mode 100644 index 00000000..94d0d3be --- /dev/null +++ b/Kernel/NetworkKit/IP.hpp @@ -0,0 +1,83 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include + +namespace NewOS +{ + class RawIPAddress6; + class RawIPAddress; + class IPFactory; + + class RawIPAddress final + { + private: + explicit RawIPAddress(char bytes[4]); + ~RawIPAddress() = default; + + RawIPAddress& operator=(const RawIPAddress&) = delete; + RawIPAddress(const RawIPAddress&) = default; + + public: + char* Address(); + + char& operator[](const Size& index); + + bool operator==(const RawIPAddress& ipv6); + bool operator!=(const RawIPAddress& ipv6); + + private: + char fAddr[4]; + + friend IPFactory; // it is the one creating these addresses, thus this + // is why the constructors are private. + }; + + /** + * @brief IPv6 address. + */ + class RawIPAddress6 final + { + private: + explicit RawIPAddress6(char Bytes[8]); + ~RawIPAddress6() = default; + + RawIPAddress6& operator=(const RawIPAddress6&) = delete; + RawIPAddress6(const RawIPAddress6&) = default; + + public: + char* Address() + { + return fAddr; + } + + char& operator[](const Size& index); + + bool operator==(const RawIPAddress6& ipv6); + bool operator!=(const RawIPAddress6& ipv6); + + private: + char fAddr[8]; + + friend IPFactory; + }; + + /** + * @brief IP Creation helpers + */ + class IPFactory final + { + public: + static ErrorOr ToStringView(Ref ipv6); + static ErrorOr ToStringView(Ref ipv4); + static bool IpCheckVersion4(const char* ip); + }; +} // namespace NewOS -- cgit v1.2.3