Add function to write DNS entries

Added function to write DNS entries to specified file
Also, added test case

Change-Id: I64250c7ee3cf7db3e7f8b5cf1669c7b4a7738637
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/dns_updater.cpp b/dns_updater.cpp
new file mode 100644
index 0000000..5c4d058
--- /dev/null
+++ b/dns_updater.cpp
@@ -0,0 +1,59 @@
+#include "config.h"
+#include "dns_updater.hpp"
+
+#include <phosphor-logging/log.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
+#include <phosphor-logging/elog-errors.hpp>
+#include <sdbusplus/bus.hpp>
+
+#include <fstream>
+
+namespace phosphor
+{
+namespace network
+{
+namespace dns
+{
+namespace updater
+{
+
+void processDNSEntries(const fs::path& inFile,
+                       const fs::path& outFile)
+{
+    using namespace phosphor::logging;
+    using namespace sdbusplus::xyz::openbmc_project::Common::Error;
+
+    std::fstream outStream(outFile, std::fstream::out);
+    if (!outStream.is_open())
+    {
+        log<level::ERR>("Unable to open output file",
+                        entry("FILE=%s", outFile.c_str()));
+        elog<InternalFailure>();
+    }
+
+    std::fstream inStream(inFile, std::fstream::in);
+    if (!inStream.is_open())
+    {
+        log<level::ERR>("Unable to open the input file",
+                        entry("FILE=%s", inFile.c_str()));
+        elog<InternalFailure>();
+    }
+
+    outStream << "### Generated by phosphor-networkd ###\n";
+
+    for (std::string line; std::getline(inStream, line);)
+    {
+        auto index = line.find("DNS=");
+        if(index != std::string::npos)
+        {
+           auto dns = line.substr(index + 4);
+           outStream << "nameserver " << dns << "\n" ;
+        }
+    }
+    return;
+}
+
+} // namespace updater
+} // namespace dns
+} // namespace network
+} // namespace phosphor