- 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/pjnath/src/pjnath-test/server.c
r5170 r5513 54 54 char strbuf[100]; 55 55 pj_status_t status; 56 pj_bool_t use_ipv6 = flags & SERVER_IPV6; 56 57 57 58 PJ_ASSERT_RETURN(stun_cfg && domain && p_test_srv, PJ_EINVAL); 58 59 59 status = pj_gethostip(pj_AF_INET(), &hostip); 60 if (status != PJ_SUCCESS) 61 return status; 60 if (use_ipv6) { 61 /* pj_gethostip() may return IPv6 link-local and will cause EINVAL 62 * error, so let's just hardcode it. 63 */ 64 pj_sockaddr_init(pj_AF_INET6(), &hostip, NULL, 0); 65 hostip.ipv6.sin6_addr.s6_addr[15] = 1; 66 } else { 67 status = pj_gethostip(GET_AF(use_ipv6), &hostip); 68 if (status != PJ_SUCCESS) 69 return status; 70 } 62 71 63 72 pool = pj_pool_create(mem, THIS_FILE, 512, 512, NULL); … … 75 84 if (flags & CREATE_DNS_SERVER) { 76 85 status = pj_dns_server_create(mem, test_srv->stun_cfg->ioqueue, 77 pj_AF_INET(), DNS_SERVER_PORT,86 GET_AF(use_ipv6), DNS_SERVER_PORT, 78 87 0, &test_srv->dns_server); 79 88 if (status != PJ_SUCCESS) { … … 86 95 pj_dns_parsed_rr rr; 87 96 pj_str_t res_name; 88 pj_in_addr ip_addr;89 97 90 98 pj_strdup2(pool, &res_name, domain); 91 ip_addr = hostip.ipv4.sin_addr; 92 pj_dns_init_a_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, &ip_addr); 99 100 if (use_ipv6) { 101 pj_dns_init_aaaa_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, 102 &hostip.ipv6.sin6_addr); 103 } else { 104 pj_dns_init_a_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, 105 &hostip.ipv4.sin_addr); 106 } 107 93 108 pj_dns_server_add_rec(test_srv->dns_server, 1, &rr); 94 109 } … … 103 118 stun_sock_cb.on_data_recvfrom = &stun_on_data_recvfrom; 104 119 105 pj_sockaddr_in_init(&bound_addr.ipv4, NULL, STUN_SERVER_PORT); 120 pj_sockaddr_init(GET_AF(use_ipv6), &bound_addr, 121 NULL, STUN_SERVER_PORT); 106 122 107 123 status = pj_activesock_create_udp(pool, &bound_addr, NULL, … … 124 140 pj_str_t res_name, target; 125 141 pj_dns_parsed_rr rr; 126 pj_in_addr ip_addr;127 142 128 143 /* Add DNS entries: … … 141 156 142 157 res_name = target; 143 ip_addr = hostip.ipv4.sin_addr; 144 pj_dns_init_a_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, &ip_addr); 158 if (use_ipv6) { 159 pj_dns_init_aaaa_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, 160 &hostip.ipv6.sin6_addr); 161 } else { 162 pj_dns_init_a_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, 163 &hostip.ipv4.sin_addr); 164 } 145 165 pj_dns_server_add_rec(test_srv->dns_server, 1, &rr); 146 166 } … … 155 175 turn_sock_cb.on_data_recvfrom = &turn_on_data_recvfrom; 156 176 157 pj_sockaddr_in _init(&bound_addr.ipv4, NULL, TURN_SERVER_PORT);177 pj_sockaddr_init(GET_AF(use_ipv6), &bound_addr, NULL, TURN_SERVER_PORT); 158 178 159 179 status = pj_activesock_create_udp(pool, &bound_addr, NULL, … … 176 196 pj_str_t res_name, target; 177 197 pj_dns_parsed_rr rr; 178 pj_in_addr ip_addr;179 198 180 199 /* Add DNS entries: … … 193 212 194 213 res_name = target; 195 ip_addr = hostip.ipv4.sin_addr; 196 pj_dns_init_a_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, &ip_addr); 214 215 if (use_ipv6) { 216 pj_dns_init_aaaa_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, 217 &hostip.ipv6.sin6_addr); 218 } else { 219 pj_dns_init_a_rr(&rr, &res_name, PJ_DNS_CLASS_IN, 60, 220 &hostip.ipv4.sin_addr); 221 } 197 222 pj_dns_server_add_rec(test_srv->dns_server, 1, &rr); 198 223 } … … 345 370 unsigned i; 346 371 pj_ssize_t len; 372 pj_bool_t use_ipv6 = PJ_FALSE; 347 373 348 374 if (status != PJ_SUCCESS) … … 352 378 353 379 test_srv = (test_server*) pj_activesock_get_user_data(asock); 380 use_ipv6 = test_srv->flags & SERVER_IPV6; 354 381 pool = pj_pool_create(test_srv->stun_cfg->pf, NULL, 512, 512, NULL); 355 382 … … 481 508 alloc->pool = pj_pool_create(test_srv->stun_cfg->pf, "alloc", 512, 512, NULL); 482 509 483 /* Create relay socket */ 484 pj_sockaddr_in_init(&alloc->alloc_addr.ipv4, NULL, 0); 485 pj_gethostip(pj_AF_INET(), &alloc->alloc_addr); 510 /* Create relay socket */ 511 pj_sockaddr_init(GET_AF(use_ipv6), &alloc->alloc_addr, NULL, 0); 512 if (use_ipv6) { 513 /* pj_gethostip() may return IPv6 link-local and will cause EINVAL 514 * error, so let's just hardcode it. 515 */ 516 pj_sockaddr_init(pj_AF_INET6(), &alloc->alloc_addr, NULL, 0); 517 alloc->alloc_addr.ipv6.sin6_addr.s6_addr[15] = 1; 518 } else { 519 status = pj_gethostip(GET_AF(use_ipv6), &alloc->alloc_addr); 520 if (status != PJ_SUCCESS) { 521 pj_pool_release(alloc->pool); 522 pj_stun_msg_create_response(pool, req, PJ_STUN_SC_SERVER_ERROR, 523 NULL, &resp); 524 goto send_pkt; 525 } 526 } 486 527 487 528 status = pj_activesock_create_udp(alloc->pool, &alloc->alloc_addr, NULL, … … 698 739 unsigned i; 699 740 741 PJ_UNUSED_ARG(addr_len); 742 700 743 if (status != PJ_SUCCESS) 701 744 return PJ_TRUE; … … 708 751 /* Check that this peer has a permission */ 709 752 for (i=0; i<alloc->perm_cnt; ++i) { 710 if (pj_sockaddr_get_len(&alloc->perm[i]) == (unsigned)addr_len && 711 pj_memcmp(pj_sockaddr_get_addr(&alloc->perm[i]), 712 pj_sockaddr_get_addr(src_addr), 713 addr_len) == 0) 753 if (pj_sockaddr_cmp(&alloc->perm[i], src_addr) == 0) 714 754 { 715 755 break;
Note: See TracChangeset
for help on using the changeset viewer.