BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJLIB-UTIL Reference

Simple STUN Helper

A simple and small footprint STUN resolution helper. More...

Data Structures

struct  pjstun_setting
 

Functions

pj_status_t pjstun_get_mapped_addr (pj_pool_factory *pf, int sock_cnt, pj_sock_t sock[], const pj_str_t *srv1, int port1, const pj_str_t *srv2, int port2, pj_sockaddr_in mapped_addr[])
 
pj_status_t pjstun_get_mapped_addr2 (pj_pool_factory *pf, const pjstun_setting *opt, int sock_cnt, pj_sock_t sock[], pj_sockaddr_in mapped_addr[])
 

Detailed Description

A simple and small footprint STUN resolution helper.

This is the older implementation of STUN client, with only one function provided (pjstun_get_mapped_addr()) to retrieve the public IP address of multiple sockets.

Function Documentation

pj_status_t pjstun_get_mapped_addr ( pj_pool_factory pf,
int  sock_cnt,
pj_sock_t  sock[],
const pj_str_t srv1,
int  port1,
const pj_str_t srv2,
int  port2,
pj_sockaddr_in  mapped_addr[] 
)

This is the main function to request the mapped address of local sockets to multiple STUN servers. This function is able to find the mapped addresses of multiple sockets simultaneously, and for each socket, two requests will be sent to two different STUN servers to see if both servers get the same public address for the same socket. (Note that application can specify the same address for the two servers, but still two requests will be sent for each server).

This function will perform necessary retransmissions of the requests if response is not received within a predetermined period. When all responses have been received, the function will compare the mapped addresses returned by the servers, and when both are equal, the address will be returned in mapped_addr argument.

Parameters
pfThe pool factory where memory will be allocated from.
sock_cntNumber of sockets in the socket array.
sockArray of local UDP sockets which public addresses are to be queried from the STUN servers.
srv1Host name or IP address string of the first STUN server.
port1The port number of the first STUN server.
srv2Host name or IP address string of the second STUN server.
port2The port number of the second STUN server.
mapped_addrArray to receive the mapped public address of the local UDP sockets, when the function returns PJ_SUCCESS.
Returns
This functions returns PJ_SUCCESS if responses are received from all servers AND all servers returned the same mapped public address. Otherwise this function may return one of the following error codes:
  • PJLIB_UTIL_ESTUNNOTRESPOND: no respons from servers.
  • PJLIB_UTIL_ESTUNSYMMETRIC: different mapped addresses are returned by servers.
  • etc.
pj_status_t pjstun_get_mapped_addr2 ( pj_pool_factory pf,
const pjstun_setting opt,
int  sock_cnt,
pj_sock_t  sock[],
pj_sockaddr_in  mapped_addr[] 
)

Another version of mapped address resolution of local sockets to multiple STUN servers configured in pjstun_setting. This function is able to find the mapped addresses of multiple sockets simultaneously, and for each socket, two requests will be sent to two different STUN servers to see if both servers get the same public address for the same socket. (Note that application can specify the same address for the two servers, but still two requests will be sent for each server).

This function will perform necessary retransmissions of the requests if response is not received within a predetermined period. When all responses have been received, the function will compare the mapped addresses returned by the servers, and when both are equal, the address will be returned in mapped_addr argument.

Parameters
pfThe pool factory where memory will be allocated from.
optThe STUN settings.
sock_cntNumber of sockets in the socket array.
sockArray of local UDP sockets which public addresses are to be queried from the STUN servers.
mapped_addrArray to receive the mapped public address of the local UDP sockets, when the function returns PJ_SUCCESS.
Returns
This functions returns PJ_SUCCESS if responses are received from all servers AND all servers returned the same mapped public address. Otherwise this function may return one of the following error codes:
  • PJLIB_UTIL_ESTUNNOTRESPOND: no respons from servers.
  • PJLIB_UTIL_ESTUNSYMMETRIC: different mapped addresses are returned by servers.
  • etc.

 


PJLIB-UTIL Open Source, small footprint, and portable asynchronous/caching DNS resolver, text scanner, STUN client, and XML library
Copyright (C) 2006-2009 Teluu Inc.