-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
815fc58
commit 842eb97
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |