blob: d6e6b47cdeb4293c1a03129d0e009179bb2339a9 [file] [log] [blame]
[email protected]b4481b222012-03-16 17:13:111// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]6998a662011-09-03 00:17:292// 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_DNS_DNS_HOSTS_H_
6#define NET_DNS_DNS_HOSTS_H_
[email protected]6998a662011-09-03 00:17:297
8#include <map>
9#include <string>
10#include <utility>
11#include <vector>
12
[email protected]b4481b222012-03-16 17:13:1113#include "base/file_path.h"
[email protected]6998a662011-09-03 00:17:2914#include "net/base/address_family.h"
15#include "net/base/net_export.h"
16#include "net/base/net_util.h" // can't forward-declare IPAddressNumber
17
18namespace net {
19
20// Parsed results of a Hosts file.
21//
22// Although Hosts files map IP address to a list of domain names, for name
23// resolution the desired mapping direction is: domain name to IP address.
24// When parsing Hosts, we apply the "first hit" rule as Windows and glibc do.
25// With a Hosts file of:
26// 300.300.300.300 localhost # bad ip
27// 127.0.0.1 localhost
28// 10.0.0.1 localhost
29// The expected resolution of localhost is 127.0.0.1.
30typedef std::pair<std::string, AddressFamily> DnsHostsKey;
31typedef std::map<DnsHostsKey, IPAddressNumber> DnsHosts;
32
33// Parses |contents| (as read from /etc/hosts or equivalent) and stores results
34// in |dns_hosts|. Invalid lines are ignored (as in most implementations).
35void NET_EXPORT_PRIVATE ParseHosts(const std::string& contents,
36 DnsHosts* dns_hosts);
37
[email protected]d6f9e9cb2012-06-14 04:28:3738// As above but reads the file pointed to by |path|.
39bool NET_EXPORT_PRIVATE ParseHostsFile(const FilePath& path,
40 DnsHosts* dns_hosts);
[email protected]b4481b222012-03-16 17:13:1141
[email protected]b4481b222012-03-16 17:13:1142
43
[email protected]6998a662011-09-03 00:17:2944} // namespace net
45
46#endif // NET_DNS_DNS_HOSTS_H_
47