Implement IPv6 support

This commit is contained in:
Cameron Gutman
2023-08-26 14:10:29 -05:00
parent 7662fe8616
commit 62a5cd959a
10 changed files with 214 additions and 27 deletions

View File

@@ -6,6 +6,8 @@
#include <tuple>
#include <boost/asio.hpp>
#include <enet/enet.h>
#include "utility.h"
@@ -24,6 +26,11 @@ namespace net {
WAN
};
enum af_e : int {
IPV4,
BOTH
};
net_e
from_enum_string(const std::string_view &view);
std::string_view
@@ -33,5 +40,39 @@ namespace net {
from_address(const std::string_view &view);
host_t
host_create(ENetAddress &addr, std::size_t peers, std::uint16_t port);
host_create(af_e af, ENetAddress &addr, std::size_t peers, std::uint16_t port);
/**
* @brief Returns the `af_e` enum value for the `address_family` config option value.
* @param view The config option value.
* @return The `af_e` enum value.
*/
af_e
af_from_enum_string(const std::string_view &view);
/**
* @brief Returns the wildcard binding address for a given address family.
* @param af Address family.
* @return Normalized address.
*/
std::string_view
af_to_any_address_string(af_e af);
/**
* @brief Returns the given address in normalized string form.
* @details Normalization converts IPv4-mapped IPv6 addresses into IPv4 addresses.
* @param address The address to normalize.
* @return Normalized address in string form.
*/
std::string
addr_to_normalized_string(boost::asio::ip::address address);
/**
* @brief Returns the given address in a normalized form for in the host portion of a URL.
* @details Normalization converts IPv4-mapped IPv6 addresses into IPv4 addresses.
* @param address The address to normalize and escape.
* @return Normalized address in URL-escaped string.
*/
std::string
addr_to_url_escaped_string(boost::asio::ip::address address);
} // namespace net