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

Side by Side Diff: mojo/dart/embedder/io/internet_address_android.cc

Issue 1327033004: Allow building mojo_shell and non-graphical apps/services on a Mac (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: review feedback Created 5 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 unified diff | Download patch
« no previous file with comments | « mojo/dart/embedder/BUILD.gn ('k') | mojo/dart/embedder/io/internet_address_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <arpa/inet.h>
6 #include <netdb.h>
7 #include <sys/socket.h>
8
9 #include "mojo/dart/embedder/io/internet_address.h"
10
11 namespace mojo {
12 namespace dart {
13
14 static void SetupSockAddr(sockaddr_storage* dest,
15 socklen_t* salen,
16 const RawAddr& addr, intptr_t addr_length) {
17 CHECK((addr_length == 4) || (addr_length == 16));
18 if (addr_length == 4) {
19 dest->ss_family = AF_INET;
20 sockaddr_in* dest4 = reinterpret_cast<sockaddr_in*>(dest);
21 *salen = sizeof(*dest4);
22 memmove(&(dest4->sin_addr), &addr.bytes[0], addr_length);
23 } else {
24 dest->ss_family = AF_INET6;
25 sockaddr_in6* dest6 = reinterpret_cast<sockaddr_in6*>(dest);
26 *salen = sizeof(*dest6);
27 memmove(&(dest6->sin6_addr), &addr.bytes[0], addr_length);
28 }
29 }
30
31 bool InternetAddress::Parse(int type, const char* address, RawAddr* addr) {
32 memset(addr, 0, IPV6_RAW_ADDR_LENGTH);
33 int result;
34 if (type == InternetAddress::TYPE_IPV4) {
35 struct sockaddr_in in;
36 result = inet_pton(AF_INET, address, &in.sin_addr);
37 memmove(addr, &in.sin_addr, IPV4_RAW_ADDR_LENGTH);
38 } else {
39 CHECK(type == InternetAddress::TYPE_IPV6);
40 sockaddr_in6 in6;
41 result = inet_pton(AF_INET6, address, &in6.sin6_addr);
42 memmove(addr, &in6.sin6_addr, IPV6_RAW_ADDR_LENGTH);
43 }
44 return result == 1;
45 }
46
47 bool InternetAddress::Reverse(const RawAddr& addr, intptr_t addr_length,
48 char* host, intptr_t host_len,
49 intptr_t* error_code,
50 const char** error_description) {
51 CHECK(host_len >= NI_MAXHOST);
52 sockaddr_storage sock_addr;
53 socklen_t salen;
54 SetupSockAddr(&sock_addr, &salen, addr, addr_length);
55 int status = getnameinfo(reinterpret_cast<sockaddr*>(&sock_addr),
56 salen,
57 host,
58 host_len,
59 NULL,
60 0,
61 NI_NAMEREQD);
62 *error_code = status;
63 if (status != 0) {
64 CHECK(*error_description == NULL);
65 *error_description = gai_strerror(status);
66 return false;
67 }
68 return true;
69 }
70
71 } // namespace dart
72 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/dart/embedder/BUILD.gn ('k') | mojo/dart/embedder/io/internet_address_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698