1131
void KwlanInterface::iwconfigProcessExited( KProcess* process )
1133
if ( process == m_iwconfigProcess )
1135
delete m_iwconfigProcess;
1136
m_iwconfigProcess = 0L;
1137
parseIwconfigOutput();
1141
void KwlanInterface::iwconfigProcessStdout( KProcess*, char* buffer, int buflen )
1143
m_iwconfigStdout += QString::fromLatin1( buffer, buflen );
1146
void KwlanInterface::parseIwconfigOutput()
1148
/* mIwconfigStdout contains the complete output of 'iwconfig' which we
1149
* are going to parse here.
1151
QMap<QString, QString> configs;
1152
QStringList ifList = QStringList::split( "\n\n", m_iwconfigStdout );
1153
QStringList::Iterator it;
1155
for ( it = ifList.begin(); it != ifList.end(); ++it )
1157
int index = ( *it ).find( ' ' );
1160
key = ( *it ).left( index );
1161
configs[key] = ( *it ).mid( index );
1163
if ( configs.find( m_controlInterface) == configs.end() )
1165
// The interface does not exist. Meaning the driver
1166
// isn't loaded and/or the interface has not been created.
1167
m_interfaceData.existing = false;
1168
m_interfaceData.available = false;
1171
if ( configs[m_controlInterface].contains( "no wireless extensions" ) )
1173
// The interface isn't a wireless device.
1174
m_interfaceData.wirelessDevice = false;
1178
// Update the wireless data of the interface.
1179
m_interfaceData.wirelessDevice = true;
1180
updateWirelessData( configs[m_controlInterface] );
1184
void KwlanInterface::updateWirelessData( QString& config )
1186
QRegExp regExp( "radio off" );
1187
if ( regExp.search( config ) > -1 ) {
1188
m_wirelessData.radioOff = TRUE;
1189
return; //The rest of the information isn't needed when radio is off.
1191
m_wirelessData.radioOff = FALSE;
1193
regExp.setPattern( "ESSID:\"?([^\"]*)\"?" );
1194
if ( regExp.search( config ) > -1 )
1195
m_wirelessData.essid = regExp.cap( 1 );
1197
regExp.setPattern( "Mode:(\\w*)" );
1198
if ( regExp.search( config ) > -1 )
1199
m_wirelessData.mode = regExp.cap( 1 );
1201
regExp.setPattern( "Frequency:([\\w|\\.]*)" );
1202
if ( regExp.search( config ) > -1 )
1203
m_wirelessData.frequency = regExp.cap( 1 );
1206
regExp.setPattern( "Channel:(\\d*)" );
1207
if ( regExp.search( config ) > -1 )
1208
m_wirelessData.channel = regExp.cap( 1 );
1211
regExp.setPattern( "Bit Rate[=:]([\\w/]*)" );
1212
if ( regExp.search( config ) > -1 )
1213
m_wirelessData.bitRate = regExp.cap( 1 );
1215
regExp.setPattern( "Signal level.(-?\\d+\\s*\\w+)" );
1216
if ( regExp.search( config ) > -1 )
1217
m_wirelessData.signal = regExp.cap( 1 );
1219
regExp.setPattern( "Noise level.(-?\\d+\\s*\\w+)" );
1220
if ( regExp.search( config ) > -1 )
1221
m_wirelessData.noise = regExp.cap( 1 );
1223
regExp.setPattern( "Link Quality[=:]([\\d/]*)" );
1224
if ( regExp.search( config ) > -1 )
1225
m_wirelessData.linkQuality = regExp.cap( 1 );
1228
void KwlanInterface::updateInterfaceData( QString& config, int type )
1230
bool hasIpAddress = TRUE;
1231
if (m_interfaceData.ipAddress.isEmpty()) hasIpAddress = FALSE;
1232
QRegExp regExp( ".*RX.*:(\\d+).*:\\d+.*:\\d+.*:\\d+" );
1233
if ( regExp.search( config ) > -1 )
1234
m_interfaceData.rxPackets = regExp.cap( 1 ).toULong();
1236
regExp.setPattern( ".*TX.*:(\\d+).*:\\d+.*:\\d+.*:\\d+" );
1237
if ( regExp.search( config ) > -1 )
1238
m_interfaceData.txPackets = regExp.cap( 1 ).toULong();
1240
regExp.setPattern( "RX bytes:(\\d+)\\s*\\(\\d+\\.\\d+\\s*\\w+\\)" );
1241
if ( regExp.search( config ) > -1 )
1243
// We count the traffic on ourself to avoid an overflow after
1245
unsigned long currentRxBytes = regExp.cap( 1 ).toULong();
1246
if ( currentRxBytes < m_interfaceData.prevRxBytes )
1248
// there was an overflow
1249
m_interfaceData.rxBytes = currentRxBytes;
1250
m_interfaceData.prevRxBytes = 0L;
1252
if ( m_interfaceData.rxBytes == 0L )
1254
// on startup set to currently received bytes
1255
m_interfaceData.rxBytes = currentRxBytes;
1256
m_interfaceData.prevRxBytes = currentRxBytes;
1259
// afterwards only add difference to previous number of bytes
1261
m_interfaceData.prevRxBytes = m_interfaceData.rxBytes;
1262
m_interfaceData.rxBytes = currentRxBytes;
1265
//m_interfaceData.incomingBytes = currentRxBytes - m_interfaceData.prevRxBytes;
1266
//m_interfaceData.prevRxBytes = currentRxBytes;
1267
m_interfaceData.rxString = KIO::convertSize( m_interfaceData.rxBytes );
1271
regExp.setPattern( "TX bytes:(\\d+)\\s*\\(\\d+\\.\\d+\\s*\\w+\\)" );
1272
if ( regExp.search( config ) > -1 )
1274
// We count the traffic on ourself to avoid an overflow after
1276
unsigned long currentTxBytes = regExp.cap( 1 ).toULong();
1277
if ( currentTxBytes < m_interfaceData.prevTxBytes )
1279
// there was an overflow
1280
m_interfaceData.txBytes = currentTxBytes;
1281
m_interfaceData.prevTxBytes = 0L;
1283
if ( m_interfaceData.txBytes == 0L )
1285
// on startup set to currently transmitted bytes
1286
m_interfaceData.txBytes = currentTxBytes;
1287
m_interfaceData.prevTxBytes = currentTxBytes;
1291
m_interfaceData.prevTxBytes = m_interfaceData.txBytes;
1292
m_interfaceData.txBytes = currentTxBytes;
1295
//m_interfaceData.outgoingBytes = currentTxBytes - m_interfaceData.prevTxBytes;
1296
//m_interfaceData.prevTxBytes = currentTxBytes;
1297
m_interfaceData.txString = KIO::convertSize( m_interfaceData.txBytes );
1301
regExp.setPattern( "inet\\s+\\w+:(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})" );
1302
if ( regExp.search( config ) > -1 )
1304
m_interfaceData.ipAddress = regExp.cap( 1 );
1305
//if (!hasIpAddress) startScriptAfterConnect();
1307
else m_interfaceData.ipAddress = "";
1308
regExp.setPattern( "(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}).*(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}).*(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})" );
1309
if ( regExp.search( config ) > -1 )
1311
m_interfaceData.broadcastAddress = regExp.cap( 2 );
1312
m_interfaceData.subnetMask = regExp.cap( 3 );
1315
m_interfaceData.broadcastAddress = "";
1316
m_interfaceData.subnetMask = "";
1320
if ( type == ETHERNET )
1322
regExp.setPattern( "(.{2}:.{2}:.{2}:.{2}:.{2}:.{2})" );
1323
if ( regExp.search( config ) > -1 )
1324
m_interfaceData.hwAddress = regExp.cap( 1 );
1326
else if ( type == PPP )
1328
regExp.setPattern( "(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}).*(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}).*(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})" );
1329
if ( regExp.search( config ) > -1 )
1330
m_interfaceData.ptpAddress = regExp.cap( 2 );
1334
1176
void KwlanInterface::logViewer()