#if defined(_MSC_VER)
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#endif
#include "lldb/Host/SocketAddress.h"
#include <cstddef>
#include <cstdio>
#if !defined(_WIN32)
#include <arpa/inet.h>
#endif
#include <cassert>
#include <cstring>
#include "lldb/Host/PosixApi.h"
#ifdef _WIN32
#ifndef INET6_ADDRSTRLEN
#define INET6_ADDRSTRLEN …
#endif
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size) {
if (size == 0) {
return nullptr;
}
switch (af) {
case AF_INET: {
{
const char *formatted = inet_ntoa(*static_cast<const in_addr *>(src));
if (formatted && strlen(formatted) < static_cast<size_t>(size)) {
return ::strcpy(dst, formatted);
}
}
return nullptr;
case AF_INET6: {
char tmp[INET6_ADDRSTRLEN] = {0};
const uint16_t *src16 = static_cast<const uint16_t *>(src);
int full_size = ::snprintf(
tmp, sizeof(tmp), "%x:%x:%x:%x:%x:%x:%x:%x", ntohs(src16[0]),
ntohs(src16[1]), ntohs(src16[2]), ntohs(src16[3]), ntohs(src16[4]),
ntohs(src16[5]), ntohs(src16[6]), ntohs(src16[7]));
if (full_size < static_cast<int>(size)) {
return ::strcpy(dst, tmp);
}
return nullptr;
}
}
}
return nullptr;
}
#endif
usingnamespacelldb_private;
SocketAddress::SocketAddress() { … }
SocketAddress::SocketAddress(const struct sockaddr &s) { … }
SocketAddress::SocketAddress(const struct sockaddr_in &s) { … }
SocketAddress::SocketAddress(const struct sockaddr_in6 &s) { … }
SocketAddress::SocketAddress(const struct sockaddr_storage &s) { … }
SocketAddress::SocketAddress(const struct addrinfo *addr_info) { … }
SocketAddress::~SocketAddress() = default;
void SocketAddress::Clear() { … }
bool SocketAddress::IsValid() const { … }
static socklen_t GetFamilyLength(sa_family_t family) { … }
socklen_t SocketAddress::GetLength() const { … }
socklen_t SocketAddress::GetMaxLength() { … }
sa_family_t SocketAddress::GetFamily() const { … }
void SocketAddress::SetFamily(sa_family_t family) { … }
std::string SocketAddress::GetIPAddress() const { … }
uint16_t SocketAddress::GetPort() const { … }
bool SocketAddress::SetPort(uint16_t port) { … }
const SocketAddress &SocketAddress::
operator=(const struct addrinfo *addr_info) { … }
const SocketAddress &SocketAddress::operator=(const struct sockaddr &s) { … }
const SocketAddress &SocketAddress::operator=(const struct sockaddr_in &s) { … }
const SocketAddress &SocketAddress::operator=(const struct sockaddr_in6 &s) { … }
const SocketAddress &SocketAddress::
operator=(const struct sockaddr_storage &s) { … }
bool SocketAddress::getaddrinfo(const char *host, const char *service,
int ai_family, int ai_socktype, int ai_protocol,
int ai_flags) { … }
std::vector<SocketAddress>
SocketAddress::GetAddressInfo(const char *hostname, const char *servname,
int ai_family, int ai_socktype, int ai_protocol,
int ai_flags) { … }
bool SocketAddress::SetToLocalhost(sa_family_t family, uint16_t port) { … }
bool SocketAddress::SetToAnyAddress(sa_family_t family, uint16_t port) { … }
bool SocketAddress::IsAnyAddr() const { … }
bool SocketAddress::IsLocalhost() const { … }
bool SocketAddress::operator==(const SocketAddress &rhs) const { … }
bool SocketAddress::operator!=(const SocketAddress &rhs) const { … }