chromium/net/socket/udp_socket_posix.cc

// Copyright 2012 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 "build/build_config.h"

#if BUILDFLAG(IS_APPLE)
// This must be defined before including <netinet/in.h>
// to use IPV6_DONTFRAG, one of the IPv6 Sockets option introduced by RFC 3542
#define __APPLE_USE_RFC_3542
#endif  // BUILDFLAG(IS_APPLE)

#include "net/socket/udp_socket_posix.h"

#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>

#include <memory>

#include "base/debug/alias.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
#include "base/rand_util.h"
#include "base/task/current_thread.h"
#include "base/task/thread_pool.h"
#include "build/chromeos_buildflags.h"
#include "net/base/cronet_buildflags.h"
#include "net/base/io_buffer.h"
#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/base/network_activity_monitor.h"
#include "net/base/sockaddr_storage.h"
#include "net/base/trace_constants.h"
#include "net/base/tracing.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_source.h"
#include "net/log/net_log_source_type.h"
#include "net/socket/socket_descriptor.h"
#include "net/socket/socket_options.h"
#include "net/socket/socket_tag.h"
#include "net/socket/udp_net_log_parameters.h"
#include "net/traffic_annotation/network_traffic_annotation.h"

#if BUILDFLAG(IS_ANDROID)
#include "base/native_library.h"
#include "net/android/network_library.h"
#endif  // BUILDFLAG(IS_ANDROID)

#if BUILDFLAG(IS_APPLE)
#include "net/base/apple/guarded_fd.h"
#endif  // BUILDFLAG(IS_APPLE)

#if BUILDFLAG(IS_MAC)
#include "base/mac/mac_util.h"
#endif  // BUILDFLAG(IS_MAC)

namespace net {

namespace {

constexpr int kBindRetries =;
constexpr int kPortStart =;
constexpr int kPortEnd =;

int GetSocketFDHash(int fd) {}

}  // namespace

UDPSocketPosix::UDPSocketPosix(DatagramSocket::BindType bind_type,
                               net::NetLog* net_log,
                               const net::NetLogSource& source)
    :{}

UDPSocketPosix::UDPSocketPosix(DatagramSocket::BindType bind_type,
                               NetLogWithSource source_net_log)
    :{}

UDPSocketPosix::~UDPSocketPosix() {}

int UDPSocketPosix::Open(AddressFamily address_family) {}

int UDPSocketPosix::AdoptOpenedSocket(AddressFamily address_family,
                                      int socket) {}

int UDPSocketPosix::ConfigureOpenedSocket() {}

void UDPSocketPosix::Close() {}

int UDPSocketPosix::GetPeerAddress(IPEndPoint* address) const {}

int UDPSocketPosix::GetLocalAddress(IPEndPoint* address) const {}

int UDPSocketPosix::Read(IOBuffer* buf,
                         int buf_len,
                         CompletionOnceCallback callback) {}

int UDPSocketPosix::RecvFrom(IOBuffer* buf,
                             int buf_len,
                             IPEndPoint* address,
                             CompletionOnceCallback callback) {}

int UDPSocketPosix::Write(
    IOBuffer* buf,
    int buf_len,
    CompletionOnceCallback callback,
    const NetworkTrafficAnnotationTag& traffic_annotation) {}

int UDPSocketPosix::SendTo(IOBuffer* buf,
                           int buf_len,
                           const IPEndPoint& address,
                           CompletionOnceCallback callback) {}

int UDPSocketPosix::SendToOrWrite(IOBuffer* buf,
                                  int buf_len,
                                  const IPEndPoint* address,
                                  CompletionOnceCallback callback) {}

int UDPSocketPosix::Connect(const IPEndPoint& address) {}

int UDPSocketPosix::InternalConnect(const IPEndPoint& address) {}

int UDPSocketPosix::Bind(const IPEndPoint& address) {}

int UDPSocketPosix::BindToNetwork(handles::NetworkHandle network) {}

int UDPSocketPosix::SetReceiveBufferSize(int32_t size) {}

int UDPSocketPosix::SetSendBufferSize(int32_t size) {}

int UDPSocketPosix::SetDoNotFragment() {}

int UDPSocketPosix::SetRecvTos() {}

void UDPSocketPosix::SetMsgConfirm(bool confirm) {}

int UDPSocketPosix::AllowAddressReuse() {}

int UDPSocketPosix::SetBroadcast(bool broadcast) {}

int UDPSocketPosix::AllowAddressSharingForMulticast() {}

void UDPSocketPosix::ReadWatcher::OnFileCanReadWithoutBlocking(int) {}

void UDPSocketPosix::WriteWatcher::OnFileCanWriteWithoutBlocking(int) {}

void UDPSocketPosix::DoReadCallback(int rv) {}

void UDPSocketPosix::DoWriteCallback(int rv) {}

void UDPSocketPosix::DidCompleteRead() {}

void UDPSocketPosix::LogRead(int result,
                             const char* bytes,
                             socklen_t addr_len,
                             const sockaddr* addr) {}

void UDPSocketPosix::DidCompleteWrite() {}

void UDPSocketPosix::LogWrite(int result,
                              const char* bytes,
                              const IPEndPoint* address) {}

// TODO(crbug.com/40285166): Because InternalRecvFromConnectedSocket() uses
// recvfrom() instead of recvmsg(), it cannot report received ECN marks for
// QUIC ACK-ECN frames. It might be time to deprecate
// experimental_recv_optimization_enabled_ if that experiment has run its
// course.
int UDPSocketPosix::InternalRecvFrom(IOBuffer* buf,
                                     int buf_len,
                                     IPEndPoint* address) {}

int UDPSocketPosix::InternalRecvFromConnectedSocket(IOBuffer* buf,
                                                    int buf_len,
                                                    IPEndPoint* address) {}

int UDPSocketPosix::InternalRecvFromNonConnectedSocket(IOBuffer* buf,
                                                       int buf_len,
                                                       IPEndPoint* address) {}

int UDPSocketPosix::InternalSendTo(IOBuffer* buf,
                                   int buf_len,
                                   const IPEndPoint* address) {}

int UDPSocketPosix::SetMulticastOptions() {}

int UDPSocketPosix::DoBind(const IPEndPoint& address) {}

int UDPSocketPosix::RandomBind(const IPAddress& address) {}

int UDPSocketPosix::JoinGroup(const IPAddress& group_address) const {}

int UDPSocketPosix::LeaveGroup(const IPAddress& group_address) const {}

int UDPSocketPosix::SetMulticastInterface(uint32_t interface_index) {}

int UDPSocketPosix::SetMulticastTimeToLive(int time_to_live) {}

int UDPSocketPosix::SetMulticastLoopbackMode(bool loopback) {}

int UDPSocketPosix::SetDiffServCodePoint(DiffServCodePoint dscp) {}

int UDPSocketPosix::SetTos(DiffServCodePoint dscp, EcnCodePoint ecn) {}

int UDPSocketPosix::SetIPv6Only(bool ipv6_only) {}

void UDPSocketPosix::DetachFromThread() {}

void UDPSocketPosix::ApplySocketTag(const SocketTag& tag) {}

int UDPSocketPosix::SetIOSNetworkServiceType(int ios_network_service_type) {}

}  // namespace net