Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
upnp Namespace Reference

UPnP port mapping. More...

Classes

class  deinit_t
 RAII helper that runs shutdown cleanup when destroyed. More...
struct  mapping_t
 UPnP port mapping description and lease state. More...
class  urls_t
 Move-only RAII wrapper generated by KITTY_USING_MOVE_T. Alias for element type. More...

Typedefs

using device_t = util::safe_ptr<UPNPDev, freeUPNPDevlist>
 Owning pointer to miniupnpc device discovery results.

Enumerations

enum class  igd_status_e : int { none = 0 , connected = 1 , disconnected , unknown_device }
 Result codes returned by the installed MiniUPnPc library. More...

Functions

bool is_valid_igd (igd_status_e status)
 Check whether a UPNP_GetValidIGD() status code identifies a usable IGD.
std::unique_ptr< platf::deinit_t > start ()
 Start UPnP port mapping and return its shutdown guard.
igd_status_e UPNP_GetValidIGDStatus (device_t &device, urls_t *urls, IGDdatas *data, std::array< char, INET6_ADDRESS_STRLEN > &lan_addr)
 Get the valid IGD status.

Variables

constexpr auto INET6_ADDRESS_STRLEN = 46
 Protocol or platform constant for inet6 address strlen.
constexpr auto IPv4 = 0
 I pv4.
constexpr auto IPv6 = 1
 I pv6.
constexpr auto PORT_MAPPING_LIFETIME = 3600s
 GameStream port offset for port mapping lifetime.
constexpr auto REFRESH_INTERVAL = 120s
 Protocol or platform constant for refresh interval.

Detailed Description

UPnP port mapping.

Enumeration Type Documentation

◆ igd_status_e

enum class upnp::igd_status_e : int
strong

Result codes returned by the installed MiniUPnPc library.

Project-owned equivalent of the UPNP_GetValidIGD() result codes. MiniUPnPc 2.2.8 (API version 18) introduced the private-address result, renumbering the values that follow it; the library's own UPNP_* symbolic names only exist starting with MiniUPnPc 2.3.0 (API version 19), so this enum centralizes the version-dependent numbering instead of relying on those names.

Enumerator
none 

No IGD was found.

connected 

A connected IGD was found.

disconnected 

A disconnected IGD was found.

unknown_device 

The device was not recognized as an IGD.

Function Documentation

◆ is_valid_igd()

bool upnp::is_valid_igd ( igd_status_e status)
nodiscard

Check whether a UPNP_GetValidIGD() status code identifies a usable IGD.

Accepts every status code that identifies a valid IGD (connected, private-IP, or disconnected). The private_ip member only exists with MiniUPnPc >= 2.2.8 (API version 18); disconnected is 2 before API 18 and 3 starting with API 18, and unknown_device is 3 or 4 respectively. Callers don't need to handle the version difference themselves.

Parameters
statusThe status returned by UPNP_GetValidIGDStatus(), converted to igd_status_e.
Returns
true if the status identifies a usable IGD, false otherwise.

◆ start()

std::unique_ptr< platf::deinit_t > upnp::start ( )
nodiscard

Start UPnP port mapping and return its shutdown guard.

Returns
Start status.

◆ UPNP_GetValidIGDStatus()

igd_status_e upnp::UPNP_GetValidIGDStatus ( device_t & device,
urls_t * urls,
IGDdatas * data,
std::array< char, INET6_ADDRESS_STRLEN > & lan_addr )

Get the valid IGD status.

This function is a wrapper around UPNP_GetValidIGD() that returns the status code. There is a pre-processor check to determine which version of the function to call based on the version of the MiniUPnPc library.

Parameters
deviceThe device.
urlsThe URLs.
dataThe IGD data.
lan_addrThe LAN address.
Returns
The IGD status as an igd_status_e value, converted from the raw UPNP_GetValidIGD() result.
Return values
igd_status_e::noneNo IGD found.
igd_status_e::connectedA valid connected IGD has been found.
igd_status_e::private_ipA valid connected IGD with a private IP address (MiniUPnPc >= 2.2.8 only).
igd_status_e::disconnectedA valid IGD has been found but it reported as not connected.
igd_status_e::unknown_deviceAn UPnP device has been found but was not recognized as an IGD.