Vishwanatha Subbanna | f00182e | 2017-10-16 19:08:59 +0530 | [diff] [blame] | 1 | #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 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace network |
| 14 | { |
| 15 | namespace dns |
| 16 | { |
| 17 | namespace updater |
| 18 | { |
| 19 | |
Vishwanatha Subbanna | 18891c6 | 2017-10-17 15:22:46 +0530 | [diff] [blame] | 20 | void updateDNSEntries(const fs::path& inFile, |
| 21 | const fs::path& outFile) |
Vishwanatha Subbanna | f00182e | 2017-10-16 19:08:59 +0530 | [diff] [blame] | 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 |