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

Side by Side Diff: net/base/net_util.h

Issue 10309002: Reimplements net::AddressList without struct addrinfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: get_canonical_name -> canonical_name. iterator to indexing Created 8 years, 7 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 | « net/base/mock_host_resolver.cc ('k') | net/base/net_util.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 Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef NET_BASE_NET_UTIL_H_ 5 #ifndef NET_BASE_NET_UTIL_H_
6 #define NET_BASE_NET_UTIL_H_ 6 #define NET_BASE_NET_UTIL_H_
7 #pragma once 7 #pragma once
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
11 #if defined(OS_WIN) 11 #if defined(OS_WIN)
12 #include <windows.h> 12 #include <windows.h>
13 #include <ws2tcpip.h> 13 #include <ws2tcpip.h>
14 #elif defined(OS_POSIX) 14 #elif defined(OS_POSIX)
15 #include <sys/types.h> 15 #include <sys/types.h>
16 #include <sys/socket.h> 16 #include <sys/socket.h>
17 #endif 17 #endif
18 18
19 #include <list> 19 #include <list>
20 #include <string> 20 #include <string>
21 #include <set> 21 #include <set>
22 #include <vector> 22 #include <vector>
23 23
24 #include "base/basictypes.h" 24 #include "base/basictypes.h"
25 #include "base/string16.h" 25 #include "base/string16.h"
26 #include "net/base/escape.h" 26 #include "net/base/escape.h"
27 #include "net/base/net_export.h" 27 #include "net/base/net_export.h"
28 28
29 struct addrinfo;
30 class FilePath; 29 class FilePath;
31 class GURL; 30 class GURL;
32 31
33 namespace base { 32 namespace base {
34 class Time; 33 class Time;
35 } 34 }
36 35
37 namespace url_canon { 36 namespace url_canon {
38 struct CanonHostInfo; 37 struct CanonHostInfo;
39 } 38 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 std::string* host, 92 std::string* host,
94 int* port); 93 int* port);
95 94
96 // Returns a host:port string for the given URL. 95 // Returns a host:port string for the given URL.
97 NET_EXPORT std::string GetHostAndPort(const GURL& url); 96 NET_EXPORT std::string GetHostAndPort(const GURL& url);
98 97
99 // Returns a host[:port] string for the given URL, where the port is omitted 98 // Returns a host[:port] string for the given URL, where the port is omitted
100 // if it is the default for the URL's scheme. 99 // if it is the default for the URL's scheme.
101 NET_EXPORT_PRIVATE std::string GetHostAndOptionalPort(const GURL& url); 100 NET_EXPORT_PRIVATE std::string GetHostAndOptionalPort(const GURL& url);
102 101
102 // Convenience struct for when you need a |struct sockaddr|.
103 struct SockaddrStorage {
104 SockaddrStorage() : addr_len(sizeof(addr_storage)),
105 addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {}
106 struct sockaddr_storage addr_storage;
107 socklen_t addr_len;
108 struct sockaddr* const addr;
109 };
110
103 // Returns the string representation of an address, like "192.168.0.1". 111 // Returns the string representation of an address, like "192.168.0.1".
104 // Returns empty string on failure. 112 // Returns empty string on failure.
105 NET_EXPORT std::string NetAddressToString(const struct addrinfo* net_address);
106 NET_EXPORT std::string NetAddressToString(const struct sockaddr* net_address, 113 NET_EXPORT std::string NetAddressToString(const struct sockaddr* net_address,
107 socklen_t address_len); 114 socklen_t address_len);
108 115
109 // Same as NetAddressToString, but additionally includes the port number. For 116 // Same as NetAddressToString, but additionally includes the port number. For
110 // example: "192.168.0.1:99" or "[::1]:80". 117 // example: "192.168.0.1:99" or "[::1]:80".
111 NET_EXPORT std::string NetAddressToStringWithPort( 118 NET_EXPORT std::string NetAddressToStringWithPort(
112 const struct addrinfo* net_address);
113 NET_EXPORT std::string NetAddressToStringWithPort(
114 const struct sockaddr* net_address, 119 const struct sockaddr* net_address,
115 socklen_t address_len); 120 socklen_t address_len);
116 121
117 // Returns the hostname of the current system. Returns empty string on failure. 122 // Returns the hostname of the current system. Returns empty string on failure.
118 NET_EXPORT std::string GetHostName(); 123 NET_EXPORT std::string GetHostName();
119 124
120 // Extracts the unescaped username/password from |url|, saving the results 125 // Extracts the unescaped username/password from |url|, saving the results
121 // into |*username| and |*password|. 126 // into |*username| and |*password|.
122 NET_EXPORT_PRIVATE void GetIdentityFromURL(const GURL& url, 127 NET_EXPORT_PRIVATE void GetIdentityFromURL(const GURL& url,
123 string16* username, 128 string16* username,
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 // IP address whose |prefix_length_in_bits| most significant bits match 414 // IP address whose |prefix_length_in_bits| most significant bits match
410 // |ip_prefix| will be matched. 415 // |ip_prefix| will be matched.
411 // 416 //
412 // In cases when an IPv4 address is being compared to an IPv6 address prefix 417 // In cases when an IPv4 address is being compared to an IPv6 address prefix
413 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped 418 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped
414 // (IPv6) addresses. 419 // (IPv6) addresses.
415 NET_EXPORT_PRIVATE bool IPNumberMatchesPrefix(const IPAddressNumber& ip_number, 420 NET_EXPORT_PRIVATE bool IPNumberMatchesPrefix(const IPAddressNumber& ip_number,
416 const IPAddressNumber& ip_prefix, 421 const IPAddressNumber& ip_prefix,
417 size_t prefix_length_in_bits); 422 size_t prefix_length_in_bits);
418 423
419 // Makes a copy of |info|. The dynamically-allocated parts are copied as well. 424 // Retuns the port field of the |sockaddr|.
420 // If |recursive| is true, chained entries via ai_next are copied too.
421 // The copy returned by this function should be freed using
422 // FreeCopyOfAddrinfo(), and NOT freeaddrinfo().
423 struct addrinfo* CreateCopyOfAddrinfo(const struct addrinfo* info,
424 bool recursive);
425
426 // Frees an addrinfo that was created by CreateCopyOfAddrinfo().
427 void FreeCopyOfAddrinfo(struct addrinfo* info);
428
429 // Returns the port field of the sockaddr in |info|.
430 const uint16* GetPortFieldFromAddrinfo(const struct addrinfo* info);
431 uint16* GetPortFieldFromAddrinfo(struct addrinfo* info);
432
433 // Returns the value of |info's| port (in host byte ordering).
434 uint16 GetPortFromAddrinfo(const struct addrinfo* info);
435
436 // Same except for struct sockaddr.
437 const uint16* GetPortFieldFromSockaddr(const struct sockaddr* address, 425 const uint16* GetPortFieldFromSockaddr(const struct sockaddr* address,
438 socklen_t address_len); 426 socklen_t address_len);
427 // Returns the value of port in |sockaddr| (in host byte ordering).
439 NET_EXPORT_PRIVATE int GetPortFromSockaddr(const struct sockaddr* address, 428 NET_EXPORT_PRIVATE int GetPortFromSockaddr(const struct sockaddr* address,
440 socklen_t address_len); 429 socklen_t address_len);
441 430
442 // Sets every addrinfo in the linked list |head| as having a port field of
443 // |port|.
444 NET_EXPORT_PRIVATE void SetPortForAllAddrinfos(struct addrinfo* head,
445 uint16 port);
446
447 // Returns true if |host| is one of the names (e.g. "localhost") or IP 431 // Returns true if |host| is one of the names (e.g. "localhost") or IP
448 // addresses (IPv4 127.0.0.0/8 or IPv6 ::1) that indicate a loopback. 432 // addresses (IPv4 127.0.0.0/8 or IPv6 ::1) that indicate a loopback.
449 // 433 //
450 // Note that this function does not check for IP addresses other than 434 // Note that this function does not check for IP addresses other than
451 // the above, although other IP addresses may point to the local 435 // the above, although other IP addresses may point to the local
452 // machine. 436 // machine.
453 NET_EXPORT_PRIVATE bool IsLocalhost(const std::string& host); 437 NET_EXPORT_PRIVATE bool IsLocalhost(const std::string& host);
454 438
455 // struct that is used by GetNetworkList() to represent a network 439 // struct that is used by GetNetworkList() to represent a network
456 // interface. 440 // interface.
(...skipping 10 matching lines...) Expand all
467 451
468 // Returns list of network interfaces except loopback interface. If an 452 // Returns list of network interfaces except loopback interface. If an
469 // interface has more than one address, a separate entry is added to 453 // interface has more than one address, a separate entry is added to
470 // the list for each address. 454 // the list for each address.
471 // Can be called only on a thread that allows IO. 455 // Can be called only on a thread that allows IO.
472 NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks); 456 NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks);
473 457
474 } // namespace net 458 } // namespace net
475 459
476 #endif // NET_BASE_NET_UTIL_H_ 460 #endif // NET_BASE_NET_UTIL_H_
OLDNEW
« no previous file with comments | « net/base/mock_host_resolver.cc ('k') | net/base/net_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698