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

Side by Side 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, 2 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 | « runtime/bin/socket.h ('k') | 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
11 #include <string.h> // NOLINT 11 #include <string.h> // NOLINT
12 #include <sys/stat.h> // NOLINT 12 #include <sys/stat.h> // NOLINT
13 #include <unistd.h> // NOLINT 13 #include <unistd.h> // NOLINT
14 #include <netinet/tcp.h> // NOLINT 14 #include <netinet/tcp.h> // NOLINT
15 15
16 #include "bin/fdutils.h" 16 #include "bin/fdutils.h"
17 #include "bin/file.h" 17 #include "bin/file.h"
18 #include "bin/log.h" 18 #include "bin/log.h"
19 #include "bin/socket.h" 19 #include "bin/socket.h"
20 20
21 21
22 namespace dart { 22 namespace dart {
23 namespace bin { 23 namespace bin {
24 24
25 SocketAddress::SocketAddress(struct sockaddr* sockaddr) { 25 SocketAddress::SocketAddress(struct sockaddr* sa) {
26 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); 26 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
27 RawAddr* raw = reinterpret_cast<RawAddr*>(sockaddr); 27 socklen_t salen = GetAddrLength(reinterpret_cast<RawAddr*>(sa));
28 const char* result; 28 if (TEMP_FAILURE_RETRY(getnameinfo(sa,
29 if (sockaddr->sa_family == AF_INET) { 29 salen,
30 result = inet_ntop(sockaddr->sa_family, 30 as_string_,
31 &raw->in.sin_addr, 31 INET6_ADDRSTRLEN,
32 as_string_, 32 NULL,
33 INET_ADDRSTRLEN); 33 0,
34 } else { 34 NI_NUMERICHOST)) != 0) {
35 ASSERT(sockaddr->sa_family == AF_INET6); 35 as_string_[0] = 0;
36 result = inet_ntop(sockaddr->sa_family,
37 &raw->in6.sin6_addr,
38 as_string_,
39 INET6_ADDRSTRLEN);
40 } 36 }
41 if (result == NULL) as_string_[0] = 0; 37 memmove(reinterpret_cast<void *>(&addr_), sa, salen);
42 memmove(reinterpret_cast<void *>(&addr_),
43 sockaddr,
44 GetAddrLength(raw));
45 } 38 }
46 39
47 40
48 bool Socket::Initialize() { 41 bool Socket::Initialize() {
49 // Nothing to do on Android. 42 // Nothing to do on Android.
50 return true; 43 return true;
51 } 44 }
52 45
53 46
54 intptr_t Socket::Create(RawAddr addr) { 47 intptr_t Socket::Create(RawAddr addr) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (TEMP_FAILURE_RETRY( 143 if (TEMP_FAILURE_RETRY(
151 getpeername(fd, 144 getpeername(fd,
152 &raw.addr, 145 &raw.addr,
153 &size))) { 146 &size))) {
154 const int kBufferSize = 1024; 147 const int kBufferSize = 1024;
155 char error_message[kBufferSize]; 148 char error_message[kBufferSize];
156 strerror_r(errno, error_message, kBufferSize); 149 strerror_r(errno, error_message, kBufferSize);
157 Log::PrintErr("Error getpeername: %s\n", error_message); 150 Log::PrintErr("Error getpeername: %s\n", error_message);
158 return false; 151 return false;
159 } 152 }
160 const void* src; 153 if (TEMP_FAILURE_RETRY(getnameinfo(&raw.addr,
161 if (raw.ss.ss_family == AF_INET6) { 154 size,
162 src = reinterpret_cast<const void*>(&raw.in6.sin6_addr); 155 host,
163 } else { 156 INET6_ADDRSTRLEN,
164 src = reinterpret_cast<const void*>(&raw.in.sin_addr); 157 NULL,
165 } 158 0,
166 if (inet_ntop(raw.ss.ss_family, 159 NI_NUMERICHOST)) != 0) {
167 src,
168 host,
169 INET_ADDRSTRLEN) == NULL) {
170 const int kBufferSize = 1024; 160 const int kBufferSize = 1024;
171 char error_message[kBufferSize]; 161 char error_message[kBufferSize];
172 strerror_r(errno, error_message, kBufferSize); 162 strerror_r(errno, error_message, kBufferSize);
173 Log::PrintErr("Error inet_ntop: %s\n", error_message); 163 Log::PrintErr("Error getnameinfo: %s\n", error_message);
174 return false; 164 return false;
175 } 165 }
176 *port = SocketAddress::GetAddrPort(&raw); 166 *port = SocketAddress::GetAddrPort(&raw);
177 return true; 167 return true;
178 } 168 }
179 169
180 170
181 void Socket::GetError(intptr_t fd, OSError* os_error) { 171 void Socket::GetError(intptr_t fd, OSError* os_error) {
182 int errorNumber; 172 int errorNumber;
183 socklen_t len = sizeof(errorNumber); 173 socklen_t len = sizeof(errorNumber);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 IPPROTO_TCP, 375 IPPROTO_TCP,
386 TCP_NODELAY, 376 TCP_NODELAY,
387 reinterpret_cast<char *>(&on), 377 reinterpret_cast<char *>(&on),
388 sizeof(on))) == 0; 378 sizeof(on))) == 0;
389 } 379 }
390 380
391 } // namespace bin 381 } // namespace bin
392 } // namespace dart 382 } // namespace dart
393 383
394 #endif // defined(TARGET_OS_ANDROID) 384 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« 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