Changeset 5350 for pjproject/trunk/pjnath/src/pjnath-test/stun_sock_test.c
- Timestamp:
- Jun 21, 2016 6:55:10 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath-test/stun_sock_test.c
r4898 r5350 90 90 /* Add MAPPED-ADDRESS or XOR-MAPPED-ADDRESS (or don't add) */ 91 91 if (srv->flag & WITH_MAPPED) { 92 pj_sockaddr_in addr; 93 94 pj_sockaddr_in_init(&addr, &srv->ip_to_send, srv->port_to_send); 92 pj_sockaddr addr; 93 pj_bool_t use_ipv6 = (srv->addr.addr.sa_family == pj_AF_INET6()); 94 95 pj_sockaddr_init(GET_AF(use_ipv6), &addr, &srv->ip_to_send, 96 srv->port_to_send); 97 95 98 pj_stun_msg_add_sockaddr_attr(pool, res_msg, PJ_STUN_ATTR_MAPPED_ADDR, 96 99 PJ_FALSE, &addr, sizeof(addr)); 97 100 } else if (srv->flag & WITH_XOR_MAPPED) { 98 pj_sockaddr_in addr; 99 100 pj_sockaddr_in_init(&addr, &srv->ip_to_send, srv->port_to_send); 101 pj_sockaddr addr; 102 pj_bool_t use_ipv6 = (srv->addr.addr.sa_family == pj_AF_INET6()); 103 104 pj_sockaddr_init(GET_AF(use_ipv6), &addr, &srv->ip_to_send, 105 srv->port_to_send); 106 101 107 pj_stun_msg_add_sockaddr_attr(pool, res_msg, 102 108 PJ_STUN_ATTR_XOR_MAPPED_ADDR, … … 134 140 pj_ioqueue_t *ioqueue, 135 141 unsigned flag, 142 pj_bool_t use_ipv6, 136 143 struct stun_srv **p_srv) 137 144 { … … 142 149 srv = PJ_POOL_ZALLOC_T(pool, struct stun_srv); 143 150 srv->flag = flag; 144 srv->ip_to_send = pj_str("1.1.1.1");151 srv->ip_to_send = (use_ipv6)?pj_str("2002:101:101::"):pj_str("1.1.1.1"); 145 152 srv->port_to_send = 1000; 146 153 147 status = pj_sockaddr_in _init(&srv->addr.ipv4, NULL, 0);154 status = pj_sockaddr_init(GET_AF(use_ipv6), &srv->addr, NULL, 0); 148 155 if (status != PJ_SUCCESS) 149 156 return status; … … 231 238 static pj_status_t create_client(pj_stun_config *cfg, 232 239 struct stun_client **p_client, 233 pj_bool_t destroy_on_err) 240 pj_bool_t destroy_on_err, 241 pj_bool_t use_ipv6) 234 242 { 235 243 pj_pool_t *pool; … … 248 256 cb.on_status = &stun_sock_on_status; 249 257 cb.on_rx_data = &stun_sock_on_rx_data; 250 status = pj_stun_sock_create(cfg, NULL, pj_AF_INET(), &cb,251 &sock_cfg,client, &client->sock);258 status = pj_stun_sock_create(cfg, NULL, GET_AF(use_ipv6), &cb, &sock_cfg, 259 client, &client->sock); 252 260 if (status != PJ_SUCCESS) { 253 261 app_perror(" pj_stun_sock_create()", status); … … 293 301 * Timeout test: scenario when no response is received from server 294 302 */ 295 static int timeout_test(pj_stun_config *cfg, pj_bool_t destroy_on_err) 303 static int timeout_test(pj_stun_config *cfg, pj_bool_t destroy_on_err, 304 pj_bool_t use_ipv6) 296 305 { 297 306 struct stun_srv *srv; … … 302 311 pj_status_t status; 303 312 304 PJ_LOG(3,(THIS_FILE, " timeout test [%d]", destroy_on_err)); 305 306 status = create_client(cfg, &client, destroy_on_err); 313 PJ_LOG(3,(THIS_FILE, " timeout test [%d] - (%s)", destroy_on_err, 314 (use_ipv6)?"IPv6":"IPv4")); 315 316 status = create_client(cfg, &client, destroy_on_err, use_ipv6); 307 317 if (status != PJ_SUCCESS) 308 318 return -10; 309 319 310 status = create_server(client->pool, cfg->ioqueue, 0, &srv);320 status = create_server(client->pool, cfg->ioqueue, 0, use_ipv6, &srv); 311 321 if (status != PJ_SUCCESS) { 312 322 destroy_client(client); … … 314 324 } 315 325 316 srv_addr = pj_str("127.0.0.1"); 326 srv_addr = (use_ipv6)?pj_str("::1"):pj_str("127.0.0.1"); 327 317 328 status = pj_stun_sock_start(client->sock, &srv_addr, 318 pj_ ntohs(srv->addr.ipv4.sin_port), NULL);329 pj_sockaddr_get_port(&srv->addr), NULL); 319 330 if (status != PJ_SUCCESS) { 320 331 destroy_server(srv); … … 362 373 for (i=0; i<7; ++i) 363 374 handle_events(cfg, 100); 375 376 if ((ret == 0) && use_ipv6) 377 ret = timeout_test(cfg, destroy_on_err, 0); 378 364 379 return ret; 365 380 } … … 370 385 * XOR-MAPPED-ADDRESS attribute. 371 386 */ 372 static int missing_attr_test(pj_stun_config *cfg, pj_bool_t destroy_on_err) 387 static int missing_attr_test(pj_stun_config *cfg, pj_bool_t destroy_on_err, 388 pj_bool_t use_ipv6) 373 389 { 374 390 struct stun_srv *srv; … … 379 395 pj_status_t status; 380 396 381 PJ_LOG(3,(THIS_FILE, " missing attribute test [%d]", destroy_on_err)); 382 383 status = create_client(cfg, &client, destroy_on_err); 397 PJ_LOG(3,(THIS_FILE, " missing attribute test [%d] - (%s)", 398 destroy_on_err, (use_ipv6)?"IPv6":"IPv4")); 399 400 status = create_client(cfg, &client, destroy_on_err, use_ipv6); 384 401 if (status != PJ_SUCCESS) 385 402 return -110; 386 403 387 status = create_server(client->pool, cfg->ioqueue, RESPOND_STUN, &srv); 404 status = create_server(client->pool, cfg->ioqueue, RESPOND_STUN, use_ipv6, 405 &srv); 388 406 if (status != PJ_SUCCESS) { 389 407 destroy_client(client); 390 408 return -120; 391 409 } 392 393 srv_addr = pj_str("127.0.0.1"); 410 srv_addr = (use_ipv6)?pj_str("::1"):pj_str("127.0.0.1"); 411 394 412 status = pj_stun_sock_start(client->sock, &srv_addr, 395 pj_ ntohs(srv->addr.ipv4.sin_port), NULL);413 pj_sockaddr_get_port(&srv->addr), NULL); 396 414 if (status != PJ_SUCCESS) { 397 415 destroy_server(srv); … … 431 449 for (i=0; i<7; ++i) 432 450 handle_events(cfg, 100); 451 452 if ((ret == 0) && use_ipv6) 453 ret = missing_attr_test(cfg, destroy_on_err, 0); 454 433 455 return ret; 434 456 } … … 437 459 * Keep-alive test. 438 460 */ 439 static int keep_alive_test(pj_stun_config *cfg )461 static int keep_alive_test(pj_stun_config *cfg, pj_bool_t use_ipv6) 440 462 { 441 463 struct stun_srv *srv; 442 464 struct stun_client *client; 443 pj_sockaddr _inmapped_addr;465 pj_sockaddr mapped_addr; 444 466 pj_stun_sock_info info; 445 467 pj_str_t srv_addr; … … 448 470 pj_status_t status; 449 471 450 PJ_LOG(3,(THIS_FILE, " normal operation")); 451 452 status = create_client(cfg, &client, PJ_TRUE); 472 PJ_LOG(3,(THIS_FILE, " normal operation - (%s)", 473 (use_ipv6)?"IPv6":"IPv4")); 474 475 status = create_client(cfg, &client, PJ_TRUE, use_ipv6); 453 476 if (status != PJ_SUCCESS) 454 477 return -310; 455 478 456 status = create_server(client->pool, cfg->ioqueue, RESPOND_STUN|WITH_XOR_MAPPED, &srv); 479 status = create_server(client->pool, cfg->ioqueue, RESPOND_STUN|WITH_XOR_MAPPED, 480 use_ipv6, &srv); 457 481 if (status != PJ_SUCCESS) { 458 482 destroy_client(client); … … 464 488 */ 465 489 PJ_LOG(3,(THIS_FILE, " initial Binding request")); 466 srv_addr = pj_str("127.0.0.1"); 490 491 srv_addr = (use_ipv6)?pj_str("::1"):pj_str("127.0.0.1"); 492 467 493 status = pj_stun_sock_start(client->sock, &srv_addr, 468 pj_ ntohs(srv->addr.ipv4.sin_port), NULL);494 pj_sockaddr_get_port(&srv->addr), NULL); 469 495 if (status != PJ_SUCCESS) { 470 496 destroy_server(srv); … … 522 548 } 523 549 /* verify the mapped address */ 524 pj_sockaddr_in_init(&mapped_addr, &srv->ip_to_send, srv->port_to_send); 550 pj_sockaddr_init(GET_AF(use_ipv6), &mapped_addr, 551 &srv->ip_to_send, srv->port_to_send); 525 552 if (pj_sockaddr_cmp(&info.mapped_addr, &mapped_addr) != 0) { 526 553 PJ_LOG(3,(THIS_FILE, " error: mapped address mismatched")); … … 659 686 660 687 /* Change mapped address in the response */ 661 srv->ip_to_send = pj_str("2.2.2.2");688 srv->ip_to_send = (use_ipv6)?pj_str("2002:202:202::"):pj_str("2.2.2.2"); 662 689 srv->port_to_send++; 663 690 … … 730 757 } 731 758 /* verify the mapped address */ 732 pj_sockaddr_in_init(&mapped_addr, &srv->ip_to_send, srv->port_to_send); 759 pj_sockaddr_init(GET_AF(use_ipv6), &mapped_addr, 760 &srv->ip_to_send, srv->port_to_send); 733 761 if (pj_sockaddr_cmp(&info.mapped_addr, &mapped_addr) != 0) { 734 762 PJ_LOG(3,(THIS_FILE, " error: mapped address mismatched")); … … 798 826 for (i=0; i<7; ++i) 799 827 handle_events(cfg, 100); 828 829 if ((ret == 0) && use_ipv6) 830 ret = keep_alive_test(cfg, 0); 831 800 832 return ret; 801 833 } … … 838 870 pj_stun_config_init(&stun_cfg, mem, 0, ioqueue, timer_heap); 839 871 840 DO_TEST(timeout_test(&stun_cfg, PJ_FALSE ));841 DO_TEST(timeout_test(&stun_cfg, PJ_TRUE ));842 843 DO_TEST(missing_attr_test(&stun_cfg, PJ_FALSE ));844 DO_TEST(missing_attr_test(&stun_cfg, PJ_TRUE ));845 846 DO_TEST(keep_alive_test(&stun_cfg ));872 DO_TEST(timeout_test(&stun_cfg, PJ_FALSE, USE_IPV6)); 873 DO_TEST(timeout_test(&stun_cfg, PJ_TRUE, USE_IPV6)); 874 875 DO_TEST(missing_attr_test(&stun_cfg, PJ_FALSE, USE_IPV6)); 876 DO_TEST(missing_attr_test(&stun_cfg, PJ_TRUE, USE_IPV6)); 877 878 DO_TEST(keep_alive_test(&stun_cfg, USE_IPV6)); 847 879 848 880 on_return:
Note: See TracChangeset
for help on using the changeset viewer.