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