diff options
Diffstat (limited to 'NetworkKit')
| -rw-r--r-- | NetworkKit/IP.hpp | 84 | ||||
| -rw-r--r-- | NetworkKit/NetworkDevice.hpp | 53 | ||||
| -rw-r--r-- | NetworkKit/compile_flags.txt | 5 |
3 files changed, 142 insertions, 0 deletions
diff --git a/NetworkKit/IP.hpp b/NetworkKit/IP.hpp new file mode 100644 index 00000000..870ebbc3 --- /dev/null +++ b/NetworkKit/IP.hpp @@ -0,0 +1,84 @@ +/* + * ======================================================== + * + * hCore + * Copyright XPX Corp, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include <NewKit/Defines.hpp> +#include <KernelKit/DebugOutput.hpp> +#include <NewKit/String.hpp> +#include <NewKit/Ref.hpp> + +namespace hCore +{ +class RawIPAddress6; +class RawIPAddress; +class NetworkManager; + +class RawIPAddress final +{ + private: + RawIPAddress(char bytes[4]); + ~RawIPAddress() = default; + + RawIPAddress &operator=(const RawIPAddress &) = delete; + RawIPAddress(const RawIPAddress &) = default; + + public: + char *Address() + { + return m_Addr; + } + + char &operator[](const Size &index); + + bool operator==(const RawIPAddress &ipv6); + bool operator!=(const RawIPAddress &ipv6); + + private: + char m_Addr[4]; + + friend NetworkManager; // it is the one creating these addresses, thus this + // is why the constructors are private. +}; + +class RawIPAddress6 final +{ + private: + RawIPAddress6(char Bytes[8]); + ~RawIPAddress6() = default; + + RawIPAddress6 &operator=(const RawIPAddress6 &) = delete; + RawIPAddress6(const RawIPAddress6 &) = default; + + public: + char *Address() + { + return m_Addr; + } + + char &operator[](const Size &index); + + bool operator==(const RawIPAddress6 &ipv6); + bool operator!=(const RawIPAddress6 &ipv6); + + private: + char m_Addr[8]; + + friend NetworkManager; +}; + +class IPHelper +{ + public: + static ErrorOr<StringView> ToStringView(Ref<RawIPAddress6> ipv6); + static ErrorOr<StringView> ToStringView(Ref<RawIPAddress> ipv4); + static bool IpCheckV4(const char *ip); + +}; +} // namespace hCore diff --git a/NetworkKit/NetworkDevice.hpp b/NetworkKit/NetworkDevice.hpp new file mode 100644 index 00000000..fd6b1d2b --- /dev/null +++ b/NetworkKit/NetworkDevice.hpp @@ -0,0 +1,53 @@ +/* + * ======================================================== + * + * hCore + * Copyright XPX Corp, all rights reserved. + * + * ======================================================== + */ + +#ifndef _INC_NETWORKDEVICE_HPP__ +#define _INC_NETWORKDEVICE_HPP__ + +#include <KernelKit/Device.hpp> +#include <NetworkKit/IP.hpp> + +namespace hCore +{ + struct NetworkDeviceCommand; + + class NetworkDevice final : public IDevice<NetworkDeviceCommand> + { + public: + NetworkDevice(void(*out)(NetworkDeviceCommand), void(*in)(NetworkDeviceCommand), + void(*on_cleanup)(void) = nullptr); + + ~NetworkDevice() override; + + public: + NetworkDevice &operator=(const NetworkDevice &) = default; + NetworkDevice(const NetworkDevice &) = default; + + public: + const char* Name() const override { return ("NetworkDevice"); } + + private: + void(*fCleanup)(void); + + }; + + struct NetworkDeviceCommand + { + UInt32 Command; + UInt32 VLan; + UInt32 DmaLow; + UInt32 DmaHigh; + }; + + using TCPNetworkDevice = NetworkDevice; + using UDPNetworkDevice = NetworkDevice; + using PPPNetworkDevice = NetworkDevice; +} // namespace hCore + +#endif // !_INC_NETWORKDEVICE_HPP__ diff --git a/NetworkKit/compile_flags.txt b/NetworkKit/compile_flags.txt new file mode 100644 index 00000000..a37ae6bf --- /dev/null +++ b/NetworkKit/compile_flags.txt @@ -0,0 +1,5 @@ +-nostdlib +-ffreestanding +-std=c++20 +-I./ +-I../ |
