- 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/nat_detect.c
r4573 r5513 85 85 pj_stun_nat_detect_cb *cb; 86 86 pj_sock_t sock; 87 pj_sockaddr _inlocal_addr;87 pj_sockaddr local_addr; 88 88 pj_ioqueue_key_t *key; 89 pj_sockaddr _inserver;90 pj_sockaddr _in*cur_server;89 pj_sockaddr server; 90 pj_sockaddr *cur_server; 91 91 pj_stun_session *stun_sess; 92 92 … … 94 94 pj_uint8_t rx_pkt[PJ_STUN_MAX_PKT_LEN]; 95 95 pj_ssize_t rx_pkt_len; 96 pj_sockaddr _insrc_addr;96 pj_sockaddr src_addr; 97 97 int src_addr_len; 98 98 … … 102 102 pj_bool_t complete; 103 103 pj_status_t status; 104 pj_sockaddr _inma;105 pj_sockaddr _inca;104 pj_sockaddr ma; 105 pj_sockaddr ca; 106 106 pj_stun_tx_data *tdata; 107 107 } result[ST_MAX]; … … 129 129 static pj_status_t send_test(nat_detect_session *sess, 130 130 enum test_type test_id, 131 const pj_sockaddr _in*alt_addr,131 const pj_sockaddr *alt_addr, 132 132 pj_uint32_t change_flag); 133 133 static void on_sess_timer(pj_timer_heap_t *th, … … 167 167 } 168 168 169 static pj_status_t get_local_interface(const pj_sockaddr _in*server,170 pj_ in_addr *local_addr)169 static pj_status_t get_local_interface(const pj_sockaddr *server, 170 pj_sockaddr *local_addr) 171 171 { 172 172 pj_sock_t sock; 173 pj_sockaddr _in tmp;173 pj_sockaddr tmp, local; 174 174 int addr_len; 175 175 pj_status_t status; 176 176 177 status = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &sock); 177 status = pj_sock_socket(server->addr.sa_family, pj_SOCK_DGRAM(), 178 0, &sock); 178 179 if (status != PJ_SUCCESS) 179 180 return status; 180 181 181 status = pj_sock_bind_in(sock, 0, 0); 182 addr_len = pj_sockaddr_get_len(server); 183 pj_bzero(&local, sizeof(pj_sockaddr)); 184 status = pj_sock_bind(sock, &local, addr_len); 182 185 if (status != PJ_SUCCESS) { 183 186 pj_sock_close(sock); … … 185 188 } 186 189 187 status = pj_sock_connect(sock, server, sizeof(pj_sockaddr_in));190 status = pj_sock_connect(sock, server, addr_len); 188 191 if (status != PJ_SUCCESS) { 189 192 pj_sock_close(sock); … … 191 194 } 192 195 193 addr_len = sizeof(pj_sockaddr_in);194 196 status = pj_sock_getsockname(sock, &tmp, &addr_len); 195 197 if (status != PJ_SUCCESS) { … … 198 200 } 199 201 200 local_addr->s_addr = tmp.sin_addr.s_addr;202 pj_sockaddr_cp(local_addr, &tmp); 201 203 202 204 pj_sock_close(sock); … … 210 212 pj_stun_nat_detect_cb *cb) 211 213 { 214 pj_sockaddr srv; 215 216 if (server) 217 pj_sockaddr_cp(&srv, server); 218 219 return pj_stun_detect_nat_type2(&srv, stun_cfg, user_data, cb); 220 } 221 222 PJ_DEF(pj_status_t) pj_stun_detect_nat_type2(const pj_sockaddr *server, 223 pj_stun_config *stun_cfg, 224 void *user_data, 225 pj_stun_nat_detect_cb *cb) 226 { 212 227 pj_pool_t *pool; 213 228 nat_detect_session *sess; 214 229 pj_stun_session_cb sess_cb; 215 230 pj_ioqueue_callback ioqueue_cb; 216 int addr_len; 231 int af, addr_len; 232 char addr[PJ_INET6_ADDRSTRLEN]; 217 233 pj_status_t status; 218 234 … … 244 260 pj_grp_lock_add_handler(sess->grp_lock, pool, sess, &sess_on_destroy); 245 261 246 pj_ memcpy(&sess->server, server, sizeof(pj_sockaddr_in));262 pj_sockaddr_cp(&sess->server, server); 247 263 248 264 /* … … 257 273 * Initialize socket. 258 274 */ 259 status = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &sess->sock); 275 af = server->addr.sa_family; 276 status = pj_sock_socket(af, pj_SOCK_DGRAM(), 0, &sess->sock); 260 277 if (status != PJ_SUCCESS) 261 278 goto on_error; … … 264 281 * Bind to any. 265 282 */ 266 pj_bzero(&sess->local_addr, sizeof(pj_sockaddr_in)); 267 sess->local_addr.sin_family = pj_AF_INET(); 268 status = pj_sock_bind(sess->sock, &sess->local_addr, 269 sizeof(pj_sockaddr_in)); 283 pj_bzero(&sess->local_addr, sizeof(pj_sockaddr)); 284 addr_len = pj_sockaddr_get_len(server); 285 status = pj_sock_bind(sess->sock, &sess->local_addr, addr_len); 270 286 if (status != PJ_SUCCESS) 271 287 goto on_error; … … 274 290 * Get local/bound address. 275 291 */ 276 addr_len = sizeof(sess->local_addr);277 292 status = pj_sock_getsockname(sess->sock, &sess->local_addr, &addr_len); 278 293 if (status != PJ_SUCCESS) … … 282 297 * Find out which interface is used to send to the server. 283 298 */ 284 status = get_local_interface(server, &sess->local_addr .sin_addr);299 status = get_local_interface(server, &sess->local_addr); 285 300 if (status != PJ_SUCCESS) 286 301 goto on_error; 287 302 288 303 PJ_LOG(5,(sess->pool->obj_name, "Local address is %s:%d", 289 pj_inet_ntoa(sess->local_addr.sin_addr), 290 pj_ntohs(sess->local_addr.sin_port)));304 pj_sockaddr_print(&sess->local_addr, addr, sizeof(addr), 0), 305 pj_sockaddr_get_port(&sess->local_addr))); 291 306 292 307 PJ_LOG(5,(sess->pool->obj_name, "Server set to %s:%d", 293 pj_inet_ntoa(server->sin_addr), 294 pj_ntohs(server->sin_port)));308 pj_sockaddr_print(server, addr, sizeof(addr), 0), 309 pj_sockaddr_get_port(server))); 295 310 296 311 /* … … 572 587 sess->result[test_id].status = status; 573 588 if (status == PJ_SUCCESS) { 574 pj_memcpy(&sess->result[test_id].ma, &mattr->sockaddr.ipv4, 575 sizeof(pj_sockaddr_in)); 576 pj_memcpy(&sess->result[test_id].ca, &ca->sockaddr.ipv4, 577 sizeof(pj_sockaddr_in)); 589 pj_sockaddr_cp(&sess->result[test_id].ma, &mattr->sockaddr); 590 pj_sockaddr_cp(&sess->result[test_id].ca, &ca->sockaddr); 578 591 } 579 592 … … 587 600 sess->result[ST_TEST_1].status == PJ_SUCCESS) 588 601 { 589 cmp = pj_memcmp(&sess->local_addr, &sess->result[ST_TEST_1].ma, 590 sizeof(pj_sockaddr_in)); 602 cmp = pj_sockaddr_cmp(&sess->local_addr, &sess->result[ST_TEST_1].ma); 591 603 if (cmp != 0) 592 604 send_test(sess, ST_TEST_1B, &sess->result[ST_TEST_1].ca, 0); … … 657 669 * NAT type. Compare the MAPPED-ADDRESS with the local address. 658 670 */ 659 cmp = pj_memcmp(&sess->local_addr, &sess->result[ST_TEST_1].ma, 660 sizeof(pj_sockaddr_in)); 671 cmp = pj_sockaddr_cmp(&sess->local_addr, &sess->result[ST_TEST_1].ma); 661 672 if (cmp==0) { 662 673 /* … … 708 719 * MAPPED-ADDRESS returned in test 1.. 709 720 */ 710 cmp = pj_memcmp(&sess->result[ST_TEST_1].ma, 711 &sess->result[ST_TEST_1B].ma, 712 sizeof(pj_sockaddr_in)); 721 cmp = pj_sockaddr_cmp(&sess->result[ST_TEST_1].ma, 722 &sess->result[ST_TEST_1B].ma); 713 723 if (cmp != 0) { 714 724 /* … … 811 821 static pj_status_t send_test(nat_detect_session *sess, 812 822 enum test_type test_id, 813 const pj_sockaddr _in*alt_addr,823 const pj_sockaddr *alt_addr, 814 824 pj_uint32_t change_flag) 815 825 { 816 826 pj_uint32_t magic, tsx_id[3]; 827 char addr[PJ_INET6_ADDRSTRLEN]; 817 828 pj_status_t status; 818 829 … … 846 857 /* Configure alternate address */ 847 858 if (alt_addr) 848 sess->cur_server = (pj_sockaddr _in*) alt_addr;859 sess->cur_server = (pj_sockaddr*) alt_addr; 849 860 else 850 861 sess->cur_server = &sess->server; … … 853 864 "Performing %s to %s:%d", 854 865 test_names[test_id], 855 pj_ inet_ntoa(sess->cur_server->sin_addr),856 pj_ ntohs(sess->cur_server->sin_port)));866 pj_sockaddr_print(sess->cur_server, addr, sizeof(addr), 0), 867 pj_sockaddr_get_port(sess->cur_server))); 857 868 858 869 /* Send the request */ 859 870 status = pj_stun_session_send_msg(sess->stun_sess, NULL, PJ_TRUE, 860 871 PJ_TRUE, sess->cur_server, 861 sizeof(pj_sockaddr_in),872 pj_sockaddr_get_len(sess->cur_server), 862 873 sess->result[test_id].tdata); 863 874 if (status != PJ_SUCCESS)
Note: See TracChangeset
for help on using the changeset viewer.