- 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/resolver.c
r5170 r5513 20 20 #include <pjlib-util/resolver.h> 21 21 #include <pjlib-util/errno.h> 22 #include <pj/compat/socket.h> 22 23 #include <pj/assert.h> 23 24 #include <pj/ctype.h> … … 80 81 struct nameserver 81 82 { 82 pj_sockaddr _inaddr; /**< Server address. */83 pj_sockaddr addr; /**< Server address. */ 83 84 84 85 enum ns_state state; /**< Nameserver state. */ … … 180 181 pj_ioqueue_key_t *udp_key; /**< UDP socket ioqueue key. */ 181 182 unsigned char udp_rx_pkt[UDPSZ];/**< UDP receive buffer. */ 182 unsigned char udp_tx_pkt[UDPSZ];/**< UDP receive buffer. */ 183 pj_ssize_t udp_len; /**< Length of received packet. */ 183 unsigned char udp_tx_pkt[UDPSZ];/**< UDP transmit buffer. */ 184 184 pj_ioqueue_op_key_t udp_op_rx_key; /**< UDP read operation key. */ 185 185 pj_ioqueue_op_key_t udp_op_tx_key; /**< UDP write operation key. */ 186 pj_sockaddr _inudp_src_addr; /**< Source address of packet */186 pj_sockaddr udp_src_addr; /**< Source address of packet */ 187 187 int udp_addr_len; /**< Source address length. */ 188 189 #if PJ_HAS_IPV6 190 /* IPv6 socket */ 191 pj_sock_t udp6_sock; /**< UDP socket. */ 192 pj_ioqueue_key_t *udp6_key; /**< UDP socket ioqueue key. */ 193 unsigned char udp6_rx_pkt[UDPSZ];/**< UDP receive buffer. */ 194 //unsigned char udp6_tx_pkt[UDPSZ];/**< UDP transmit buffer. */ 195 pj_ioqueue_op_key_t udp6_op_rx_key;/**< UDP read operation key. */ 196 pj_ioqueue_op_key_t udp6_op_tx_key;/**< UDP write operation key. */ 197 pj_sockaddr udp6_src_addr; /**< Source address of packet */ 198 int udp6_addr_len; /**< Source address length. */ 199 #endif 188 200 189 201 /* Settings */ … … 238 250 resv->udp_sock = PJ_INVALID_SOCKET; 239 251 } 252 253 #if PJ_HAS_IPV6 254 if (resv->udp6_key != NULL) { 255 pj_ioqueue_unregister(resv->udp6_key); 256 resv->udp6_key = NULL; 257 resv->udp6_sock = PJ_INVALID_SOCKET; 258 } else if (resv->udp6_sock != PJ_INVALID_SOCKET) { 259 pj_sock_close(resv->udp6_sock); 260 resv->udp6_sock = PJ_INVALID_SOCKET; 261 } 262 #endif 240 263 } 241 264 … … 245 268 { 246 269 pj_ioqueue_callback socket_cb; 270 pj_sockaddr bound_addr; 271 pj_ssize_t rx_pkt_size; 247 272 pj_status_t status; 248 273 … … 270 295 271 296 /* Start asynchronous read to the UDP socket */ 272 r esv->udp_len= sizeof(resv->udp_rx_pkt);297 rx_pkt_size = sizeof(resv->udp_rx_pkt); 273 298 resv->udp_addr_len = sizeof(resv->udp_src_addr); 274 299 status = pj_ioqueue_recvfrom(resv->udp_key, &resv->udp_op_rx_key, 275 resv->udp_rx_pkt, &r esv->udp_len,300 resv->udp_rx_pkt, &rx_pkt_size, 276 301 PJ_IOQUEUE_ALWAYS_ASYNC, 277 302 &resv->udp_src_addr, &resv->udp_addr_len); 278 303 if (status != PJ_EPENDING) 279 304 return status; 305 306 307 #if PJ_HAS_IPV6 308 /* Also setup IPv6 socket */ 309 310 /* Create the UDP socket */ 311 status = pj_sock_socket(pj_AF_INET6(), pj_SOCK_DGRAM(), 0, 312 &resv->udp6_sock); 313 if (status != PJ_SUCCESS) { 314 /* Skip IPv6 socket on system without IPv6 (see ticket #1953) */ 315 if (status == PJ_STATUS_FROM_OS(OSERR_EAFNOSUPPORT)) { 316 PJ_LOG(3,(resv->name.ptr, 317 "System does not support IPv6, resolver will " 318 "ignore any IPv6 nameservers")); 319 return PJ_SUCCESS; 320 } 321 return status; 322 } 323 324 /* Bind to any address/port */ 325 pj_sockaddr_init(pj_AF_INET6(), &bound_addr, NULL, 0); 326 status = pj_sock_bind(resv->udp6_sock, &bound_addr, 327 pj_sockaddr_get_len(&bound_addr)); 328 if (status != PJ_SUCCESS) 329 return status; 330 331 /* Register to ioqueue */ 332 pj_bzero(&socket_cb, sizeof(socket_cb)); 333 socket_cb.on_read_complete = &on_read_complete; 334 status = pj_ioqueue_register_sock(resv->pool, resv->ioqueue, 335 resv->udp6_sock, resv, &socket_cb, 336 &resv->udp6_key); 337 if (status != PJ_SUCCESS) 338 return status; 339 340 pj_ioqueue_op_key_init(&resv->udp6_op_rx_key, 341 sizeof(resv->udp6_op_rx_key)); 342 pj_ioqueue_op_key_init(&resv->udp6_op_tx_key, 343 sizeof(resv->udp6_op_tx_key)); 344 345 /* Start asynchronous read to the UDP socket */ 346 rx_pkt_size = sizeof(resv->udp6_rx_pkt); 347 resv->udp6_addr_len = sizeof(resv->udp6_src_addr); 348 status = pj_ioqueue_recvfrom(resv->udp6_key, &resv->udp6_op_rx_key, 349 resv->udp6_rx_pkt, &rx_pkt_size, 350 PJ_IOQUEUE_ALWAYS_ASYNC, 351 &resv->udp6_src_addr, &resv->udp6_addr_len); 352 if (status != PJ_EPENDING) 353 return status; 354 #else 355 PJ_UNUSED_ARG(bound_addr); 356 #endif 280 357 281 358 return PJ_SUCCESS; … … 475 552 struct nameserver *ns = &resolver->ns[i]; 476 553 477 status = pj_sockaddr_in_init(&ns->addr, &servers[i], 478 (pj_uint16_t)(ports ? ports[i] : PORT)); 554 status = pj_sockaddr_init(pj_AF_INET(), &ns->addr, &servers[i], 555 (pj_uint16_t)(ports ? ports[i] : PORT)); 556 if (status != PJ_SUCCESS) 557 status = pj_sockaddr_init(pj_AF_INET6(), &ns->addr, &servers[i], 558 (pj_uint16_t)(ports ? ports[i] : PORT)); 479 559 if (status != PJ_SUCCESS) { 480 560 pj_mutex_unlock(resolver->mutex); … … 580 660 { 581 661 unsigned pkt_size; 582 unsigned i, server_cnt ;662 unsigned i, server_cnt, send_cnt; 583 663 unsigned servers[PJ_DNS_RESOLVER_MAX_NS]; 584 664 pj_time_val now; … … 613 693 614 694 /* Check if the socket is available for sending */ 615 if (pj_ioqueue_is_pending(resolver->udp_key, &resolver->udp_op_tx_key)) { 695 if (pj_ioqueue_is_pending(resolver->udp_key, &resolver->udp_op_tx_key) 696 #if PJ_HAS_IPV6 697 || (resolver->udp6_key && 698 pj_ioqueue_is_pending(resolver->udp6_key, 699 &resolver->udp6_op_tx_key)) 700 #endif 701 ) 702 { 616 703 ++q->transmit_cnt; 617 704 PJ_LOG(4,(resolver->name.ptr, … … 638 725 639 726 /* Send the packet to name servers */ 727 send_cnt = 0; 640 728 for (i=0; i<server_cnt; ++i) { 729 char addr[PJ_INET6_ADDRSTRLEN]; 641 730 pj_ssize_t sent = (pj_ssize_t) pkt_size; 642 731 struct nameserver *ns = &resolver->ns[servers[i]]; 643 732 644 status = pj_ioqueue_sendto(resolver->udp_key, 645 &resolver->udp_op_tx_key, 646 resolver->udp_tx_pkt, &sent, 0, 647 &resolver->ns[servers[i]].addr, 648 sizeof(pj_sockaddr_in)); 733 if (ns->addr.addr.sa_family == pj_AF_INET()) { 734 status = pj_ioqueue_sendto(resolver->udp_key, 735 &resolver->udp_op_tx_key, 736 resolver->udp_tx_pkt, &sent, 0, 737 &ns->addr, 738 pj_sockaddr_get_len(&ns->addr)); 739 if (status == PJ_SUCCESS || status == PJ_EPENDING) 740 send_cnt++; 741 } 742 #if PJ_HAS_IPV6 743 else if (resolver->udp6_key) { 744 status = pj_ioqueue_sendto(resolver->udp6_key, 745 &resolver->udp6_op_tx_key, 746 resolver->udp_tx_pkt, &sent, 0, 747 &ns->addr, 748 pj_sockaddr_get_len(&ns->addr)); 749 if (status == PJ_SUCCESS || status == PJ_EPENDING) 750 send_cnt++; 751 } 752 #endif 753 else { 754 continue; 755 } 649 756 650 757 PJ_PERROR(4,(resolver->name.ptr, status, … … 652 759 (q->transmit_cnt==0? "Transmitting":"Re-transmitting"), 653 760 (int)pkt_size, servers[i], 654 pj_ inet_ntoa(ns->addr.sin_addr),655 (int)pj_ntohs(ns->addr.sin_port),761 pj_sockaddr_print(&ns->addr, addr, sizeof(addr), 2), 762 pj_sockaddr_get_port(&ns->addr), 656 763 pj_dns_get_type_name(q->key.qtype), 657 764 q->key.name)); … … 662 769 } 663 770 } 771 772 if (send_cnt == 0) 773 return PJLIB_UTIL_EDNSNOWORKINGNS; 664 774 665 775 ++q->transmit_cnt; … … 747 857 struct res_key key; 748 858 struct cached_res *cache; 749 pj_dns_async_query *q ;859 pj_dns_async_query *q, *p_q = NULL; 750 860 pj_uint32_t hval; 751 861 pj_status_t status = PJ_SUCCESS; … … 760 870 /* Check type */ 761 871 PJ_ASSERT_RETURN(type > 0 && type < 0xFFFF, PJ_EINVAL); 762 763 if (p_query)764 *p_query = NULL;765 872 766 873 /* Build resource key for looking up hash tables */ … … 823 930 status = PJ_SUCCESS; 824 931 825 goto on_return; 932 /* 933 * We cannot write to *p_query after calling cb because what 934 * p_query points to may have been freed by cb. 935 * Refer to ticket #1974. 936 */ 937 pj_mutex_unlock(resolver->mutex); 938 return status; 826 939 } 827 940 … … 855 968 * query completes. 856 969 */ 970 p_q = nq; 857 971 status = PJ_SUCCESS; 858 972 goto on_return; … … 882 996 0, q->hbufkey, q); 883 997 998 p_q = q; 999 1000 on_return: 884 1001 if (p_query) 885 *p_query = q; 886 887 on_return: 1002 *p_query = p_q; 1003 888 1004 pj_mutex_unlock(resolver->mutex); 889 1005 return status; … … 1027 1143 1028 1144 1145 /* 1146 * DNS response containing A and/or AAAA packet. 1147 */ 1148 PJ_DEF(pj_status_t) pj_dns_parse_addr_response( 1149 const pj_dns_parsed_packet *pkt, 1150 pj_dns_addr_record *rec) 1151 { 1152 enum { MAX_SEARCH = 20 }; 1153 pj_str_t hostname, alias = {NULL, 0}, *resname; 1154 pj_size_t bufstart = 0; 1155 pj_size_t bufleft; 1156 unsigned i, ansidx, cnt=0; 1157 1158 PJ_ASSERT_RETURN(pkt && rec, PJ_EINVAL); 1159 1160 /* Init the record */ 1161 pj_bzero(rec, sizeof(*rec)); 1162 1163 bufleft = sizeof(rec->buf_); 1164 1165 /* Return error if there's error in the packet. */ 1166 if (PJ_DNS_GET_RCODE(pkt->hdr.flags)) 1167 return PJ_STATUS_FROM_DNS_RCODE(PJ_DNS_GET_RCODE(pkt->hdr.flags)); 1168 1169 /* Return error if there's no query section */ 1170 if (pkt->hdr.qdcount == 0) 1171 return PJLIB_UTIL_EDNSINANSWER; 1172 1173 /* Return error if there's no answer */ 1174 if (pkt->hdr.anscount == 0) 1175 return PJLIB_UTIL_EDNSNOANSWERREC; 1176 1177 /* Get the hostname from the query. */ 1178 hostname = pkt->q[0].name; 1179 1180 /* Copy hostname to the record */ 1181 if (hostname.slen > (int)bufleft) { 1182 return PJ_ENAMETOOLONG; 1183 } 1184 1185 pj_memcpy(&rec->buf_[bufstart], hostname.ptr, hostname.slen); 1186 rec->name.ptr = &rec->buf_[bufstart]; 1187 rec->name.slen = hostname.slen; 1188 1189 bufstart += hostname.slen; 1190 bufleft -= hostname.slen; 1191 1192 /* Find the first RR which name matches the hostname. */ 1193 for (ansidx=0; ansidx < pkt->hdr.anscount; ++ansidx) { 1194 if (pj_stricmp(&pkt->ans[ansidx].name, &hostname)==0) 1195 break; 1196 } 1197 1198 if (ansidx == pkt->hdr.anscount) 1199 return PJLIB_UTIL_EDNSNOANSWERREC; 1200 1201 resname = &hostname; 1202 1203 /* Keep following CNAME records. */ 1204 while (pkt->ans[ansidx].type == PJ_DNS_TYPE_CNAME && 1205 cnt++ < MAX_SEARCH) 1206 { 1207 resname = &pkt->ans[ansidx].rdata.cname.name; 1208 1209 if (!alias.slen) 1210 alias = *resname; 1211 1212 for (i=0; i < pkt->hdr.anscount; ++i) { 1213 if (pj_stricmp(resname, &pkt->ans[i].name)==0) 1214 break; 1215 } 1216 1217 if (i==pkt->hdr.anscount) 1218 return PJLIB_UTIL_EDNSNOANSWERREC; 1219 1220 ansidx = i; 1221 } 1222 1223 if (cnt >= MAX_SEARCH) 1224 return PJLIB_UTIL_EDNSINANSWER; 1225 1226 if (pkt->ans[ansidx].type != PJ_DNS_TYPE_A && 1227 pkt->ans[ansidx].type != PJ_DNS_TYPE_AAAA) 1228 { 1229 return PJLIB_UTIL_EDNSINANSWER; 1230 } 1231 1232 /* Copy alias to the record, if present. */ 1233 if (alias.slen) { 1234 if (alias.slen > (int)bufleft) 1235 return PJ_ENAMETOOLONG; 1236 1237 pj_memcpy(&rec->buf_[bufstart], alias.ptr, alias.slen); 1238 rec->alias.ptr = &rec->buf_[bufstart]; 1239 rec->alias.slen = alias.slen; 1240 1241 bufstart += alias.slen; 1242 bufleft -= alias.slen; 1243 } 1244 1245 /* Get the IP addresses. */ 1246 cnt = 0; 1247 for (i=0; i < pkt->hdr.anscount && cnt < PJ_DNS_MAX_IP_IN_A_REC ; ++i) { 1248 if ((pkt->ans[i].type == PJ_DNS_TYPE_A || 1249 pkt->ans[i].type == PJ_DNS_TYPE_AAAA) && 1250 pj_stricmp(&pkt->ans[i].name, resname)==0) 1251 { 1252 if (pkt->ans[i].type == PJ_DNS_TYPE_A) { 1253 rec->addr[cnt].af = pj_AF_INET(); 1254 rec->addr[cnt].ip.v4 = pkt->ans[i].rdata.a.ip_addr; 1255 } else { 1256 rec->addr[cnt].af = pj_AF_INET6(); 1257 rec->addr[cnt].ip.v6 = pkt->ans[i].rdata.aaaa.ip_addr; 1258 } 1259 ++cnt; 1260 } 1261 } 1262 rec->addr_count = cnt; 1263 1264 if (cnt == 0) 1265 return PJLIB_UTIL_EDNSNOANSWERREC; 1266 1267 return PJ_SUCCESS; 1268 } 1269 1270 1029 1271 /* Set nameserver state */ 1030 1272 static void set_nameserver_state(pj_dns_resolver *resolver, … … 1035 1277 struct nameserver *ns = &resolver->ns[index]; 1036 1278 enum ns_state old_state = ns->state; 1279 char addr[PJ_INET6_ADDRSTRLEN]; 1037 1280 1038 1281 ns->state = state; … … 1048 1291 1049 1292 PJ_LOG(5, (resolver->name.ptr, "Nameserver %s:%d state changed %s --> %s", 1050 pj_ inet_ntoa(ns->addr.sin_addr),1051 (int)pj_ntohs(ns->addr.sin_port),1293 pj_sockaddr_print(&ns->addr, addr, sizeof(addr), 2), 1294 pj_sockaddr_get_port(&ns->addr), 1052 1295 state_names[old_state], state_names[state])); 1053 1296 } … … 1128 1371 /* Update name server status */ 1129 1372 static void report_nameserver_status(pj_dns_resolver *resolver, 1130 const pj_sockaddr _in*ns_addr,1373 const pj_sockaddr *ns_addr, 1131 1374 const pj_dns_parsed_packet *pkt) 1132 1375 { … … 1148 1391 } 1149 1392 1150 if (!pkt || rcode == PJ_DNS_RCODE_SERVFAIL || 1393 /* Some nameserver is reported to respond with PJ_DNS_RCODE_SERVFAIL for 1394 * missing AAAA record, and the standard doesn't seem to specify that 1395 * SERVFAIL should prevent the server to be contacted again for other 1396 * queries. So let's not mark nameserver as bad for SERVFAIL response. 1397 */ 1398 if (!pkt || /* rcode == PJ_DNS_RCODE_SERVFAIL || */ 1151 1399 rcode == PJ_DNS_RCODE_REFUSED || 1152 1400 rcode == PJ_DNS_RCODE_NOTAUTH) … … 1165 1413 struct nameserver *ns = &resolver->ns[i]; 1166 1414 1167 if (ns->addr.sin_addr.s_addr == ns_addr->sin_addr.s_addr && 1168 ns->addr.sin_port == ns_addr->sin_port && 1169 ns->addr.sin_family == ns_addr->sin_family) 1170 { 1415 if (pj_sockaddr_cmp(&ns->addr, ns_addr) == 0) { 1171 1416 if (q_id == ns->q_id) { 1172 1417 /* Calculate response time */ … … 1233 1478 ttl = resolver->settings.cache_max_ttl; 1234 1479 1480 /* Get a cache response entry */ 1481 cache = (struct cached_res *) pj_hash_get(resolver->hrescache, key, 1482 sizeof(*key), &hval); 1483 1235 1484 /* If TTL is zero, clear the same entry in the hash table */ 1236 1485 if (ttl == 0) { 1237 cache = (struct cached_res *) pj_hash_get(resolver->hrescache, key,1238 sizeof(*key), &hval);1239 1486 /* Remove the entry before releasing its pool (see ticket #1710) */ 1240 1487 pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL); … … 1246 1493 } 1247 1494 1248 /* Get a cache response entry */1249 cache = (struct cached_res *) pj_hash_get(resolver->hrescache, key,1250 sizeof(*key), &hval);1251 1495 if (cache == NULL) { 1252 cache = alloc_entry(resolver);1253 } else if (cache->ref_cnt > 1) {1254 /* When cache entry is being used by callback (to app), just decrement1255 * ref_cnt so it will be freed after the callback returns and allocate1256 * new entry.1257 */1258 cache->ref_cnt--;1259 1496 cache = alloc_entry(resolver); 1260 1497 } else { … … 1262 1499 pj_hash_set(NULL, resolver->hrescache, key, sizeof(*key), hval, NULL); 1263 1500 1264 /* Reset cache to avoid bloated cache pool */ 1265 reset_entry(&cache); 1501 if (cache->ref_cnt > 1) { 1502 /* When cache entry is being used by callback (to app), 1503 * just decrement ref_cnt so it will be freed after 1504 * the callback returns and allocate new entry. 1505 */ 1506 cache->ref_cnt--; 1507 cache = alloc_entry(resolver); 1508 } else { 1509 /* Reset cache to avoid bloated cache pool */ 1510 reset_entry(&cache); 1511 } 1266 1512 } 1267 1513 … … 1391 1637 pj_dns_parsed_packet *dns_pkt; 1392 1638 pj_dns_async_query *q; 1639 char addr[PJ_INET6_ADDRSTRLEN]; 1640 pj_sockaddr *src_addr; 1641 int *src_addr_len; 1642 unsigned char *rx_pkt; 1643 pj_ssize_t rx_pkt_size; 1393 1644 pj_status_t status; 1394 1645 PJ_USE_EXCEPTION; … … 1396 1647 1397 1648 resolver = (pj_dns_resolver *) pj_ioqueue_get_user_data(key); 1649 pj_assert(resolver); 1650 1651 #if PJ_HAS_IPV6 1652 if (key == resolver->udp6_key) { 1653 src_addr = &resolver->udp6_src_addr; 1654 src_addr_len = &resolver->udp6_addr_len; 1655 rx_pkt = resolver->udp6_rx_pkt; 1656 rx_pkt_size = sizeof(resolver->udp6_rx_pkt); 1657 } else 1658 #endif 1659 { 1660 src_addr = &resolver->udp_src_addr; 1661 src_addr_len = &resolver->udp_addr_len; 1662 rx_pkt = resolver->udp_rx_pkt; 1663 rx_pkt_size = sizeof(resolver->udp_rx_pkt); 1664 } 1665 1398 1666 pj_mutex_lock(resolver->mutex); 1399 1667 … … 1405 1673 status = (pj_status_t)-bytes_read; 1406 1674 pj_strerror(status, errmsg, sizeof(errmsg)); 1407 PJ_LOG(4,(resolver->name.ptr, 1408 "DNS resolver read error from %s:%d: %s", 1409 pj_inet_ntoa(resolver->udp_src_addr.sin_addr), 1410 pj_ntohs(resolver->udp_src_addr.sin_port), 1411 errmsg)); 1675 PJ_LOG(4,(resolver->name.ptr, "DNS resolver read error: %s", errmsg)); 1412 1676 1413 1677 goto read_next_packet; … … 1417 1681 "Received %d bytes DNS response from %s:%d", 1418 1682 (int)bytes_read, 1419 pj_ inet_ntoa(resolver->udp_src_addr.sin_addr),1420 pj_ ntohs(resolver->udp_src_addr.sin_port)));1683 pj_sockaddr_print(src_addr, addr, sizeof(addr), 2), 1684 pj_sockaddr_get_port(src_addr))); 1421 1685 1422 1686 … … 1433 1697 dns_pkt = NULL; 1434 1698 PJ_TRY { 1435 status = pj_dns_parse_packet(pool, r esolver->udp_rx_pkt,1699 status = pj_dns_parse_packet(pool, rx_pkt, 1436 1700 (unsigned)bytes_read, &dns_pkt); 1437 1701 } … … 1442 1706 1443 1707 /* Update nameserver status */ 1444 report_nameserver_status(resolver, &resolver->udp_src_addr, dns_pkt);1708 report_nameserver_status(resolver, src_addr, dns_pkt); 1445 1709 1446 1710 /* Handle parse error */ … … 1451 1715 PJ_LOG(3,(resolver->name.ptr, 1452 1716 "Error parsing DNS response from %s:%d: %s", 1453 pj_ inet_ntoa(resolver->udp_src_addr.sin_addr),1454 pj_ ntohs(resolver->udp_src_addr.sin_port),1717 pj_sockaddr_print(src_addr, addr, sizeof(addr), 2), 1718 pj_sockaddr_get_port(src_addr), 1455 1719 errmsg)); 1456 1720 goto read_next_packet; … … 1464 1728 PJ_LOG(5,(resolver->name.ptr, 1465 1729 "DNS response from %s:%d id=%d discarded", 1466 pj_ inet_ntoa(resolver->udp_src_addr.sin_addr),1467 pj_ ntohs(resolver->udp_src_addr.sin_port),1730 pj_sockaddr_print(src_addr, addr, sizeof(addr), 2), 1731 pj_sockaddr_get_port(src_addr), 1468 1732 (unsigned)dns_pkt->hdr.id)); 1469 1733 goto read_next_packet; … … 1528 1792 pj_pool_release(pool); 1529 1793 } 1530 bytes_read = sizeof(resolver->udp_rx_pkt); 1531 resolver->udp_addr_len = sizeof(resolver->udp_src_addr); 1532 status = pj_ioqueue_recvfrom(resolver->udp_key, op_key, 1533 resolver->udp_rx_pkt, 1534 &bytes_read, PJ_IOQUEUE_ALWAYS_ASYNC, 1535 &resolver->udp_src_addr, 1536 &resolver->udp_addr_len); 1794 1795 status = pj_ioqueue_recvfrom(key, op_key, rx_pkt, &rx_pkt_size, 1796 PJ_IOQUEUE_ALWAYS_ASYNC, 1797 src_addr, src_addr_len); 1798 1537 1799 if (status != PJ_EPENDING) { 1538 1800 char errmsg[PJ_ERR_MSG_SIZE]; … … 1634 1896 PJ_LOG(3,(resolver->name.ptr, " Name servers:")); 1635 1897 for (i=0; i<resolver->ns_count; ++i) { 1898 char addr[PJ_INET6_ADDRSTRLEN]; 1636 1899 struct nameserver *ns = &resolver->ns[i]; 1637 1900 1638 1901 PJ_LOG(3,(resolver->name.ptr, 1639 1902 " NS %d: %s:%d (state=%s until %ds, rtt=%d ms)", 1640 i, pj_inet_ntoa(ns->addr.sin_addr), 1641 pj_ntohs(ns->addr.sin_port), 1903 i, 1904 pj_sockaddr_print(&ns->addr, addr, sizeof(addr), 2), 1905 pj_sockaddr_get_port(&ns->addr), 1642 1906 state_names[ns->state], 1643 1907 ns->state_expiry.sec - now.sec,
Note: See TracChangeset
for help on using the changeset viewer.