diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-06-15 16:03:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-15 16:03:38 +0200 |
| commit | eb9df5eea339812513c25a8d3b2eeb03c633e7ac (patch) | |
| tree | efcdaaa25d08daadcd27e0597a0fb20defc49a23 /dev/kernel/src/Network | |
| parent | 6511afbf405c31513bc88ab06bca58218610a994 (diff) | |
| parent | f7e5542dc13519cc78c204b4062acb0b71296a58 (diff) | |
Merge pull request #41 from nekernel-org/dev
NeKernel v0.0.3e1
Diffstat (limited to 'dev/kernel/src/Network')
| -rw-r--r-- | dev/kernel/src/Network/IPAddr.cc | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/dev/kernel/src/Network/IPAddr.cc b/dev/kernel/src/Network/IPAddr.cc index beb69470..b341af8f 100644 --- a/dev/kernel/src/Network/IPAddr.cc +++ b/dev/kernel/src/Network/IPAddr.cc @@ -8,11 +8,11 @@ #include <NetworkKit/IP.h> namespace Kernel { -Char* RawIPAddress::Address() { +UInt8* RawIPAddress::Address() { return fAddr; } -RawIPAddress::RawIPAddress(char bytes[4]) { +RawIPAddress::RawIPAddress(UInt8 bytes[4]) { rt_copy_memory(bytes, fAddr, 4); } @@ -32,30 +32,30 @@ BOOL RawIPAddress::operator!=(const RawIPAddress& ipv4) { return true; } -Char& RawIPAddress::operator[](const Size& index) { +UInt8& RawIPAddress::operator[](const Size& index) { kout << "[RawIPAddress::operator[]] Fetching Index...\r"; - static char IP_PLACEHOLDER = '0'; - if (index > 4) return IP_PLACEHOLDER; + static UInt8 IP_PLACEHOLDER = '0'; + if (index >= 4) return IP_PLACEHOLDER; return fAddr[index]; } -RawIPAddress6::RawIPAddress6(char bytes[8]) { - rt_copy_memory(bytes, fAddr, 8); +RawIPAddress6::RawIPAddress6(UInt8 bytes[16]) { + rt_copy_memory(bytes, fAddr, 16); } -char& RawIPAddress6::operator[](const Size& index) { +UInt8& RawIPAddress6::operator[](const Size& index) { kout << "[RawIPAddress6::operator[]] Fetching Index...\r"; - static char IP_PLACEHOLDER = '0'; - if (index > 8) return IP_PLACEHOLDER; + static UInt8 IP_PLACEHOLDER = '0'; + if (index >= 16) return IP_PLACEHOLDER; return fAddr[index]; } bool RawIPAddress6::operator==(const RawIPAddress6& ipv6) { - for (SizeT index = 0; index < 8; ++index) { + for (SizeT index = 0; index < 16; ++index) { if (ipv6.fAddr[index] != fAddr[index]) return false; } @@ -63,23 +63,28 @@ bool RawIPAddress6::operator==(const RawIPAddress6& ipv6) { } bool RawIPAddress6::operator!=(const RawIPAddress6& ipv6) { - for (SizeT index = 0; index < 8; ++index) { + for (SizeT index = 0; index < 16; ++index) { if (ipv6.fAddr[index] == fAddr[index]) return false; } return true; } +/// @todo ErrorOr<KString> IPFactory::ToKString(Ref<RawIPAddress6>& ipv6) { - auto str = KStringBuilder::Construct(ipv6.Leak().Address()); + NE_UNUSED(ipv6); + auto str = KStringBuilder::Construct(0); return str; } +/// @todo ErrorOr<KString> IPFactory::ToKString(Ref<RawIPAddress>& ipv4) { - auto str = KStringBuilder::Construct(ipv4.Leak().Address()); + NE_UNUSED(ipv4); + auto str = KStringBuilder::Construct(0); return str; } +/// @note Doesn't catch IPs such as 256.999.0.1, UNSAFE! bool IPFactory::IpCheckVersion4(const Char* ip) { if (!ip) return NO; @@ -89,6 +94,7 @@ bool IPFactory::IpCheckVersion4(const Char* ip) { if (ip[base] == '.') { cnter = 0; } else { + if (!rt_is_alnum(ip[base])) return false; if (cnter == 3) return false; ++cnter; |
