views:

1923

answers:

6

I am designing a p2p application which works on port 30000. My router is not UPnP so I required to forward a port to router. But Skype a another p2p application works without port forwarding on my pc. When I analyzed it with wireshark I found its using UDP port 48980, 58544. I am using c++.

There is a library in python here which does it for Nat PMP routers. Is it possible to programmatically forward port to router irrespective of type of router and operating system. What should be the approach to do it in c++ or any other language.

+6  A: 

UDP hole punching is (one) of ways how to traverse through the NAT.

Yossarian
I am not able to understand difference between router and NAT ? Do we forward port to router or NAT? Isn't hole punching equivalent to sending data from both sides at the same time which does not work when we work on different port. Thanks
Xinus
A router routes information from one network to another. NAT is the process of having a private address range on the internal network and only having the router have a valid address on the other network. Router is a physical device, NAT is something you do.
rein
A: 

I think Skype uses http port 80, if no other ports are available.

EDIT: And also apparently port 443 - presumably because those ports are open by default on most home firewalls.

Mark B
It does not use port 80 thats for sure , it uses UDP port 48980, 58544
Xinus
I beg to differ: http://tinyurl.com/ybp5ddc
Mark B
@Mark B: It doesn't matter what ports it uses for outgoing communication. The question here is how it connects two parties without the requirement to have at least one of them being either on a public IP or have a port forwarded. This is answered in a simplified way by "rein" above.For outgoing ports it will use whatever it finds working, preferring some over others.
Fredrik
+2  A: 

You have to use an intermediary server, and initiate communication from the client side. As Yossarian mentioned, from that point one possibility is UDP hole punching. Depending on the type of application (and whether it's truly P2P or not) you might keep the go-between server in place the entire time.

Joe
+4  A: 

Skype works in a very interesting way. From what I've read (and this is a while ago) it works as follows:

  • Skype server maintains a list of all users and IPs.
  • Skype user A wants to speak to user B Skype user A sends a network packet to user B's IP address and waits for a response. (user B never gets this packet).
  • Skype user A notifies server of IP/port combination on which it is waiting for a response
  • Server notifies user B to send a response to
  • user A on the specified port A connection is made.

This is probably over simplified but last I checked, this is how it works. (Someone correct me if I'm wrong).

rein
A: 

Skype uses another peers as intermediate point when direct connection is not possible.

i.e. Peer A wants to connect to peer B, but peer B has all ports closed, then communication is initiated through peer C which has open ports.

+4  A: 

It's described very well in this article How-Skype-Co-get-round-firewalls

Martin Beckett