summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/interfaces/interface.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/interfaces/interface.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/interfaces/interface.cpp68
1 files changed, 34 insertions, 34 deletions
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp
index cc45525..69b55d1 100644
--- a/noncore/settings/networksettings/interfaces/interface.cpp
+++ b/noncore/settings/networksettings/interfaces/interface.cpp
@@ -1,10 +1,10 @@
1/** 1/**
2 * $Author$ 2 * $Author$
3 * $Date$ 3 * $Date$
4 */ 4 */
5 5
6#include "interface.h" 6#include "interface.h"
7#include <qdatetime.h> 7#include <qdatetime.h>
8#include <qfile.h> 8#include <qfile.h>
9#include <qdir.h> 9#include <qdir.h>
10#include <qfileinfo.h> 10#include <qfileinfo.h>
@@ -21,61 +21,61 @@ Interface::Interface(QObject * parent, const char * name, bool newSatus): QObjec
21} 21}
22 22
23/** 23/**
24 * Set status 24 * Set status
25 * @param newStatus - the new status 25 * @param newStatus - the new status
26 * emit updateInterface 26 * emit updateInterface
27 */ 27 */
28void Interface::setStatus(bool newStatus){ 28void Interface::setStatus(bool newStatus){
29 if(status != newStatus){ 29 if(status != newStatus){
30 status = newStatus; 30 status = newStatus;
31 refresh(); 31 refresh();
32 } 32 }
33}; 33};
34 34
35/** 35/**
36 * Set if attached or not (802.11 card pulled out for example) 36 * Set if attached or not (802.11 card pulled out for example)
37 * @param isAttached - if attached 37 * @param isAttached - if attached
38 * emit updateInterface 38 * emit updateInterface
39 */ 39 */
40void Interface::setAttached(bool isAttached){ 40void Interface::setAttached(bool isAttached){
41 attached = isAttached; 41 attached = isAttached;
42 emit(updateInterface(this)); 42 emit(updateInterface(this));
43}; 43};
44 44
45/** 45/**
46 * Set Hardware name 46 * Set Hardware name
47 * @param name - the new name 47 * @param name - the new name
48 * emit updateInterface 48 * emit updateInterface
49 */ 49 */
50void Interface::setHardwareName(const QString &name){ 50void Interface::setHardwareName(const QString &name){
51 hardwareName = name; 51 hardwareName = name;
52 emit(updateInterface(this)); 52 emit(updateInterface(this));
53}; 53};
54 54
55/** 55/**
56 * Set Module owner 56 * Set Module owner
57 * @param owner - the new owner 57 * @param owner - the new owner
58 * emit updateInterface 58 * emit updateInterface
59 */ 59 */
60void Interface::setModuleOwner(Module *owner){ 60void Interface::setModuleOwner(Module *owner){
61 moduleOwner = owner; 61 moduleOwner = owner;
62 emit(updateInterface(this)); 62 emit(updateInterface(this));
63}; 63};
64 64
65 65
66/** 66/**
67 * Try to start the interface. 67 * Try to start the interface.
68 */ 68 */
69void Interface::start(){ 69void Interface::start(){
70 // check to see if we are already running. 70 // check to see if we are already running.
71 if(true == status){ 71 if(true == status){
72 emit (updateMessage("Unable to start interface,\n already started")); 72 emit (updateMessage("Unable to start interface,\n already started"));
73 return; 73 return;
74 } 74 }
75 75
76 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); 76 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1());
77 // See if it was successfull... 77 // See if it was successfull...
78 if(ret != 0){ 78 if(ret != 0){
79 emit (updateMessage("Starting interface failed")); 79 emit (updateMessage("Starting interface failed"));
80 return; 80 return;
81 } 81 }
@@ -86,18 +86,18 @@ void Interface::start(){
86} 86}
87 87
88/** 88/**
89 * Try to stop the interface. 89 * Try to stop the interface.
90 */ 90 */
91void Interface::stop(){ 91void Interface::stop(){
92 // check to see if we are already stopped. 92 // check to see if we are already stopped.
93 if(false == status){ 93 if(false == status){
94 emit (updateMessage("Unable to stop interface,\n already stopped")); 94 emit (updateMessage("Unable to stop interface,\n already stopped"));
95 return; 95 return;
96 } 96 }
97 97
98 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); 98 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1());
99 if(ret != 0){ 99 if(ret != 0){
100 emit (updateMessage("Stopping interface failed")); 100 emit (updateMessage("Stopping interface failed"));
101 return; 101 return;
102 } 102 }
103 103
@@ -105,13 +105,13 @@ void Interface::stop(){
105 refresh(); 105 refresh();
106 emit (updateMessage("Stop successfull")); 106 emit (updateMessage("Stop successfull"));
107} 107}
108 108
109/** 109/**
110 * Try to restart the interface. 110 * Try to restart the interface.
111 */ 111 */
112void Interface::restart(){ 112void Interface::restart(){
113 stop(); 113 stop();
114 start(); 114 start();
115} 115}
116 116
117/** 117/**
@@ -130,32 +130,32 @@ bool Interface::refresh(){
130 dhcpServerIp = ""; 130 dhcpServerIp = "";
131 leaseObtained = ""; 131 leaseObtained = "";
132 leaseExpires = ""; 132 leaseExpires = "";
133 emit(updateInterface(this)); 133 emit(updateInterface(this));
134 return true; 134 return true;
135 } 135 }
136 136
137 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name()); 137 QString fileName = QString("/tmp/%1_ifconfig_info").arg(this->name());
138 int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1()); 138 int ret = system(QString("LANG=C %1 %2 > %3").arg(IFCONFIG).arg(this->name()).arg(fileName).latin1());
139 if(ret != 0){ 139 if(ret != 0){
140 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1()); 140 qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
141 return false; 141 return false;
142 } 142 }
143 143
144 QFile file(fileName); 144 QFile file(fileName);
145 if (!file.open(IO_ReadOnly)){ 145 if (!file.open(IO_ReadOnly)){
146 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 146 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
147 return false; 147 return false;
148 } 148 }
149 149
150 // Set to the defaults 150 // Set to the defaults
151 macAddress = ""; 151 macAddress = "";
152 ip = "0.0.0.0"; 152 ip = "0.0.0.0";
153 subnetMask = "0.0.0.0"; 153 subnetMask = "0.0.0.0";
154 broadcast = ""; 154 broadcast = "";
155 155
156 QTextStream stream( &file ); 156 QTextStream stream( &file );
157 QString line; 157 QString line;
158 while ( !stream.eof() ) { 158 while ( !stream.eof() ) {
159 line = stream.readLine(); 159 line = stream.readLine();
160 if(line.contains("HWaddr")){ 160 if(line.contains("HWaddr")){
161 int mac = line.find("HWaddr"); 161 int mac = line.find("HWaddr");
@@ -182,36 +182,36 @@ bool Interface::refresh(){
182 // DHCP TESTING 182 // DHCP TESTING
183 // reset DHCP info 183 // reset DHCP info
184 dhcpServerIp = ""; 184 dhcpServerIp = "";
185 leaseObtained = ""; 185 leaseObtained = "";
186 leaseExpires = ""; 186 leaseExpires = "";
187 dhcp = false; 187 dhcp = false;
188 188
189 QString dhcpDirectory(DHCP_INFO_DIR); 189 QString dhcpDirectory(DHCP_INFO_DIR);
190 QDir d(dhcpDirectory); 190 QDir d(dhcpDirectory);
191 if(!d.exists(dhcpDirectory)) 191 if(!d.exists(dhcpDirectory))
192 dhcpDirectory = "/var/run"; 192 dhcpDirectory = "/var/run";
193 193
194 // See if we have 194 // See if we have
195 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name())); 195 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(this->name()));
196 // If there is no DHCP information then exit now with no errors. 196 // If there is no DHCP information then exit now with no errors.
197 if(!QFile::exists(dhcpFile)){ 197 if(!QFile::exists(dhcpFile)){
198 emit(updateInterface(this)); 198 emit(updateInterface(this));
199 return true; 199 return true;
200 } 200 }
201 201
202 file.setName(dhcpFile); 202 file.setName(dhcpFile);
203 if (!file.open(IO_ReadOnly)){ 203 if (!file.open(IO_ReadOnly)){
204 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 204 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
205 return false; 205 return false;
206 } 206 }
207 207
208 // leaseTime and renewalTime and used if pid and deamon exe can be accessed. 208 // leaseTime and renewalTime and used if pid and deamon exe can be accessed.
209 int leaseTime = 0; 209 int leaseTime = 0;
210 int renewalTime = 0; 210 int renewalTime = 0;
211 211
212 stream.setDevice( &file ); 212 stream.setDevice( &file );
213 while ( !stream.eof() ) { 213 while ( !stream.eof() ) {
214 line = stream.readLine(); 214 line = stream.readLine();
215 if(line.contains("DHCPSIADDR=")) 215 if(line.contains("DHCPSIADDR="))
216 dhcpServerIp = line.mid(11, line.length()); 216 dhcpServerIp = line.mid(11, line.length());
217 if(line.contains("LEASETIME=")) 217 if(line.contains("LEASETIME="))
@@ -219,13 +219,13 @@ bool Interface::refresh(){
219 if(line.contains("RENEWALTIME=")) 219 if(line.contains("RENEWALTIME="))
220 renewalTime = line.mid(12, line.length()).toInt(); 220 renewalTime = line.mid(12, line.length()).toInt();
221 } 221 }
222 file.close(); 222 file.close();
223 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1()); 223 //qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
224 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1()); 224 //qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
225 225
226 // Get the pid of the deamond 226 // Get the pid of the deamond
227 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name())); 227 dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(this->name()));
228 file.setName(dhcpFile); 228 file.setName(dhcpFile);
229 if (!file.open(IO_ReadOnly)){ 229 if (!file.open(IO_ReadOnly)){
230 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1()); 230 qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
231 return false; 231 return false;
@@ -241,34 +241,34 @@ bool Interface::refresh(){
241 241
242 if( pid == -1){ 242 if( pid == -1){
243 qDebug("Interface: Could not get pid of dhcpc deamon."); 243 qDebug("Interface: Could not get pid of dhcpc deamon.");
244 return false; 244 return false;
245 } 245 }
246 246
247 // Get the start running time of the deamon 247 // Get the start running time of the deamon
248 fileName = (QString("/proc/%1/stat").arg(pid)); 248 fileName = (QString("/proc/%1/stat").arg(pid));
249 file.setName(fileName); 249 file.setName(fileName);
250 stream.setDevice( &file ); 250 stream.setDevice( &file );
251 if (!file.open(IO_ReadOnly)){ 251 if (!file.open(IO_ReadOnly)){
252 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1()); 252 qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
253 return false; 253 return false;
254 } 254 }
255 while ( !stream.eof() ) { 255 while ( !stream.eof() ) {
256 line = stream.readLine(); 256 line = stream.readLine();
257 } 257 }
258 file.close(); 258 file.close();
259 long time = 0; 259 long time = 0;
260 // Grab the start time 260 // Grab the start time
261 // pid com state ppid pgrp session tty_nr tpgid flags 261 // pid com state ppid pgrp session tty_nr tpgid flags
262 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u " 262 sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
263 // minflt cminflt majflt cmajflt utime stime cutime cstime priority 263 // minflt cminflt majflt cmajflt utime stime cutime cstime priority
264 "%*u %*u %*u %*u %*u %*u %*d %*d %*d " 264 "%*u %*u %*u %*u %*u %*u %*d %*d %*d "
265 // nice 0 itrealvalue starttime 265 // nice 0 itrealvalue starttime
266 "%*d %*d %*d %lu", (long*) &time); 266 "%*d %*d %*d %lu", (long*) &time);
267 time = time/100; 267 time = time/100;
268 268
269 QDateTime datetime(QDateTime::currentDateTime()); 269 QDateTime datetime(QDateTime::currentDateTime());
270 270
271 // Get the uptime of the computer. 271 // Get the uptime of the computer.
272 QFile f("/proc/uptime"); 272 QFile f("/proc/uptime");
273 if ( f.open(IO_ReadOnly) ) { // file opened successfully 273 if ( f.open(IO_ReadOnly) ) { // file opened successfully
274 QTextStream t( &f ); // use a text stream 274 QTextStream t( &f ); // use a text stream
@@ -278,25 +278,25 @@ bool Interface::refresh(){
278 f.close(); 278 f.close();
279 } 279 }
280 else{ 280 else{
281 qDebug("Interface: Can't open /proc/uptime to retrive uptime."); 281 qDebug("Interface: Can't open /proc/uptime to retrive uptime.");
282 return false; 282 return false;
283 } 283 }
284 284
285 datetime = datetime.addSecs(time); 285 datetime = datetime.addSecs(time);
286 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1()); 286 //qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
287 287
288 // Calculate the start and renew times 288 // Calculate the start and renew times
289 leaseObtained= datetime.toString(); 289 leaseObtained= datetime.toString();
290 290
291 // Calculate the start and renew times 291 // Calculate the start and renew times
292 datetime = datetime.addSecs(leaseTime); 292 datetime = datetime.addSecs(leaseTime);
293 leaseExpires = datetime.toString(); 293 leaseExpires = datetime.toString();
294 294
295 dhcp = true; 295 dhcp = true;
296 296
297 emit(updateInterface(this)); 297 emit(updateInterface(this));
298 return true; 298 return true;
299} 299}
300 300
301// interface.cpp 301// interface.cpp
302 302