summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/NetworkKit/IP.hxx
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 18:35:34 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 18:35:34 +0200
commitf3d931aa7cfaf96baef8383b59a8938779541ee7 (patch)
treefdb9fc51badb3dbd03e46ab0766a49d9522e13e2 /dev/Kernel/NetworkKit/IP.hxx
parent86640816e8b1d3595365f1fcc8a2a9e61fb40ff1 (diff)
[IMP] Moved source code into dev/ folder.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/NetworkKit/IP.hxx')
-rw-r--r--dev/Kernel/NetworkKit/IP.hxx83
1 files changed, 83 insertions, 0 deletions
diff --git a/dev/Kernel/NetworkKit/IP.hxx b/dev/Kernel/NetworkKit/IP.hxx
new file mode 100644
index 00000000..6003021e
--- /dev/null
+++ b/dev/Kernel/NetworkKit/IP.hxx
@@ -0,0 +1,83 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <KernelKit/DebugOutput.hxx>
+#include <NewKit/Defines.hxx>
+#include <NewKit/Ref.hxx>
+#include <NewKit/String.hxx>
+
+namespace Kernel
+{
+ 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<StringView> ToStringView(Ref<RawIPAddress6>& ipv6);
+ static ErrorOr<StringView> ToStringView(Ref<RawIPAddress>& ipv4);
+ static bool IpCheckVersion4(const char* ip);
+ };
+} // namespace Kernel