Added name resolution code for linux.

This commit is contained in:
2024-08-20 13:54:52 +02:00
parent a755de5c5f
commit 04a28e220c
4 changed files with 197 additions and 75 deletions

View File

@@ -17,6 +17,8 @@ struct IPv4Address
auto operator<=>(const IPv4Address&) const noexcept = default;
[[nodiscard]] std::string toString() const;
[[nodiscard]]
static Optional<IPv4Address> fromString(std::string_view stringView) noexcept;
};
@@ -27,11 +29,23 @@ struct IPv6Address
auto operator<=>(const IPv6Address&) const noexcept = default;
[[nodiscard]] std::string toString() const;
[[nodiscard]]
static Optional<IPv6Address> fromString(std::string_view stringView) noexcept;
};
using ip_address_t = std::variant<IPv4Address, IPv6Address>;
[[nodiscard]]
inline std::string ipAddressToString(const ip_address_t& address) noexcept
{
if (address.valueless_by_exception())
{
return "";
}
return std::visit([](const auto& addr) { return addr.toString(); }, address);
}
[[nodiscard]]
inline Optional<ip_address_t> ipAddressFromString(std::string_view stringView) noexcept
{