author | benmeyer <benmeyer> | 2003-01-13 19:08:27 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2003-01-13 19:08:27 (UTC) |
commit | 0c29de3bd4eeaeb1bd250f8e72fc12ba8700a4c8 (patch) (side-by-side diff) | |
tree | 9bc7fe1214ad2e93994bda3e7646ccc9a4013589 | |
parent | b5e3438b22606a00e17afd14674aa685739237c1 (diff) | |
download | opie-0c29de3bd4eeaeb1bd250f8e72fc12ba8700a4c8.zip opie-0c29de3bd4eeaeb1bd250f8e72fc12ba8700a4c8.tar.gz opie-0c29de3bd4eeaeb1bd250f8e72fc12ba8700a4c8.tar.bz2 |
test
-rw-r--r-- | noncore/settings/networksettings/interfaces/interface.cpp | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp index 864d9b5..2ace5fd 100644 --- a/noncore/settings/networksettings/interfaces/interface.cpp +++ b/noncore/settings/networksettings/interfaces/interface.cpp @@ -1,198 +1,196 @@ -$Header$ - /** * $Author$ * $Date$ - * $Name$ + * $Id$ */ #include "interface.h" #include <qdatetime.h> #include <qfile.h> #include <qdir.h> #include <qfileinfo.h> #include <qtextstream.h> #define IFCONFIG "/sbin/ifconfig" #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)); }; /** * 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 successfull... if(ret != 0){ emit (updateMessage("Starting interface failed")); return; } status = true; refresh(); emit (updateMessage("Start successfull")); } /** * 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){ emit (updateMessage("Stopping interface failed")); return; } status = false; refresh(); emit (updateMessage("Stop successfull")); } /** * 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 successfull. */ 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("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); if(ret != 0){ qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); return false; } QFile file(fileName); if (!file.open(IO_ReadOnly)){ qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 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()); } if(line.contains("inet addr")){ int ipl = line.find("inet addr"); int space = line.find(" ", ipl+10); ip = line.mid(ipl+10, space-ipl-10); } if(line.contains("Mask")){ int mask = line.find("Mask"); subnetMask = line.mid(mask+5, line.length()); } if(line.contains("Bcast")){ int mask = line.find("Bcast"); int space = line.find(" ", mask+6); broadcast = line.mid(mask+6, space-mask-6); } } file.close(); QFile::remove(fileName); // DHCP TESTING // reset DHCP info dhcpServerIp = ""; leaseObtained = ""; leaseExpires = ""; dhcp = false; QString dhcpDirectory(DHCP_INFO_DIR); QDir d(dhcpDirectory); if(!d.exists(dhcpDirectory)) dhcpDirectory = "/var/run"; // See if we have QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); |