xref: /aosp_15_r20/external/cronet/net/dns/public/resolv_reader.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors
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_DNS_PUBLIC_RESOLV_READER_H_
6 #define NET_DNS_PUBLIC_RESOLV_READER_H_
7 
8 #include <resolv.h>
9 
10 #include <memory>
11 #include <optional>
12 #include <vector>
13 
14 #include "net/base/ip_endpoint.h"
15 #include "net/base/net_export.h"
16 #include "net/dns/public/scoped_res_state.h"
17 
18 namespace net {
19 
20 // Test-overridable class to handle the interactions with OS APIs for reading
21 // resolv.conf.
22 class NET_EXPORT ResolvReader {
23  public:
24   virtual ~ResolvReader() = default;
25 
26   // Null on failure.
27   virtual std::unique_ptr<ScopedResState> GetResState();
28 };
29 
30 // Returns configured DNS servers or nullopt on failure.
31 NET_EXPORT std::optional<std::vector<IPEndPoint>> GetNameservers(
32     const struct __res_state& res);
33 
34 }  // namespace net
35 
36 #endif  // NET_DNS_PUBLIC_RESOLV_READER_H_
37