Skip to content

Commit

Permalink
libraries: libcore[socektaddress]
Browse files Browse the repository at this point in the history
  • Loading branch information
krishpranav committed Oct 1, 2023
1 parent 815fc58 commit 842eb97
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions libraries/libcore/socketaddress.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @file socketaddress.h
* @author Krisna Pranav
* @brief socket address
* @version 6.0
* @date 2023-10-01
*
* @copyright Copyright (c) 2021 - 2023 pranaOS Developers, Krisna Pranav
*
*/

#pragma once

#include <mods/ipv4address.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>

namespace Core
{

class SocketAddress
{
public:
enum class Type
{
Invalid,
IPv4,
Local
}; // enum class Type

SocketAddress() {}

SocketAddress(const IPv4Address& address)
: m_type(Type::IPv4)
, m_ipv4_address(address)
{}

static SocketAddress local(const String& address)
{
SocketAddress addr;
addr.m_type = Type::Local;
addr.m_local_address = address;
return addr;
}

Type type() const
{
return m_type;
}

bool is_valid() const
{
return m_type != Type::Invalid;
}

IPv4Address ipv4_address() const
{
return m_ipv4_address;
}

private:
Type m_type { Type::Invalid };
IPv4Address m_ipv4_address;
u16 m_port { 0 };
String m_local_address;
}; // class SocketAddress

} // namespace Core

0 comments on commit 842eb97

Please sign in to comment.