Changeset 1326
- Timestamp:
- May 30, 2007 4:23:43 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip/sip_resolve.c
r1240 r1326 761 761 if (status==PJ_SUCCESS && pkt->hdr.anscount != 0) { 762 762 763 unsigned srv_idx; 764 763 765 /* Update IP address of the corresponding hostname */ 764 for ( i=0; i<query->srv_cnt; ++i) {766 for (srv_idx=0; srv_idx<query->srv_cnt; ++srv_idx) { 765 767 if (pj_stricmp(&pkt->ans[0].name, 766 &query->srv[ i].target_name)==0)768 &query->srv[srv_idx].target_name)==0) 767 769 { 768 770 break; … … 770 772 } 771 773 772 if ( i== query->srv_cnt) {774 if (srv_idx == query->srv_cnt) { 773 775 PJ_LOG(4,(query->objname, 774 776 "Received answer to DNS A request with no matching " … … 776 778 (int)pkt->ans[0].name.slen, pkt->ans[0].name.ptr)); 777 779 } else { 778 unsigned j; 779 780 query->srv[i].addr[query->srv[i].addr_cnt++].s_addr = 781 pkt->ans[0].rdata.a.ip_addr.s_addr; 780 int ans_idx = -1; 781 unsigned k, j; 782 pj_str_t cname = { NULL, 0 }; 783 784 /* Find the first DNS A record in the answer while processing 785 * the CNAME info found in the response. 786 */ 787 for (k=0; k < pkt->hdr.anscount; ++k) { 788 789 pj_dns_parsed_rr *rr = &pkt->ans[k]; 790 791 if (rr->type == PJ_DNS_TYPE_A && 792 (cname.slen == 0 || pj_stricmp(&rr->name, &cname)==0)) 793 { 794 if (ans_idx == -1) 795 ans_idx = k; 796 797 } else if (rr->type == PJ_DNS_TYPE_CNAME && 798 pj_stricmp(&query->srv[srv_idx].target_name, 799 &rr->name)==0) 800 { 801 cname = rr->rdata.cname.name; 802 } 803 } 804 805 if (ans_idx == -1) { 806 /* There's no DNS A answer! */ 807 PJ_LOG(5,(query->objname, 808 "No DNS A record in response!")); 809 status = PJLIB_UTIL_EDNSNOANSWERREC; 810 goto on_error; 811 } 812 813 query->srv[srv_idx].addr[query->srv[srv_idx].addr_cnt++].s_addr = 814 pkt->ans[ans_idx].rdata.a.ip_addr.s_addr; 782 815 783 816 PJ_LOG(5,(query->objname, 784 817 "DNS A for %.*s: %s", 785 (int)query->srv[ i].target_name.slen,786 query->srv[ i].target_name.ptr,787 pj_inet_ntoa(pkt->ans[ 0].rdata.a.ip_addr)));818 (int)query->srv[srv_idx].target_name.slen, 819 query->srv[srv_idx].target_name.ptr, 820 pj_inet_ntoa(pkt->ans[ans_idx].rdata.a.ip_addr))); 788 821 789 822 /* Check for multiple IP addresses */ 790 for (j= 1; j<pkt->hdr.anscount &&791 query->srv[ i].addr_cnt < ADDR_MAX_COUNT; ++j)823 for (j=ans_idx+1; j<pkt->hdr.anscount && 824 query->srv[srv_idx].addr_cnt < ADDR_MAX_COUNT; ++j) 792 825 { 793 query->srv[ i].addr[query->srv[i].addr_cnt++].s_addr =826 query->srv[srv_idx].addr[query->srv[srv_idx].addr_cnt++].s_addr = 794 827 pkt->ans[j].rdata.a.ip_addr.s_addr; 795 828 796 829 PJ_LOG(5,(query->objname, 797 830 "Additional DNS A for %.*s: %s", 798 (int)query->srv[ i].target_name.slen,799 query->srv[ i].target_name.ptr,831 (int)query->srv[srv_idx].target_name.slen, 832 query->srv[srv_idx].target_name.ptr, 800 833 pj_inet_ntoa(pkt->ans[j].rdata.a.ip_addr))); 801 834 }
Note: See TracChangeset
for help on using the changeset viewer.