Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
network.h
Go to the documentation of this file.
1
5#pragma once
6
7// standard includes
8#include <span>
9#include <tuple>
10#include <utility>
11#include <vector>
12
13// lib includes
14#include <boost/asio.hpp>
15#include <enet/enet.h>
16
17// local includes
18#include "network_link.h"
19#include "utility.h"
20
21namespace net {
22 void free_host(ENetHost *host);
23
33 std::uint16_t map_port(int port);
34
35 using host_t = util::safe_ptr<ENetHost, free_host>;
36 using peer_t = ENetPeer *;
37 using packet_t = util::safe_ptr<ENetPacket, enet_packet_destroy>;
38
39 enum net_e : int {
43 };
44
45 enum af_e : int {
48 };
49
50 net_e from_enum_string(const std::string_view &view);
51 std::string_view to_enum_string(net_e net);
52
61 net_e from_address(const std::string_view &view);
62
71 net_e from_address(const std::string_view &view, std::span<const interface_address_t> links);
72
81 net_e from_address_ranges(const std::string_view &view);
82
87 std::vector<interface_address_t> interface_addresses();
88
94 raw_address_t to_raw_address(const boost::asio::ip::address &address);
95
96 // Optional error output describes initialization/socket failures without
97 // assuming that every ENet failure is a port conflict. Cleared on success.
98 host_t host_create(af_e af, ENetAddress &addr, std::uint16_t port, boost::system::error_code *error = nullptr);
99
100 // Apply to every streaming socket, including the Asio video/audio sockets.
101 bool prevent_socket_inheritance(boost::asio::ip::udp::socket::native_handle_type socket, boost::system::error_code &error);
102
116 bool udp_port_available(af_e af, std::uint16_t port);
117
123 af_e af_from_enum_string(const std::string_view &view);
124
130 std::string_view af_to_any_address_string(af_e af);
131
138 boost::asio::ip::address normalize_address(boost::asio::ip::address address);
139
146 std::string addr_to_normalized_string(boost::asio::ip::address address);
147
154 std::string addr_to_url_escaped_string(boost::asio::ip::address address);
155
161 int encryption_mode_for_address(boost::asio::ip::address address);
162
168 std::string mdns_instance_name(const std::string_view &hostname);
169} // namespace net
std::uint16_t map_port(int port)
Map a specified port based on the base port.
Definition network.cpp:350
af_e
Definition network.h:45
@ IPV4
IPv4 only.
Definition network.h:46
@ BOTH
IPv4 and IPv6.
Definition network.h:47
net_e
Definition network.h:39
@ PC
PC.
Definition network.h:40
@ WAN
WAN.
Definition network.h:42
@ LAN
LAN.
Definition network.h:41
Declarations for utility functions.