blob: c81ffde34ada56f1957aeebe345f6733eb3ee025 [file] [log] [blame]
[email protected]d0d49dd82012-01-26 00:03:591// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c36f0642009-09-09 01:10:502// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
tfarina77021d62015-10-11 20:19:035#ifndef NET_DNS_DNS_UTIL_H_
6#define NET_DNS_DNS_UTIL_H_
[email protected]c36f0642009-09-09 01:10:507
8#include <string>
9
[email protected]d069c11a2013-04-13 00:01:5510#include "base/strings/string_piece.h"
ttuttlecf1158bf2016-03-18 16:37:4411#include "base/time/time.h"
[email protected]172da1b2011-08-12 15:52:2612#include "net/base/net_export.h"
ttuttlecf1158bf2016-03-18 16:37:4413#include "net/base/network_change_notifier.h"
[email protected]b3ccac82010-08-04 15:54:4014
[email protected]c36f0642009-09-09 01:10:5015namespace net {
16
juliatuttle317860e2016-05-12 14:47:2217class AddressList;
18
[email protected]c36f0642009-09-09 01:10:5019// DNSDomainFromDot - convert a domain string to DNS format. From DJB's
20// public domain DNS library.
21//
22// dotted: a string in dotted form: "www.google.com"
23// out: a result in DNS form: "\x03www\x06google\x03com\x00"
[email protected]7556ea22011-12-08 19:29:1524NET_EXPORT_PRIVATE bool DNSDomainFromDot(const base::StringPiece& dotted,
[email protected]172da1b2011-08-12 15:52:2625 std::string* out);
[email protected]c36f0642009-09-09 01:10:5026
mmenked6e9161aff2016-09-09 21:55:4427// Checks that a hostname is valid. Simple wrapper around DNSDomainFromDot.
28NET_EXPORT_PRIVATE bool IsValidDNSDomain(const base::StringPiece& dotted);
29
[email protected]d0d49dd82012-01-26 00:03:5930// DNSDomainToString converts a domain in DNS format to a dotted string.
31// Excludes the dot at the end.
[email protected]7556ea22011-12-08 19:29:1532NET_EXPORT_PRIVATE std::string DNSDomainToString(
33 const base::StringPiece& domain);
[email protected]f060be32011-02-17 17:20:2834
tfarinaecc304ec2015-12-16 05:37:5435// Returns true if it can determine that only loopback addresses are configured.
36// i.e. if only 127.0.0.1 and ::1 are routable.
37// Also returns false if it cannot determine this.
38NET_EXPORT_PRIVATE bool HaveOnlyLoopbackAddresses();
39
ttuttlecf1158bf2016-03-18 16:37:4440#if !defined(OS_NACL)
41NET_EXPORT_PRIVATE
42base::TimeDelta GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault(
43 const char* field_trial_name,
44 base::TimeDelta default_delta,
45 NetworkChangeNotifier::ConnectionType connection_type);
46#endif // !defined(OS_NACL)
47
juliatuttle317860e2016-05-12 14:47:2248// How similar or different two AddressLists are (see values for details).
49// Used in histograms; do not modify existing values.
50enum AddressListDeltaType {
51 // Both lists contain the same addresses in the same order.
52 DELTA_IDENTICAL = 0,
53 // Both lists contain the same addresses in a different order.
54 DELTA_REORDERED = 1,
55 // The two lists have at least one address in common, but not all of them.
56 DELTA_OVERLAP = 2,
57 // The two lists have no addresses in common.
58 DELTA_DISJOINT = 3,
59 MAX_DELTA_TYPE
60};
61
62// Compares two AddressLists to see how similar or different their addresses
63// are. (See |AddressListDeltaType| for details of exactly what's checked.)
64AddressListDeltaType FindAddressListDeltaType(const AddressList& a,
65 const AddressList& b);
66
[email protected]c36f0642009-09-09 01:10:5067} // namespace net
68
tfarina77021d62015-10-11 20:19:0369#endif // NET_DNS_DNS_UTIL_H_