00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "config.hh"
00020
00021 #ifndef QOLYESTER_ENABLE_VIRTUAL
00022
00023 # ifndef QOLYESTER_DAEMON_SYS_LINUX_INTERFACECONFIG_HXX
00024 # define QOLYESTER_DAEMON_SYS_LINUX_INTERFACECONFIG_HXX 1
00025
00026 # include <fstream>
00027 # include <cerrno>
00028
00029 # include "utl/exception.hh"
00030 # include "utl/log.hh"
00031
00032 # include "interfaceconfig.hh"
00033
00034 namespace olsr {
00035
00036 extern debug_ostream_t debug;
00037
00038 namespace sys {
00039
00040 namespace internal {
00041
00042 void
00043 InterfaceConfig::get_and_set(const std::string& path,
00044 const std::string& value,
00045 std::string& old_value) {
00046 std::fstream variable(path.c_str());
00047
00048 if (variable.fail())
00049 throw errnoexcept_t(std::string("Opening of ") + path +
00050 " failed: " + strerror(errno), errno);
00051
00052 char buffer[256];
00053
00054 variable.getline(buffer, sizeof buffer);
00055
00056 old_value.assign(buffer);
00057
00058 variable.seekp(0);
00059
00060 variable << value << std::endl;
00061
00062 debug << "sysctl: " << path << " = " << old_value << " <- "
00063 << value << std::endl;
00064
00065 }
00066
00067 void
00068 InterfaceConfig::set(const std::string& path, const std::string& value) {
00069 std::fstream variable(path.c_str(), std::ios::out);
00070 if (variable.fail())
00071 throw errnoexcept_t(std::string("Opening of ") + path +
00072 " failed: " + strerror(errno), errno);
00073
00074 variable << value << std::endl;
00075
00076 debug << "sysctl: " << path << " <- " << value << std::endl;
00077 }
00078
00079 }
00080
00081 }
00082
00083 }
00084
00085 # endif // ! QOLYESTER_DAEMON_SYS_LINUX_INTERFACECONFIG_HXX
00086
00087 #endif // ! QOLYESTER_ENABLE_VIRTUAL