///////////////////////////////////////////////////////
| 566 | |
| 567 | //////////////////////////////////////////////////////////// |
| 568 | std::vector<sf::String> Dns::queryNs(const String& hostname, const std::vector<IpAddress>& servers, std::optional<Time> timeout) |
| 569 | { |
| 570 | std::vector<sf::String> nsRecords; |
| 571 | |
| 572 | if (hostname.isEmpty()) |
| 573 | return nsRecords; |
| 574 | |
| 575 | auto encoded = encodeHostname(hostname); |
| 576 | |
| 577 | // On Android the libc provided resolv API doesn't work, we will have to do the work ourselves |
| 578 | #if defined(SFML_SYSTEM_ANDROID) |
| 579 | const auto& serversToQuery = servers.empty() ? getAndroidServers() : servers; |
| 580 | #else |
| 581 | const auto& serversToQuery = servers; |
| 582 | #endif |
| 583 | |
| 584 | if (!serversToQuery.empty()) |
| 585 | { |
| 586 | queryDns( |
| 587 | [&](const char* data, std::size_t length, const char* messageBegin, std::uint16_t responseType, std::uint16_t responseClass) |
| 588 | { |
| 589 | // NS, IN |
| 590 | if ((responseType != 2) || (responseClass != 1)) |
| 591 | return; |
| 592 | |
| 593 | if (auto nameserver = readName(data, data + length, messageBegin); !nameserver.empty()) |
| 594 | nsRecords.emplace_back(decodeHostname(nameserver)); |
| 595 | }, |
| 596 | timeout, |
| 597 | {{serversToQuery, |
| 598 | 2, // NS |
| 599 | 1, // IN |
| 600 | encoded}}); |
| 601 | |
| 602 | return nsRecords; |
| 603 | } |
| 604 | |
| 605 | #if defined(SFML_SYSTEM_WINDOWS) |
| 606 | const auto records = getRecords(encoded, DNS_TYPE_NS); |
| 607 | for (const auto* ptr = records.get(); ptr; ptr = ptr->pNext) |
| 608 | { |
| 609 | if ((ptr->wType == DNS_TYPE_NS) && (ptr->Data.NS.pNameHost != nullptr)) |
| 610 | nsRecords.emplace_back(decodeHostname(sf::String(ptr->Data.NS.pNameHost).toAnsiString())); |
| 611 | } |
| 612 | #else |
| 613 | getRecords(encoded, |
| 614 | ns_t_ns, |
| 615 | [&nsRecords](const ns_msg& handle, const ns_rr& record) |
| 616 | { |
| 617 | std::array<char, NS_MAXCDNAME> nameserver{}; |
| 618 | |
| 619 | if (const auto result = dn_expand(ns_msg_base(handle), |
| 620 | ns_msg_end(handle), |
| 621 | ns_rr_rdata(record), |
| 622 | nameserver.data(), |
| 623 | nameserver.size()); |
| 624 | result >= 0) |
| 625 | { |
nothing calls this directly
no test coverage detected