diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-03-26 19:21:20 +0000 |
---|---|---|
committer | <> | 2014-05-08 15:03:54 +0000 |
commit | fb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch) | |
tree | c2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/Main/src-server/HostDnsServiceResolvConf.cpp | |
parent | 58ed4748338f9466599adfc8a9171280ed99e23f (diff) | |
download | VirtualBox-master.tar.gz |
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
Diffstat (limited to 'src/VBox/Main/src-server/HostDnsServiceResolvConf.cpp')
-rw-r--r-- | src/VBox/Main/src-server/HostDnsServiceResolvConf.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/VBox/Main/src-server/HostDnsServiceResolvConf.cpp b/src/VBox/Main/src-server/HostDnsServiceResolvConf.cpp new file mode 100644 index 00000000..3b2ceeb8 --- /dev/null +++ b/src/VBox/Main/src-server/HostDnsServiceResolvConf.cpp @@ -0,0 +1,91 @@ +/* -*- indent-tabs-mode: nil; -*- */ +#include <VBox/com/string.h> +#include <VBox/com/ptr.h> + + +#ifdef RT_OS_OS2 +# include <sys/socket.h> +typedef int socklen_t; +#endif + +#include <stdio.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> + + +#include <iprt/assert.h> +#include <iprt/err.h> +#include <iprt/file.h> +#include <iprt/critsect.h> + +#include <VBox/log.h> + +#include <string> + +#include "HostDnsService.h" +#include "../../Devices/Network/slirp/resolv_conf_parser.h" + + +struct HostDnsServiceResolvConf::Data +{ + Data(const char *fileName):resolvConfFilename(fileName){}; + + std::string resolvConfFilename; +}; + +const std::string& HostDnsServiceResolvConf::resolvConf() const +{ + return m->resolvConfFilename; +} + + +HostDnsServiceResolvConf::~HostDnsServiceResolvConf() +{ + if (m) + { + delete m; + m = NULL; + } +} + +HRESULT HostDnsServiceResolvConf::init(const char *aResolvConfFileName) +{ + m = new Data(aResolvConfFileName); + + HostDnsMonitor::init(); + + readResolvConf(); + + return S_OK; +} + + +HRESULT HostDnsServiceResolvConf::readResolvConf() +{ + struct rcp_state st; + + st.rcps_flags = RCPSF_NO_STR2IPCONV; + int rc = rcp_parse(&st, m->resolvConfFilename.c_str()); + if (rc == -1) + return S_OK; + + HostDnsInformation info; + for (unsigned i = 0; i != st.rcps_num_nameserver; ++i) + { + AssertBreak(st.rcps_str_nameserver[i]); + info.servers.push_back(st.rcps_str_nameserver[i]); + } + + if (st.rcps_domain) + info.domain = st.rcps_domain; + + for (unsigned i = 0; i != st.rcps_num_searchlist; ++i) + { + AssertBreak(st.rcps_searchlist[i]); + info.searchList.push_back(st.rcps_searchlist[i]); + } + setInfo(info); + + return S_OK; +} |