003 File Manager
Current Path:
/usr/src/contrib/llvm-project/lldb/source/Host/common
usr
/
src
/
contrib
/
llvm-project
/
lldb
/
source
/
Host
/
common
/
📁
..
📄
Editline.cpp
(52.55 KB)
📄
File.cpp
(19.23 KB)
📄
FileAction.cpp
(2.16 KB)
📄
FileCache.cpp
(3.38 KB)
📄
FileSystem.cpp
(14.09 KB)
📄
GetOptInc.cpp
(12.53 KB)
📄
Host.cpp
(21.11 KB)
📄
HostInfoBase.cpp
(12.08 KB)
📄
HostNativeThreadBase.cpp
(1.92 KB)
📄
HostProcess.cpp
(1.5 KB)
📄
HostThread.cpp
(1.47 KB)
📄
LZMA.cpp
(4.76 KB)
📄
LockFileBase.cpp
(2.25 KB)
📄
MainLoop.cpp
(10.67 KB)
📄
MonitoringProcessLauncher.cpp
(2.44 KB)
📄
NativeProcessProtocol.cpp
(26.66 KB)
📄
NativeRegisterContext.cpp
(14.02 KB)
📄
NativeThreadProtocol.cpp
(755 B)
📄
NativeWatchpointList.cpp
(941 B)
📄
OptionParser.cpp
(2.38 KB)
📄
PipeBase.cpp
(893 B)
📄
ProcessLaunchInfo.cpp
(11.86 KB)
📄
ProcessRunLock.cpp
(1.43 KB)
📄
PseudoTerminal.cpp
(9.53 KB)
📄
Socket.cpp
(14.42 KB)
📄
SocketAddress.cpp
(8.52 KB)
📄
StringConvert.cpp
(2.53 KB)
📄
TCPSocket.cpp
(9.17 KB)
📄
Terminal.cpp
(6.24 KB)
📄
ThreadLauncher.cpp
(2.54 KB)
📄
UDPSocket.cpp
(4.3 KB)
📄
XML.cpp
(14.23 KB)
Editing: UDPSocket.cpp
//===-- UDPSocket.cpp -----------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "lldb/Host/common/UDPSocket.h" #include "lldb/Host/Config.h" #include "lldb/Utility/Log.h" #if LLDB_ENABLE_POSIX #include <arpa/inet.h> #include <sys/socket.h> #endif #include <memory> using namespace lldb; using namespace lldb_private; namespace { const int kDomain = AF_INET; const int kType = SOCK_DGRAM; static const char *g_not_supported_error = "Not supported"; } UDPSocket::UDPSocket(NativeSocket socket) : Socket(ProtocolUdp, true, true) { m_socket = socket; } UDPSocket::UDPSocket(bool should_close, bool child_processes_inherit) : Socket(ProtocolUdp, should_close, child_processes_inherit) {} size_t UDPSocket::Send(const void *buf, const size_t num_bytes) { return ::sendto(m_socket, static_cast<const char *>(buf), num_bytes, 0, m_sockaddr, m_sockaddr.GetLength()); } Status UDPSocket::Connect(llvm::StringRef name) { return Status("%s", g_not_supported_error); } Status UDPSocket::Listen(llvm::StringRef name, int backlog) { return Status("%s", g_not_supported_error); } Status UDPSocket::Accept(Socket *&socket) { return Status("%s", g_not_supported_error); } llvm::Expected<std::unique_ptr<UDPSocket>> UDPSocket::Connect(llvm::StringRef name, bool child_processes_inherit) { std::unique_ptr<UDPSocket> socket; Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION)); LLDB_LOG(log, "host/port = {0}", name); Status error; std::string host_str; std::string port_str; int32_t port = INT32_MIN; if (!DecodeHostAndPort(name, host_str, port_str, port, &error)) return error.ToError(); // At this point we have setup the receive port, now we need to setup the UDP // send socket struct addrinfo hints; struct addrinfo *service_info_list = nullptr; ::memset(&hints, 0, sizeof(hints)); hints.ai_family = kDomain; hints.ai_socktype = kType; int err = ::getaddrinfo(host_str.c_str(), port_str.c_str(), &hints, &service_info_list); if (err != 0) { error.SetErrorStringWithFormat( #if defined(_WIN32) && defined(UNICODE) "getaddrinfo(%s, %s, &hints, &info) returned error %i (%S)", #else "getaddrinfo(%s, %s, &hints, &info) returned error %i (%s)", #endif host_str.c_str(), port_str.c_str(), err, gai_strerror(err)); return error.ToError(); } for (struct addrinfo *service_info_ptr = service_info_list; service_info_ptr != nullptr; service_info_ptr = service_info_ptr->ai_next) { auto send_fd = CreateSocket( service_info_ptr->ai_family, service_info_ptr->ai_socktype, service_info_ptr->ai_protocol, child_processes_inherit, error); if (error.Success()) { socket.reset(new UDPSocket(send_fd)); socket->m_sockaddr = service_info_ptr; break; } else continue; } ::freeaddrinfo(service_info_list); if (!socket) return error.ToError(); SocketAddress bind_addr; // Only bind to the loopback address if we are expecting a connection from // localhost to avoid any firewall issues. const bool bind_addr_success = (host_str == "127.0.0.1" || host_str == "localhost") ? bind_addr.SetToLocalhost(kDomain, port) : bind_addr.SetToAnyAddress(kDomain, port); if (!bind_addr_success) { error.SetErrorString("Failed to get hostspec to bind for"); return error.ToError(); } bind_addr.SetPort(0); // Let the source port # be determined dynamically err = ::bind(socket->GetNativeSocket(), bind_addr, bind_addr.GetLength()); struct sockaddr_in source_info; socklen_t address_len = sizeof (struct sockaddr_in); err = ::getsockname(socket->GetNativeSocket(), (struct sockaddr *)&source_info, &address_len); return std::move(socket); } std::string UDPSocket::GetRemoteConnectionURI() const { if (m_socket != kInvalidSocketValue) { return std::string(llvm::formatv( "udp://[{0}]:{1}", m_sockaddr.GetIPAddress(), m_sockaddr.GetPort())); } return ""; }
Upload File
Create Folder