52 std::unique_ptr<UDPSocket> socket;
55 LLDB_LOG(log,
"host/port = {0}", name);
60 return host_port.takeError();
65 struct addrinfo hints;
66 struct addrinfo *service_info_list =
nullptr;
68 ::memset(&hints, 0,
sizeof(hints));
70 hints.ai_socktype =
kType;
71 int err = ::getaddrinfo(host_port->hostname.c_str(), std::to_string(host_port->port).c_str(), &hints,
75#
if defined(_WIN32) && defined(UNICODE)
76 "getaddrinfo(%s, %d, &hints, &info) returned error %i (%S)",
78 "getaddrinfo(%s, %d, &hints, &info) returned error %i (%s)",
80 host_port->hostname.c_str(), host_port->port, err, gai_strerror(err));
81 return error.ToError();
84 for (
struct addrinfo *service_info_ptr = service_info_list;
85 service_info_ptr !=
nullptr;
86 service_info_ptr = service_info_ptr->ai_next) {
88 CreateSocket(service_info_ptr->ai_family, service_info_ptr->ai_socktype,
89 service_info_ptr->ai_protocol,
error);
90 if (
error.Success()) {
92 socket->m_sockaddr = service_info_ptr;
98 ::freeaddrinfo(service_info_list);
101 return error.ToError();
107 const bool bind_addr_success = (host_port->hostname ==
"127.0.0.1" || host_port->hostname ==
"localhost")
111 if (!bind_addr_success) {
113 return error.ToError();
118 err = ::bind(socket->GetNativeSocket(), bind_addr, bind_addr.
GetLength());
120 struct sockaddr_in source_info;
121 socklen_t address_len =
sizeof (
struct sockaddr_in);
122 err = ::getsockname(socket->GetNativeSocket(),
123 (
struct sockaddr *)&source_info, &address_len);
125 return std::move(socket);