#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/base/ip_address.h"
#include <stddef.h>
#include <algorithm>
#include <array>
#include <climits>
#include <optional>
#include <string_view>
#include "base/check_op.h"
#include "base/debug/alias.h"
#include "base/debug/crash_logging.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "base/values.h"
#include "net/base/parse_number.h"
#include "url/gurl.h"
#include "url/url_canon_ip.h"
namespace net {
namespace {
constexpr uint8_t kIPv4MappedPrefix[] = …;
bool IPAddressPrefixCheck(const IPAddressBytes& ip_address,
const uint8_t* ip_prefix,
size_t prefix_length_in_bits) { … }
bool CreateIPMask(IPAddressBytes* ip_address,
size_t prefix_length_in_bits,
size_t ip_address_length) { … }
bool IsPubliclyRoutableIPv4(const IPAddressBytes& ip_address) { … }
bool IsPubliclyRoutableIPv6(const IPAddressBytes& ip_address) { … }
bool ParseIPLiteralToBytes(std::string_view ip_literal, IPAddressBytes* bytes) { … }
}
IPAddressBytes::IPAddressBytes() : … { … }
IPAddressBytes::IPAddressBytes(base::span<const uint8_t> data) { … }
IPAddressBytes::~IPAddressBytes() = default;
IPAddressBytes::IPAddressBytes(IPAddressBytes const& other) = default;
void IPAddressBytes::Assign(base::span<const uint8_t> data) { … }
bool IPAddressBytes::operator<(const IPAddressBytes& other) const { … }
bool IPAddressBytes::operator==(const IPAddressBytes& other) const { … }
bool IPAddressBytes::operator!=(const IPAddressBytes& other) const { … }
void IPAddressBytes::Append(base::span<const uint8_t> data) { … }
size_t IPAddressBytes::EstimateMemoryUsage() const { … }
std::optional<IPAddress> IPAddress::FromValue(const base::Value& value) { … }
std::optional<IPAddress> IPAddress::FromIPLiteral(std::string_view ip_literal) { … }
IPAddress::IPAddress() = default;
IPAddress::IPAddress(const IPAddress& other) = default;
IPAddress::IPAddress(const IPAddressBytes& address) : … { … }
IPAddress::IPAddress(base::span<const uint8_t> address)
: … { … }
IPAddress::IPAddress(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3) { … }
IPAddress::IPAddress(uint8_t b0,
uint8_t b1,
uint8_t b2,
uint8_t b3,
uint8_t b4,
uint8_t b5,
uint8_t b6,
uint8_t b7,
uint8_t b8,
uint8_t b9,
uint8_t b10,
uint8_t b11,
uint8_t b12,
uint8_t b13,
uint8_t b14,
uint8_t b15) { … }
IPAddress::~IPAddress() = default;
bool IPAddress::IsIPv4() const { … }
bool IPAddress::IsIPv6() const { … }
bool IPAddress::IsValid() const { … }
bool IPAddress::IsPubliclyRoutable() const { … }
bool IPAddress::IsZero() const { … }
bool IPAddress::IsIPv4MappedIPv6() const { … }
bool IPAddress::IsLoopback() const { … }
bool IPAddress::IsLinkLocal() const { … }
bool IPAddress::IsUniqueLocalIPv6() const { … }
bool IPAddress::AssignFromIPLiteral(std::string_view ip_literal) { … }
std::vector<uint8_t> IPAddress::CopyBytesToVector() const { … }
IPAddress IPAddress::IPv4Localhost() { … }
IPAddress IPAddress::IPv6Localhost() { … }
IPAddress IPAddress::AllZeros(size_t num_zero_bytes) { … }
IPAddress IPAddress::IPv4AllZeros() { … }
IPAddress IPAddress::IPv6AllZeros() { … }
bool IPAddress::CreateIPv4Mask(IPAddress* ip_address,
size_t mask_prefix_length) { … }
bool IPAddress::CreateIPv6Mask(IPAddress* ip_address,
size_t mask_prefix_length) { … }
bool IPAddress::operator==(const IPAddress& that) const { … }
bool IPAddress::operator!=(const IPAddress& that) const { … }
bool IPAddress::operator<(const IPAddress& that) const { … }
std::string IPAddress::ToString() const { … }
base::Value IPAddress::ToValue() const { … }
size_t IPAddress::EstimateMemoryUsage() const { … }
std::string IPAddressToStringWithPort(const IPAddress& address, uint16_t port) { … }
std::string IPAddressToPackedString(const IPAddress& address) { … }
IPAddress ConvertIPv4ToIPv4MappedIPv6(const IPAddress& address) { … }
IPAddress ConvertIPv4MappedIPv6ToIPv4(const IPAddress& address) { … }
bool IPAddressMatchesPrefix(const IPAddress& ip_address,
const IPAddress& ip_prefix,
size_t prefix_length_in_bits) { … }
bool ParseCIDRBlock(std::string_view cidr_literal,
IPAddress* ip_address,
size_t* prefix_length_in_bits) { … }
bool ParseURLHostnameToAddress(std::string_view hostname,
IPAddress* ip_address) { … }
size_t CommonPrefixLength(const IPAddress& a1, const IPAddress& a2) { … }
size_t MaskPrefixLength(const IPAddress& mask) { … }
Dns64PrefixLength ExtractPref64FromIpv4onlyArpaAAAA(const IPAddress& address) { … }
IPAddress ConvertIPv4ToIPv4EmbeddedIPv6(const IPAddress& ipv4_address,
const IPAddress& ipv6_address,
Dns64PrefixLength prefix_length) { … }
}