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 = (AI_V4MAPPED | AI_ADDRCONFIG); | 242 hints.ai_flags = 0; |
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 // We failed, try without AI_ADDRCONFIG. This can happen when looking up | 247 ASSERT(*os_error == NULL); |
248 // e.g. '::1', when there are no global IPv6 addresses. | 248 *os_error = new OSError(status, |
249 hints.ai_flags = AI_V4MAPPED; | 249 gai_strerror(status), |
250 status = getaddrinfo(host, 0, &hints, &info); | 250 OSError::kGetAddressInfo); |
251 if (status != 0) { | 251 return NULL; |
252 ASSERT(*os_error == NULL); | |
253 *os_error = new OSError(status, | |
254 gai_strerror(status), | |
255 OSError::kGetAddressInfo); | |
256 return NULL; | |
257 } | |
258 } | 252 } |
259 intptr_t count = 0; | 253 intptr_t count = 0; |
260 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { | 254 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { |
261 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++; | 255 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++; |
262 } | 256 } |
263 intptr_t i = 0; | 257 intptr_t i = 0; |
264 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count); | 258 AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count); |
265 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { | 259 for (struct addrinfo* c = info; c != NULL; c = c->ai_next) { |
266 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) { | 260 if (c->ai_family == AF_INET || c->ai_family == AF_INET6) { |
267 addresses->SetAt(i, new SocketAddress(c->ai_addr)); | 261 addresses->SetAt(i, new SocketAddress(c->ai_addr)); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 mreq.gr_interface = interfaceIndex; | 618 mreq.gr_interface = interfaceIndex; |
625 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); | 619 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); |
626 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt( | 620 return TEMP_FAILURE_RETRY_BLOCK_SIGNALS(setsockopt( |
627 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; | 621 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; |
628 } | 622 } |
629 | 623 |
630 } // namespace bin | 624 } // namespace bin |
631 } // namespace dart | 625 } // namespace dart |
632 | 626 |
633 #endif // defined(TARGET_OS_LINUX) | 627 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |