Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am quite familiar with TCP and UDP. I understand the process by which TCP establishes connections and other theoretical facts about TCP but when reading up about TCP hole punching for NAT Transversal, I have become stumped by how connect(), accept() and listen() is done in TCP. Is it a single or multiple sockets that are used for all this in TCP and is is this done the same way in UDP

share|improve this question
2  
2 sockets are used for this on each side. en.wikipedia.org/wiki/TCP_hole_punching –  ott-- Jan 30 '13 at 16:47
    
connect(), accept(), and listen() are Berkeley socket API functions, and do not directly relate to the packets actually sent on the wire. –  Greg Hewgill Jan 30 '13 at 20:50
add comment

1 Answer

Your question is about sockets, but I think you might be confused about what a NAT does.

For an incoming connection from a WAN computer to a NATted computer to work, the NAT has to be told, via a configuration mechanism, to forward packets from the WAN destined for a particular port to a port on one of the NATted computers.

For a connection originated on either side of the NAT, the NAT stores the packet's 5-tuple (source IP address, source port, protocol, destination IP address, destination port) and uses this information to determine where to forward packets

For packets destined for the WAN, the NAT rewrites the source address so that all responses are sent to it.

Because the NAT is acting like a transparent "man in the middle", all the socket functions work completely normally.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.