OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <arpa/inet.h> | 5 #include <arpa/inet.h> |
6 #include <netdb.h> | 6 #include <netdb.h> |
7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
8 | 8 |
9 #include "mojo/dart/embedder/io/internet_address.h" | 9 #include "mojo/dart/embedder/io/internet_address.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 static void SetupSockAddr(sockaddr_storage* dest, | 14 static void SetupSockAddr(sockaddr_storage* dest, |
15 socklen_t* salen, | 15 socklen_t* salen, |
16 const RawAddr& addr, intptr_t addr_length) { | 16 const RawAddr& addr, |
17 intptr_t addr_length) { | |
jamesr
2015/09/10 01:13:29
according to 'diff' internet_address_linux.cc and
| |
17 CHECK((addr_length == 4) || (addr_length == 16)); | 18 CHECK((addr_length == 4) || (addr_length == 16)); |
18 if (addr_length == 4) { | 19 if (addr_length == 4) { |
19 dest->ss_family = AF_INET; | 20 dest->ss_family = AF_INET; |
20 sockaddr_in* dest4 = reinterpret_cast<sockaddr_in*>(dest); | 21 sockaddr_in* dest4 = reinterpret_cast<sockaddr_in*>(dest); |
21 *salen = sizeof(*dest4); | 22 *salen = sizeof(*dest4); |
22 memmove(&(dest4->sin_addr), &addr.bytes[0], addr_length); | 23 memmove(&(dest4->sin_addr), &addr.bytes[0], addr_length); |
23 } else { | 24 } else { |
24 dest->ss_family = AF_INET6; | 25 dest->ss_family = AF_INET6; |
25 sockaddr_in6* dest6 = reinterpret_cast<sockaddr_in6*>(dest); | 26 sockaddr_in6* dest6 = reinterpret_cast<sockaddr_in6*>(dest); |
26 *salen = sizeof(*dest6); | 27 *salen = sizeof(*dest6); |
(...skipping 10 matching lines...) Expand all Loading... | |
37 memmove(addr, &in.sin_addr, IPV4_RAW_ADDR_LENGTH); | 38 memmove(addr, &in.sin_addr, IPV4_RAW_ADDR_LENGTH); |
38 } else { | 39 } else { |
39 CHECK(type == InternetAddress::TYPE_IPV6); | 40 CHECK(type == InternetAddress::TYPE_IPV6); |
40 sockaddr_in6 in6; | 41 sockaddr_in6 in6; |
41 result = inet_pton(AF_INET6, address, &in6.sin6_addr); | 42 result = inet_pton(AF_INET6, address, &in6.sin6_addr); |
42 memmove(addr, &in6.sin6_addr, IPV6_RAW_ADDR_LENGTH); | 43 memmove(addr, &in6.sin6_addr, IPV6_RAW_ADDR_LENGTH); |
43 } | 44 } |
44 return result == 1; | 45 return result == 1; |
45 } | 46 } |
46 | 47 |
47 bool InternetAddress::Reverse(const RawAddr& addr, intptr_t addr_length, | 48 bool InternetAddress::Reverse(const RawAddr& addr, |
48 char* host, intptr_t host_len, | 49 intptr_t addr_length, |
50 char* host, | |
51 intptr_t host_len, | |
49 intptr_t* error_code, | 52 intptr_t* error_code, |
50 const char** error_description) { | 53 const char** error_description) { |
51 CHECK(host_len >= NI_MAXHOST); | 54 CHECK(host_len >= NI_MAXHOST); |
52 sockaddr_storage sock_addr; | 55 sockaddr_storage sock_addr; |
53 socklen_t salen; | 56 socklen_t salen; |
54 SetupSockAddr(&sock_addr, &salen, addr, addr_length); | 57 SetupSockAddr(&sock_addr, &salen, addr, addr_length); |
55 int status = getnameinfo(reinterpret_cast<sockaddr*>(&sock_addr), | 58 int status = getnameinfo(reinterpret_cast<sockaddr*>(&sock_addr), salen, host, |
56 salen, | 59 host_len, NULL, 0, NI_NAMEREQD); |
57 host, | |
58 host_len, | |
59 NULL, | |
60 0, | |
61 NI_NAMEREQD); | |
62 *error_code = status; | 60 *error_code = status; |
63 if (status != 0) { | 61 if (status != 0) { |
64 CHECK(*error_description == NULL); | 62 CHECK(*error_description == NULL); |
65 *error_description = gai_strerror(status); | 63 *error_description = gai_strerror(status); |
66 return false; | 64 return false; |
67 } | 65 } |
68 return true; | 66 return true; |
69 } | 67 } |
70 | 68 |
71 } // namespace dart | 69 } // namespace dart |
72 } // namespace mojo | 70 } // namespace mojo |
OLD | NEW |