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

Side by Side Diff: net/base/host_resolver_proc.cc

Issue 9716020: Add base::HostToNetXX() & NetToHostXX(), and use them to replace htonX() & ntohX() in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 years, 8 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/base/host_resolver_proc.h" 5 #include "net/base/host_resolver_proc.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/sys_byteorder.h"
10 #include "net/base/address_list.h" 11 #include "net/base/address_list.h"
11 #include "net/base/dns_reloader.h" 12 #include "net/base/dns_reloader.h"
12 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
13 #include "net/base/sys_addrinfo.h" 14 #include "net/base/sys_addrinfo.h"
14 15
15 #if defined(OS_OPENBSD) 16 #if defined(OS_OPENBSD)
16 #define AI_ADDRCONFIG 0 17 #define AI_ADDRCONFIG 0
17 #endif 18 #endif
18 19
19 namespace net { 20 namespace net {
20 21
21 namespace { 22 namespace {
22 23
23 bool IsAllLocalhostOfOneFamily(const struct addrinfo* ai) { 24 bool IsAllLocalhostOfOneFamily(const struct addrinfo* ai) {
24 bool saw_v4_localhost = false; 25 bool saw_v4_localhost = false;
25 bool saw_v6_localhost = false; 26 bool saw_v6_localhost = false;
26 for (; ai != NULL; ai = ai->ai_next) { 27 for (; ai != NULL; ai = ai->ai_next) {
27 switch (ai->ai_family) { 28 switch (ai->ai_family) {
28 case AF_INET: { 29 case AF_INET: {
29 const struct sockaddr_in* addr_in = 30 const struct sockaddr_in* addr_in =
30 reinterpret_cast<struct sockaddr_in*>(ai->ai_addr); 31 reinterpret_cast<struct sockaddr_in*>(ai->ai_addr);
31 if ((ntohl(addr_in->sin_addr.s_addr) & 0xff000000) == 0x7f000000) 32 if ((base::NetToHost32(addr_in->sin_addr.s_addr) & 0xff000000) ==
33 0x7f000000)
32 saw_v4_localhost = true; 34 saw_v4_localhost = true;
33 else 35 else
34 return false; 36 return false;
35 break; 37 break;
36 } 38 }
37 case AF_INET6: { 39 case AF_INET6: {
38 const struct sockaddr_in6* addr_in6 = 40 const struct sockaddr_in6* addr_in6 =
39 reinterpret_cast<struct sockaddr_in6*>(ai->ai_addr); 41 reinterpret_cast<struct sockaddr_in6*>(ai->ai_addr);
40 if (IN6_IS_ADDR_LOOPBACK(&addr_in6->sin6_addr)) 42 if (IN6_IS_ADDR_LOOPBACK(&addr_in6->sin6_addr))
41 saw_v6_localhost = true; 43 saw_v6_localhost = true;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 #endif 234 #endif
233 235
234 return ERR_NAME_NOT_RESOLVED; 236 return ERR_NAME_NOT_RESOLVED;
235 } 237 }
236 238
237 *addrlist = AddressList::CreateByAdoptingFromSystem(ai); 239 *addrlist = AddressList::CreateByAdoptingFromSystem(ai);
238 return OK; 240 return OK;
239 } 241 }
240 242
241 } // namespace net 243 } // namespace net
OLDNEW
« no previous file with comments | « native_client_sdk/src/build_tools/debug_server/debug_stub/transport_common.cc ('k') | net/base/ip_endpoint.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698