Changeset 4224
- Timestamp:
- Aug 9, 2012 5:21:25 AM (12 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/include/pjlib-util/stun_simple.h
r3553 r4224 200 200 pj_sockaddr_in mapped_addr[]); 201 201 202 203 /* 204 * This structre describes configurable setting for requesting mapped address. 205 */ 206 typedef struct pjstun_setting 207 { 208 /** 209 * Specifies whether STUN request generated by old STUN library should 210 * insert magic cookie (specified in RFC 5389) in the transaction ID. 211 */ 212 pj_bool_t use_stun2; 213 214 /** 215 * Host name or IP address string of the first STUN server. 216 */ 217 pj_str_t srv1; 218 219 /** 220 * The port number of the first STUN server. 221 */ 222 int port1; 223 224 /** 225 * Host name or IP address string of the second STUN server. 226 */ 227 pj_str_t srv2; 228 229 /** 230 * The port number of the second STUN server. 231 */ 232 int port2; 233 234 } pjstun_setting; 235 236 237 /** 238 * Another version of mapped address resolution of local sockets to multiple 239 * STUN servers configured in #pjstun_setting. This function is able to find 240 * the mapped addresses of multiple sockets simultaneously, and for each 241 * socket, two requests will be sent to two different STUN servers to see if 242 * both servers get the same public address for the same socket. (Note that 243 * application can specify the same address for the two servers, but still 244 * two requests will be sent for each server). 245 * 246 * This function will perform necessary retransmissions of the requests if 247 * response is not received within a predetermined period. When all responses 248 * have been received, the function will compare the mapped addresses returned 249 * by the servers, and when both are equal, the address will be returned in 250 * \a mapped_addr argument. 251 * 252 * @param pf The pool factory where memory will be allocated from. 253 * @param opt The STUN settings. 254 * @param sock_cnt Number of sockets in the socket array. 255 * @param sock Array of local UDP sockets which public addresses are 256 * to be queried from the STUN servers. 257 * @param mapped_addr Array to receive the mapped public address of the local 258 * UDP sockets, when the function returns PJ_SUCCESS. 259 * 260 * @return This functions returns PJ_SUCCESS if responses are 261 * received from all servers AND all servers returned the 262 * same mapped public address. Otherwise this function may 263 * return one of the following error codes: 264 * - PJLIB_UTIL_ESTUNNOTRESPOND: no respons from servers. 265 * - PJLIB_UTIL_ESTUNSYMMETRIC: different mapped addresses 266 * are returned by servers. 267 * - etc. 268 * 269 */ 270 PJ_DECL(pj_status_t) pjstun_get_mapped_addr2( pj_pool_factory *pf, 271 const pjstun_setting *opt, 272 int sock_cnt, 273 pj_sock_t sock[], 274 pj_sockaddr_in mapped_addr[]); 275 276 202 277 PJ_END_DECL 203 278 -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_simple_client.c
r3999 r4224 43 43 pj_sockaddr_in mapped_addr[]) 44 44 { 45 pjstun_setting opt; 46 47 pj_bzero(&opt, sizeof(opt)); 48 opt.use_stun2 = PJ_FALSE; 49 opt.srv1 = *srv1; 50 opt.port1 = port1; 51 opt.srv2 = *srv2; 52 opt.port2 = port2; 53 54 return pjstun_get_mapped_addr2(pf, &opt, sock_cnt, sock, mapped_addr); 55 } 56 57 PJ_DEF(pj_status_t) pjstun_get_mapped_addr2(pj_pool_factory *pf, 58 const pjstun_setting *opt, 59 int sock_cnt, 60 pj_sock_t sock[], 61 pj_sockaddr_in mapped_addr[]) 62 { 45 63 unsigned srv_cnt; 64 const pj_str_t *srv1, *srv2; 65 int port1, port2; 46 66 pj_sockaddr_in srv_addr[2]; 47 67 int i, send_cnt = 0, nfds; … … 60 80 PJ_CHECK_STACK(); 61 81 82 srv1 = &opt->srv1; 83 port1 = opt->port1; 84 srv2 = &opt->srv1; 85 port2 = opt->port2; 86 62 87 TRACE_((THIS_FILE, "Entering pjstun_get_mapped_addr()")); 63 88 … … 82 107 if (status != PJ_SUCCESS) 83 108 goto on_error; 109 110 /* Insert magic cookie (specified in RFC 5389) when requested to. */ 111 if (opt->use_stun2) { 112 pjstun_msg_hdr *hdr = (pjstun_msg_hdr*)out_msg; 113 hdr->tsx[0] = pj_htonl(STUN_MAGIC); 114 } 84 115 85 116 TRACE_((THIS_FILE, " Binding request created.")); -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r4218 r4224 1463 1463 1464 1464 /** 1465 * This specifies whether STUN requests for resolving socket mapped 1466 * address should use the new format, i.e: having STUN magic cookie 1467 * in its transaction ID. 1468 * 1469 * Default: PJ_FALSE 1470 */ 1471 pj_bool_t stun_map_use_stun2; 1472 1473 /** 1465 1474 * Support for adding and parsing NAT type in the SDP to assist 1466 1475 * troubleshooting. The valid values are: -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r4219 r4224 1923 1923 1924 1924 } else if (stun_srv.slen) { 1925 pjstun_setting stun_opt; 1926 1925 1927 /* 1926 1928 * STUN is specified, resolve the address with STUN. … … 1932 1934 } 1933 1935 1934 status = pjstun_get_mapped_addr(&pjsua_var.cp.factory, 1, &sock, 1935 &stun_srv, pj_ntohs(pjsua_var.stun_srv.ipv4.sin_port), 1936 &stun_srv, pj_ntohs(pjsua_var.stun_srv.ipv4.sin_port), 1937 &p_pub_addr->ipv4); 1936 pj_bzero(&stun_opt, sizeof(stun_opt)); 1937 stun_opt.use_stun2 = pjsua_var.ua_cfg.stun_map_use_stun2; 1938 stun_opt.srv1 = stun_opt.srv2 = stun_srv; 1939 stun_opt.port1 = stun_opt.port2 = 1940 pj_ntohs(pjsua_var.stun_srv.ipv4.sin_port); 1941 status = pjstun_get_mapped_addr2(&pjsua_var.cp.factory, &stun_opt, 1942 1, &sock, &p_pub_addr->ipv4); 1938 1943 if (status != PJ_SUCCESS) { 1939 1944 pjsua_perror(THIS_FILE, "Error contacting STUN server", status); -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
r4218 r4224 329 329 char ip_addr[32]; 330 330 pj_str_t stun_srv; 331 pjstun_setting stun_opt; 331 332 332 333 pj_ansi_strcpy(ip_addr, … … 334 335 stun_srv = pj_str(ip_addr); 335 336 336 status=pjstun_get_mapped_addr(&pjsua_var.cp.factory, 2, sock, 337 &stun_srv, pj_ntohs(pjsua_var.stun_srv.ipv4.sin_port), 338 &stun_srv, pj_ntohs(pjsua_var.stun_srv.ipv4.sin_port), 339 mapped_addr); 337 pj_bzero(&stun_opt, sizeof(stun_opt)); 338 stun_opt.use_stun2 = pjsua_var.ua_cfg.stun_map_use_stun2; 339 stun_opt.srv1 = stun_opt.srv2 = stun_srv; 340 stun_opt.port1 = stun_opt.port2 = 341 pj_ntohs(pjsua_var.stun_srv.ipv4.sin_port); 342 status=pjstun_get_mapped_addr2(&pjsua_var.cp.factory, &stun_opt, 343 2, sock, mapped_addr); 340 344 if (status != PJ_SUCCESS) { 341 345 pjsua_perror(THIS_FILE, "STUN resolve error", status);
Note: See TracChangeset
for help on using the changeset viewer.