Group PJNATH_NAT_DETECT

group PJNATH_NAT_DETECT

NAT Classification/Detection Tool.

This module provides one function to perform NAT classification and detection. NAT type detection is performed by calling pj_stun_detect_nat_type() function.

Typedefs

typedef void pj_stun_nat_detect_cb(void *user_data, const pj_stun_nat_detect_result *res)

Type of callback to be called when the NAT detection function has completed.

Enums

enum pj_stun_nat_type

This enumeration describes the NAT types, as specified by RFC 3489 Section 5, NAT Variations.

Values:

PJ_STUN_NAT_TYPE_UNKNOWN

NAT type is unknown because the detection has not been performed.

PJ_STUN_NAT_TYPE_ERR_UNKNOWN

NAT type is unknown because there is failure in the detection process, possibly because server does not support RFC 3489.

PJ_STUN_NAT_TYPE_OPEN

This specifies that the client has open access to Internet (or at least, its behind a firewall that behaves like a full-cone NAT, but without the translation)

PJ_STUN_NAT_TYPE_BLOCKED

This specifies that communication with server has failed, probably because UDP packets are blocked.

PJ_STUN_NAT_TYPE_SYMMETRIC_UDP

Firewall that allows UDP out, and responses have to come back to the source of the request (like a symmetric NAT, but no translation.

PJ_STUN_NAT_TYPE_FULL_CONE

A full cone NAT is one where all requests from the same internal IP address and port are mapped to the same external IP address and port. Furthermore, any external host can send a packet to the internal host, by sending a packet to the mapped external address.

PJ_STUN_NAT_TYPE_SYMMETRIC

A symmetric NAT is one where all requests from the same internal IP address and port, to a specific destination IP address and port, are mapped to the same external IP address and port. If the same host sends a packet with the same source address and port, but to a different destination, a different mapping is used. Furthermore, only the external host that receives a packet can send a UDP packet back to the internal host.

PJ_STUN_NAT_TYPE_RESTRICTED

A restricted cone NAT is one where all requests from the same internal IP address and port are mapped to the same external IP address and port. Unlike a full cone NAT, an external host (with IP address X) can send a packet to the internal host only if the internal host had previously sent a packet to IP address X.

PJ_STUN_NAT_TYPE_PORT_RESTRICTED

A port restricted cone NAT is like a restricted cone NAT, but the restriction includes port numbers. Specifically, an external host can send a packet, with source IP address X and source port P, to the internal host only if the internal host had previously sent a packet to IP address X and port P.

Functions

const char *pj_stun_get_nat_name(pj_stun_nat_type type)

Get the NAT name from the specified NAT type.

Return

NAT name.

Parameters
  • type: NAT type.

pj_status_t pj_stun_detect_nat_type(const pj_sockaddr_in *server, pj_stun_config *stun_cfg, void *user_data, pj_stun_nat_detect_cb *cb)

Perform NAT classification function according to the procedures specified in RFC 3489. Once this function returns successfully, the procedure will run in the “background” and will complete asynchronously. Application can register a callback to be notified when such detection has completed.

See also pj_stun_detect_nat_type2() which supports IPv6.

Return

If this function returns PJ_SUCCESS, the procedure will complete asynchronously and callback will be called when it completes. For other return values, it means that an error has occured and the procedure did not start.

Parameters
  • server: STUN server address.

  • stun_cfg: A structure containing various STUN configurations, such as the ioqueue and timer heap instance used to receive network I/O and timer events.

  • user_data: Application data, which will be returned back in the callback.

  • cb: Callback to be registered to receive notification about detection result.

pj_status_t pj_stun_detect_nat_type2(const pj_sockaddr *server, pj_stun_config *stun_cfg, void *user_data, pj_stun_nat_detect_cb *cb)

Variant of pj_stun_detect_nat_type() that supports IPv6.

Return

If this function returns PJ_SUCCESS, the procedure will complete asynchronously and callback will be called when it completes. For other return values, it means that an error has occured and the procedure did not start.

Parameters
  • server: STUN server address.

  • stun_cfg: A structure containing various STUN configurations, such as the ioqueue and timer heap instance used to receive network I/O and timer events.

  • user_data: Application data, which will be returned back in the callback.

  • cb: Callback to be registered to receive notification about detection result.

struct pj_stun_nat_detect_result
#include <nat_detect.h>

This structure contains the result of NAT classification function.