OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_BASE_NET_UTIL_H_ | |
6 #define NET_BASE_NET_UTIL_H_ | |
7 | |
8 #include "build/build_config.h" | |
9 | |
10 #if defined(OS_WIN) | |
11 #include <windows.h> | |
12 #include <ws2tcpip.h> | |
13 #elif defined(OS_POSIX) | |
14 #include <sys/types.h> | |
15 #include <sys/socket.h> | |
16 #endif | |
17 | |
18 #include <string> | |
19 #include <vector> | |
20 | |
21 #include "base/basictypes.h" | |
22 #include "base/strings/string16.h" | |
23 #include "base/strings/utf_offset_string_conversions.h" | |
24 #include "net/base/address_family.h" | |
25 #include "net/base/escape.h" | |
26 #include "net/base/net_export.h" | |
27 #include "net/base/network_change_notifier.h" | |
28 | |
29 class GURL; | |
30 | |
31 namespace base { | |
32 class Time; | |
33 } | |
34 | |
35 namespace url { | |
36 struct CanonHostInfo; | |
37 struct Parsed; | |
38 } | |
39 | |
40 namespace net { | |
41 | |
42 // Used by FormatUrl to specify handling of certain parts of the url. | |
43 typedef uint32 FormatUrlType; | |
44 typedef uint32 FormatUrlTypes; | |
45 | |
46 // IPAddressNumber is used to represent an IP address's numeric value as an | |
47 // array of bytes, from most significant to least significant. This is the | |
48 // network byte ordering. | |
49 // | |
50 // IPv4 addresses will have length 4, whereas IPv6 address will have length 16. | |
51 typedef std::vector<unsigned char> IPAddressNumber; | |
52 typedef std::vector<IPAddressNumber> IPAddressList; | |
53 | |
54 static const size_t kIPv4AddressSize = 4; | |
55 static const size_t kIPv6AddressSize = 16; | |
56 #if defined(OS_WIN) | |
57 // Bluetooth address size. Windows Bluetooth is supported via winsock. | |
58 static const size_t kBluetoothAddressSize = 6; | |
59 #endif | |
60 | |
61 // Nothing is ommitted. | |
62 NET_EXPORT extern const FormatUrlType kFormatUrlOmitNothing; | |
63 | |
64 // If set, any username and password are removed. | |
65 NET_EXPORT extern const FormatUrlType kFormatUrlOmitUsernamePassword; | |
66 | |
67 // If the scheme is 'http://', it's removed. | |
68 NET_EXPORT extern const FormatUrlType kFormatUrlOmitHTTP; | |
69 | |
70 // Omits the path if it is just a slash and there is no query or ref. This is | |
71 // meaningful for non-file "standard" URLs. | |
72 NET_EXPORT extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname; | |
73 | |
74 // Convenience for omitting all unecessary types. | |
75 NET_EXPORT extern const FormatUrlType kFormatUrlOmitAll; | |
76 | |
77 // Returns the number of explicitly allowed ports; for testing. | |
78 NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts(); | |
79 | |
80 // Splits an input of the form <host>[":"<port>] into its consitituent parts. | |
81 // Saves the result into |*host| and |*port|. If the input did not have | |
82 // the optional port, sets |*port| to -1. | |
83 // Returns true if the parsing was successful, false otherwise. | |
84 // The returned host is NOT canonicalized, and may be invalid. | |
85 // | |
86 // IPv6 literals must be specified in a bracketed form, for instance: | |
87 // [::1]:90 and [::1] | |
88 // | |
89 // The resultant |*host| in both cases will be "::1" (not bracketed). | |
90 NET_EXPORT bool ParseHostAndPort( | |
91 std::string::const_iterator host_and_port_begin, | |
92 std::string::const_iterator host_and_port_end, | |
93 std::string* host, | |
94 int* port); | |
95 NET_EXPORT bool ParseHostAndPort( | |
96 const std::string& host_and_port, | |
97 std::string* host, | |
98 int* port); | |
99 | |
100 // Returns a host:port string for the given URL. | |
101 NET_EXPORT std::string GetHostAndPort(const GURL& url); | |
102 | |
103 // Returns a host[:port] string for the given URL, where the port is omitted | |
104 // if it is the default for the URL's scheme. | |
105 NET_EXPORT_PRIVATE std::string GetHostAndOptionalPort(const GURL& url); | |
106 | |
107 // Returns true if |hostname| contains a non-registerable or non-assignable | |
108 // domain name (eg: a gTLD that has not been assigned by IANA) or an IP address | |
109 // that falls in an IANA-reserved range. | |
110 NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname); | |
111 | |
112 // Returns true if an IP address hostname is in a range reserved by the IANA. | |
113 // Works with both IPv4 and IPv6 addresses, and only compares against a given | |
114 // protocols's reserved ranges. | |
115 NET_EXPORT bool IsIPAddressReserved(const IPAddressNumber& address); | |
116 | |
117 // Convenience struct for when you need a |struct sockaddr|. | |
118 struct SockaddrStorage { | |
119 SockaddrStorage() : addr_len(sizeof(addr_storage)), | |
120 addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {} | |
121 SockaddrStorage(const SockaddrStorage& other); | |
122 void operator=(const SockaddrStorage& other); | |
123 | |
124 struct sockaddr_storage addr_storage; | |
125 socklen_t addr_len; | |
126 struct sockaddr* const addr; | |
127 }; | |
128 | |
129 // Extracts the IP address and port portions of a sockaddr. |port| is optional, | |
130 // and will not be filled in if NULL. | |
131 bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr, | |
132 socklen_t sock_addr_len, | |
133 const unsigned char** address, | |
134 size_t* address_len, | |
135 uint16* port); | |
136 | |
137 // Returns the string representation of an IP address. | |
138 // For example: "192.168.0.1" or "::1". | |
139 NET_EXPORT std::string IPAddressToString(const uint8* address, | |
140 size_t address_len); | |
141 | |
142 // Returns the string representation of an IP address along with its port. | |
143 // For example: "192.168.0.1:99" or "[::1]:80". | |
144 NET_EXPORT std::string IPAddressToStringWithPort(const uint8* address, | |
145 size_t address_len, | |
146 uint16 port); | |
147 | |
148 // Same as IPAddressToString() but for a sockaddr. This output will not include | |
149 // the IPv6 scope ID. | |
150 NET_EXPORT std::string NetAddressToString(const struct sockaddr* sa, | |
151 socklen_t sock_addr_len); | |
152 | |
153 // Same as IPAddressToStringWithPort() but for a sockaddr. This output will not | |
154 // include the IPv6 scope ID. | |
155 NET_EXPORT std::string NetAddressToStringWithPort(const struct sockaddr* sa, | |
156 socklen_t sock_addr_len); | |
157 | |
158 // Same as IPAddressToString() but for an IPAddressNumber. | |
159 NET_EXPORT std::string IPAddressToString(const IPAddressNumber& addr); | |
160 | |
161 // Same as IPAddressToStringWithPort() but for an IPAddressNumber. | |
162 NET_EXPORT std::string IPAddressToStringWithPort( | |
163 const IPAddressNumber& addr, uint16 port); | |
164 | |
165 // Returns the address as a sequence of bytes in network-byte-order. | |
166 NET_EXPORT std::string IPAddressToPackedString(const IPAddressNumber& addr); | |
167 | |
168 // Returns the hostname of the current system. Returns empty string on failure. | |
169 NET_EXPORT std::string GetHostName(); | |
170 | |
171 // Extracts the unescaped username/password from |url|, saving the results | |
172 // into |*username| and |*password|. | |
173 NET_EXPORT_PRIVATE void GetIdentityFromURL(const GURL& url, | |
174 base::string16* username, | |
175 base::string16* password); | |
176 | |
177 // Returns either the host from |url|, or, if the host is empty, the full spec. | |
178 NET_EXPORT std::string GetHostOrSpecFromURL(const GURL& url); | |
179 | |
180 // Return the value of the HTTP response header with name 'name'. 'headers' | |
181 // should be in the format that URLRequest::GetResponseHeaders() returns. | |
182 // Returns the empty string if the header is not found. | |
183 NET_EXPORT std::string GetSpecificHeader(const std::string& headers, | |
184 const std::string& name); | |
185 | |
186 // Converts the given host name to unicode characters. This can be called for | |
187 // any host name, if the input is not IDN or is invalid in some way, we'll just | |
188 // return the ASCII source so it is still usable. | |
189 // | |
190 // The input should be the canonicalized ASCII host name from GURL. This | |
191 // function does NOT accept UTF-8! | |
192 // | |
193 // |languages| is a comma separated list of ISO 639 language codes. It | |
194 // is used to determine whether a hostname is 'comprehensible' to a user | |
195 // who understands languages listed. |host| will be converted to a | |
196 // human-readable form (Unicode) ONLY when each component of |host| is | |
197 // regarded as 'comprehensible'. Scipt-mixing is not allowed except that | |
198 // Latin letters in the ASCII range can be mixed with a limited set of | |
199 // script-language pairs (currently Han, Kana and Hangul for zh,ja and ko). | |
200 // When |languages| is empty, even that mixing is not allowed. | |
201 NET_EXPORT base::string16 IDNToUnicode(const std::string& host, | |
202 const std::string& languages); | |
203 | |
204 // Canonicalizes |host| and returns it. Also fills |host_info| with | |
205 // IP address information. |host_info| must not be NULL. | |
206 NET_EXPORT std::string CanonicalizeHost(const std::string& host, | |
207 url::CanonHostInfo* host_info); | |
208 | |
209 // Returns true if |host| is not an IP address and is compliant with a set of | |
210 // rules based on RFC 1738 and tweaked to be compatible with the real world. | |
211 // The rules are: | |
212 // * One or more components separated by '.' | |
213 // * Each component begins with an alphanumeric character or '-' | |
214 // * Each component contains only alphanumeric characters and '-' or '_' | |
215 // * Each component ends with an alphanumeric character or '-' | |
216 // * The last component begins with an alphanumeric character | |
217 // * Optional trailing dot after last component (means "treat as FQDN") | |
218 // | |
219 // NOTE: You should only pass in hosts that have been returned from | |
220 // CanonicalizeHost(), or you may not get accurate results. | |
221 NET_EXPORT bool IsCanonicalizedHostCompliant(const std::string& host); | |
222 | |
223 // Call these functions to get the html snippet for a directory listing. | |
224 // The return values of both functions are in UTF-8. | |
225 NET_EXPORT std::string GetDirectoryListingHeader(const base::string16& title); | |
226 | |
227 // Given the name of a file in a directory (ftp or local) and | |
228 // other information (is_dir, size, modification time), it returns | |
229 // the html snippet to add the entry for the file to the directory listing. | |
230 // Currently, it's a script tag containing a call to a Javascript function | |
231 // |addRow|. | |
232 // | |
233 // |name| is the file name to be displayed. |raw_bytes| will be used | |
234 // as the actual target of the link (so for example, ftp links should use | |
235 // server's encoding). If |raw_bytes| is an empty string, UTF-8 encoded |name| | |
236 // will be used. | |
237 // | |
238 // Both |name| and |raw_bytes| are escaped internally. | |
239 NET_EXPORT std::string GetDirectoryListingEntry(const base::string16& name, | |
240 const std::string& raw_bytes, | |
241 bool is_dir, int64 size, | |
242 base::Time modified); | |
243 | |
244 // If text starts with "www." it is removed, otherwise text is returned | |
245 // unmodified. | |
246 NET_EXPORT base::string16 StripWWW(const base::string16& text); | |
247 | |
248 // Runs |url|'s host through StripWWW(). |url| must be valid. | |
249 NET_EXPORT base::string16 StripWWWFromHost(const GURL& url); | |
250 | |
251 // Checks if |port| is in the valid range (0 to 65535, though 0 is technically | |
252 // reserved). Should be used before casting a port to a uint16. | |
253 NET_EXPORT bool IsPortValid(int port); | |
254 | |
255 // Checks |port| against a list of ports which are restricted by default. | |
256 // Returns true if |port| is allowed, false if it is restricted. | |
257 NET_EXPORT bool IsPortAllowedByDefault(int port); | |
258 | |
259 // Checks |port| against a list of ports which are restricted by the FTP | |
260 // protocol. Returns true if |port| is allowed, false if it is restricted. | |
261 NET_EXPORT_PRIVATE bool IsPortAllowedByFtp(int port); | |
262 | |
263 // Check if banned |port| has been overriden by an entry in | |
264 // |explicitly_allowed_ports_|. | |
265 NET_EXPORT_PRIVATE bool IsPortAllowedByOverride(int port); | |
266 | |
267 // Set socket to non-blocking mode | |
268 NET_EXPORT int SetNonBlocking(int fd); | |
269 | |
270 // Formats the host in |url| and appends it to |output|. The host formatter | |
271 // takes the same accept languages component as ElideURL(). | |
272 NET_EXPORT void AppendFormattedHost(const GURL& url, | |
273 const std::string& languages, | |
274 base::string16* output); | |
275 | |
276 // Creates a string representation of |url|. The IDN host name may be in Unicode | |
277 // if |languages| accepts the Unicode representation. |format_type| is a bitmask | |
278 // of FormatUrlTypes, see it for details. |unescape_rules| defines how to clean | |
279 // the URL for human readability. You will generally want |UnescapeRule::SPACES| | |
280 // for display to the user if you can handle spaces, or |UnescapeRule::NORMAL| | |
281 // if not. If the path part and the query part seem to be encoded in %-encoded | |
282 // UTF-8, decodes %-encoding and UTF-8. | |
283 // | |
284 // The last three parameters may be NULL. | |
285 // | |
286 // |new_parsed| will be set to the parsing parameters of the resultant URL. | |
287 // | |
288 // |prefix_end| will be the length before the hostname of the resultant URL. | |
289 // | |
290 // |offset[s]_for_adjustment| specifies one or more offsets into the original | |
291 // URL, representing insertion or selection points between characters: if the | |
292 // input is "http://foo.com/", offset 0 is before the entire URL, offset 7 is | |
293 // between the scheme and the host, and offset 15 is after the end of the URL. | |
294 // Valid input offsets range from 0 to the length of the input URL string. On | |
295 // exit, each offset will have been modified to reflect any changes made to the | |
296 // output string. For example, if |url| is "http://a:b@c.com/", | |
297 // |omit_username_password| is true, and an offset is 12 (pointing between 'c' | |
298 // and '.'), then on return the output string will be "http://c.com/" and the | |
299 // offset will be 8. If an offset cannot be successfully adjusted (e.g. because | |
300 // it points into the middle of a component that was entirely removed or into | |
301 // the middle of an encoding sequence), it will be set to base::string16::npos. | |
302 // For consistency, if an input offset points between the scheme and the | |
303 // username/password, and both are removed, on output this offset will be 0 | |
304 // rather than npos; this means that offsets at the starts and ends of removed | |
305 // components are always transformed the same way regardless of what other | |
306 // components are adjacent. | |
307 NET_EXPORT base::string16 FormatUrl(const GURL& url, | |
308 const std::string& languages, | |
309 FormatUrlTypes format_types, | |
310 UnescapeRule::Type unescape_rules, | |
311 url::Parsed* new_parsed, | |
312 size_t* prefix_end, | |
313 size_t* offset_for_adjustment); | |
314 NET_EXPORT base::string16 FormatUrlWithOffsets( | |
315 const GURL& url, | |
316 const std::string& languages, | |
317 FormatUrlTypes format_types, | |
318 UnescapeRule::Type unescape_rules, | |
319 url::Parsed* new_parsed, | |
320 size_t* prefix_end, | |
321 std::vector<size_t>* offsets_for_adjustment); | |
322 // This function is like those above except it takes |adjustments| rather | |
323 // than |offset[s]_for_adjustment|. |adjustments| will be set to reflect all | |
324 // the transformations that happened to |url| to convert it into the returned | |
325 // value. | |
326 NET_EXPORT base::string16 FormatUrlWithAdjustments( | |
327 const GURL& url, | |
328 const std::string& languages, | |
329 FormatUrlTypes format_types, | |
330 UnescapeRule::Type unescape_rules, | |
331 url::Parsed* new_parsed, | |
332 size_t* prefix_end, | |
333 base::OffsetAdjuster::Adjustments* adjustments); | |
334 | |
335 // This is a convenience function for FormatUrl() with | |
336 // format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical | |
337 // set of flags for "URLs to display to the user". You should be cautious about | |
338 // using this for URLs which will be parsed or sent to other applications. | |
339 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) { | |
340 return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES, | |
341 NULL, NULL, NULL); | |
342 } | |
343 | |
344 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a | |
345 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname. | |
346 NET_EXPORT bool CanStripTrailingSlash(const GURL& url); | |
347 | |
348 // Strip the portions of |url| that aren't core to the network request. | |
349 // - user name / password | |
350 // - reference section | |
351 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url); | |
352 | |
353 NET_EXPORT void SetExplicitlyAllowedPorts(const std::string& allowed_ports); | |
354 | |
355 class NET_EXPORT ScopedPortException { | |
356 public: | |
357 explicit ScopedPortException(int port); | |
358 ~ScopedPortException(); | |
359 | |
360 private: | |
361 int port_; | |
362 | |
363 DISALLOW_COPY_AND_ASSIGN(ScopedPortException); | |
364 }; | |
365 | |
366 // Returns true if it can determine that only loopback addresses are configured. | |
367 // i.e. if only 127.0.0.1 and ::1 are routable. | |
368 // Also returns false if it cannot determine this. | |
369 bool HaveOnlyLoopbackAddresses(); | |
370 | |
371 // Returns AddressFamily of the address. | |
372 NET_EXPORT_PRIVATE AddressFamily GetAddressFamily( | |
373 const IPAddressNumber& address); | |
374 | |
375 // Maps the given AddressFamily to either AF_INET, AF_INET6 or AF_UNSPEC. | |
376 NET_EXPORT_PRIVATE int ConvertAddressFamily(AddressFamily address_family); | |
377 | |
378 // Parses a URL-safe IP literal (see RFC 3986, Sec 3.2.2) to its numeric value. | |
379 // Returns true on success, and fills |ip_number| with the numeric value | |
380 NET_EXPORT bool ParseURLHostnameToNumber(const std::string& hostname, | |
381 IPAddressNumber* ip_number); | |
382 | |
383 // Parses an IP address literal (either IPv4 or IPv6) to its numeric value. | |
384 // Returns true on success and fills |ip_number| with the numeric value. | |
385 NET_EXPORT bool ParseIPLiteralToNumber(const std::string& ip_literal, | |
386 IPAddressNumber* ip_number); | |
387 | |
388 // Converts an IPv4 address to an IPv4-mapped IPv6 address. | |
389 // For example 192.168.0.1 would be converted to ::ffff:192.168.0.1. | |
390 NET_EXPORT_PRIVATE IPAddressNumber ConvertIPv4NumberToIPv6Number( | |
391 const IPAddressNumber& ipv4_number); | |
392 | |
393 // Returns true iff |address| is an IPv4-mapped IPv6 address. | |
394 NET_EXPORT_PRIVATE bool IsIPv4Mapped(const IPAddressNumber& address); | |
395 | |
396 // Converts an IPv4-mapped IPv6 address to IPv4 address. Should only be called | |
397 // on IPv4-mapped IPv6 addresses. | |
398 NET_EXPORT_PRIVATE IPAddressNumber ConvertIPv4MappedToIPv4( | |
399 const IPAddressNumber& address); | |
400 | |
401 // Parses an IP block specifier from CIDR notation to an | |
402 // (IP address, prefix length) pair. Returns true on success and fills | |
403 // |*ip_number| with the numeric value of the IP address and sets | |
404 // |*prefix_length_in_bits| with the length of the prefix. | |
405 // | |
406 // CIDR notation literals can use either IPv4 or IPv6 literals. Some examples: | |
407 // | |
408 // 10.10.3.1/20 | |
409 // a:b:c::/46 | |
410 // ::1/128 | |
411 NET_EXPORT bool ParseCIDRBlock(const std::string& cidr_literal, | |
412 IPAddressNumber* ip_number, | |
413 size_t* prefix_length_in_bits); | |
414 | |
415 // Compares an IP address to see if it falls within the specified IP block. | |
416 // Returns true if it does, false otherwise. | |
417 // | |
418 // The IP block is given by (|ip_prefix|, |prefix_length_in_bits|) -- any | |
419 // IP address whose |prefix_length_in_bits| most significant bits match | |
420 // |ip_prefix| will be matched. | |
421 // | |
422 // In cases when an IPv4 address is being compared to an IPv6 address prefix | |
423 // and vice versa, the IPv4 addresses will be converted to IPv4-mapped | |
424 // (IPv6) addresses. | |
425 NET_EXPORT_PRIVATE bool IPNumberMatchesPrefix(const IPAddressNumber& ip_number, | |
426 const IPAddressNumber& ip_prefix, | |
427 size_t prefix_length_in_bits); | |
428 | |
429 // Retuns the port field of the |sockaddr|. | |
430 const uint16* GetPortFieldFromSockaddr(const struct sockaddr* address, | |
431 socklen_t address_len); | |
432 // Returns the value of port in |sockaddr| (in host byte ordering). | |
433 NET_EXPORT_PRIVATE int GetPortFromSockaddr(const struct sockaddr* address, | |
434 socklen_t address_len); | |
435 | |
436 // Returns true if |host| is one of the names (e.g. "localhost") or IP | |
437 // addresses (IPv4 127.0.0.0/8 or IPv6 ::1) that indicate a loopback. | |
438 // | |
439 // Note that this function does not check for IP addresses other than | |
440 // the above, although other IP addresses may point to the local | |
441 // machine. | |
442 NET_EXPORT_PRIVATE bool IsLocalhost(const std::string& host); | |
443 | |
444 // A subset of IP address attributes which are actionable by the | |
445 // application layer. Currently unimplemented for all hosts; | |
446 // IP_ADDRESS_ATTRIBUTE_NONE is always returned. | |
447 enum IPAddressAttributes { | |
448 IP_ADDRESS_ATTRIBUTE_NONE = 0, | |
449 | |
450 // A temporary address is dynamic by nature and will not contain MAC | |
451 // address. Presence of MAC address in IPv6 addresses can be used to | |
452 // track an endpoint and cause privacy concern. Please refer to | |
453 // RFC4941. | |
454 IP_ADDRESS_ATTRIBUTE_TEMPORARY = 1 << 0, | |
455 | |
456 // A temporary address could become deprecated once the preferred | |
457 // lifetime is reached. It is still valid but shouldn't be used to | |
458 // create new connections. | |
459 IP_ADDRESS_ATTRIBUTE_DEPRECATED = 1 << 1, | |
460 }; | |
461 | |
462 // struct that is used by GetNetworkList() to represent a network | |
463 // interface. | |
464 struct NET_EXPORT NetworkInterface { | |
465 NetworkInterface(); | |
466 NetworkInterface(const std::string& name, | |
467 const std::string& friendly_name, | |
468 uint32 interface_index, | |
469 NetworkChangeNotifier::ConnectionType type, | |
470 const IPAddressNumber& address, | |
471 uint32 prefix_length, | |
472 int ip_address_attributes); | |
473 ~NetworkInterface(); | |
474 | |
475 std::string name; | |
476 std::string friendly_name; // Same as |name| on non-Windows. | |
477 uint32 interface_index; // Always 0 on Android. | |
478 NetworkChangeNotifier::ConnectionType type; | |
479 IPAddressNumber address; | |
480 uint32 prefix_length; | |
481 int ip_address_attributes; // Combination of |IPAddressAttributes|. | |
482 }; | |
483 | |
484 typedef std::vector<NetworkInterface> NetworkInterfaceList; | |
485 | |
486 // Policy settings to include/exclude network interfaces. | |
487 enum HostAddressSelectionPolicy { | |
488 INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES = 0x0, | |
489 EXCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES = 0x1, | |
490 }; | |
491 | |
492 // Returns list of network interfaces except loopback interface. If an | |
493 // interface has more than one address, a separate entry is added to | |
494 // the list for each address. | |
495 // Can be called only on a thread that allows IO. | |
496 NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks, | |
497 int policy); | |
498 | |
499 // Gets the SSID of the currently associated WiFi access point if there is one. | |
500 // Otherwise, returns empty string. | |
501 // Currently only implemented on Linux, ChromeOS and Android. | |
502 NET_EXPORT std::string GetWifiSSID(); | |
503 | |
504 // General category of the IEEE 802.11 (wifi) physical layer operating mode. | |
505 enum WifiPHYLayerProtocol { | |
506 // No wifi support or no associated AP. | |
507 WIFI_PHY_LAYER_PROTOCOL_NONE, | |
508 // An obsolete modes introduced by the original 802.11, e.g. IR, FHSS. | |
509 WIFI_PHY_LAYER_PROTOCOL_ANCIENT, | |
510 // 802.11a, OFDM-based rates. | |
511 WIFI_PHY_LAYER_PROTOCOL_A, | |
512 // 802.11b, DSSS or HR DSSS. | |
513 WIFI_PHY_LAYER_PROTOCOL_B, | |
514 // 802.11g, same rates as 802.11a but compatible with 802.11b. | |
515 WIFI_PHY_LAYER_PROTOCOL_G, | |
516 // 802.11n, HT rates. | |
517 WIFI_PHY_LAYER_PROTOCOL_N, | |
518 // Unclassified mode or failure to identify. | |
519 WIFI_PHY_LAYER_PROTOCOL_UNKNOWN | |
520 }; | |
521 | |
522 // Characterize the PHY mode of the currently associated access point. | |
523 // Currently only available on OS_WIN. | |
524 NET_EXPORT WifiPHYLayerProtocol GetWifiPHYLayerProtocol(); | |
525 | |
526 enum WifiOptions { | |
527 // Disables background SSID scans. | |
528 WIFI_OPTIONS_DISABLE_SCAN = 1 << 0, | |
529 // Enables media streaming mode. | |
530 WIFI_OPTIONS_MEDIA_STREAMING_MODE = 1 << 1 | |
531 }; | |
532 | |
533 class NET_EXPORT ScopedWifiOptions { | |
534 public: | |
535 ScopedWifiOptions() {} | |
536 virtual ~ScopedWifiOptions(); | |
537 | |
538 private: | |
539 DISALLOW_COPY_AND_ASSIGN(ScopedWifiOptions); | |
540 }; | |
541 | |
542 // Set temporary options on all wifi interfaces. | |
543 // |options| is an ORed bitfield of WifiOptions. | |
544 // Options are automatically disabled when the scoped pointer | |
545 // is freed. Currently only available on OS_WIN. | |
546 NET_EXPORT scoped_ptr<ScopedWifiOptions> SetWifiOptions(int options); | |
547 | |
548 // Returns number of matching initial bits between the addresses |a1| and |a2|. | |
549 unsigned CommonPrefixLength(const IPAddressNumber& a1, | |
550 const IPAddressNumber& a2); | |
551 | |
552 // Computes the number of leading 1-bits in |mask|. | |
553 unsigned MaskPrefixLength(const IPAddressNumber& mask); | |
554 | |
555 // Differentiated Services Code Point. | |
556 // See http://tools.ietf.org/html/rfc2474 for details. | |
557 enum DiffServCodePoint { | |
558 DSCP_NO_CHANGE = -1, | |
559 DSCP_FIRST = DSCP_NO_CHANGE, | |
560 DSCP_DEFAULT = 0, // Same as DSCP_CS0 | |
561 DSCP_CS0 = 0, // The default | |
562 DSCP_CS1 = 8, // Bulk/background traffic | |
563 DSCP_AF11 = 10, | |
564 DSCP_AF12 = 12, | |
565 DSCP_AF13 = 14, | |
566 DSCP_CS2 = 16, | |
567 DSCP_AF21 = 18, | |
568 DSCP_AF22 = 20, | |
569 DSCP_AF23 = 22, | |
570 DSCP_CS3 = 24, | |
571 DSCP_AF31 = 26, | |
572 DSCP_AF32 = 28, | |
573 DSCP_AF33 = 30, | |
574 DSCP_CS4 = 32, | |
575 DSCP_AF41 = 34, // Video | |
576 DSCP_AF42 = 36, // Video | |
577 DSCP_AF43 = 38, // Video | |
578 DSCP_CS5 = 40, // Video | |
579 DSCP_EF = 46, // Voice | |
580 DSCP_CS6 = 48, // Voice | |
581 DSCP_CS7 = 56, // Control messages | |
582 DSCP_LAST = DSCP_CS7 | |
583 }; | |
584 | |
585 } // namespace net | |
586 | |
587 #endif // NET_BASE_NET_UTIL_H_ | |
OLD | NEW |