summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/mainwindowimp.cpp
authorkergoth <kergoth>2003-04-14 17:14:45 (UTC)
committer kergoth <kergoth>2003-04-14 17:14:45 (UTC)
commit4c0ff8a1bdc4750ee36c713392d0842e9eb9eeb3 (patch) (unidiff)
tree86648bb91854c4c94ddabff7c4b57aa5215a1073 /noncore/settings/networksettings/mainwindowimp.cpp
parent1b4605559dfb77f2bb69903d7e6a982c764aadbe (diff)
downloadopie-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.
Diffstat (limited to 'noncore/settings/networksettings/mainwindowimp.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp79
1 files changed, 48 insertions, 31 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 @@
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
@@ -149,3 +151,3 @@ MainWindowImp::~MainWindowImp(){
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)
@@ -153,30 +155,47 @@ void MainWindowImp::getAllInterfaces(){
153 155
154 char buf[8*1024]; 156 struct ifreq ifr;
157 QStringList ifaces;
158 QFile procFile(QString(_PROCNETDEV));
159 int result;
160
161 if (! procFile.exists()) {
162 struct ifreq ifrs[100];
155 struct ifconf ifc; 163 struct ifconf ifc;
156 ifc.ifc_len = sizeof(buf); 164 ifc.ifc_len = sizeof(ifrs);
157 ifc.ifc_req = (struct ifreq *) buf; 165 ifc.ifc_req = ifrs;
158 int result=ioctl(sockfd, SIOCGIFCONF, &ifc); 166 result = ioctl(sockfd, SIOCGIFCONF, &ifc);
159 167
160 for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){ 168 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) {
161 struct ifreq *ifr =(struct ifreq *) ptr; 169 struct ifreq *pifr = &ifrs[i];
162 int len = sizeof(struct sockaddr); 170
163#ifdef HAVE_SOCKADDR_SA_LEN 171 ifaces += pifr->ifr_name;
164 if (ifr->ifr_addr.sa_len > len) 172 }
165 len = ifr->ifr_addr.sa_len; /* length > 16 */ 173 } else {
166#endif 174 procFile.open(IO_ReadOnly);
167 ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ 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){ 191
173 case AF_INET: 192 strcpy(ifr.ifr_name, (*it).latin1());
174 sinptr = (struct sockaddr_in *) &ifr->ifr_addr; 193
175 flags=0; 194 qWarning("ifr.ifr_name=%s\n", ifr.ifr_name);
176 195
177 struct ifreq ifcopy; 196 struct ifreq ifcopy;
178 ifcopy=*ifr; 197 ifcopy = ifr;
179 result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy); 198 result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy);
180 flags=ifcopy.ifr_flags; 199 flags=ifcopy.ifr_flags;
181 i = new Interface(this, ifr->ifr_name, false); 200 i = new Interface(this, ifr.ifr_name, false);
182 i->setAttached(true); 201 i->setAttached(true);
@@ -198,2 +217,3 @@ void MainWindowImp::getAllInterfaces(){
198 217
218 qWarning("Adding interface %s to interfaceNames\n", ifr.ifr_name);
199 interfaceNames.insert(i->getInterfaceName(), i); 219 interfaceNames.insert(i->getInterfaceName(), i);
@@ -201,9 +221,2 @@ void MainWindowImp::getAllInterfaces(){
201 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 221 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
202 break;
203
204 default:
205 qDebug(ifr->ifr_name);
206 qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1());
207 break;
208 }
209 } 222 }
@@ -230,3 +243,7 @@ void MainWindowImp::loadModules(const QString &path){
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());
@@ -245,3 +262,3 @@ Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &
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
@@ -252,3 +269,3 @@ Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &
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