summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/Sources/Network
diff options
context:
space:
mode:
Diffstat (limited to 'dev/Kernel/Sources/Network')
-rw-r--r--dev/Kernel/Sources/Network/IP.cxx126
-rw-r--r--dev/Kernel/Sources/Network/IPC.cxx68
-rw-r--r--dev/Kernel/Sources/Network/NetworkDevice.cxx35
3 files changed, 229 insertions, 0 deletions
diff --git a/dev/Kernel/Sources/Network/IP.cxx b/dev/Kernel/Sources/Network/IP.cxx
new file mode 100644
index 00000000..3e5462a1
--- /dev/null
+++ b/dev/Kernel/Sources/Network/IP.cxx
@@ -0,0 +1,126 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NetworkKit/IP.hxx>
+#include <NewKit/Utils.hxx>
+
+namespace Kernel
+{
+ char* RawIPAddress::Address()
+ {
+ return fAddr;
+ }
+
+ RawIPAddress::RawIPAddress(char bytes[4])
+ {
+ rt_copy_memory(bytes, fAddr, 4);
+ }
+
+ bool RawIPAddress::operator==(const RawIPAddress& ipv4)
+ {
+ for (Size index = 0; index < 4; ++index)
+ {
+ if (ipv4.fAddr[index] != fAddr[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ bool RawIPAddress::operator!=(const RawIPAddress& ipv4)
+ {
+ for (Size index = 0; index < 4; ++index)
+ {
+ if (ipv4.fAddr[index] == fAddr[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ char& RawIPAddress::operator[](const Size& index)
+ {
+ kcout << "[RawIPAddress::operator[]] Fetching Index...\r";
+
+ static char IP_PLACEHOLDER = '0';
+ if (index > 4)
+ return IP_PLACEHOLDER;
+
+ return fAddr[index];
+ }
+
+ RawIPAddress6::RawIPAddress6(char bytes[8])
+ {
+ rt_copy_memory(bytes, fAddr, 8);
+ }
+
+ char& RawIPAddress6::operator[](const Size& index)
+ {
+ kcout << "[RawIPAddress6::operator[]] Fetching Index...\r";
+
+ static char IP_PLACEHOLDER = '0';
+ if (index > 8)
+ return IP_PLACEHOLDER;
+
+ return fAddr[index];
+ }
+
+ bool RawIPAddress6::operator==(const RawIPAddress6& ipv6)
+ {
+ for (SizeT index = 0; index < 8; ++index)
+ {
+ if (ipv6.fAddr[index] != fAddr[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ bool RawIPAddress6::operator!=(const RawIPAddress6& ipv6)
+ {
+ for (SizeT index = 0; index < 8; ++index)
+ {
+ if (ipv6.fAddr[index] == fAddr[index])
+ return false;
+ }
+
+ return true;
+ }
+
+ ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress6>& ipv6)
+ {
+ auto str = StringBuilder::Construct(ipv6.Leak().Address());
+ return str;
+ }
+
+ ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress>& ipv4)
+ {
+ auto str = StringBuilder::Construct(ipv4.Leak().Address());
+ return str;
+ }
+
+ bool IPFactory::IpCheckVersion4(const char* ip)
+ {
+ int cnter = 0;
+
+ for (Size base = 0; base < rt_string_len(ip); ++base)
+ {
+ if (ip[base] == '.')
+ {
+ cnter = 0;
+ }
+ else
+ {
+ if (cnter == 3)
+ return false;
+
+ ++cnter;
+ }
+ }
+
+ return true;
+ }
+} // namespace Kernel
diff --git a/dev/Kernel/Sources/Network/IPC.cxx b/dev/Kernel/Sources/Network/IPC.cxx
new file mode 100644
index 00000000..f703e650
--- /dev/null
+++ b/dev/Kernel/Sources/Network/IPC.cxx
@@ -0,0 +1,68 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NetworkKit/IPC.hxx>
+#include <KernelKit/LPC.hxx>
+#include <KernelKit/ProcessScheduler.hxx>
+
+using namespace Kernel;
+
+/// @internal
+/// @brief The internal sanitize function.
+Bool ipc_int_sanitize_packet(IPC_MESSAGE_STRUCT* pckt)
+{
+ auto endian = DEDUCE_ENDIAN(pckt, ((char*)pckt)[0]);
+
+ switch (endian)
+ {
+ case Endian::kEndianBig: {
+ if (pckt->IpcEndianess == eIPCEPLittleEndian)
+ goto ipc_check_failed;
+
+ break;
+ }
+ case Endian::kEndianLittle: {
+ if (pckt->IpcEndianess == eIPCEPBigEndian)
+ goto ipc_check_failed;
+
+ break;
+ }
+ case Endian::kEndianMixed:
+ break;
+ default:
+ goto ipc_check_failed;
+ }
+
+ if (pckt->IpcFrom == pckt->IpcTo ||
+ pckt->IpcPacketSize > cIPCEPMsgSize)
+ {
+ goto ipc_check_failed;
+ }
+
+ return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cRemoteHeaderMagic;
+
+ipc_check_failed:
+ ErrLocal() = kErrorIPC;
+ return false;
+}
+
+namespace Kernel
+{
+ /// @brief Sanitize packet function
+ /// @retval true packet is correct.
+ /// @retval false packet is incorrect and process has crashed.
+ Bool ipc_sanitize_packet(IPC_MESSAGE_STRUCT* pckt)
+ {
+ if (!pckt ||
+ !ipc_int_sanitize_packet(pckt))
+ {
+ ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
+ return false;
+ }
+
+ return true;
+ }
+} // namespace Kernel
diff --git a/dev/Kernel/Sources/Network/NetworkDevice.cxx b/dev/Kernel/Sources/Network/NetworkDevice.cxx
new file mode 100644
index 00000000..1bcd9e24
--- /dev/null
+++ b/dev/Kernel/Sources/Network/NetworkDevice.cxx
@@ -0,0 +1,35 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <NetworkKit/NetworkDevice.hxx>
+#include <NewKit/Utils.hxx>
+
+namespace Kernel
+{
+ /// \brief Getter for fNetworkName.
+ const char* NetworkDevice::Name() const
+ {
+ return this->fNetworkName;
+ }
+
+ /// \brief Setter for fNetworkName.
+ Boolean NetworkDevice::Name(const char* strView)
+ {
+ if (strView == nullptr)
+ return false;
+
+ if (*strView == 0)
+ return false;
+
+ if (rt_string_len(strView) > cNetworkNameLen)
+ return false;
+
+ rt_copy_memory((VoidPtr)strView,
+ (VoidPtr)this->fNetworkName, rt_string_len(strView));
+
+ return true;
+ }
+} // namespace Kernel