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

Unified Diff: runtime/bin/socket_macos.cc

Issue 16514010: Add NetworkAdaptor to dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review update. Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/socket_linux.cc ('k') | runtime/bin/socket_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_macos.cc
diff --git a/runtime/bin/socket_macos.cc b/runtime/bin/socket_macos.cc
index 40b92cfa53ab99d2adaae369e6cb21f82a325016..bcf46d242dad00e196fa454975ade9062390e9aa 100644
--- a/runtime/bin/socket_macos.cc
+++ b/runtime/bin/socket_macos.cc
@@ -22,17 +22,17 @@
namespace dart {
namespace bin {
-SocketAddress::SocketAddress(struct addrinfo* addrinfo) {
+SocketAddress::SocketAddress(struct sockaddr* sockaddr) {
ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
- RawAddr* raw = reinterpret_cast<RawAddr*>(addrinfo->ai_addr);
- const char* result = inet_ntop(addrinfo->ai_family,
+ RawAddr* raw = reinterpret_cast<RawAddr*>(sockaddr);
+ const char* result = inet_ntop(sockaddr->sa_family,
&raw->in.sin_addr,
as_string_,
INET6_ADDRSTRLEN);
if (result == NULL) as_string_[0] = 0;
memmove(reinterpret_cast<void *>(&addr_),
- addrinfo->ai_addr,
- addrinfo->ai_addrlen);
+ sockaddr,
+ GetAddrLength(raw));
}
@@ -61,7 +61,7 @@ intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) {
intptr_t result = TEMP_FAILURE_RETRY(
connect(fd,
&addr.addr,
- SocketAddress::GetAddrLength(addr)));
+ SocketAddress::GetAddrLength(&addr)));
if (result == 0 || errno == EINPROGRESS) {
return fd;
}
@@ -220,6 +220,53 @@ SocketAddresses* Socket::LookupAddress(const char* host,
}
+static bool ShouldIncludeIfaAddrs(struct ifaddrs* ifa, int lookup_family) {
+ int family = ifa->ifa_addr->sa_family;
+ if (lookup_family == family) return true;
+ if (lookup_family == AF_UNSPEC &&
+ (family == AF_INET || family == AF_INET6)) {
+ return true;
+ }
+ return false;
+}
+
+
+AddressList<InterfaceSocketAddress>* Socket::ListInterfaces(
+ int type,
+ OSError** os_error) {
+ struct ifaddrs* ifaddr;
+
+ int status = getifaddrs(&ifaddr);
+ if (status != 0) {
+ ASSERT(*os_error == NULL);
+ *os_error = new OSError(status,
+ gai_strerror(status),
+ OSError::kGetAddressInfo);
+ return NULL;
+ }
+
+ int lookup_family = SocketAddress::FromType(type);
+
+ intptr_t count = 0;
+ for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ShouldIncludeIfaAddrs(ifa, lookup_family)) count++;
+ }
+
+ AddressList<InterfaceSocketAddress>* addresses =
+ new AddressList<InterfaceSocketAddress>(count);
+ int i = 0;
+ for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ShouldIncludeIfaAddrs(ifa, lookup_family)) {
+ addresses->SetAt(i, new InterfaceSocketAddress(
+ ifa->ifa_addr, strdup(ifa->ifa_name)));
+ i++;
+ }
+ }
+ freeifaddrs(ifaddr);
+ return addresses;
+}
+
+
intptr_t ServerSocket::CreateBindListen(RawAddr addr,
intptr_t port,
intptr_t backlog,
@@ -245,7 +292,7 @@ intptr_t ServerSocket::CreateBindListen(RawAddr addr,
if (TEMP_FAILURE_RETRY(
bind(fd,
&addr.addr,
- SocketAddress::GetAddrLength(addr))) < 0) {
+ SocketAddress::GetAddrLength(&addr))) < 0) {
VOID_TEMP_FAILURE_RETRY(close(fd));
return -1;
}
« no previous file with comments | « runtime/bin/socket_linux.cc ('k') | runtime/bin/socket_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698