summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp125
1 files changed, 71 insertions, 54 deletions
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index 765b522..50131d8 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -33,26 +33,28 @@
33#if QT_VERSION < 300 33#if QT_VERSION < 300
34#include <qlist.h> 34#include <qlist.h>
35#else 35#else
36#include <qptrlist.h> 36#include <qptrlist.h>
37#endif 37#endif
38#include <qdir.h> 38#include <qdir.h>
39#include <qfile.h> 39#include <qfile.h>
40#include <qtextstream.h> 40#include <qtextstream.h>
41#include <qregexp.h> 41#include <qregexp.h>
42 42
43#include <net/if.h> 43#include <net/if.h>
44#include <sys/ioctl.h> 44#include <sys/ioctl.h>
45#include <sys/socket.h>
45 46
46#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" 47#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
48#define _PROCNETDEV "/proc/net/dev"
47 49
48MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name), advancedUserMode(true), scheme(DEFAULT_SCHEME){ 50MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name), advancedUserMode(true), scheme(DEFAULT_SCHEME){
49 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 51 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
50 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 52 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
51 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 53 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
52 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 54 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
53 55
54 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); 56 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
55 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); 57 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
56 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); 58 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
57 59
58 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); 60 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
@@ -138,128 +140,143 @@ MainWindowImp::~MainWindowImp(){
138 // What fucking shit this is. 140 // What fucking shit this is.
139 //delete it.data(); 141 //delete it.data();
140 } 142 }
141#else 143#else
142 // klibloader automaticly deletes the libraries for us... 144 // klibloader automaticly deletes the libraries for us...
143#endif 145#endif
144} 146}
145 147
146/** 148/**
147 * Query the kernel for all of the interfaces. 149 * Query the kernel for all of the interfaces.
148 */ 150 */
149void MainWindowImp::getAllInterfaces(){ 151void MainWindowImp::getAllInterfaces(){
150 int sockfd = socket(AF_INET, SOCK_DGRAM, 0); 152 int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
151 if(sockfd == -1) 153 if(sockfd == -1)
152 return; 154 return;
153 155
154 char buf[8*1024]; 156 struct ifreq ifr;
155 struct ifconf ifc; 157 QStringList ifaces;
156 ifc.ifc_len = sizeof(buf); 158 QFile procFile(QString(_PROCNETDEV));
157 ifc.ifc_req = (struct ifreq *) buf; 159 int result;
158 int result=ioctl(sockfd, SIOCGIFCONF, &ifc); 160
159 161 if (! procFile.exists()) {
160 for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){ 162 struct ifreq ifrs[100];
161 struct ifreq *ifr =(struct ifreq *) ptr; 163 struct ifconf ifc;
162 int len = sizeof(struct sockaddr); 164 ifc.ifc_len = sizeof(ifrs);
163#ifdef HAVE_SOCKADDR_SA_LEN 165 ifc.ifc_req = ifrs;
164 if (ifr->ifr_addr.sa_len > len) 166 result = ioctl(sockfd, SIOCGIFCONF, &ifc);
165 len = ifr->ifr_addr.sa_len; /* length > 16 */ 167
166#endif 168 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) {
167 ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ 169 struct ifreq *pifr = &ifrs[i];
170
171 ifaces += pifr->ifr_name;
172 }
173 } else {
174 procFile.open(IO_ReadOnly);
175 QString line;
176 QTextStream procTs(&procFile);
177 int loc = -1;
178
179 procTs.readLine(); // eat a line
180 procTs.readLine(); // eat a line
181 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
182 if((loc = line.find(":")) != -1) {
183 ifaces += line.left(loc);
184 }
185 }
186 }
168 187
169 int flags; 188 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) {
170 struct sockaddr_in *sinptr; 189 int flags = 0, family;
171 Interface *i = NULL; 190 Interface *i = NULL;
172 switch (ifr->ifr_addr.sa_family){
173 case AF_INET:
174 sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
175 flags=0;
176
177 struct ifreq ifcopy;
178 ifcopy=*ifr;
179 result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy);
180 flags=ifcopy.ifr_flags;
181 i = new Interface(this, ifr->ifr_name, false);
182 i->setAttached(true);
183 if ((flags & IFF_UP) == IFF_UP)
184 i->setStatus(true);
185 else
186 i->setStatus(false);
187
188 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
189 i->setHardwareName("Ethernet");
190 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
191 i->setHardwareName("Point to Point");
192 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
193 i->setHardwareName("Multicast");
194 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
195 i->setHardwareName("Loopback");
196 else
197 i->setHardwareName("Unknown");
198 191
199 interfaceNames.insert(i->getInterfaceName(), i); 192 strcpy(ifr.ifr_name, (*it).latin1());
200 updateInterface(i);
201 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
202 break;
203 193
204 default: 194 qWarning("ifr.ifr_name=%s\n", ifr.ifr_name);
205 qDebug(ifr->ifr_name); 195
206 qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1()); 196 struct ifreq ifcopy;
207 break; 197 ifcopy = ifr;
208 } 198 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
199 flags = ifcopy.ifr_flags;
200 i = new Interface(this, ifr.ifr_name, false);
201 i->setAttached(true);
202 if ((flags & IFF_UP) == IFF_UP)
203 i->setStatus(true);
204 else
205 i->setStatus(false);
206
207 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
208 i->setHardwareName("Ethernet");
209 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
210 i->setHardwareName("Point to Point");
211 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
212 i->setHardwareName("Multicast");
213 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
214 i->setHardwareName("Loopback");
215 else
216 i->setHardwareName("Unknown");
217
218 qWarning("Adding interface %s to interfaceNames\n", ifr.ifr_name);
219 interfaceNames.insert(i->getInterfaceName(), i);
220 updateInterface(i);
221 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
209 } 222 }
210} 223}
211 224
212/** 225/**
213 * Load all modules that are found in the path 226 * Load all modules that are found in the path
214 * @param path a directory that is scaned for any plugins that can be loaded 227 * @param path a directory that is scaned for any plugins that can be loaded
215 * and attempts to load them 228 * and attempts to load them
216 */ 229 */
217void MainWindowImp::loadModules(const QString &path){ 230void MainWindowImp::loadModules(const QString &path){
218#ifdef DEBUG 231#ifdef DEBUG
219 qDebug("MainWindowImp::loadModules: %s", path.latin1()); 232 qDebug("MainWindowImp::loadModules: %s", path.latin1());
220#endif 233#endif
221 QDir d(path); 234 QDir d(path);
222 if(!d.exists()) 235 if(!d.exists())
223 return; 236 return;
224 237
225 // Don't want sym links 238 // Don't want sym links
226 d.setFilter( QDir::Files | QDir::NoSymLinks ); 239 d.setFilter( QDir::Files | QDir::NoSymLinks );
227 const QFileInfoList *list = d.entryInfoList(); 240 const QFileInfoList *list = d.entryInfoList();
228 QFileInfoListIterator it( *list ); 241 QFileInfoListIterator it( *list );
229 QFileInfo *fi; 242 QFileInfo *fi;
230 while ( (fi=it.current()) ) { 243 while ( (fi=it.current()) ) {
244#ifdef QWS
245 if(fi->fileName().contains(".so")){
246#else
231 if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")){ 247 if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")){
248#endif
232 loadPlugin(path + "/" + fi->fileName()); 249 loadPlugin(path + "/" + fi->fileName());
233 } 250 }
234 ++it; 251 ++it;
235 } 252 }
236} 253}
237 254
238/** 255/**
239 * Attempt to load a function and resolve a function. 256 * Attempt to load a function and resolve a function.
240 * @param pluginFileName - the name of the file in which to attempt to load 257 * @param pluginFileName - the name of the file in which to attempt to load
241 * @param resolveString - function pointer to resolve 258 * @param resolveString - function pointer to resolve
242 * @return pointer to the function with name resolveString or NULL 259 * @return pointer to the function with name resolveString or NULL
243 */ 260 */
244Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){ 261Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){
245#ifdef DEBUG 262#ifdef DEBUG
246 qDebug("MainWindowImp::loadPlugin: %s", pluginFileName.latin1()); 263 qDebug("MainWindowImp::loadPlugin: %s: resolving %s", pluginFileName.latin1(), resolveString.latin1());
247#endif 264#endif
248#ifdef QWS 265#ifdef QWS
249 QLibrary *lib = new QLibrary(pluginFileName); 266 QLibrary *lib = new QLibrary(pluginFileName);
250 void *functionPointer = lib->resolve(resolveString); 267 void *functionPointer = lib->resolve(resolveString);
251 if( !functionPointer ){ 268 if( !functionPointer ){
252#ifdef DEBUG 269#ifdef DEBUG
253 qDebug("MainWindowImp::loadPlugin: File: %s is not a plugin, but though was.", pluginFileName.latin1()); 270 qDebug("MainWindowImp::loadPlugin: Warning: %s is not a plugin", pluginFileName.latin1());
254#endif 271#endif
255 delete lib; 272 delete lib;
256 return NULL; 273 return NULL;
257 } 274 }
258 // Try to get an object. 275 // Try to get an object.
259 Module *object = ((Module* (*)()) functionPointer)(); 276 Module *object = ((Module* (*)()) functionPointer)();
260 if(object == NULL){ 277 if(object == NULL){
261#ifdef DEBUG 278#ifdef DEBUG
262 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 279 qDebug("MainWindowImp: Couldn't create object, but did load library!");
263#endif 280#endif
264 delete lib; 281 delete lib;
265 return NULL; 282 return NULL;