author | kergoth <kergoth> | 2003-04-14 17:14:45 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2003-04-14 17:14:45 (UTC) |
commit | 4c0ff8a1bdc4750ee36c713392d0842e9eb9eeb3 (patch) (side-by-side diff) | |
tree | 86648bb91854c4c94ddabff7c4b57aa5215a1073 | |
parent | 1b4605559dfb77f2bb69903d7e6a982c764aadbe (diff) | |
download | opie-4c0ff8a1bdc4750ee36c713392d0842e9eb9eeb3.zip opie-4c0ff8a1bdc4750ee36c713392d0842e9eb9eeb3.tar.gz opie-4c0ff8a1bdc4750ee36c713392d0842e9eb9eeb3.tar.bz2 |
BUGFIX: obtaining a network interface list via an ioctl does not always
return all available interfaces. Per busybox ifconfig,
use /proc/net/dev as a preferred interface list if it exists,
and fall back to the ioctl method if it does not.
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 125 |
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 @@ -44,4 +44,6 @@ #include <sys/ioctl.h>
+#include <sys/socket.h>
#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
+#define _PROCNETDEV "/proc/net/dev"
@@ -149,3 +151,3 @@ MainWindowImp::~MainWindowImp(){ void MainWindowImp::getAllInterfaces(){
- int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+ int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
if(sockfd == -1)
@@ -153,57 +155,68 @@ void MainWindowImp::getAllInterfaces(){ - char buf[8*1024];
- struct ifconf ifc;
- ifc.ifc_len = sizeof(buf);
- ifc.ifc_req = (struct ifreq *) buf;
- int result=ioctl(sockfd, SIOCGIFCONF, &ifc);
-
- for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){
- struct ifreq *ifr =(struct ifreq *) ptr;
- int len = sizeof(struct sockaddr);
-#ifdef HAVE_SOCKADDR_SA_LEN
- if (ifr->ifr_addr.sa_len > len)
- len = ifr->ifr_addr.sa_len; /* length > 16 */
-#endif
- ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */
+ struct ifreq ifr;
+ QStringList ifaces;
+ QFile procFile(QString(_PROCNETDEV));
+ int result;
+
+ if (! procFile.exists()) {
+ struct ifreq ifrs[100];
+ struct ifconf ifc;
+ ifc.ifc_len = sizeof(ifrs);
+ ifc.ifc_req = ifrs;
+ result = ioctl(sockfd, SIOCGIFCONF, &ifc);
+
+ for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) {
+ struct ifreq *pifr = &ifrs[i];
+
+ ifaces += pifr->ifr_name;
+ }
+ } else {
+ procFile.open(IO_ReadOnly);
+ QString line;
+ QTextStream procTs(&procFile);
+ int loc = -1;
+
+ procTs.readLine(); // eat a line
+ procTs.readLine(); // eat a line
+ while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
+ if((loc = line.find(":")) != -1) {
+ ifaces += line.left(loc);
+ }
+ }
+ }
- int flags;
- struct sockaddr_in *sinptr;
+ for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) {
+ int flags = 0, family;
Interface *i = NULL;
- switch (ifr->ifr_addr.sa_family){
- case AF_INET:
- sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
- flags=0;
-
- struct ifreq ifcopy;
- ifcopy=*ifr;
- result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy);
- flags=ifcopy.ifr_flags;
- i = new Interface(this, ifr->ifr_name, false);
- i->setAttached(true);
- if ((flags & IFF_UP) == IFF_UP)
- i->setStatus(true);
- else
- i->setStatus(false);
-
- if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
- i->setHardwareName("Ethernet");
- else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
- i->setHardwareName("Point to Point");
- else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
- i->setHardwareName("Multicast");
- else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
- i->setHardwareName("Loopback");
- else
- i->setHardwareName("Unknown");
- interfaceNames.insert(i->getInterfaceName(), i);
- updateInterface(i);
- connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
- break;
+ strcpy(ifr.ifr_name, (*it).latin1());
- default:
- qDebug(ifr->ifr_name);
- qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1());
- break;
- }
+ qWarning("ifr.ifr_name=%s\n", ifr.ifr_name);
+
+ struct ifreq ifcopy;
+ ifcopy = ifr;
+ result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
+ flags = ifcopy.ifr_flags;
+ i = new Interface(this, ifr.ifr_name, false);
+ i->setAttached(true);
+ if ((flags & IFF_UP) == IFF_UP)
+ i->setStatus(true);
+ else
+ i->setStatus(false);
+
+ if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
+ i->setHardwareName("Ethernet");
+ else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
+ i->setHardwareName("Point to Point");
+ else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
+ i->setHardwareName("Multicast");
+ else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
+ i->setHardwareName("Loopback");
+ else
+ i->setHardwareName("Unknown");
+
+ qWarning("Adding interface %s to interfaceNames\n", ifr.ifr_name);
+ interfaceNames.insert(i->getInterfaceName(), i);
+ updateInterface(i);
+ connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
}
@@ -230,3 +243,7 @@ void MainWindowImp::loadModules(const QString &path){ while ( (fi=it.current()) ) {
+#ifdef QWS
+ if(fi->fileName().contains(".so")){
+#else
if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")){
+#endif
loadPlugin(path + "/" + fi->fileName());
@@ -245,3 +262,3 @@ Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString & #ifdef DEBUG
- qDebug("MainWindowImp::loadPlugin: %s", pluginFileName.latin1());
+ qDebug("MainWindowImp::loadPlugin: %s: resolving %s", pluginFileName.latin1(), resolveString.latin1());
#endif
@@ -252,3 +269,3 @@ Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString & #ifdef DEBUG
- qDebug("MainWindowImp::loadPlugin: File: %s is not a plugin, but though was.", pluginFileName.latin1());
+ qDebug("MainWindowImp::loadPlugin: Warning: %s is not a plugin", pluginFileName.latin1());
#endif
|