Merge pull request #8496 from sum2012/ANR2ME-portset

Support port offset by @ANR2ME
This commit is contained in:
Henrik Rydgård 2016-01-24 11:35:53 +01:00
commit 0550cd306d
7 changed files with 19 additions and 13 deletions

View File

@ -684,6 +684,7 @@ static ConfigSetting systemParamSettings[] = {
ConfigSetting("NickName", &g_Config.sNickName, "PPSSPP", true, true),
ConfigSetting("proAdhocServer", &g_Config.proAdhocServer, "coldbird.net", true, true),
ConfigSetting("MacAddress", &g_Config.sMACAddress, &CreateRandMAC, true, true),
ConfigSetting("PortOffset", &g_Config.iPortOffset, 0, true, true),
ReportedConfigSetting("Language", &g_Config.iLanguage, &DefaultSystemParamLanguage, true, true),
ConfigSetting("TimeFormat", &g_Config.iTimeFormat, PSP_SYSTEMPARAM_TIME_FORMAT_24HR, true, true),
ConfigSetting("DateFormat", &g_Config.iDateFormat, PSP_SYSTEMPARAM_DATE_FORMAT_YYYYMMDD, true, true),

View File

@ -363,6 +363,7 @@ public:
std::string sNickName;
std::string proAdhocServer;
std::string sMACAddress;
int iPortOffset;
int iLanguage;
int iTimeFormat;
int iDateFormat;

View File

@ -31,6 +31,7 @@
#include "proAdhoc.h"
#include "i18n/i18n.h"
uint16_t portOffset = g_Config.iPortOffset;
uint32_t fakePoolSize = 0;
SceNetAdhocMatchingContext * contexts = NULL;
int one = 1;

View File

@ -795,6 +795,7 @@ extern SceNetAdhocPdpStat * pdp[255];
extern SceNetAdhocPtpStat * ptp[255];
extern std::map<int, AdhocctlHandler> adhocctlHandlers;
extern uint16_t portOffset;
extern uint32_t fakePoolSize;
extern SceNetAdhocMatchingContext * contexts;
extern int one;

View File

@ -52,6 +52,7 @@ static void __ResetInitNetLib() {
}
void __NetInit() {
portOffset = g_Config.iPortOffset;
//net::Init();
#ifdef _MSC_VER
WSADATA data;

View File

@ -276,7 +276,7 @@ static int sceNetAdhocPdpCreate(const char *mac, u32 port, int bufferSize, u32 u
addr.sin_addr.s_addr = INADDR_ANY;
//if (port < 7) addr.sin_port = htons(port + 1341); else // <= 443
addr.sin_port = htons(port); // This not safe in any way...
addr.sin_port = htons(port + portOffset ); // This not safe in any way...
// The port might be under 1024 (ie. GTA:VCS use port 1, Ford Street Racing use port 0 (UNUSED_PORT), etc) and already used by other application/host OS, should we add 1024 to the port whenever it tried to use an already used port?
// Bound Socket to local Port
@ -303,7 +303,7 @@ static int sceNetAdhocPdpCreate(const char *mac, u32 port, int bufferSize, u32 u
// Fill in Data
internal->id = usocket;
internal->laddr = *saddr;
internal->lport = getLocalPort(usocket); //should use the port given to the socket (in case it's UNUSED_PORT port) isn't?
internal->lport = getLocalPort(usocket) - portOffset; //should use the port given to the socket (in case it's UNUSED_PORT port) isn't?
internal->rcv_sb_cc = bufferSize;
// Link Socket to Translator ID
@ -427,7 +427,7 @@ static int sceNetAdhocPdpSend(int id, const char *mac, u32 port, void *data, int
// Fill in Target Structure
sockaddr_in target;
target.sin_family = AF_INET;
target.sin_port = htons(dport);
target.sin_port = htons(dport + portOffset);
// Get Peer IP
if (resolveMAC((SceNetEtherAddr *)daddr, (uint32_t *)&target.sin_addr.s_addr)) {
@ -495,7 +495,7 @@ static int sceNetAdhocPdpSend(int id, const char *mac, u32 port, void *data, int
sockaddr_in target;
target.sin_family = AF_INET;
target.sin_addr.s_addr = peer->ip_addr;
target.sin_port = htons(dport);
target.sin_port = htons(dport + portOffset);
// Send Data
changeBlockingMode(socket->id, flag);
@ -633,7 +633,7 @@ static int sceNetAdhocPdpRecv(int id, void *addr, void * port, void *buf, void *
if (resolveIP(sin.sin_addr.s_addr, &mac)) {
// Provide Sender Information
*saddr = mac;
*sport = ntohs(sin.sin_port);
*sport = ntohs(sin.sin_port) - portOffset;
// Save Length
*len = received;
@ -1639,7 +1639,7 @@ static int sceNetAdhocPtpOpen(const char *srcmac, int sport, const char *dstmac,
}
// Valid Ports
if (!isPTPPortInUse(sport) && dport != 0) {
if (!isPTPPortInUse(sport) /*&& dport != 0*/) {
// Valid Arguments
if (bufsize > 0 && rexmt_int > 0 && rexmt_cnt > 0) {
// Create Infrastructure Socket
@ -1659,14 +1659,14 @@ static int sceNetAdhocPtpOpen(const char *srcmac, int sport, const char *dstmac,
// addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = htons(sport);
addr.sin_port = htons(sport + portOffset);
// Bound Socket to local Port
if (bind(tcpsocket, (sockaddr *)&addr, sizeof(addr)) == 0) {
// Update sport with the port assigned by bind
// Update sport with the port assigned binternal->lport = ntohs(local.sin_port)y bind
socklen_t len = sizeof(addr);
if (getsockname(tcpsocket, (sockaddr *)&addr, &len) == 0) {
sport = ntohs(addr.sin_port);
sport = ntohs(addr.sin_port) - portOffset;
}
// Allocate Memory
@ -1850,11 +1850,11 @@ static int sceNetAdhocPtpAccept(int id, u32 peerMacAddrPtr, u32 peerPortPtr, int
// Copy Local Address Data to Structure
getLocalMac(&internal->laddr);
internal->lport = ntohs(local.sin_port);
internal->lport = ntohs(local.sin_port) - portOffset;
// Copy Peer Address Data to Structure
internal->paddr = mac;
internal->pport = ntohs(peeraddr.sin_port);
internal->pport = ntohs(peeraddr.sin_port) - portOffset;
// Set Connected State
internal->state = ADHOC_PTP_STATE_ESTABLISHED;
@ -1942,7 +1942,7 @@ static int sceNetAdhocPtpConnect(int id, int timeout, int flag) {
// Setup Target Address
// sin.sin_len = sizeof(sin);
sin.sin_family = AF_INET;
sin.sin_port = htons(socket->pport);
sin.sin_port = htons(socket->pport + portOffset);
// Grab Peer IP
if (resolveMAC(&socket->paddr, (uint32_t *)&sin.sin_addr.s_addr)) {
@ -2131,7 +2131,7 @@ static int sceNetAdhocPtpListen(const char *srcmac, int sport, int bufsize, int
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = htons(sport);
addr.sin_port = htons(sport + portOffset);
int iResult = 0;
// Bound Socket to local Port

View File

@ -477,6 +477,7 @@ void GameSettingsScreen::CreateViews() {
#endif
networkingSettings->Add(new CheckBox(&g_Config.bEnableAdhocServer, n->T("Enable built-in PRO Adhoc Server", "Enable built-in PRO Adhoc Server")));
networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sMACAddress, n->T("Change Mac Address"), nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeMacAddress);
networkingSettings->Add(new PopupSliderChoice(&g_Config.iPortOffset, 0, 60000, n->T("Port offset", "Port offset(0 = PSP compatibility)"), 100, screenManager()));
ViewGroup *toolsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT));
toolsScroll->SetTag("GameSettingsTools");