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

Option for both local and external port (with code) #57

Open
DennisBorCom opened this issue Mar 21, 2020 · 3 comments
Open

Option for both local and external port (with code) #57

DennisBorCom opened this issue Mar 21, 2020 · 3 comments

Comments

@DennisBorCom
Copy link

Currently this library seems only to support one port number for both local external. It would be nice to be able to specifiy both an internal and external port.

E.g. I'm running a web server at machine X which should me accessible on outside port 80. Also, I'm running an IOT project which runs on port 80 (local), but should have a different external port.

I'm running a modified version of the TinyUPNP library myself, with a couple of little changes:

TinyUPnP.cpp

line 54 from:

void TinyUPnP::addPortMappingConfig(IPAddress ruleIP, int rulePort, String ruleProtocol, int ruleLeaseDuration, String ruleFriendlyName)

to:

void TinyUPnP::addPortMappingConfig(IPAddress ruleIP, int internalPort, int externalPort, String ruleProtocol, int ruleLeaseDuration, String ruleFriendlyName) {

line 59 from:

newUpnpRule->internalPort = rulePort;

to:

newUpnpRule->internalPort = internalPort;

line 60 from:

newUpnpRule->externalPort = rulePort;

to

newUpnpRule->externalPort = externalPort;

line 436 from:

sprintf(integer_string, "%d", rule_ptr->internalPort);

to:

sprintf(integer_string, "%d", rule_ptr->externalPort);

line 810 from:

sprintf(integer_string, "%d", rule_ptr->internalPort);

to:

sprintf(integer_string, "%d", rule_ptr->externalPort);

TinyUPnP.h

line 107 from:

void addPortMappingConfig(IPAddress ruleIP /* can be NULL */, int rulePort, String ruleProtocol, int ruleLeaseDuration, String ruleFriendlyName);

to:

void addPortMappingConfig(IPAddress ruleIP /* can be NULL */ ,int internalPort, int externalPort, String ruleProtocol, int ruleLeaseDuration, String ruleFriendlyName);

Tested and working on my ESP8266 firmware.

@ofekp
Copy link
Owner

ofekp commented Mar 21, 2020

Wanna make the change an I will merge?
I think I can get to it next week if not

@DennisBorCom
Copy link
Author

DennisBorCom commented Mar 22, 2020

Hi Ofek,

Made the changes, including function overloading for users with the current library version for compatibility. I'm pretty new to GitHub and don't know how to upload files here, so I've uploaded it to my server:


https://pondctrl.dennisbor.com/tools/TinyUPnP/TinyUPnP.cpp

https://pondctrl.dennisbor.com/tools/TinyUPnP/TinyUPnP.h

@ofekp
Copy link
Owner

ofekp commented Mar 26, 2020

Awesome, thank you so much for this!
I will prepare the PR after issue_51 is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants