Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
StunClient.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Wildfire Games.
2 * Copyright (C) 2013-2016 SuperTuxKart-Team.
3 * This file is part of 0 A.D.
4 *
5 * 0 A.D. is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * 0 A.D. is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef STUNCLIENT_H
20#define STUNCLIENT_H
21
23
24#include <string>
25
26class CStr8;
27
28typedef struct _ENetHost ENetHost;
29
30namespace StunClient
31{
32/**
33 * Return the publicly accessible IP of the given ENet host/socket.
34 * This is done by contacting STUN server.
35 * The return IP & port should only be considered valid for the give host/socket.
36 */
37bool FindPublicIP(ENetHost& enetClient, CStr8& ip, std::uint16_t& port);
38
39/**
40 * Send a message to the target server with the given ENet host/socket.
41 * This will open a port on the local gateway (if any) to receive trafic,
42 * allowing the recipient to answer (thus 'punching a hole' in the NAT).
43 * NB: this assumes consistent NAT, i.e. the outgoing port is always the same for the given client,
44 * thus allowing the IP discovered via STUN to be sent to the target server.
45 */
46void SendHolePunchingMessages(ENetHost& enetClient, const std::string& serverAddress, std::uint16_t serverPort);
47
48/**
49 * Return the local IP.
50 * Technically not a STUN method, but convenient to define here.
51 */
52bool FindLocalIP(CStr8& ip);
53}
54
55#endif // STUNCLIENT_H
struct _ENetHost ENetHost
Definition: NetClient.h:50
Definition: StunClient.cpp:42
void SendHolePunchingMessages(ENetHost &enetClient, const std::string &serverAddress, std::uint16_t serverPort)
Send a message to the target server with the given ENet host/socket.
Definition: StunClient.cpp:357
bool FindLocalIP(CStr &ip)
Definition: StunClient.cpp:376
bool FindPublicIP(ENetHost &transactionHost, CStr &ip, std::uint16_t &port)
Definition: StunClient.cpp:340