| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 231 |
| 232 | 232 |
| 233 AddressList<SocketAddress>* Socket::LookupAddress(const char* host, | 233 AddressList<SocketAddress>* Socket::LookupAddress(const char* host, |
| 234 int type, | 234 int type, |
| 235 OSError** os_error) { | 235 OSError** os_error) { |
| 236 // Perform a name lookup for a host name. | 236 // Perform a name lookup for a host name. |
| 237 struct addrinfo hints; | 237 struct addrinfo hints; |
| 238 memset(&hints, 0, sizeof(hints)); | 238 memset(&hints, 0, sizeof(hints)); |
| 239 hints.ai_family = SocketAddress::FromType(type); | 239 hints.ai_family = SocketAddress::FromType(type); |
| 240 hints.ai_socktype = SOCK_STREAM; | 240 hints.ai_socktype = SOCK_STREAM; |
| 241 hints.ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG); | 241 hints.ai_flags = 0; |
| 242 hints.ai_protocol = IPPROTO_TCP; | 242 hints.ai_protocol = IPPROTO_TCP; |
| 243 struct addrinfo* info = NULL; | 243 struct addrinfo* info = NULL; |
| 244 int status = getaddrinfo(host, 0, &hints, &info); | 244 int status = getaddrinfo(host, 0, &hints, &info); |
| 245 if (status != 0) { | 245 if (status != 0) { |
| 246 // We failed, try without AI_ADDRCONFIG. This can happen when looking up | 246 ASSERT(*os_error == NULL); |
| 247 // e.g. '::1', when there are no IPv6 addresses. | 247 *os_error = new OSError(status, |
| 248 hints.ai_flags = AI_V4MAPPED; | 248 gai_strerror(status), |
| 249 status = getaddrinfo(host, 0, &hints, &info); | 249 OSError::kGetAddressInfo); |
| 250 if (status != 0) { | 250 return NULL; |
| 251 ASSERT(*os_error == NULL); | |
| 252 *os_error = new OSError(status, | |
| 253 gai_strerror(status), | |
| 254 OSError::kGetAddressInfo); | |
| 255 return NULL; | |
| 256 } | |
| 257 } | 251 } |
| 258 intptr_t count = 0; | 252 intptr_t count = 0; |
| 259 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { | 253 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { |
| 260 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++; | 254 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++; |
| 261 } | 255 } |
| 262 intptr_t i = 0; | 256 intptr_t i = 0; |
| 263 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count); | 257 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count); |
| 264 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { | 258 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { |
| 265 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) { | 259 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) { |
| 266 addresses->SetAt(i, new SocketAddress(c->ai_addr)); | 260 addresses->SetAt(i, new SocketAddress(c->ai_addr)); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 mreq.gr_interface = interfaceIndex; | 576 mreq.gr_interface = interfaceIndex; |
| 583 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); | 577 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); |
| 584 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt( | 578 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt( |
| 585 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; | 579 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; |
| 586 } | 580 } |
| 587 | 581 |
| 588 } // namespace bin | 582 } // namespace bin |
| 589 } // namespace dart | 583 } // namespace dart |
| 590 | 584 |
| 591 #endif // defined(TARGET_OS_ANDROID) | 585 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |