tags:

views:

200

answers:

5

I have a sockets program that requires port 1002 to be open and I wanna know how to port forward in C++ on windows so i may use this port freely?

+1  A: 

You can't port forward in a programming language, that is something that is set up on the router.

Hogan
UPnP provides an XML API to do this; many (if not all) routers support this out of the box.
Luke
If routers don't port forward in software I'm not sure how they manage it...
Jonathon
@Jon: very cute. Given the OP's level of understanding, I think (as I'm sure you do) my question was helpful.
Hogan
+5  A: 

Port forwarding is done upstream of the client system, typically on the router.

I believe some applications use Universal Plug and Play to communicate with the upstream router to open a port publicly but you'll have to do a lot of research to see how it's done: I haven't the slightest.

antik
+3  A: 

So, you need UPnP or NAT-PMP. Your system may have libraries for doing those protocols, or you can use muniupnp, which has both a server to run on a Linux or BSD box to test against, and a client library.

There is no guarantee that will work, so you may need to go further and use STUN, TURN or ICE. There's a library for doing those things here.

And always remember, sometimes it's just impossible. Implement IPv6 as well, sometimes that works when IPv4 doesn't. Encourage users to install v6 and Teredo.

Andrew McGregor
A: 

Starting with Windows XP, Microsoft offers a UPnP library. It's actually fairly complicated to use as the library just offers the basics of communicating with network devices. You will have to study the various UPnP specifications in order to perform device-specific tasks such as port forwarding. Believe me, this is a lot of hard work to do to accomplish relatively little; better to just put it in your documentation somewhere that the user might have to consult their router manual in order to forward the necessary ports. This is what almost everybody does.

Luke
amen. it's very hard
Matt Joiner
UPnP is hard to use as a programmer, almost as hard as successfully configuring a port forward on a router is for the average "DHCP? what's-an-IP-address?" user. You may as well just have tech support call them, save some time ;-) NATs and firewalls are a great example of a technology that's hostile to good user experience, it's very difficult for the system and the average user to communicate in terms they both understand.
Steve Jessop
A: 

I believe the most popular approach is to write documentation that tells the user what port(s) to open on their firewall.

bk1e
My experience has been that it's just as common to leave the user to search the internet for forum posts telling them what inbound ports the application uses ;-)
Steve Jessop