Declarations for networking related functions.
More...
#include <tuple>
#include <utility>
#include <boost/asio.hpp>
#include <enet/enet.h>
#include "utility.h"
Go to the source code of this file.
|
|
using | net::host_t = util::safe_ptr<ENetHost, free_host> |
| | Owning ENet host pointer released with enet_host_destroy.
|
| |
|
using | net::packet_t = util::safe_ptr<ENetPacket, enet_packet_destroy> |
| | Owning ENet packet pointer released with enet_packet_destroy.
|
| |
|
using | net::peer_t = ENetPeer * |
| | Raw ENet peer handle owned by an ENet host.
|
| |
Declarations for networking related functions.
◆ af_e
Enumerates supported af options.
| Enumerator |
|---|
| IPV4 | IPv4 only.
|
| BOTH | IPv4 and IPv6.
|
◆ net_e
Enumerates supported net options.
| Enumerator |
|---|
| PC | PC.
|
| LAN | LAN.
|
| WAN | WAN.
|
◆ addr_to_normalized_string()
| std::string net::addr_to_normalized_string |
( |
boost::asio::ip::address | address | ) |
|
Get the given address in normalized string form.
Normalization converts IPv4-mapped IPv6 addresses into IPv4 addresses.
- Parameters
-
| address | The address to normalize. |
- Returns
- Normalized address in string form.
◆ addr_to_url_escaped_string()
| std::string net::addr_to_url_escaped_string |
( |
boost::asio::ip::address | address | ) |
|
Get the given address in a normalized form for the host portion of a URL.
Normalization converts IPv4-mapped IPv6 addresses into IPv4 addresses.
- Parameters
-
| address | The address to normalize and escape. |
- Returns
- Normalized address in URL-escaped string.
◆ af_from_enum_string()
| af_e net::af_from_enum_string |
( |
const std::string_view & | view | ) |
|
Convert a config address-family string to the matching enum.
- Parameters
-
| view | The config option value. |
- Returns
- Address-family enum represented by the string.
◆ af_to_any_address_string()
| std::string_view net::af_to_any_address_string |
( |
af_e | af | ) |
|
Get the wildcard binding address for a given address family.
- Parameters
-
- Returns
- Normalized address.
◆ encryption_mode_for_address()
| int net::encryption_mode_for_address |
( |
boost::asio::ip::address | address | ) |
|
Get the encryption mode for the given remote endpoint address.
- Parameters
-
| address | The address used to look up the desired encryption mode. |
- Returns
- The WAN or LAN encryption mode, based on the provided address.
◆ free_host()
| void net::free_host |
( |
ENetHost * | host | ) |
|
Destroy an ENet host allocated by host_create().
- Parameters
-
| host | Host name or address to resolve. |
◆ from_address()
| net_e net::from_address |
( |
const std::string_view & | view | ) |
|
Convert a Boost address family to Sunshine network enum value.
- Parameters
-
| view | Boost.Log record view being formatted. |
- Returns
- Value converted from address.
◆ from_enum_string()
| net_e net::from_enum_string |
( |
const std::string_view & | view | ) |
|
Convert configuration text to a network enum value.
- Parameters
-
| view | Boost.Log record view being formatted. |
- Returns
- Value converted from enum string.
◆ get_bind_address()
| std::string net::get_bind_address |
( |
af_e | af | ) |
|
Get the binding address to use based on config.
- Parameters
-
- Returns
- The configured bind address or wildcard if not configured.
◆ host_create()
| host_t net::host_create |
( |
af_e | af, |
|
|
ENetAddress & | addr, |
|
|
std::uint16_t | port ) |
Create an ENet host with the requested address family.
- Parameters
-
| af | Address family used for socket creation or binding. |
| addr | Network address to bind, parse, or format. |
| port | TCP or UDP port number. |
- Returns
- ENet host bound to the requested address and port, or an empty handle on failure.
◆ map_port()
| std::uint16_t net::map_port |
( |
int | port | ) |
|
Map a specified port based on the base port.
- Parameters
-
| port | The port to map as a difference from the base port. |
- Returns
- The mapped port number.
*Examples**
std::uint16_t mapped_port = net::map_port(1);
- Todo
- Ensure port is not already in use by another application.
◆ mdns_instance_name()
| std::string net::mdns_instance_name |
( |
const std::string_view & | hostname | ) |
|
Returns a string for use as the instance name for mDNS.
- Parameters
-
| hostname | The hostname to use for instance name generation. |
- Returns
- Hostname-based instance name or "Sunshine" if hostname is invalid.
◆ normalize_address()
| boost::asio::ip::address net::normalize_address |
( |
boost::asio::ip::address | address | ) |
|
Convert an address to a normalized form.
Normalization converts IPv4-mapped IPv6 addresses into IPv4 addresses.
- Parameters
-
| address | The address to normalize. |
- Returns
- Normalized address.
◆ to_enum_string()
| std::string_view net::to_enum_string |
( |
net_e | net | ) |
|
Convert a network enum value to configuration text.
- Parameters
-
| net | Network scope to convert or format. |
- Returns
- Value converted to enum string.