#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/dns/address_sorter_posix.h"
#include <netinet/in.h>
#include <memory>
#include <utility>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_BSD)
#include <sys/socket.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <string.h>
#include <sys/ioctl.h>
#if BUILDFLAG(IS_IOS)
#include "net/dns/netinet_in_var_ios.h"
#else
#include <netinet/in_var.h>
#endif
#endif
#include <vector>
#include "base/containers/unique_ptr_adapters.h"
#include "base/logging.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/log/net_log_source.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/datagram_client_socket.h"
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "net/base/address_tracker_linux.h"
#endif
namespace net {
namespace {
bool ComparePolicy(const AddressSorterPosix::PolicyEntry& p1,
const AddressSorterPosix::PolicyEntry& p2) { … }
AddressSorterPosix::PolicyTable LoadPolicy(
const AddressSorterPosix::PolicyEntry* table,
size_t size) { … }
unsigned GetPolicyValue(const AddressSorterPosix::PolicyTable& table,
const IPAddress& address) { … }
bool IsIPv6Multicast(const IPAddress& address) { … }
AddressSorterPosix::AddressScope GetIPv6MulticastScope(
const IPAddress& address) { … }
bool IsIPv6Loopback(const IPAddress& address) { … }
bool IsIPv6LinkLocal(const IPAddress& address) { … }
bool IsIPv6SiteLocal(const IPAddress& address) { … }
AddressSorterPosix::AddressScope GetScope(
const AddressSorterPosix::PolicyTable& ipv4_scope_table,
const IPAddress& address) { … }
const AddressSorterPosix::PolicyEntry kDefaultPrecedenceTable[] = …;
const AddressSorterPosix::PolicyEntry kDefaultLabelTable[] = …;
const AddressSorterPosix::PolicyEntry kDefaultIPv4ScopeTable[] = …;
struct DestinationInfo { … };
bool CompareDestinations(const DestinationInfo& dst_a,
const DestinationInfo& dst_b) { … }
}
class AddressSorterPosix::SortContext { … };
AddressSorterPosix::AddressSorterPosix(ClientSocketFactory* socket_factory)
: … { … }
AddressSorterPosix::~AddressSorterPosix() { … }
void AddressSorterPosix::Sort(const std::vector<IPEndPoint>& endpoints,
CallbackType callback) const { … }
void AddressSorterPosix::OnIPAddressChanged() { … }
void AddressSorterPosix::FillPolicy(const IPAddress& address,
SourceAddressInfo* info) const { … }
void AddressSorterPosix::FinishedSort(SortContext* sort_context) const { … }
std::unique_ptr<AddressSorter> AddressSorter::CreateAddressSorter() { … }
}