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

Unified Diff: runtime/bin/socket_android.cc

Issue 25411003: Remove usage of legacy inet_ntop from dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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.h ('k') | runtime/bin/socket_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_android.cc
diff --git a/runtime/bin/socket_android.cc b/runtime/bin/socket_android.cc
index 18b2bd88133b1499680dae428095809732199cb2..38c1c7f889d84941d39c3902036b60714a8b0ca5 100644
--- a/runtime/bin/socket_android.cc
+++ b/runtime/bin/socket_android.cc
@@ -22,26 +22,19 @@
namespace dart {
namespace bin {
-SocketAddress::SocketAddress(struct sockaddr* sockaddr) {
+SocketAddress::SocketAddress(struct sockaddr* sa) {
ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
- RawAddr* raw = reinterpret_cast<RawAddr*>(sockaddr);
- const char* result;
- if (sockaddr->sa_family == AF_INET) {
- result = inet_ntop(sockaddr->sa_family,
- &raw->in.sin_addr,
- as_string_,
- INET_ADDRSTRLEN);
- } else {
- ASSERT(sockaddr->sa_family == AF_INET6);
- result = inet_ntop(sockaddr->sa_family,
- &raw->in6.sin6_addr,
- as_string_,
- INET6_ADDRSTRLEN);
+ socklen_t salen = GetAddrLength(reinterpret_cast<RawAddr*>(sa));
+ if (TEMP_FAILURE_RETRY(getnameinfo(sa,
+ salen,
+ as_string_,
+ INET6_ADDRSTRLEN,
+ NULL,
+ 0,
+ NI_NUMERICHOST)) != 0) {
+ as_string_[0] = 0;
}
- if (result == NULL) as_string_[0] = 0;
- memmove(reinterpret_cast<void *>(&addr_),
- sockaddr,
- GetAddrLength(raw));
+ memmove(reinterpret_cast<void *>(&addr_), sa, salen);
}
@@ -157,20 +150,17 @@ bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) {
Log::PrintErr("Error getpeername: %s\n", error_message);
return false;
}
- const void* src;
- if (raw.ss.ss_family == AF_INET6) {
- src = reinterpret_cast<const void*>(&raw.in6.sin6_addr);
- } else {
- src = reinterpret_cast<const void*>(&raw.in.sin_addr);
- }
- if (inet_ntop(raw.ss.ss_family,
- src,
- host,
- INET_ADDRSTRLEN) == NULL) {
+ if (TEMP_FAILURE_RETRY(getnameinfo(&raw.addr,
+ size,
+ host,
+ INET6_ADDRSTRLEN,
+ NULL,
+ 0,
+ NI_NUMERICHOST)) != 0) {
const int kBufferSize = 1024;
char error_message[kBufferSize];
strerror_r(errno, error_message, kBufferSize);
- Log::PrintErr("Error inet_ntop: %s\n", error_message);
+ Log::PrintErr("Error getnameinfo: %s\n", error_message);
return false;
}
*port = SocketAddress::GetAddrPort(&raw);
« no previous file with comments | « runtime/bin/socket.h ('k') | runtime/bin/socket_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698