author | zecke <zecke> | 2004-12-20 22:29:08 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-12-20 22:29:08 (UTC) |
commit | fd530016abd98bb6164c1ac962de0ca11d82e407 (patch) (side-by-side diff) | |
tree | ed352181c3c490ddf300665699a096a494028ef6 | |
parent | 89b3fd61bdd13e62ff64bd7ab0b15c10a964b867 (diff) | |
download | opie-fd530016abd98bb6164c1ac962de0ca11d82e407.zip opie-fd530016abd98bb6164c1ac962de0ca11d82e407.tar.gz opie-fd530016abd98bb6164c1ac962de0ca11d82e407.tar.bz2 |
Restore Changes:
Call ifup/ifdown INTERFACE instead of ifconfig as requested
by Chris Larson
-rw-r--r-- | noncore/settings/networksettings/interfaces/interface.cpp | 46 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces/interface.h | 1 |
2 files changed, 42 insertions, 5 deletions
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp index 46f3e19..44c0264 100644 --- a/noncore/settings/networksettings/interfaces/interface.cpp +++ b/noncore/settings/networksettings/interfaces/interface.cpp @@ -1,166 +1,202 @@ /** * $Author$ * $Date$ */ #include "interface.h" #include <opie2/odebug.h> +#include <opie2/oprocess.h> +#include <opie2/owait.h> +#include <qpe/global.h> + +#include <qapplication.h> #include <qdatetime.h> #include <qfile.h> #include <qdir.h> #include <qfileinfo.h> #include <qtextstream.h> #define IFCONFIG "/sbin/ifconfig" +#define IF_UP "/sbin/ifup" +#define IF_DOWN "/sbin/ifdown" #define DHCP_INFO_DIR "/etc/dhcpc" #include <stdio.h> #include <stdlib.h> Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), hardwareName("Unknown"), moduleOwner(NULL), status(newSatus), attached(false), dhcp(false), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"){ refresh(); } /** * Set status * @param newStatus - the new status * emit updateInterface */ void Interface::setStatus(bool newStatus){ if(status != newStatus){ status = newStatus; refresh(); } }; /** * Set if attached or not (802.11 card pulled out for example) * @param isAttached - if attached * emit updateInterface */ void Interface::setAttached(bool isAttached){ attached = isAttached; emit(updateInterface(this)); }; /** * Set Hardware name * @param name - the new name * emit updateInterface */ void Interface::setHardwareName(const QString &name){ hardwareName = name; emit(updateInterface(this)); }; /** * Set Module owner * @param owner - the new owner * emit updateInterface */ void Interface::setModuleOwner(Module *owner){ moduleOwner = owner; emit(updateInterface(this)); }; +bool Interface::callProcess( const QStringList& names ) { + Opie::Ui::OWait *owait = new Opie::Ui::OWait(); + Global::statusMessage( tr( "Restarting interface" ) ); + + owait->show(); + qApp->processEvents(); + + Opie::Core::OProcess restart; + restart << names; + if ( !restart.start(Opie::Core::OProcess::Block, + Opie::Core::OProcess::NoCommunication ) ) { + owarn << "unable to spawn command" << names << oendl; + return false; + } + owait->hide(); + delete owait; + + if ( restart.normalExit() || restart.exitStatus() != 0 ) + return false; + + return true; +} + /** * Try to start the interface. */ void Interface::start(){ // check to see if we are already running. if(true == status){ emit (updateMessage("Unable to start interface,\n already started")); return; } - int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); - // See if it was successful... - if(ret != 0){ + /* prepare command and call it */ + QStringList lst; + lst << IF_UP; + lst << name(); + if ( !callProcess(lst) ) { emit (updateMessage("Starting interface failed")); return; } status = true; refresh(); emit (updateMessage("Start successful")); } /** * Try to stop the interface. */ void Interface::stop(){ // check to see if we are already stopped. if(false == status){ emit (updateMessage("Unable to stop interface,\n already stopped")); return; } - int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); - if(ret != 0){ + QStringList lst; + lst << IF_DOWN; + lst << name(); + + /* prepare command and call it */ + if( !callProcess( lst ) ){ emit (updateMessage("Stopping interface failed")); return; } status = false; refresh(); emit (updateMessage("Stop successful")); } /** * Try to restart the interface. */ void Interface::restart(){ stop(); start(); } /** * Try to refresh the information about the interface. * First call ifconfig, then check the dhcp-info file * @return bool true if successful. */ bool Interface::refresh(){ // See if we are up. if(status == false){ macAddress = ""; ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; dhcp = false; dhcpServerIp = ""; leaseObtained = ""; leaseExpires = ""; emit(updateInterface(this)); return true; } QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); int ret = system(QString("LANG=C %1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); if(ret != 0){ odebug << QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1() << oendl; return false; } QFile file(fileName); if (!file.open(IO_ReadOnly)){ odebug << QString("Interface: Can't open file: %1").arg(fileName).latin1() << oendl; return false; } // Set to the defaults macAddress = ""; ip = "0.0.0.0"; subnetMask = "0.0.0.0"; broadcast = ""; QTextStream stream( &file ); QString line; while ( !stream.eof() ) { line = stream.readLine(); if(line.contains("HWaddr")){ int mac = line.find("HWaddr"); macAddress = line.mid(mac+7, line.length()); } diff --git a/noncore/settings/networksettings/interfaces/interface.h b/noncore/settings/networksettings/interfaces/interface.h index 83ab088..e9ab0c2 100644 --- a/noncore/settings/networksettings/interfaces/interface.h +++ b/noncore/settings/networksettings/interfaces/interface.h @@ -1,80 +1,81 @@ #ifndef INTERFACE_H #define INTERFACE_H #include <qstring.h> #include <qobject.h> class Module; /** * A Interface represents a physical device. You can * inherit it and create also virtual devices. Like saved * ppp dial ups or vpn. Interface is used for representing * your interface to the User and its actions. * */ class Interface : public QObject{ Q_OBJECT signals: void updateInterface(Interface *i); void updateMessage(const QString &message); public: Interface(QObject * parent=0, const char * name= "unknown", bool status = false); QString getInterfaceName() const { QString n(this->name()); return n; }; void setInterfaceName( const QString &n ) { this->setName(n); }; bool getStatus() const { return status; }; void setStatus(bool newStatus); bool isAttached() const { return attached; }; void setAttached(bool isAttached=false); QString getHardwareName() const { return hardwareName; }; void setHardwareName(const QString &name="Unknown"); Module* getModuleOwner() const { return moduleOwner; }; void setModuleOwner(Module *owner=NULL); // inet information. QString getMacAddress() const { return macAddress; }; QString getIp() const { return ip; }; QString getSubnetMask() const { return subnetMask; }; QString getBroadcast() const { return broadcast; }; bool isDhcp() const { return dhcp; }; QString getDhcpServerIp() const { return dhcpServerIp; }; QString getLeaseObtained() const { return leaseObtained; }; QString getLeaseExpires() const { return leaseExpires; }; public slots: virtual bool refresh(); virtual void start(); virtual void stop(); virtual void restart(); protected: + bool callProcess( const QStringList& name ); // Interface information QString hardwareName; Module *moduleOwner; bool status; bool attached; // Network information bool dhcp; QString dhcpServerIp; QString leaseObtained; QString leaseExpires; QString macAddress; QString ip; QString broadcast; QString subnetMask; }; #endif // interface.h |