summaryrefslogtreecommitdiffstats
path: root/src/sysInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sysInfo.cpp')
-rw-r--r--src/sysInfo.cpp51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/sysInfo.cpp b/src/sysInfo.cpp
index 8c93c52..266c210 100644
--- a/src/sysInfo.cpp
+++ b/src/sysInfo.cpp
@@ -3,43 +3,46 @@
#include <QTime>
#include <QNetworkInterface>
+//static int eth0_index = 0;
+// ------------------------------------------------------------------------------------------------
sysInfo::sysInfo(){
if (debug) qDebug() << "sysInfo created.";
+ // Maybe search for eth0, etc
}
+// ------------------------------------------------------------------------------------------------
sysInfo::~sysInfo(){}
+// ------------------------------------------------------------------------------------------------
QString sysInfo::getInfo(QString& infoName){
if (debug) qDebug() << "sysInfo : getInfo(" << infoName << ")";
if (infoName == QString("mac"))
return getMACAddress();
else if (infoName == QString("ip"))
return getIPAddress();
- // still here? --> error
- return "error";
+ // still here?
+ return "info_error";
}
+// ------------------------------------------------------------------------------------------------
QString sysInfo::getMACAddress(){
- QNetworkInterface *qNetI = new QNetworkInterface();
- QList<QNetworkInterface> list;
- list=qNetI->allInterfaces();
- QString str;
- QString macAddress;
- for (int i = 0; i < list.size(); ++i) {
- str = list.at(i).name();
- macAddress = list.at(i).hardwareAddress();
- if (debug) qDebug() << str << " : " << macAddress;
+ /* Returns MAC address of eth0 for now. */
+ QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0"));
+ if (!qni.isValid()){
+ if (debug) qDebug() << "No interface matching \"eth0\" found.";
+ return "no_eth0";
}
- // returns only the latest found interface ... to fix
- return macAddress;
+ //eth0_index = qni.index();
+ return qni.hardwareAddress();
}
-
+// ------------------------------------------------------------------------------------------------
QString sysInfo::getIPAddress(){
- QString ipAddress = "";
- QNetworkInterface *qNetI = new QNetworkInterface();
- QList<QHostAddress> list;
- list=qNetI->allAddresses();
- for (int i = 0; i < list.size(); ++i) {
- ipAddress = list.at(i).toString();
- if (debug) qDebug() << "IP Address" << " : " << ipAddress;
- }
- // returns only the latest found interface ... to fix
- return ipAddress;
+ // Again for eth0 only at the moment.
+ // TODO: this doesn't quite work yet...
+ QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0"));
+ QList<QHostAddress> addrlist = qni.allAddresses();
+ foreach(QHostAddress addr, addrlist){
+ if (addr.protocol() == QAbstractSocket::IPv6Protocol)
+ qDebug() << "eth0: IPv4 Address: " << addr.toString();
+ return addr.toString();
+ }
+ // still here?
+ return "ip_error";
}