Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support port offset by @ANR2ME #8496

Merged
merged 1 commit into from
Jan 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ struct Config {
std::string sNickName;
std::string proAdhocServer;
std::string sMACAddress;
int iPortOffset;
int iLanguage;
int iTimeFormat;
int iDateFormat;
Expand Down
1 change: 1 addition & 0 deletions Core/HLE/proAdhoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Core/HLE/proAdhoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Core/HLE/sceNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static void __ResetInitNetLib() {
}

void __NetInit() {
portOffset = g_Config.iPortOffset;
//net::Init();
#ifdef _MSC_VER
WSADATA data;
Expand Down
26 changes: 13 additions & 13 deletions Core/HLE/sceNetAdhoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down