Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

interfaceconfig.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2003, 2004, 2005 Laboratoire de Recherche en Informatique
00002 
00003 // This file is part of Qolyester.
00004 
00005 // Qolyester is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 // Qolyester is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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     } // namespace internal
00080 
00081   } // namespace sys
00082 
00083 } // namespace olsr
00084 
00085 # endif // ! QOLYESTER_DAEMON_SYS_LINUX_INTERFACECONFIG_HXX
00086 
00087 #endif // ! QOLYESTER_ENABLE_VIRTUAL

Generated on Thu Jul 28 21:21:47 2005 for Qolyester daemon by  doxygen 1.4.1