summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/interfaces/interface.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp
index 230dbe1..f0d93d6 100644
--- a/noncore/settings/networksettings/interfaces/interface.cpp
+++ b/noncore/settings/networksettings/interfaces/interface.cpp
@@ -1,197 +1,197 @@
1/** 1/**
2 * $Author$ 2 * $Author$
3 * $Date$ 3 * $Date$
4 * $Id$ 4 * $Id$
5 * $File$ 5 * $Name$
6 */ 6 */
7 7
8#include "interface.h" 8#include "interface.h"
9#include <qdatetime.h> 9#include <qdatetime.h>
10#include <qfile.h> 10#include <qfile.h>
11#include <qdir.h> 11#include <qdir.h>
12#include <qfileinfo.h> 12#include <qfileinfo.h>
13#include <qtextstream.h> 13#include <qtextstream.h>
14 14
15#define IFCONFIG "/sbin/ifconfig" 15#define IFCONFIG "/sbin/ifconfig"
16#define DHCP_INFO_DIR "/etc/dhcpc" 16#define DHCP_INFO_DIR "/etc/dhcpc"
17 17
18#include <stdio.h> 18#include <stdio.h>
19#include <stdlib.h> 19#include <stdlib.h>
20 20
21Interface::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"){ 21Interface::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"){
22 refresh(); 22 refresh();
23} 23}
24 24
25/** 25/**
26 * Set status 26 * Set status
27 * @param newStatus - the new status 27 * @param newStatus - the new status
28 * emit updateInterface 28 * emit updateInterface
29 */ 29 */
30void Interface::setStatus(bool newStatus){ 30void Interface::setStatus(bool newStatus){
31 if(status != newStatus){ 31 if(status != newStatus){
32 status = newStatus; 32 status = newStatus;
33 refresh(); 33 refresh();
34 } 34 }
35}; 35};
36 36
37/** 37/**
38 * Set if attached or not (802.11 card pulled out for example) 38 * Set if attached or not (802.11 card pulled out for example)
39 * @param isAttached - if attached 39 * @param isAttached - if attached
40 * emit updateInterface 40 * emit updateInterface
41 */ 41 */
42void Interface::setAttached(bool isAttached){ 42void Interface::setAttached(bool isAttached){
43 attached = isAttached; 43 attached = isAttached;
44 emit(updateInterface(this)); 44 emit(updateInterface(this));
45}; 45};
46 46
47/** 47/**
48 * Set Hardware name 48 * Set Hardware name
49 * @param name - the new name 49 * @param name - the new name
50 * emit updateInterface 50 * emit updateInterface
51 */ 51 */
52void Interface::setHardwareName(const QString &name){ 52void Interface::setHardwareName(const QString &name){
53 hardwareName = name; 53 hardwareName = name;
54 emit(updateInterface(this)); 54 emit(updateInterface(this));
55}; 55};
56 56
57/** 57/**
58 * Set Module owner 58 * Set Module owner
59 * @param owner - the new owner 59 * @param owner - the new owner
60 * emit updateInterface 60 * emit updateInterface
61 */ 61 */
62void Interface::setModuleOwner(Module *owner){ 62void Interface::setModuleOwner(Module *owner){
63 moduleOwner = owner; 63 moduleOwner = owner;
64 emit(updateInterface(this)); 64 emit(updateInterface(this));
65}; 65};
66 66
67 67
68/** 68/**
69 * Try to start the interface. 69 * Try to start the interface.
70 */ 70 */
71void Interface::start(){ 71void Interface::start(){
72 // check to see if we are already running. 72 // check to see if we are already running.
73 if(true == status){ 73 if(true == status){
74 emit (updateMessage("Unable to start interface,\n already started")); 74 emit (updateMessage("Unable to start interface,\n already started"));
75 return; 75 return;
76 } 76 }
77 77
78 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); 78 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1());
79 // See if it was successfull... 79 // See if it was successfull...
80 if(ret != 0){ 80 if(ret != 0){
81 emit (updateMessage("Starting interface failed")); 81 emit (updateMessage("Starting interface failed"));
82 return; 82 return;
83 } 83 }
84 84
85 status = true; 85 status = true;
86 refresh(); 86 refresh();
87 emit (updateMessage("Start successfull")); 87 emit (updateMessage("Start successfull"));
88} 88}
89 89
90/** 90/**
91 * Try to stop the interface. 91 * Try to stop the interface.
92 */ 92 */
93void Interface::stop(){ 93void Interface::stop(){
94 // check to see if we are already stopped. 94 // check to see if we are already stopped.
95 if(false == status){ 95 if(false == status){
96 emit (updateMessage("Unable to stop interface,\n already stopped")); 96 emit (updateMessage("Unable to stop interface,\n already stopped"));
97 return; 97 return;
98 } 98 }
99 99
100 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); 100 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1());
101 if(ret != 0){ 101 if(ret != 0){
102 emit (updateMessage("Stopping interface failed")); 102 emit (updateMessage("Stopping interface failed"));
103 return; 103 return;
104 } 104 }
105 105
106 status = false; 106 status = false;
107 refresh(); 107 refresh();
108 emit (updateMessage("Stop successfull")); 108 emit (updateMessage("Stop successfull"));
109} 109}
110 110
111/** 111/**
112 * Try to restart the interface. 112 * Try to restart the interface.
113 */ 113 */
114void Interface::restart(){ 114void Interface::restart(){
115 stop(); 115 stop();
116 start(); 116 start();
117} 117}
118 118
119/** 119/**
120 * Try to refresh the information about the interface. 120 * Try to refresh the information about the interface.
121 * First call ifconfig, then check the dhcp-info file 121 * First call ifconfig, then check the dhcp-info file
122 * @return bool true if successfull. 122 * @return bool true if successfull.
123 */ 123 */
124bool Interface::refresh(){ 124bool Interface::refresh(){
125 // See if we are up. 125 // See if we are up.
126 if(status == false){ 126 if(status == false){
127 macAddress = ""; 127 macAddress = "";
128 ip = "0.0.0.0"; 128 ip = "0.0.0.0";
129 subnetMask = "0.0.0.0"; 129 subnetMask = "0.0.0.0";
130 broadcast = ""; 130 broadcast = "";
131 dhcp = false; 131 dhcp = false;
132 dhcpServerIp = ""; 132 dhcpServerIp = "";
133 leaseObtained = ""; 133 leaseObtained = "";
134 leaseExpires = ""; 134 leaseExpires = "";
135 emit(updateInterface(this)); 135 emit(updateInterface(this));
136 return true; 136 return true;
137 } 137 }
138 138
139 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); 139 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name());
140 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); 140 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1());
141 if(ret != 0){ 141 if(ret != 0){
142 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); 142 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
143 return false; 143 return false;
144 } 144 }
145 145
146 QFile file(fileName); 146 QFile file(fileName);
147 if (!file.open(IO_ReadOnly)){ 147 if (!file.open(IO_ReadOnly)){
148 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 148 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
149 return false; 149 return false;
150 } 150 }
151 151
152 // Set to the defaults 152 // Set to the defaults
153 macAddress = ""; 153 macAddress = "";
154 ip = "0.0.0.0"; 154 ip = "0.0.0.0";
155 subnetMask = "0.0.0.0"; 155 subnetMask = "0.0.0.0";
156 broadcast = ""; 156 broadcast = "";
157 157
158 QTextStream stream( &file ); 158 QTextStream stream( &file );
159 QString line; 159 QString line;
160 while ( !stream.eof() ) { 160 while ( !stream.eof() ) {
161 line = stream.readLine(); 161 line = stream.readLine();
162 if(line.contains("HWaddr")){ 162 if(line.contains("HWaddr")){
163 int mac = line.find("HWaddr"); 163 int mac = line.find("HWaddr");
164 macAddress = line.mid(mac+7, line.length()); 164 macAddress = line.mid(mac+7, line.length());
165 } 165 }
166 if(line.contains("inet addr")){ 166 if(line.contains("inet addr")){
167 int ipl = line.find("inet addr"); 167 int ipl = line.find("inet addr");
168 int space = line.find(" ", ipl+10); 168 int space = line.find(" ", ipl+10);
169 ip = line.mid(ipl+10, space-ipl-10); 169 ip = line.mid(ipl+10, space-ipl-10);
170 } 170 }
171 if(line.contains("Mask")){ 171 if(line.contains("Mask")){
172 int mask = line.find("Mask"); 172 int mask = line.find("Mask");
173 subnetMask = line.mid(mask+5, line.length()); 173 subnetMask = line.mid(mask+5, line.length());
174 } 174 }
175 if(line.contains("Bcast")){ 175 if(line.contains("Bcast")){
176 int mask = line.find("Bcast"); 176 int mask = line.find("Bcast");
177 int space = line.find(" ", mask+6); 177 int space = line.find(" ", mask+6);
178 broadcast = line.mid(mask+6, space-mask-6); 178 broadcast = line.mid(mask+6, space-mask-6);
179 } 179 }
180 } 180 }
181 file.close(); 181 file.close();
182 QFile::remove(fileName); 182 QFile::remove(fileName);
183 183
184 // DHCP TESTING 184 // DHCP TESTING
185 // reset DHCP info 185 // reset DHCP info
186 dhcpServerIp = ""; 186 dhcpServerIp = "";
187 leaseObtained = ""; 187 leaseObtained = "";
188 leaseExpires = ""; 188 leaseExpires = "";
189 dhcp = false; 189 dhcp = false;
190 190
191 QString dhcpDirectory(DHCP_INFO_DIR); 191 QString dhcpDirectory(DHCP_INFO_DIR);
192 QDir d(dhcpDirectory); 192 QDir d(dhcpDirectory);
193 if(!d.exists(dhcpDirectory)) 193 if(!d.exists(dhcpDirectory))
194 dhcpDirectory = "/var/run"; 194 dhcpDirectory = "/var/run";
195 195
196 // See if we have 196 // See if we have
197 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); 197 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name()));