Changeset 4365
- Timestamp:
- Feb 21, 2013 6:06:51 PM (12 years ago)
- Location:
- pjproject/trunk/pjnath/src/pjnath
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath/ice_session.c
r4360 r4365 719 719 pj_ice_sess_cand *lcand; 720 720 pj_status_t status = PJ_SUCCESS; 721 char address[PJ_INET6_ADDRSTRLEN]; 721 722 722 723 PJ_ASSERT_RETURN(ice && comp_id && … … 738 739 pj_strdup(ice->pool, &lcand->foundation, foundation); 739 740 lcand->prio = CALC_CAND_PRIO(ice, type, local_pref, lcand->comp_id); 740 pj_ memcpy(&lcand->addr, addr, addr_len);741 pj_ memcpy(&lcand->base_addr, base_addr, addr_len);741 pj_sockaddr_cp(&lcand->addr, addr); 742 pj_sockaddr_cp(&lcand->base_addr, base_addr); 742 743 if (rel_addr == NULL) 743 744 rel_addr = base_addr; 744 745 pj_memcpy(&lcand->rel_addr, rel_addr, addr_len); 745 746 746 pj_ansi_strcpy(ice->tmp.txt, pj_inet_ntoa(lcand->addr.ipv4.sin_addr)); 747 pj_ansi_strcpy(ice->tmp.txt, pj_sockaddr_print(&lcand->addr, address, 748 sizeof(address), 0)); 747 749 LOG4((ice->obj_name, 748 750 "Candidate %d added: comp_id=%d, type=%s, foundation=%.*s, " … … 754 756 lcand->foundation.ptr, 755 757 ice->tmp.txt, 756 (int)pj_ntohs(lcand->addr.ipv4.sin_port),757 pj_inet_ntoa(lcand->base_addr.ipv4.sin_addr),758 (int)pj_htons(lcand->base_addr.ipv4.sin_port),758 pj_sockaddr_get_port(&lcand->addr), 759 pj_sockaddr_print(&lcand->base_addr, address, sizeof(address), 0), 760 pj_sockaddr_get_port(&lcand->base_addr), 759 761 lcand->prio, lcand->prio)); 760 762 … … 893 895 const pj_ice_sess_cand *lcand = check->lcand; 894 896 const pj_ice_sess_cand *rcand = check->rcand; 895 char laddr[PJ_INET6_ADDRSTRLEN] ;897 char laddr[PJ_INET6_ADDRSTRLEN], raddr[PJ_INET6_ADDRSTRLEN]; 896 898 int len; 897 899 898 900 PJ_CHECK_STACK(); 899 901 900 pj_ansi_strcpy(laddr, pj_inet_ntoa(lcand->addr.ipv4.sin_addr)); 901 902 if (lcand->addr.addr.sa_family == pj_AF_INET()) { 903 len = pj_ansi_snprintf(buffer, bufsize, 904 "%d: [%d] %s:%d-->%s:%d", 905 (int)GET_CHECK_ID(clist, check), 906 check->lcand->comp_id, 907 laddr, (int)pj_ntohs(lcand->addr.ipv4.sin_port), 908 pj_inet_ntoa(rcand->addr.ipv4.sin_addr), 909 (int)pj_ntohs(rcand->addr.ipv4.sin_port)); 910 } else { 911 len = pj_ansi_snprintf(buffer, bufsize, "IPv6->IPv6"); 912 } 913 902 pj_ansi_strcpy(laddr, pj_sockaddr_print(&lcand->addr, laddr, 903 sizeof(laddr), 0)); 904 905 len = pj_ansi_snprintf(buffer, bufsize, 906 "%d: [%d] %s:%d-->%s:%d", 907 (int)GET_CHECK_ID(clist, check), 908 check->lcand->comp_id, 909 pj_sockaddr_print(&lcand->addr, laddr, 910 sizeof(laddr), 0), 911 pj_sockaddr_get_port(&lcand->addr), 912 pj_sockaddr_print(&rcand->addr, raddr, 913 sizeof(raddr), 0), 914 pj_sockaddr_get_port(&rcand->addr)); 914 915 915 916 if (len < 0) … … 1015 1016 } 1016 1017 1017 enum1018 {1019 SOCKADDR_EQUAL = 0,1020 SOCKADDR_NOT_EQUAL = 11021 };1022 1023 /* Utility: compare sockaddr.1024 * Returns 0 if equal.1025 */1026 static int sockaddr_cmp(const pj_sockaddr *a1, const pj_sockaddr *a2)1027 {1028 if (a1->addr.sa_family != a2->addr.sa_family)1029 return SOCKADDR_NOT_EQUAL;1030 1031 if (a1->addr.sa_family == pj_AF_INET()) {1032 return !(a1->ipv4.sin_addr.s_addr == a2->ipv4.sin_addr.s_addr &&1033 a1->ipv4.sin_port == a2->ipv4.sin_port);1034 } else if (a1->addr.sa_family == pj_AF_INET6()) {1035 return pj_memcmp(&a1->ipv6, &a2->ipv6, sizeof(a1->ipv6));1036 } else {1037 pj_assert(!"Invalid address family!");1038 return SOCKADDR_NOT_EQUAL;1039 }1040 }1041 1042 1043 1018 /* Prune checklist, this must have been done after the checklist 1044 1019 * is sorted. … … 1072 1047 continue; 1073 1048 1074 if ( sockaddr_cmp(&srflx->base_addr, &host->addr) == 0) {1049 if (pj_sockaddr_cmp(&srflx->base_addr, &host->addr) == 0) { 1075 1050 /* Replace this SRFLX with its BASE */ 1076 1051 clist->checks[i].lcand = host; … … 1080 1055 1081 1056 if (j==ice->lcand_cnt) { 1057 char baddr[PJ_INET6_ADDRSTRLEN]; 1082 1058 /* Host candidate not found this this srflx! */ 1083 1059 LOG4((ice->obj_name, 1084 1060 "Base candidate %s:%d not found for srflx candidate %d", 1085 pj_inet_ntoa(srflx->base_addr.ipv4.sin_addr), 1086 pj_ntohs(srflx->base_addr.ipv4.sin_port), 1061 pj_sockaddr_print(&srflx->base_addr, baddr, 1062 sizeof(baddr), 0), 1063 pj_sockaddr_get_port(&srflx->base_addr), 1087 1064 GET_LCAND_ID(clist->checks[i].lcand))); 1088 1065 return PJNATH_EICENOHOSTCAND; … … 1112 1089 reason = "duplicate found"; 1113 1090 } else if ((rjcand == ricand) && 1114 ( sockaddr_cmp(&ljcand->base_addr,1091 (pj_sockaddr_cmp(&ljcand->base_addr, 1115 1092 &licand->base_addr)==0)) 1116 1093 { … … 1840 1817 status = pj_stun_session_send_msg(comp->stun_sess, msg_data, PJ_FALSE, 1841 1818 PJ_TRUE, &rcand->addr, 1842 sizeof(pj_sockaddr_in), check->tdata); 1819 pj_sockaddr_get_len(&rcand->addr), 1820 check->tdata); 1843 1821 if (status != PJ_SUCCESS) { 1844 1822 check->tdata = NULL; … … 2293 2271 * Request was sent from. 2294 2272 */ 2295 if (sockaddr_cmp(&check->rcand->addr, (const pj_sockaddr*)src_addr) != 0) { 2273 if (pj_sockaddr_cmp(&check->rcand->addr, (const pj_sockaddr*)src_addr)!=0) 2274 { 2296 2275 status = PJNATH_EICEINSRCADDR; 2297 2276 LOG4((ice->obj_name, … … 2344 2323 pj_assert(lcand == NULL); 2345 2324 for (i=0; i<ice->lcand_cnt; ++i) { 2346 if ( sockaddr_cmp(&xaddr->sockaddr, &ice->lcand[i].addr) == 0) {2325 if (pj_sockaddr_cmp(&xaddr->sockaddr, &ice->lcand[i].addr) == 0) { 2347 2326 /* Match */ 2348 2327 lcand = &ice->lcand[i]; … … 2380 2359 &check->lcand->base_addr, 2381 2360 &check->lcand->base_addr, 2382 sizeof(pj_sockaddr_in), &cand_id); 2361 pj_sockaddr_get_len(&xaddr->sockaddr), 2362 &cand_id); 2383 2363 if (status != PJ_SUCCESS) { 2384 2364 check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED, … … 2619 2599 rcheck->transport_id = ((pj_ice_msg_data*)token)->transport_id; 2620 2600 rcheck->src_addr_len = src_addr_len; 2621 pj_ memcpy(&rcheck->src_addr, src_addr, src_addr_len);2601 pj_sockaddr_cp(&rcheck->src_addr, src_addr); 2622 2602 rcheck->use_candidate = (uc_attr != NULL); 2623 2603 rcheck->priority = prio_attr->value; … … 2657 2637 */ 2658 2638 for (i=0; i<ice->rcand_cnt; ++i) { 2659 if ( sockaddr_cmp(&rcheck->src_addr, &ice->rcand[i].addr)==0)2639 if (pj_sockaddr_cmp(&rcheck->src_addr, &ice->rcand[i].addr)==0) 2660 2640 break; 2661 2641 } … … 2667 2647 */ 2668 2648 if (i == ice->rcand_cnt) { 2649 char raddr[PJ_INET6_ADDRSTRLEN]; 2669 2650 if (ice->rcand_cnt >= PJ_ICE_MAX_CAND) { 2670 2651 LOG4((ice->obj_name, … … 2678 2659 rcand->type = PJ_ICE_CAND_TYPE_PRFLX; 2679 2660 rcand->prio = rcheck->priority; 2680 pj_ memcpy(&rcand->addr, &rcheck->src_addr, rcheck->src_addr_len);2661 pj_sockaddr_cp(&rcand->addr, &rcheck->src_addr); 2681 2662 2682 2663 /* Foundation is random, unique from other foundation */ … … 2687 2668 2688 2669 LOG4((ice->obj_name, 2689 "Added new remote candidate from the request: %s:%d",2690 pj_inet_ntoa(rcand->addr.ipv4.sin_addr),2691 (int)pj_ntohs(rcand->addr.ipv4.sin_port)));2670 "Added new remote candidate from the request: %s:%d", 2671 pj_sockaddr_print(&rcand->addr, raddr, sizeof(raddr), 0), 2672 pj_sockaddr_get_port(&rcand->addr))); 2692 2673 2693 2674 } else { … … 2706 2687 pj_ice_sess_check *c = &ice->clist.checks[i]; 2707 2688 if (/*c->lcand == lcand ||*/ 2708 sockaddr_cmp(&c->lcand->base_addr, &lcand->base_addr)==0)2689 pj_sockaddr_cmp(&c->lcand->base_addr, &lcand->base_addr)==0) 2709 2690 { 2710 2691 lcand = c->lcand; … … 2955 2936 data, data_len, 2956 2937 &addr, 2957 sizeof(pj_sockaddr_in));2938 pj_sockaddr_get_len(&addr)); 2958 2939 2959 2940 on_return: -
pjproject/trunk/pjnath/src/pjnath/ice_strans.c
r4360 r4365 1321 1321 pj_ice_strans_comp *comp; 1322 1322 pj_status_t status; 1323 char daddr[PJ_INET6_ADDRSTRLEN]; 1323 1324 1324 1325 PJ_ASSERT_RETURN(comp_id && comp_id <= ice_st->comp_cnt, PJ_EINVAL); … … 1327 1328 1328 1329 TRACE_PKT((comp->ice_st->obj_name, 1329 "Component %d TX packet to %s:%d with transport %d",1330 comp_id,1331 pj_inet_ntoa(((pj_sockaddr_in*)dst_addr)->sin_addr),1332 (int)pj_ntohs(((pj_sockaddr_in*)dst_addr)->sin_port),1333 transport_id));1330 "Component %d TX packet to %s:%d with transport %d", 1331 comp_id, 1332 pj_sockaddr_print(dst_addr, daddr, sizeof(addr), 0), 1333 pj_sockaddr_get_port(dst_addr), 1334 transport_id)); 1334 1335 1335 1336 if (transport_id == TP_TURN) {
Note: See TracChangeset
for help on using the changeset viewer.