CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2010

    Windows firewall and the upnp framework

    Dear experts
    I am currently working on a simple file transfer application, I would like the receiving end to be able to punch a whole through the router using upnp to accept the connection, my reason for this is to make it easer for the average user, of course they may not know how to manually forward ports.

    I am using the IUPnPNAT COM interface witch i looked up from the msdn libary. the problem i am getting is around the Add() function.
    hr = pSPMC->Add(29000, L"TCP", 29000, L"", true, L"Recv_File", &pSPM);
          printf("Log: Failed to forward port 29000: 0x%081x\n", hr);
          return 1;
    When it comes to this part of the code, it locks up. I then realised that ports (TCP "2869" & UDP "1900") have to be opened on the windows firewall to be able to communicate with the router. I then tried to open these ports using the "Windows firewall API" but had no luck. For some strange reason i cannot open or close these ports unless the UPnP Framwork is enabled. When the framwork is enabled the ports are open by default and the application forwards the port "29000" without fail. The problem i am faced with now is i cant keep that framework enabled. so i thought i would try a cheeky system call to enable the framework and disable it once the program has finished etc.
    system("netsh firewall set service type = upnp mode = enable");
    // Forward port, create a socket accept and recv the file etc.
    system("netsh firewall set service type = upnp mode = disable");
    When using this method another problem occurs. The first time you run the application, it locks up again when it comes to forwarding the port. but the second time you execute the program the port forwards without fail. it seems that its trying to forward the port before the framework is ready. If anyone out there can help me with this or mention any other methods i can get round this i will be very grateful. i am a self taught and coding is my hobby :-)
    Last edited by RipRage; August 29th, 2010 at 10:13 AM.

  2. #2
    Join Date
    Jan 2010

    Re: Windows firewall and the upnp framework

    Problem solved :-)

  3. #3
    Join Date
    Jul 2011

    Re: Windows firewall and the upnp framework

    Hello sir, can you please explain how you solved the problem ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.