summaryrefslogtreecommitdiff
path: root/Libraries/LibCore/CSocketAddress.h
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibCore/CSocketAddress.h')
-rw-r--r--Libraries/LibCore/CSocketAddress.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/Libraries/LibCore/CSocketAddress.h b/Libraries/LibCore/CSocketAddress.h
new file mode 100644
index 0000000000..019a0869fb
--- /dev/null
+++ b/Libraries/LibCore/CSocketAddress.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include <AK/IPv4Address.h>
+
+class CSocketAddress {
+public:
+ enum class Type {
+ Invalid,
+ IPv4,
+ Local
+ };
+
+ CSocketAddress() {}
+ CSocketAddress(const IPv4Address& address)
+ : m_type(Type::IPv4)
+ , m_ipv4_address(address)
+ {
+ }
+
+ Type type() const { return m_type; }
+ bool is_valid() const { return m_type != Type::Invalid; }
+ IPv4Address ipv4_address() const { return m_ipv4_address; }
+
+ String to_string() const
+ {
+ switch (m_type) {
+ case Type::IPv4:
+ return m_ipv4_address.to_string();
+ default:
+ return "[CSocketAddress]";
+ }
+ }
+
+private:
+ Type m_type { Type::Invalid };
+ IPv4Address m_ipv4_address;
+};