I have been reading the NAT traversal requiring the use of an external STUN server. There are few public STUN servers but I do not know how to use them to find out my public IP that can be used by the other client to initiate the connection. Being a noob in this, I am not able to find out the correct documents for this using the BSD sockets. If someone can explain how can i find my public IP taking BSD sockets as base would be good. Also if you can provide good links for this, it wpuld also be appreciated.
Asked
Active
Viewed 295 times
1 Answers
1
It's in the STUN bind response. RFC 5389, the STUN specification, explains how on page 7:
The STUN server copies that source transport address into an XOR-MAPPED- ADDRESS attribute in the STUN Binding response and sends the Binding response back to the STUN client. As this packet passes back through a NAT, the NAT will modify the destination transport address in the IP header, but the transport address in the XOR-MAPPED-ADDRESS attribute within the body of the STUN response will remain untouched. In this way, the client can learn its reflexive transport address allocated by the outermost NAT with respect to the STUN server.

David Schwartz
- 31,449
- 2
- 55
- 84