1
/* This file is part of the KDE project
2
Copyright (C) 2008 Dario Freddi <drf54321@gmail.com>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
20
#include "networkinterface.h"
24
class WicdNetworkInterfacePrivate
27
WicdNetworkInterfacePrivate(const QString &name);
29
quint32 parseIPv4Address(const QString & addressString);
35
WicdNetworkInterfacePrivate::WicdNetworkInterfacePrivate(const QString &n)
40
quint32 WicdNetworkInterfacePrivate::parseIPv4Address(const QString & addressString)
42
const QStringList parts = addressString.split(QChar::fromLatin1('.'), QString::SkipEmptyParts);
43
if (parts.count() != 4)
47
for (int i = 0; i < 4; ++i) {
49
const short value = parts.at(i).toShort(&ok);
50
if (value < 0 || value > 255)
52
address |= (value << ((3 - i) * 8));
57
WicdNetworkInterface::WicdNetworkInterface(const QString &name)
58
: NetworkInterface(), d(new WicdNetworkInterfacePrivate(name))
63
WicdNetworkInterface::~WicdNetworkInterface()
68
QString WicdNetworkInterface::interfaceName() const
73
QString WicdNetworkInterface::ipInterfaceName() const
78
bool WicdNetworkInterface::firmwareMissing() const
80
// TODO: check if wicd can detect firmware missing.
84
Solid::Control::IPv4Config WicdNetworkInterface::ipV4Config() const
86
// Let's parse ifconfig here
90
ifconfig.setEnvironment(QStringList() << QProcess::systemEnvironment() << "LANG=C");
91
ifconfig.start(QString("ifconfig %1").arg(d->name));
92
ifconfig.waitForFinished();
94
QString result = ifconfig.readAllStandardOutput();
96
QStringList lines = result.split('\n');
98
if (!result.contains("inet addr:")) {
99
return Solid::Control::IPv4Config(
100
QList<Solid::Control::IPv4Address>(),
101
QList<quint32>() /*nameservers*/,
102
QStringList() /* domains */,
103
QList<Solid::Control::IPv4Route>() /* routes*/);
105
QString inetadd = lines.at(1).split("inet addr:").at(1).split(' ').at(0);
106
QString bcast = lines.at(1).split("Bcast:").at(1).split(' ').at(0);
107
QString mask = lines.at(1).split("Mask:").at(1);
109
Solid::Control::IPv4Address address(
110
d->parseIPv4Address(inetadd),
111
d->parseIPv4Address(mask),
112
d->parseIPv4Address(bcast));
114
QList<quint32> dnsServers;
115
dnsServers.append(d->parseIPv4Address(bcast));
117
return Solid::Control::IPv4Config(
118
QList<Solid::Control::IPv4Address>() << address,
119
dnsServers /*nameservers*/,
120
QStringList() /* domains */,
121
QList<Solid::Control::IPv4Route>() /* routes*/);
124
QString WicdNetworkInterface::uni() const
129
QString WicdNetworkInterface::udi() const
134
int WicdNetworkInterface::designSpeed() const
139
bool WicdNetworkInterface::activateConnection(const QString &, const QVariantMap &)
144
bool WicdNetworkInterface::deactivateConnection()
149
void WicdNetworkInterface::disconnectInterface()
153
#include "networkinterface.moc"