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

Side by Side Diff: runtime/bin/socket_linux.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_android.cc ('k') | runtime/bin/socket_macos.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) 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
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 #include <ifaddrs.h> // NOLINT 15 #include <ifaddrs.h> // NOLINT
16 16
17 #include "bin/fdutils.h" 17 #include "bin/fdutils.h"
18 #include "bin/file.h" 18 #include "bin/file.h"
19 #include "bin/log.h" 19 #include "bin/log.h"
20 #include "bin/socket.h" 20 #include "bin/socket.h"
21 21
22 22
23 namespace dart { 23 namespace dart {
24 namespace bin { 24 namespace bin {
25 25
26 SocketAddress::SocketAddress(struct sockaddr* sockaddr) { 26 SocketAddress::SocketAddress(struct sockaddr* sa) {
27 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); 27 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
28 RawAddr* raw = reinterpret_cast<RawAddr*>(sockaddr); 28 socklen_t salen = GetAddrLength(reinterpret_cast<RawAddr*>(sa));
29 const char* result; 29 if (TEMP_FAILURE_RETRY(getnameinfo(sa,
30 if (sockaddr->sa_family == AF_INET) { 30 salen,
31 result = inet_ntop(sockaddr->sa_family, 31 as_string_,
32 &raw->in.sin_addr, 32 INET6_ADDRSTRLEN,
33 as_string_, 33 NULL,
34 INET_ADDRSTRLEN); 34 0,
35 } else { 35 NI_NUMERICHOST)) != 0) {
36 ASSERT(sockaddr->sa_family == AF_INET6); 36 as_string_[0] = 0;
37 result = inet_ntop(sockaddr->sa_family,
38 &raw->in6.sin6_addr,
39 as_string_,
40 INET6_ADDRSTRLEN);
41 } 37 }
42 if (result == NULL) as_string_[0] = 0; 38 memmove(reinterpret_cast<void *>(&addr_), sa, salen);
43 memmove(reinterpret_cast<void *>(&addr_),
44 sockaddr,
45 GetAddrLength(raw));
46 } 39 }
47 40
48 41
49 bool Socket::Initialize() { 42 bool Socket::Initialize() {
50 // Nothing to do on Linux. 43 // Nothing to do on Linux.
51 return true; 44 return true;
52 } 45 }
53 46
54 47
55 intptr_t Socket::Create(RawAddr addr) { 48 intptr_t Socket::Create(RawAddr addr) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 if (TEMP_FAILURE_RETRY( 144 if (TEMP_FAILURE_RETRY(
152 getpeername(fd, 145 getpeername(fd,
153 &raw.addr, 146 &raw.addr,
154 &size))) { 147 &size))) {
155 const int kBufferSize = 1024; 148 const int kBufferSize = 1024;
156 char error_buf[kBufferSize]; 149 char error_buf[kBufferSize];
157 Log::PrintErr("Error getpeername: %s\n", 150 Log::PrintErr("Error getpeername: %s\n",
158 strerror_r(errno, error_buf, kBufferSize)); 151 strerror_r(errno, error_buf, kBufferSize));
159 return false; 152 return false;
160 } 153 }
161 const void* src; 154 if (TEMP_FAILURE_RETRY(getnameinfo(&raw.addr,
162 if (raw.ss.ss_family == AF_INET6) { 155 size,
163 src = reinterpret_cast<const void*>(&raw.in6.sin6_addr); 156 host,
164 } else { 157 INET6_ADDRSTRLEN,
165 src = reinterpret_cast<const void*>(&raw.in.sin_addr); 158 NULL,
166 } 159 0,
167 if (inet_ntop(raw.ss.ss_family, 160 NI_NUMERICHOST)) != 0) {
168 src,
169 host,
170 INET_ADDRSTRLEN) == NULL) {
171 const int kBufferSize = 1024; 161 const int kBufferSize = 1024;
172 char error_buf[kBufferSize]; 162 char error_buf[kBufferSize];
173 Log::PrintErr("Error inet_ntop: %s\n", 163 Log::PrintErr("Error getnameinfo: %s\n",
174 strerror_r(errno, error_buf, kBufferSize)); 164 strerror_r(errno, error_buf, kBufferSize));
175 return false; 165 return false;
176 } 166 }
177 *port = SocketAddress::GetAddrPort(&raw); 167 *port = SocketAddress::GetAddrPort(&raw);
178 return true; 168 return true;
179 } 169 }
180 170
181 171
182 void Socket::GetError(intptr_t fd, OSError* os_error) { 172 void Socket::GetError(intptr_t fd, OSError* os_error) {
183 int len = sizeof(errno); 173 int len = sizeof(errno);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 IPPROTO_TCP, 416 IPPROTO_TCP,
427 TCP_NODELAY, 417 TCP_NODELAY,
428 reinterpret_cast<char *>(&on), 418 reinterpret_cast<char *>(&on),
429 sizeof(on))) == 0; 419 sizeof(on))) == 0;
430 } 420 }
431 421
432 } // namespace bin 422 } // namespace bin
433 } // namespace dart 423 } // namespace dart
434 424
435 #endif // defined(TARGET_OS_LINUX) 425 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/socket_android.cc ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698