Stunner is a simple STUN library and client built on top of it in C++, which helps to determine the NAT type, STUN mapped IP and port. I did this as an exercise for myself and it's thus based upon RFC 3489. If there is enough interest, then I might work on support for the latest STUN draft. It doesn't support the shared secret requests and responses as described in RFC 3489. The main reason for this is that I don't see any STUN server, which requires or supports the shared secret requests. Again, if there is enough interest then I will add this as well. All the basic classes for parsing and sending STUN requests and responses are there, thus it should be fairly easy to build a STUN server based on the library. The library is single threaded and uses the select I/O model for
If you are not sure what STUN is, then please refer to RFC 3489.
Using the STUN Client
To determine the NAT type and STUN mapped IP, you can call the following functions:
CStunClientHelper clientHelper ("stun.xten.com");
NAT_TYPE Nat = clientHelper.GetNatType ();
GetNatType function performs the tests as described in RFC 3489 and
GetStunMappedAddress function gets you the public IP by sending a binding request.
Points of Interest
In case we fail to get a response for a request then we don't retry eight times as specified in RFC 3489, instead we just try three times. Moreover, we don't wait for ten seconds of receiving a response and check if all further responses to the request have the same IP and perform other validations as described in RFC 3489. The reason for this is to make the STUN client return back in proper time so that the application could use the results, however if you want the behavior described in RFC 3489 then add
STRICT_IMPLEMENTATION to the preprocessor definitions. And for logging to a file, add
LOG_TO_FILE to the preprocessor definitions.
- 7th February, 2008: Released first version