Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: runtime/bin/socket_android.cc

Issue 168943002: Fix host lookup on linux, to skip IPv6 if there are no global IPv6 addresses. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/socket_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 = 0; 241 hints.ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG);
Søren Gjesse 2014/02/17 08:01:38 Looking at the getaddrinfo man page this is the de
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 ASSERT(*os_error == NULL); 246 // We failed, try without AI_ADDRCONFIG. This can happen when looking up
247 *os_error = new OSError(status, 247 // e.g. '::1', when there are no IPv6 addresses.
248 gai_strerror(status), 248 hints.ai_flags = AI_V4MAPPED;
249 OSError::kGetAddressInfo); 249 status = getaddrinfo(host, 0, &hints, &info);
250 return NULL; 250 if (status != 0) {
251 ASSERT(*os_error == NULL);
252 *os_error = new OSError(status,
253 gai_strerror(status),
254 OSError::kGetAddressInfo);
255 return NULL;
256 }
251 } 257 }
252 intptr_t count = 0; 258 intptr_t count = 0;
253 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { 259 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
254 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++; 260 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++;
255 } 261 }
256 intptr_t i = 0; 262 intptr_t i = 0;
257 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count); 263 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count);
258 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { 264 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
259 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) { 265 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) {
260 addresses->SetAt(i, new SocketAddress(c->ai_addr)); 266 addresses->SetAt(i, new SocketAddress(c->ai_addr));
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 mreq.gr_interface = interfaceIndex; 582 mreq.gr_interface = interfaceIndex;
577 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); 583 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr));
578 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt( 584 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt(
579 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; 585 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0;
580 } 586 }
581 587
582 } // namespace bin 588 } // namespace bin
583 } // namespace dart 589 } // namespace dart
584 590
585 #endif // defined(TARGET_OS_ANDROID) 591 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/socket_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698