| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 7 | 7 |
| 8 #include <errno.h> // NOLINT | 8 #include <errno.h> // NOLINT |
| 9 #include <stdio.h> // NOLINT | 9 #include <stdio.h> // NOLINT |
| 10 #include <stdlib.h> // NOLINT | 10 #include <stdlib.h> // NOLINT |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 232 |
| 233 | 233 |
| 234 AddressList<SocketAddress>* Socket::LookupAddress(const char* host, | 234 AddressList<SocketAddress>* Socket::LookupAddress(const char* host, |
| 235 int type, | 235 int type, |
| 236 OSError** os_error) { | 236 OSError** os_error) { |
| 237 // Perform a name lookup for a host name. | 237 // Perform a name lookup for a host name. |
| 238 struct addrinfo hints; | 238 struct addrinfo hints; |
| 239 memset(&hints, 0, sizeof(hints)); | 239 memset(&hints, 0, sizeof(hints)); |
| 240 hints.ai_family = SocketAddress::FromType(type); | 240 hints.ai_family = SocketAddress::FromType(type); |
| 241 hints.ai_socktype = SOCK_STREAM; | 241 hints.ai_socktype = SOCK_STREAM; |
| 242 hints.ai_flags = 0; | 242 hints.ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG); |
| 243 hints.ai_protocol = IPPROTO_TCP; | 243 hints.ai_protocol = IPPROTO_TCP; |
| 244 struct addrinfo* info = NULL; | 244 struct addrinfo* info = NULL; |
| 245 int status = getaddrinfo(host, 0, &hints, &info); | 245 int status = getaddrinfo(host, 0, &hints, &info); |
| 246 if (status != 0) { | 246 if (status != 0) { |
| 247 ASSERT(*os_error == NULL); | 247 // We failed, try without AI_ADDRCONFIG. This can happen when looking up |
| 248 *os_error = new OSError(status, | 248 // e.g. '::1', when there are no global IPv6 addresses. |
| 249 gai_strerror(status), | 249 hints.ai_flags = AI_V4MAPPED; |
| 250 OSError::kGetAddressInfo); | 250 status = getaddrinfo(host, 0, &hints, &info); |
| 251 return NULL; | 251 if (status != 0) { |
| 252 ASSERT(*os_error == NULL); |
| 253 *os_error = new OSError(status, |
| 254 gai_strerror(status), |
| 255 OSError::kGetAddressInfo); |
| 256 return NULL; |
| 257 } |
| 252 } | 258 } |
| 253 intptr_t count = 0; | 259 intptr_t count = 0; |
| 254 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { | 260 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { |
| 255 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++; | 261 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++; |
| 256 } | 262 } |
| 257 intptr_t i = 0; | 263 intptr_t i = 0; |
| 258 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count); | 264 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count); |
| 259 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { | 265 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { |
| 260 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) { | 266 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) { |
| 261 addresses->SetAt(i, new SocketAddress(c->ai_addr)); | 267 addresses->SetAt(i, new SocketAddress(c->ai_addr)); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 mreq.gr_interface = interfaceIndex; | 624 mreq.gr_interface = interfaceIndex; |
| 619 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); | 625 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); |
| 620 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt( | 626 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt( |
| 621 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; | 627 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; |
| 622 } | 628 } |
| 623 | 629 |
| 624 } // namespace bin | 630 } // namespace bin |
| 625 } // namespace dart | 631 } // namespace dart |
| 626 | 632 |
| 627 #endif // defined(TARGET_OS_LINUX) | 633 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |