mirror of
https://github.com/libretro/parallel-dc.git
synced 2026-11-08 17:27:41 -10:00
core/hw/arm7/vbaARM.cpp, the BBA and RTL8139 sources, the miniupnp wrapper and three headers in core/oslib were stored with CRLF line endings; everything else in core/ outside deps is LF. Only the line endings change. A patch that touches a CRLF file does not go through a plain git am, which strips the CRs from the patch on the way in and then finds the file does not match. That is why this patch carries these files whole, as binary, and why it had to come before anything else could be done to them.
82 lines
2.5 KiB
C++
Executable File
82 lines
2.5 KiB
C++
Executable File
/*
|
|
Copyright 2020 flyinghead
|
|
|
|
This file is part of Flycast.
|
|
|
|
Flycast is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
Flycast is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with Flycast. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
#include <miniupnpc.h>
|
|
#include <upnpcommands.h>
|
|
#include "types.h"
|
|
#include "miniupnp.h"
|
|
|
|
#ifndef UPNP_LOCAL_PORT_ANY
|
|
#define UPNP_LOCAL_PORT_ANY 0
|
|
#endif
|
|
|
|
bool MiniUPnP::Init()
|
|
{
|
|
int error = 0;
|
|
#if MINIUPNPC_API_VERSION >= 14
|
|
UPNPDev *devlist = upnpDiscover(2000, nullptr, nullptr, UPNP_LOCAL_PORT_ANY, 0, 2, &error);
|
|
#else
|
|
UPNPDev *devlist = upnpDiscover(2000, nullptr, nullptr, UPNP_LOCAL_PORT_ANY, 0, &error);
|
|
#endif
|
|
if (devlist == nullptr)
|
|
{
|
|
INFO_LOG(MODEM, "UPnP discover failed: error %d", error);
|
|
return false;
|
|
}
|
|
error = UPNP_GetValidIGD(devlist, &urls, &data, lanAddress, sizeof(lanAddress));
|
|
freeUPNPDevlist(devlist);
|
|
if (error != 1)
|
|
{
|
|
INFO_LOG(MODEM, "Internet Gateway not found: error %d", error);
|
|
return false;
|
|
}
|
|
wanAddress[0] = 0;
|
|
if (UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, wanAddress) != 0)
|
|
INFO_LOG(MODEM, "Cannot determine external IP address");
|
|
return true;
|
|
}
|
|
|
|
void MiniUPnP::Term()
|
|
{
|
|
for (const auto& port : mappedPorts)
|
|
UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.first.c_str(),
|
|
port.second ? "TCP" : "UDP", nullptr);
|
|
mappedPorts.clear();
|
|
FreeUPNPUrls(&urls);
|
|
}
|
|
|
|
bool MiniUPnP::AddPortMapping(int port, bool tcp)
|
|
{
|
|
std::string portStr(std::to_string(port));
|
|
int error = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
|
|
portStr.c_str(), // WAN port
|
|
portStr.c_str(), // LAN port
|
|
lanAddress,
|
|
"Flycast",
|
|
tcp ? "TCP" : "UDP",
|
|
nullptr, // remote (peer) host address or nullptr for no restriction
|
|
"86400"); // port map lease duration (in seconds) or zero for "as long as possible"
|
|
if (error != 0)
|
|
{
|
|
INFO_LOG(MODEM, "Port %d redirection failed: error %d", port, error);
|
|
return false;
|
|
}
|
|
mappedPorts.push_back(std::make_pair(portStr, tcp));
|
|
return true;
|
|
}
|