Disclaimer: I've carefully read every similar topic here and did a google search. Non of those answered my questions, so I would like to accumulate information in this topic. P.S. I might not be so good in English, sorry about that.
I want to make a p2p application (a game). Obviously lots of people will run this program on a machine which is a part of a local network with one internet access point (router) and app simply will not work without port forwarding. So, I did a research and found out that I can do automatic port forwarding with UPnP. Micro test-code were written to access port forwarding:
bool CPortController::Init() {
HRESULT result = CoInitialize(NULL); // Must be NULL
if (FAILED(result)) return false;
result = CoCreateInstance(__uuidof(UPnPNAT), NULL, CLSCTX_ALL, __uuidof(IUPnPNAT), (void **)&Nat);
if (FAILED(result) || !Nat) return false;
result = Nat->get_StaticPortMappingCollection(&Collection);
if (FAILED(result) || !Collection) return false; // Here I'm getting S_OK as result, but Collection is always == 0
return true;
}
Searched for reason of that(see comment in code) happening I've found: 1. Old system (nope, I have Win7 with updates) 2. Router might not have UPnP capability or it might not be enabled 3. Firewall might be blocking TCP port 2869 or UDP port 1900 which are both needed for UPnP
Sadly, I don't have access to router to check last 2, but it's not that important since Skype and uTorrent (both p2p) works perfectly. I need to find the way to do the same trick and forward port automatically with my app without asking user to do anything.
About UPnP libraries: I've found few UPnP libraries (PlatinumUPnP, miniUPnP), but they seems to have so much code oriented on finding smart devices and putting them together ... uhm ... I'm not sure I need this to complete my task and I can't find a piece of code (which not using those WinUPnPAPI, I listed above) for auto-port-forwarding.
I'm a bit lost now. Could anyone show me a direction to continue research ? Maybe there is something else than UPnP for that ? Maybe there is a lib (which I missed) to use ? Spread some light, please. Thank you in advance.