16#define _WINSOCK_DEPRECATED_NO_WARNINGS
35#ifndef INET6_ADDRSTRLEN
36#define INET6_ADDRSTRLEN 46
40const char *inet_ntop(
int af,
const void *src,
char *dst, socklen_t size) {
48 const char *formatted = inet_ntoa(*
static_cast<const in_addr *
>(src));
49 if (formatted && strlen(formatted) <
static_cast<size_t>(size)) {
50 return ::strcpy(dst, formatted);
55 char tmp[INET6_ADDRSTRLEN] = {0};
56 const uint16_t *src16 =
static_cast<const uint16_t *
>(src);
57 int full_size = ::snprintf(
58 tmp,
sizeof(tmp),
"%x:%x:%x:%x:%x:%x:%x:%x", ntohs(src16[0]),
59 ntohs(src16[1]), ntohs(src16[2]), ntohs(src16[3]), ntohs(src16[4]),
60 ntohs(src16[5]), ntohs(src16[6]), ntohs(src16[7]));
61 if (full_size <
static_cast<int>(size)) {
62 return ::strcpy(dst, tmp);
107 return sizeof(
struct sockaddr_in);
109 return sizeof(
struct sockaddr_in6);
111 assert(0 &&
"Unsupported address family");
116#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
132#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
139 char str[INET6_ADDRSTRLEN] = {0};
180operator=(
const struct addrinfo *addr_info) {
182 if (addr_info && addr_info->ai_addr && addr_info->ai_addrlen > 0 &&
184 ::memcpy(&
m_socket_addr, addr_info->ai_addr, addr_info->ai_addrlen);
205operator=(
const struct sockaddr_storage &s) {
211 int ai_family,
int ai_socktype,
int ai_protocol,
215 auto addresses =
GetAddressInfo(host, service, ai_family, ai_socktype,
216 ai_protocol, ai_flags);
217 if (!addresses.empty())
218 *
this = addresses[0];
222std::vector<SocketAddress>
224 int ai_family,
int ai_socktype,
int ai_protocol,
226 std::vector<SocketAddress> addr_list;
228 struct addrinfo hints;
229 memset(&hints, 0,
sizeof(hints));
230 hints.ai_family = ai_family;
231 hints.ai_socktype = ai_socktype;
232 hints.ai_protocol = ai_protocol;
233 hints.ai_flags = ai_flags;
235 struct addrinfo *service_info_list =
nullptr;
236 int err =
::getaddrinfo(hostname, servname, &hints, &service_info_list);
237 if (err == 0 && service_info_list) {
238 for (
struct addrinfo *service_ptr = service_info_list;
239 service_ptr !=
nullptr; service_ptr = service_ptr->ai_next) {
244 if (service_info_list)
245 ::freeaddrinfo(service_info_list);
323 return !(*
this == rhs);
static socklen_t GetFamilyLength(sa_family_t family)
static std::vector< SocketAddress > GetAddressInfo(const char *hostname, const char *servname, int ai_family, int ai_socktype, int ai_protocol, int ai_flags=0)
void SetFamily(sa_family_t family)
bool SetToLocalhost(sa_family_t family, uint16_t port)
const SocketAddress & operator=(const struct addrinfo *addr_info)
bool operator!=(const SocketAddress &rhs) const
sa_family_t GetFamily() const
bool SetToAnyAddress(sa_family_t family, uint16_t port)
socklen_t GetLength() const
bool getaddrinfo(const char *host, const char *service, int ai_family=PF_UNSPEC, int ai_socktype=0, int ai_protocol=0, int ai_flags=0)
std::string GetIPAddress() const
static socklen_t GetMaxLength()
union lldb_private::SocketAddress::sockaddr_tag sockaddr_t
bool SetPort(uint16_t port)
bool operator==(const SocketAddress &rhs) const
A class that represents a running process on the host machine.
struct sockaddr_in sa_ipv4
struct sockaddr_in6 sa_ipv6
struct sockaddr_storage sa_storage