blob: 5c4d05809b4f420ea9aa197e490e9e3088fa2865 [file] [log] [blame]
Vishwanatha Subbannaf00182e2017-10-16 19:08:59 +05301#include "config.h"
2#include "dns_updater.hpp"
3
4#include <phosphor-logging/log.hpp>
5#include <xyz/openbmc_project/Common/error.hpp>
6#include <phosphor-logging/elog-errors.hpp>
7#include <sdbusplus/bus.hpp>
8
9#include <fstream>
10
11namespace phosphor
12{
13namespace network
14{
15namespace dns
16{
17namespace updater
18{
19
20void processDNSEntries(const fs::path& inFile,
21 const fs::path& outFile)
22{
23 using namespace phosphor::logging;
24 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
25
26 std::fstream outStream(outFile, std::fstream::out);
27 if (!outStream.is_open())
28 {
29 log<level::ERR>("Unable to open output file",
30 entry("FILE=%s", outFile.c_str()));
31 elog<InternalFailure>();
32 }
33
34 std::fstream inStream(inFile, std::fstream::in);
35 if (!inStream.is_open())
36 {
37 log<level::ERR>("Unable to open the input file",
38 entry("FILE=%s", inFile.c_str()));
39 elog<InternalFailure>();
40 }
41
42 outStream << "### Generated by phosphor-networkd ###\n";
43
44 for (std::string line; std::getline(inStream, line);)
45 {
46 auto index = line.find("DNS=");
47 if(index != std::string::npos)
48 {
49 auto dns = line.substr(index + 4);
50 outStream << "nameserver " << dns << "\n" ;
51 }
52 }
53 return;
54}
55
56} // namespace updater
57} // namespace dns
58} // namespace network
59} // namespace phosphor