chromium/net/base/ip_address.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#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 {

// The prefix for IPv6 mapped IPv4 addresses.
// https://tools.ietf.org/html/rfc4291#section-2.5.5.2
constexpr uint8_t kIPv4MappedPrefix[] =;

// Note that this function assumes:
// * |ip_address| is at least |prefix_length_in_bits| (bits) long;
// * |ip_prefix| is at least |prefix_length_in_bits| (bits) long.
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) {}

// Returns false if |ip_address| matches any of the reserved IPv4 ranges. This
// method operates on a list of reserved IPv4 ranges. Some ranges are
// consolidated.
// Sources for info:
// www.iana.org/assignments/ipv4-address-space/ipv4-address-space.xhtml
// www.iana.org/assignments/iana-ipv4-special-registry/
// iana-ipv4-special-registry.xhtml
bool IsPubliclyRoutableIPv4(const IPAddressBytes& ip_address) {}

// Returns false if |ip_address| matches any of the IPv6 ranges IANA reserved
// for local networks. This method operates on an allowlist of non-reserved
// IPv6 ranges, plus the list of reserved IPv4 ranges mapped to IPv6.
// Sources for info:
// www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml
bool IsPubliclyRoutableIPv6(const IPAddressBytes& ip_address) {}

bool ParseIPLiteralToBytes(std::string_view ip_literal, IPAddressBytes* bytes) {}

}  // namespace

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 {}

// static
std::optional<IPAddress> IPAddress::FromValue(const base::Value& value) {}

// static
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 {}

// static
IPAddress IPAddress::IPv4Localhost() {}

// static
IPAddress IPAddress::IPv6Localhost() {}

// static
IPAddress IPAddress::AllZeros(size_t num_zero_bytes) {}

// static
IPAddress IPAddress::IPv4AllZeros() {}

// static
IPAddress IPAddress::IPv6AllZeros() {}

// static
bool IPAddress::CreateIPv4Mask(IPAddress* ip_address,
                               size_t mask_prefix_length) {}

// static
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) {}

}  // namespace net