- Timestamp:
- Dec 28, 2016 3:40:07 AM (8 years ago)
- Location:
- pjproject/branches/projects/uwp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/uwp
- Property svn:mergeinfo changed
/pjproject/trunk (added) merged: 5209,5212-5234,5237-5253,5255,5257-5292,5294-5297,5299-5332,5334-5394,5396-5438,5440-5469,5471-5496,5498-5510
- Property svn:mergeinfo changed
-
pjproject/branches/projects/uwp/pjlib-util/src/pjlib-util-test/resolver_test.c
r4537 r5513 192 192 size -= 6; 193 193 194 } else if (rr->type == PJ_DNS_TYPE_AAAA) { 195 196 if (size < 18) 197 return -1; 198 199 /* RDLEN is 16 */ 200 write16(p, 16); 201 202 /* Address */ 203 pj_memcpy(p+2, &rr->rdata.aaaa.ip_addr, 16); 204 205 p += 18; 206 size -= 18; 207 194 208 } else if (rr->type == PJ_DNS_TYPE_CNAME || 195 209 rr->type == PJ_DNS_TYPE_NS || … … 331 345 pj_fd_set_t rset; 332 346 pj_time_val timeout = {0, 500}; 333 pj_sockaddr _insrc_addr;347 pj_sockaddr src_addr; 334 348 pj_dns_parsed_packet *req; 335 349 char pkt[1024]; … … 406 420 static void destroy(void); 407 421 408 static int init( void)422 static int init(pj_bool_t use_ipv6) 409 423 { 410 424 pj_status_t status; … … 413 427 int i; 414 428 415 nameservers[0] = pj_str("127.0.0.1"); 429 if (use_ipv6) { 430 nameservers[0] = pj_str("::1"); 431 nameservers[1] = pj_str("::1"); 432 } else { 433 nameservers[0] = pj_str("127.0.0.1"); 434 nameservers[1] = pj_str("127.0.0.1"); 435 } 416 436 ports[0] = 5553; 417 nameservers[1] = pj_str("127.0.0.1");418 437 ports[1] = 5554; 419 438 … … 426 445 pj_assert(status == PJ_SUCCESS); 427 446 447 thread_quit = PJ_FALSE; 448 428 449 for (i=0; i<2; ++i) { 429 pj_sockaddr_in addr; 430 431 status = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &g_server[i].sock); 450 pj_sockaddr addr; 451 452 status = pj_sock_socket((use_ipv6? pj_AF_INET6() : pj_AF_INET()), 453 pj_SOCK_DGRAM(), 0, &g_server[i].sock); 432 454 if (status != PJ_SUCCESS) 433 455 return -10; 434 456 435 pj_sockaddr_in_init(&addr, NULL, (pj_uint16_t)g_server[i].port); 436 437 status = pj_sock_bind(g_server[i].sock, &addr, sizeof(addr)); 457 pj_sockaddr_init((use_ipv6? pj_AF_INET6() : pj_AF_INET()), 458 &addr, NULL, (pj_uint16_t)g_server[i].port); 459 460 status = pj_sock_bind(g_server[i].sock, &addr, pj_sockaddr_get_len(&addr)); 438 461 if (status != PJ_SUCCESS) 439 462 return -20; … … 687 710 688 711 rc = pj_dns_parse_a_response(&pkt, &rec); 712 pj_assert(rc == PJLIB_UTIL_EDNSNOANSWERREC); 713 714 return 0; 715 } 716 717 718 //////////////////////////////////////////////////////////////////////////// 719 /* DNS A/AAAA parser tests */ 720 static int addr_parser_test(void) 721 { 722 pj_dns_parsed_packet pkt; 723 pj_dns_addr_record rec; 724 pj_status_t rc; 725 726 PJ_LOG(3,(THIS_FILE, " DNS A/AAAA record parser tests")); 727 728 pkt.q = PJ_POOL_ZALLOC_T(pool, pj_dns_parsed_query); 729 pkt.ans = (pj_dns_parsed_rr*) 730 pj_pool_calloc(pool, 32, sizeof(pj_dns_parsed_rr)); 731 732 /* Simple answer with direct A record, but with addition of 733 * a CNAME and another A to confuse the parser. 734 */ 735 PJ_LOG(3,(THIS_FILE, " A RR with duplicate CNAME/A")); 736 pkt.hdr.flags = 0; 737 pkt.hdr.qdcount = 1; 738 pkt.q[0].type = PJ_DNS_TYPE_A; 739 pkt.q[0].dnsclass = 1; 740 pkt.q[0].name = pj_str("ahost"); 741 pkt.hdr.anscount = 4; 742 743 /* This is the RR corresponding to the query */ 744 pkt.ans[0].name = pj_str("ahost"); 745 pkt.ans[0].type = PJ_DNS_TYPE_A; 746 pkt.ans[0].dnsclass = 1; 747 pkt.ans[0].ttl = 1; 748 pkt.ans[0].rdata.a.ip_addr.s_addr = 0x01020304; 749 750 /* CNAME to confuse the parser */ 751 pkt.ans[1].name = pj_str("ahost"); 752 pkt.ans[1].type = PJ_DNS_TYPE_CNAME; 753 pkt.ans[1].dnsclass = 1; 754 pkt.ans[1].ttl = 1; 755 pkt.ans[1].rdata.cname.name = pj_str("bhost"); 756 757 /* DNS A RR to confuse the parser */ 758 pkt.ans[2].name = pj_str("bhost"); 759 pkt.ans[2].type = PJ_DNS_TYPE_A; 760 pkt.ans[2].dnsclass = 1; 761 pkt.ans[2].ttl = 1; 762 pkt.ans[2].rdata.a.ip_addr.s_addr = 0x0203; 763 764 /* Additional RR corresponding to the query, DNS AAAA RR */ 765 pkt.ans[3].name = pj_str("ahost"); 766 pkt.ans[3].type = PJ_DNS_TYPE_AAAA; 767 pkt.ans[3].dnsclass = 1; 768 pkt.ans[3].ttl = 1; 769 pkt.ans[3].rdata.aaaa.ip_addr.u6_addr32[0] = 0x01020304; 770 771 772 rc = pj_dns_parse_addr_response(&pkt, &rec); 773 pj_assert(rc == PJ_SUCCESS); 774 pj_assert(pj_strcmp2(&rec.name, "ahost")==0); 775 pj_assert(rec.alias.slen == 0); 776 pj_assert(rec.addr_count == 2); 777 pj_assert(rec.addr[0].af==pj_AF_INET() && rec.addr[0].ip.v4.s_addr == 0x01020304); 778 pj_assert(rec.addr[1].af==pj_AF_INET6() && rec.addr[1].ip.v6.u6_addr32[0] == 0x01020304); 779 780 /* Answer with the target corresponds to a CNAME entry, but not 781 * as the first record, and with additions of some CNAME and A 782 * entries to confuse the parser. 783 */ 784 PJ_LOG(3,(THIS_FILE, " CNAME RR with duplicate CNAME/A")); 785 pkt.hdr.flags = 0; 786 pkt.hdr.qdcount = 1; 787 pkt.q[0].type = PJ_DNS_TYPE_A; 788 pkt.q[0].dnsclass = 1; 789 pkt.q[0].name = pj_str("ahost"); 790 pkt.hdr.anscount = 4; 791 792 /* This is the DNS A record for the alias */ 793 pkt.ans[0].name = pj_str("ahostalias"); 794 pkt.ans[0].type = PJ_DNS_TYPE_A; 795 pkt.ans[0].dnsclass = 1; 796 pkt.ans[0].ttl = 1; 797 pkt.ans[0].rdata.a.ip_addr.s_addr = 0x02020202; 798 799 /* CNAME entry corresponding to the query */ 800 pkt.ans[1].name = pj_str("ahost"); 801 pkt.ans[1].type = PJ_DNS_TYPE_CNAME; 802 pkt.ans[1].dnsclass = 1; 803 pkt.ans[1].ttl = 1; 804 pkt.ans[1].rdata.cname.name = pj_str("ahostalias"); 805 806 /* Another CNAME to confuse the parser */ 807 pkt.ans[2].name = pj_str("ahost"); 808 pkt.ans[2].type = PJ_DNS_TYPE_CNAME; 809 pkt.ans[2].dnsclass = 1; 810 pkt.ans[2].ttl = 1; 811 pkt.ans[2].rdata.cname.name = pj_str("ahostalias2"); 812 813 /* Another DNS A to confuse the parser */ 814 pkt.ans[3].name = pj_str("ahostalias2"); 815 pkt.ans[3].type = PJ_DNS_TYPE_A; 816 pkt.ans[3].dnsclass = 1; 817 pkt.ans[3].ttl = 1; 818 pkt.ans[3].rdata.a.ip_addr.s_addr = 0x03030303; 819 820 rc = pj_dns_parse_addr_response(&pkt, &rec); 821 pj_assert(rc == PJ_SUCCESS); 822 pj_assert(pj_strcmp2(&rec.name, "ahost")==0); 823 pj_assert(pj_strcmp2(&rec.alias, "ahostalias")==0); 824 pj_assert(rec.addr_count == 1); 825 pj_assert(rec.addr[0].ip.v4.s_addr == 0x02020202); 826 827 /* 828 * No query section. 829 */ 830 PJ_LOG(3,(THIS_FILE, " No query section")); 831 pkt.hdr.qdcount = 0; 832 pkt.hdr.anscount = 0; 833 834 rc = pj_dns_parse_addr_response(&pkt, &rec); 835 pj_assert(rc == PJLIB_UTIL_EDNSINANSWER); 836 837 /* 838 * No answer section. 839 */ 840 PJ_LOG(3,(THIS_FILE, " No answer section")); 841 pkt.hdr.flags = 0; 842 pkt.hdr.qdcount = 1; 843 pkt.q[0].type = PJ_DNS_TYPE_A; 844 pkt.q[0].dnsclass = 1; 845 pkt.q[0].name = pj_str("ahost"); 846 pkt.hdr.anscount = 0; 847 848 rc = pj_dns_parse_addr_response(&pkt, &rec); 849 pj_assert(rc == PJLIB_UTIL_EDNSNOANSWERREC); 850 851 /* 852 * Answer doesn't match query. 853 */ 854 PJ_LOG(3,(THIS_FILE, " Answer doesn't match query")); 855 pkt.hdr.flags = 0; 856 pkt.hdr.qdcount = 1; 857 pkt.q[0].type = PJ_DNS_TYPE_A; 858 pkt.q[0].dnsclass = 1; 859 pkt.q[0].name = pj_str("ahost"); 860 pkt.hdr.anscount = 1; 861 862 /* An answer that doesn't match the query */ 863 pkt.ans[0].name = pj_str("ahostalias"); 864 pkt.ans[0].type = PJ_DNS_TYPE_A; 865 pkt.ans[0].dnsclass = 1; 866 pkt.ans[0].ttl = 1; 867 pkt.ans[0].rdata.a.ip_addr.s_addr = 0x02020202; 868 869 rc = pj_dns_parse_addr_response(&pkt, &rec); 870 pj_assert(rc == PJLIB_UTIL_EDNSNOANSWERREC); 871 872 873 /* 874 * DNS CNAME that doesn't have corresponding DNS A. 875 */ 876 PJ_LOG(3,(THIS_FILE, " CNAME with no matching DNS A RR (1)")); 877 pkt.hdr.flags = 0; 878 pkt.hdr.qdcount = 1; 879 pkt.q[0].type = PJ_DNS_TYPE_A; 880 pkt.q[0].dnsclass = 1; 881 pkt.q[0].name = pj_str("ahost"); 882 pkt.hdr.anscount = 1; 883 884 /* The CNAME */ 885 pkt.ans[0].name = pj_str("ahost"); 886 pkt.ans[0].type = PJ_DNS_TYPE_CNAME; 887 pkt.ans[0].dnsclass = 1; 888 pkt.ans[0].ttl = 1; 889 pkt.ans[0].rdata.cname.name = pj_str("ahostalias"); 890 891 rc = pj_dns_parse_addr_response(&pkt, &rec); 892 pj_assert(rc == PJLIB_UTIL_EDNSNOANSWERREC); 893 894 895 /* 896 * DNS CNAME that doesn't have corresponding DNS A. 897 */ 898 PJ_LOG(3,(THIS_FILE, " CNAME with no matching DNS A RR (2)")); 899 pkt.hdr.flags = 0; 900 pkt.hdr.qdcount = 1; 901 pkt.q[0].type = PJ_DNS_TYPE_A; 902 pkt.q[0].dnsclass = 1; 903 pkt.q[0].name = pj_str("ahost"); 904 pkt.hdr.anscount = 2; 905 906 /* The CNAME */ 907 pkt.ans[0].name = pj_str("ahost"); 908 pkt.ans[0].type = PJ_DNS_TYPE_CNAME; 909 pkt.ans[0].dnsclass = 1; 910 pkt.ans[0].ttl = 1; 911 pkt.ans[0].rdata.cname.name = pj_str("ahostalias"); 912 913 /* DNS A record, but the name doesn't match */ 914 pkt.ans[1].name = pj_str("ahost"); 915 pkt.ans[1].type = PJ_DNS_TYPE_A; 916 pkt.ans[1].dnsclass = 1; 917 pkt.ans[1].ttl = 1; 918 pkt.ans[1].rdata.a.ip_addr.s_addr = 0x01020304; 919 920 rc = pj_dns_parse_addr_response(&pkt, &rec); 689 921 pj_assert(rc == PJLIB_UTIL_EDNSNOANSWERREC); 690 922 … … 1006 1238 res->ans[1].name = pj_str(alias); 1007 1239 res->ans[1].rdata.a.ip_addr.s_addr = IP_ADDR1; 1240 1241 } else if (pkt->q[0].type == PJ_DNS_TYPE_AAAA) { 1242 char *alias = "sipalias.somedomain.com"; 1243 1244 pj_assert(pj_strcmp2(&res->q[0].name, target)==0); 1245 1246 res->hdr.anscount = 2; 1247 res->ans[0].type = PJ_DNS_TYPE_CNAME; 1248 res->ans[0].dnsclass = 1; 1249 res->ans[0].ttl = 1000; /* resolver should select minimum TTL */ 1250 res->ans[0].name = res->q[0].name; 1251 res->ans[0].rdata.cname.name = pj_str(alias); 1252 1253 res->ans[1].type = PJ_DNS_TYPE_AAAA; 1254 res->ans[1].dnsclass = 1; 1255 res->ans[1].ttl = 1; 1256 res->ans[1].name = pj_str(alias); 1257 res->ans[1].rdata.aaaa.ip_addr.u6_addr32[0] = IP_ADDR1; 1258 res->ans[1].rdata.aaaa.ip_addr.u6_addr32[1] = IP_ADDR1; 1259 res->ans[1].rdata.aaaa.ip_addr.u6_addr32[2] = IP_ADDR1; 1260 res->ans[1].rdata.aaaa.ip_addr.u6_addr32[3] = IP_ADDR1; 1008 1261 } 1009 1262 … … 1027 1280 PJ_ASSERT_ON_FAIL(pj_strcmp2(&rec->entry[0].server.alias, "sipalias.somedomain.com")==0, 1028 1281 return); 1029 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr[0].s_addr == IP_ADDR1, return); 1282 1283 /* IPv4 only */ 1284 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr_count == 1, return); 1285 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr[0].ip.v4.s_addr == IP_ADDR1, return); 1030 1286 PJ_ASSERT_ON_FAIL(rec->entry[0].port == PORT1, return); 1031 1287 1032 1288 1033 1289 } 1290 1034 1291 1035 1292 static void srv_cb_1b(void *user_data, … … 1045 1302 PJ_ASSERT_ON_FAIL(rec->count == 0, return); 1046 1303 } 1304 1305 1306 static void srv_cb_1c(void *user_data, 1307 pj_status_t status, 1308 const pj_dns_srv_record *rec) 1309 { 1310 PJ_UNUSED_ARG(user_data); 1311 1312 pj_sem_post(sem); 1313 1314 PJ_ASSERT_ON_FAIL(status == PJ_SUCCESS, return); 1315 PJ_ASSERT_ON_FAIL(rec->count == 1, return); 1316 PJ_ASSERT_ON_FAIL(rec->entry[0].priority == 1, return); 1317 PJ_ASSERT_ON_FAIL(rec->entry[0].weight == 2, return); 1318 1319 PJ_ASSERT_ON_FAIL(pj_strcmp2(&rec->entry[0].server.name, "sip.somedomain.com")==0, 1320 return); 1321 PJ_ASSERT_ON_FAIL(pj_strcmp2(&rec->entry[0].server.alias, "sipalias.somedomain.com")==0, 1322 return); 1323 PJ_ASSERT_ON_FAIL(rec->entry[0].port == PORT1, return); 1324 1325 /* IPv4 and IPv6 */ 1326 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr_count == 2, return); 1327 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr[0].af == pj_AF_INET() && 1328 rec->entry[0].server.addr[0].ip.v4.s_addr == IP_ADDR1, return); 1329 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr[1].af == pj_AF_INET6() && 1330 rec->entry[0].server.addr[1].ip.v6.u6_addr32[0] == IP_ADDR1, return); 1331 } 1332 1333 1334 static void srv_cb_1d(void *user_data, 1335 pj_status_t status, 1336 const pj_dns_srv_record *rec) 1337 { 1338 PJ_UNUSED_ARG(user_data); 1339 1340 pj_sem_post(sem); 1341 1342 PJ_ASSERT_ON_FAIL(status == PJ_SUCCESS, return); 1343 PJ_ASSERT_ON_FAIL(rec->count == 1, return); 1344 PJ_ASSERT_ON_FAIL(rec->entry[0].priority == 1, return); 1345 PJ_ASSERT_ON_FAIL(rec->entry[0].weight == 2, return); 1346 1347 PJ_ASSERT_ON_FAIL(pj_strcmp2(&rec->entry[0].server.name, "sip.somedomain.com")==0, 1348 return); 1349 PJ_ASSERT_ON_FAIL(pj_strcmp2(&rec->entry[0].server.alias, "sipalias.somedomain.com")==0, 1350 return); 1351 PJ_ASSERT_ON_FAIL(rec->entry[0].port == PORT1, return); 1352 1353 /* IPv6 only */ 1354 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr_count == 1, return); 1355 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr[0].af == pj_AF_INET6() && 1356 rec->entry[0].server.addr[0].ip.v6.u6_addr32[0] == IP_ADDR1, return); 1357 } 1358 1047 1359 1048 1360 static int srv_resolver_test(void) … … 1079 1391 ((set.qretr_count + 2) * set.qretr_delay)); 1080 1392 1393 1394 /* DNS SRV option PJ_DNS_SRV_RESOLVE_AAAA */ 1395 PJ_LOG(3,(THIS_FILE, " srv_resolve(): option PJ_DNS_SRV_RESOLVE_AAAA")); 1396 1397 g_server[0].action = ACTION_CB; 1398 g_server[0].action_cb = &action1_1; 1399 g_server[1].action = ACTION_CB; 1400 g_server[1].action_cb = &action1_1; 1401 1402 g_server[0].pkt_count = 0; 1403 g_server[1].pkt_count = 0; 1404 1405 status = pj_dns_srv_resolve(&domain, &res_name, 5061, pool, resolver, 1406 PJ_DNS_SRV_RESOLVE_AAAA, 1407 NULL, &srv_cb_1c, NULL); 1408 pj_assert(status == PJ_SUCCESS); 1409 1410 pj_sem_wait(sem); 1411 1412 pj_thread_sleep(1000); 1413 1414 /* DNS SRV option PJ_DNS_SRV_RESOLVE_AAAA_ONLY */ 1415 PJ_LOG(3,(THIS_FILE, " srv_resolve(): option PJ_DNS_SRV_RESOLVE_AAAA_ONLY")); 1416 1417 g_server[0].action = ACTION_CB; 1418 g_server[0].action_cb = &action1_1; 1419 g_server[1].action = ACTION_CB; 1420 g_server[1].action_cb = &action1_1; 1421 1422 g_server[0].pkt_count = 0; 1423 g_server[1].pkt_count = 0; 1424 1425 status = pj_dns_srv_resolve(&domain, &res_name, 5061, pool, resolver, 1426 PJ_DNS_SRV_RESOLVE_AAAA_ONLY, 1427 NULL, &srv_cb_1d, NULL); 1428 pj_assert(status == PJ_SUCCESS); 1429 1430 pj_sem_wait(sem); 1431 1432 pj_thread_sleep(1000); 1433 1434 1081 1435 /* Successful scenario */ 1082 1436 PJ_LOG(3,(THIS_FILE, " srv_resolve(): parallel queries")); … … 1103 1457 PJ_LOG(3,(THIS_FILE, " srv_resolve(): cache expires scenario")); 1104 1458 1105 1106 1459 pj_thread_sleep(1000); 1107 1460 … … 1114 1467 1115 1468 pj_sem_wait(sem); 1469 1116 1470 1117 1471 return 0; … … 1172 1526 res->ans[1].ttl = 1; 1173 1527 res->ans[1].rdata.a.ip_addr.s_addr = IP_ADDR2; 1528 1529 } else if (pkt->q[0].type == PJ_DNS_TYPE_AAAA) { 1530 char *alias = "sipalias01." TARGET; 1531 1532 pj_assert(pj_strcmp2(&res->q[0].name, TARGET)==0); 1533 1534 res->hdr.anscount = 2; 1535 res->ans[0].type = PJ_DNS_TYPE_CNAME; 1536 res->ans[0].dnsclass = 1; 1537 res->ans[0].name = res->q[0].name; 1538 res->ans[0].ttl = 1; 1539 res->ans[0].rdata.cname.name = pj_str(alias); 1540 1541 res->ans[1].type = PJ_DNS_TYPE_AAAA; 1542 res->ans[1].dnsclass = 1; 1543 res->ans[1].ttl = 1; 1544 res->ans[1].name = pj_str(alias); 1545 res->ans[1].rdata.aaaa.ip_addr.u6_addr32[0] = IP_ADDR2; 1546 res->ans[1].rdata.aaaa.ip_addr.u6_addr32[1] = IP_ADDR2; 1547 res->ans[1].rdata.aaaa.ip_addr.u6_addr32[2] = IP_ADDR2; 1548 res->ans[1].rdata.aaaa.ip_addr.u6_addr32[3] = IP_ADDR2; 1174 1549 } 1175 1550 … … 1193 1568 PJ_ASSERT_ON_FAIL(pj_strcmp2(&rec->entry[0].server.alias, "sipalias01." TARGET)==0, 1194 1569 return); 1195 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr[0].s_addr == IP_ADDR2, return);1196 1570 PJ_ASSERT_ON_FAIL(rec->entry[0].port == PORT2, return); 1571 1572 /* IPv4 only */ 1573 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr_count == 1, return); 1574 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr[0].af == pj_AF_INET() && 1575 rec->entry[0].server.addr[0].ip.v4.s_addr == IP_ADDR2, return); 1576 } 1577 1578 static void srv_cb_2a(void *user_data, 1579 pj_status_t status, 1580 const pj_dns_srv_record *rec) 1581 { 1582 PJ_UNUSED_ARG(user_data); 1583 1584 pj_sem_post(sem); 1585 1586 PJ_ASSERT_ON_FAIL(status == PJ_SUCCESS, return); 1587 PJ_ASSERT_ON_FAIL(rec->count == 1, return); 1588 PJ_ASSERT_ON_FAIL(rec->entry[0].priority == 0, return); 1589 PJ_ASSERT_ON_FAIL(rec->entry[0].weight == 0, return); 1590 PJ_ASSERT_ON_FAIL(pj_strcmp2(&rec->entry[0].server.name, TARGET)==0, 1591 return); 1592 PJ_ASSERT_ON_FAIL(pj_strcmp2(&rec->entry[0].server.alias, "sipalias01." TARGET)==0, 1593 return); 1594 PJ_ASSERT_ON_FAIL(rec->entry[0].port == PORT2, return); 1595 1596 /* IPv4 and IPv6 */ 1597 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr_count == 2, return); 1598 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr[0].af == pj_AF_INET() && 1599 rec->entry[0].server.addr[0].ip.v4.s_addr == IP_ADDR2, return); 1600 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr[1].af == pj_AF_INET6() && 1601 rec->entry[0].server.addr[1].ip.v6.u6_addr32[0] == IP_ADDR2, return); 1602 } 1603 1604 static void srv_cb_2b(void *user_data, 1605 pj_status_t status, 1606 const pj_dns_srv_record *rec) 1607 { 1608 PJ_UNUSED_ARG(user_data); 1609 1610 pj_sem_post(sem); 1611 1612 PJ_ASSERT_ON_FAIL(status == PJ_SUCCESS, return); 1613 PJ_ASSERT_ON_FAIL(rec->count == 1, return); 1614 PJ_ASSERT_ON_FAIL(rec->entry[0].priority == 0, return); 1615 PJ_ASSERT_ON_FAIL(rec->entry[0].weight == 0, return); 1616 PJ_ASSERT_ON_FAIL(pj_strcmp2(&rec->entry[0].server.name, TARGET)==0, 1617 return); 1618 PJ_ASSERT_ON_FAIL(pj_strcmp2(&rec->entry[0].server.alias, "sipalias01." TARGET)==0, 1619 return); 1620 PJ_ASSERT_ON_FAIL(rec->entry[0].port == PORT2, return); 1621 1622 /* IPv6 only */ 1623 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr_count == 1, return); 1624 PJ_ASSERT_ON_FAIL(rec->entry[0].server.addr[0].af == pj_AF_INET6() && 1625 rec->entry[0].server.addr[0].ip.v6.u6_addr32[0] == IP_ADDR2, return); 1197 1626 } 1198 1627 … … 1203 1632 pj_str_t res_name = pj_str("_sip._udp."); 1204 1633 1634 /* Fallback test */ 1205 1635 PJ_LOG(3,(THIS_FILE, " srv_resolve(): fallback test")); 1206 1636 … … 1235 1665 pj_assert(g_server[0].pkt_count == 0); 1236 1666 pj_assert(g_server[1].pkt_count == 0); 1667 1668 /* Clear cache */ 1669 pj_thread_sleep(1000); 1670 1671 /* Fallback with PJ_DNS_SRV_FALLBACK_A and PJ_DNS_SRV_FALLBACK_AAAA */ 1672 PJ_LOG(3,(THIS_FILE, " srv_resolve(): fallback to DNS A and AAAA")); 1673 1674 g_server[0].action = ACTION_CB; 1675 g_server[0].action_cb = &action2_1; 1676 g_server[1].action = ACTION_CB; 1677 g_server[1].action_cb = &action2_1; 1678 1679 status = pj_dns_srv_resolve(&domain, &res_name, PORT2, pool, resolver, 1680 PJ_DNS_SRV_FALLBACK_A | PJ_DNS_SRV_FALLBACK_AAAA, 1681 NULL, &srv_cb_2a, NULL); 1682 if (status != PJ_SUCCESS) { 1683 app_perror(" srv_resolve error", status); 1684 pj_assert(status == PJ_SUCCESS); 1685 } 1686 1687 pj_sem_wait(sem); 1688 1689 /* Clear cache */ 1690 pj_thread_sleep(1000); 1691 1692 /* Fallback with PJ_DNS_SRV_FALLBACK_AAAA only */ 1693 PJ_LOG(3,(THIS_FILE, " srv_resolve(): fallback to DNS AAAA only")); 1694 1695 g_server[0].action = ACTION_CB; 1696 g_server[0].action_cb = &action2_1; 1697 g_server[1].action = ACTION_CB; 1698 g_server[1].action_cb = &action2_1; 1699 1700 status = pj_dns_srv_resolve(&domain, &res_name, PORT2, pool, resolver, 1701 PJ_DNS_SRV_FALLBACK_AAAA, 1702 NULL, &srv_cb_2b, NULL); 1703 if (status != PJ_SUCCESS) { 1704 app_perror(" srv_resolve error", status); 1705 pj_assert(status == PJ_SUCCESS); 1706 } 1707 1708 pj_sem_wait(sem); 1709 1710 /* Clear cache */ 1711 pj_thread_sleep(1000); 1237 1712 1238 1713 return 0; … … 1334 1809 1335 1810 for (j=0; j<PJ_DNS_MAX_IP_IN_A_REC; ++j) { 1336 pj_assert(rec->entry[i].server.addr[j]. s_addr == IP_ADDR3+j);1811 pj_assert(rec->entry[i].server.addr[j].ip.v4.s_addr == IP_ADDR3+j); 1337 1812 } 1338 1813 } … … 1375 1850 int rc; 1376 1851 1377 rc = init( );1852 rc = init(PJ_FALSE); 1378 1853 if (rc != 0) 1379 1854 goto on_error; … … 1383 1858 goto on_error; 1384 1859 1860 rc = addr_parser_test(); 1861 if (rc != 0) 1862 goto on_error; 1863 1385 1864 rc = simple_test(); 1386 1865 if (rc != 0) … … 1396 1875 1397 1876 destroy(); 1877 1878 1879 #if PJ_HAS_IPV6 1880 /* Similar tests using IPv6 socket and without parser tests */ 1881 PJ_LOG(3,(THIS_FILE, "Re-run DNS resolution tests using IPv6 socket")); 1882 1883 rc = init(PJ_TRUE); 1884 if (rc != 0) 1885 goto on_error; 1886 1887 rc = simple_test(); 1888 if (rc != 0) 1889 goto on_error; 1890 1891 rc = dns_test(); 1892 if (rc != 0) 1893 goto on_error; 1894 1895 srv_resolver_test(); 1896 srv_resolver_fallback_test(); 1897 srv_resolver_many_test(); 1898 1899 destroy(); 1900 #endif 1901 1398 1902 return 0; 1399 1903 … … 1403 1907 } 1404 1908 1405
Note: See TracChangeset
for help on using the changeset viewer.