Port Mapper port forwarding library

Hi all,

Wasn’t sure if I should announce this on the tools board or here, but I’ve released a new a version of my library that does port forwarding on NAT-enabled routers. You can find it at https://github.com/offbynull/portmapper.

This should be a pretty useful tool for you devs that are working on P2P networked games. Advantages that it has over existing Java port forwarding libs …

  • Supports all 3 port mapping protocols: UPnP-IGD, NAT-PMP, and PCP
  • Supports both new and old UPnP-IGD service types – including the IPv6 firewall service
  • It’s been tested on all the major platforms: Android, Windows, Linux, and Mac

If you do happen to use it and you notice a bug, don’t hesitate to make a bug report. I’ll do my best to fix it quickly.

Hi

Interesting library!
You seem knowledgeable about NAT stuff, I’d be interested in a couple of things:

  • How many routers support any of those 3 protocols? e.g. would that apply to 802.11b or newer models in general?
  • Would you say I can rely on availability of port mapping enabled routers, or should I setup relay servers (as described in ICE/TURN)?
  • How have you tested that your library works as expected? I see you have unit and integration tests, have they been tested on real routers? If yes, please list on which ones.

How did this not get more attention?!

Hi,

Sorry for the delay. I’m going to try to answer your questions as best I can. I hope this helps …

How many routers support any of those 3 protocols? e.g. would that apply to 802.11b or newer models in general?

Nearly all routers support at least one of the 3. It doesn’t matter if the router is wired, wireless, or both.

  • UPnP-IGD is the most widely supported protocol. It’s been around for a very long time, and pretty much every router I’ve come across seems to support it (except Apple routers).
  • NAT-PMP is a newer protocol that’s supported by many newer routers (past 3 or 4 years maybe) – including Apple.
  • PCP is the newest protocol that’s supported by a few newer routers – including Apple.

Would you say I can rely on availability of port mapping enabled routers, or should I setup relay servers (as described in ICE/TURN)?

It depends. Don’t expect things to work 100% of the time…

  • you may be blocked by firewalls that are beyond your control – e.g. even though you tell your router to open up a certain port, your ISP may still block you
  • ancient routers may have quirks that cause them to lose mappings or behave bizarrely
  • some routers may disable these protocols by default for security reasons, or require authentication (which I don’t support yet)

You can try port mapping. If that fails, you can fallback to relay servers. Hole punching may also be an option.

How have you tested that your library works as expected? I see you have unit and integration tests, have they been tested on real routers? If yes, please list on which ones.

I have an Apple Airport router and a few other cheap routers that I test against. I also test against miniupnpd (miniupnpd is a port mapping server used by lots of routers – supports all 3 protocols). I’ve also written a small app on my phone that uses the library to map ports every time I make a new WiFi connection.