1 | /* -*- indent-tabs-mode: nil; -*- */
|
---|
2 | #include <VBox/com/string.h>
|
---|
3 | #include <VBox/com/ptr.h>
|
---|
4 |
|
---|
5 |
|
---|
6 | #ifdef RT_OS_OS2
|
---|
7 | # include <sys/socket.h>
|
---|
8 | typedef int socklen_t;
|
---|
9 | #endif
|
---|
10 |
|
---|
11 | #include <stdio.h>
|
---|
12 | #include <sys/socket.h>
|
---|
13 | #include <netinet/in.h>
|
---|
14 | #include <arpa/inet.h>
|
---|
15 |
|
---|
16 |
|
---|
17 | #include <iprt/assert.h>
|
---|
18 | #include <iprt/err.h>
|
---|
19 | #include <iprt/file.h>
|
---|
20 | #include <iprt/critsect.h>
|
---|
21 |
|
---|
22 | #include <VBox/log.h>
|
---|
23 |
|
---|
24 | #include <string>
|
---|
25 |
|
---|
26 | #include "HostDnsService.h"
|
---|
27 | #include "../../Devices/Network/slirp/resolv_conf_parser.h"
|
---|
28 |
|
---|
29 |
|
---|
30 | struct HostDnsServiceResolvConf::Data
|
---|
31 | {
|
---|
32 | Data(const char *fileName):resolvConfFilename(fileName){};
|
---|
33 |
|
---|
34 | std::string resolvConfFilename;
|
---|
35 | };
|
---|
36 |
|
---|
37 | const std::string& HostDnsServiceResolvConf::resolvConf() const
|
---|
38 | {
|
---|
39 | return m->resolvConfFilename;
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
43 | HostDnsServiceResolvConf::~HostDnsServiceResolvConf()
|
---|
44 | {
|
---|
45 | if (m)
|
---|
46 | {
|
---|
47 | delete m;
|
---|
48 | m = NULL;
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | HRESULT HostDnsServiceResolvConf::init(const char *aResolvConfFileName)
|
---|
53 | {
|
---|
54 | m = new Data(aResolvConfFileName);
|
---|
55 |
|
---|
56 | HostDnsMonitor::init();
|
---|
57 |
|
---|
58 | readResolvConf();
|
---|
59 |
|
---|
60 | return S_OK;
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | HRESULT HostDnsServiceResolvConf::readResolvConf()
|
---|
65 | {
|
---|
66 | struct rcp_state st;
|
---|
67 |
|
---|
68 | st.rcps_flags = RCPSF_NO_STR2IPCONV;
|
---|
69 | int rc = rcp_parse(&st, m->resolvConfFilename.c_str());
|
---|
70 | if (rc == -1)
|
---|
71 | return S_OK;
|
---|
72 |
|
---|
73 | HostDnsInformation info;
|
---|
74 | for (unsigned i = 0; i != st.rcps_num_nameserver; ++i)
|
---|
75 | {
|
---|
76 | AssertBreak(st.rcps_str_nameserver[i]);
|
---|
77 | info.servers.push_back(st.rcps_str_nameserver[i]);
|
---|
78 | }
|
---|
79 |
|
---|
80 | if (st.rcps_domain)
|
---|
81 | info.domain = st.rcps_domain;
|
---|
82 |
|
---|
83 | for (unsigned i = 0; i != st.rcps_num_searchlist; ++i)
|
---|
84 | {
|
---|
85 | AssertBreak(st.rcps_searchlist[i]);
|
---|
86 | info.searchList.push_back(st.rcps_searchlist[i]);
|
---|
87 | }
|
---|
88 | setInfo(info);
|
---|
89 |
|
---|
90 | return S_OK;
|
---|
91 | }
|
---|