* Fixed a bug in BNetworkRoster::GetNextInterface() that caused an endless loop

and always returned the first interface.
* Fixed bug #6436 by using the new BNetworkRoster functionality.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37994 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-08-09 19:12:51 +00:00
parent 4af124a15a
commit f65256c2e7
3 changed files with 18 additions and 31 deletions
+6 -1
View File
@@ -49,6 +49,9 @@ BNetworkRoster::GetNextInterface(uint32* cookie,
{ {
// TODO: think about caching the interfaces! // TODO: think about caching the interfaces!
if (cookie == NULL)
return B_BAD_VALUE;
// get a list of all interfaces // get a list of all interfaces
int socket = ::socket(AF_INET, SOCK_DGRAM, 0); int socket = ::socket(AF_INET, SOCK_DGRAM, 0);
@@ -82,8 +85,10 @@ BNetworkRoster::GetNextInterface(uint32* cookie,
for (uint32 i = 0; interfaces < end; i++) { for (uint32 i = 0; interfaces < end; i++) {
interface.SetTo(interfaces[0].ifr_name); interface.SetTo(interfaces[0].ifr_name);
if (i == *cookie) if (i == *cookie) {
(*cookie)++;
return B_OK; return B_OK;
}
interfaces = (ifreq*)((uint8*)interfaces interfaces = (ifreq*)((uint8*)interfaces
+ _SIZEOF_ADDR_IFREQ(interfaces[0])); + _SIZEOF_ADDR_IFREQ(interfaces[0]));
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2009 Haiku Inc. All rights reserved. * Copyright 2004-2010 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -45,6 +45,8 @@
#include <Directory.h> #include <Directory.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <fs_interface.h> #include <fs_interface.h>
#include <NetworkInterface.h>
#include <NetworkRoster.h>
#include <Path.h> #include <Path.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@@ -235,38 +237,17 @@ EthernetSettingsView::_GatherInterfaces()
{ {
// iterate over all interfaces and retrieve minimal status // iterate over all interfaces and retrieve minimal status
ifconf config;
config.ifc_len = sizeof(config.ifc_value);
if (ioctl(fSocket, SIOCGIFCOUNT, &config, sizeof(struct ifconf)) < 0)
return;
uint32 count = (uint32)config.ifc_value;
if (count == 0)
return;
void* buffer = malloc(count * sizeof(struct ifreq));
if (buffer == NULL)
return;
MemoryDeleter deleter(buffer);
config.ifc_len = count * sizeof(struct ifreq);
config.ifc_buf = buffer;
if (ioctl(fSocket, SIOCGIFCONF, &config, sizeof(struct ifconf)) < 0)
return;
ifreq* interface = (ifreq*)buffer;
fInterfaces.MakeEmpty(); fInterfaces.MakeEmpty();
for (uint32 i = 0; i < count; i++) { BNetworkRoster& roster = BNetworkRoster::Default();
if (strncmp(interface->ifr_name, "loop", 4) && interface->ifr_name[0]) { BNetworkInterface interface;
fInterfaces.AddItem(new BString(interface->ifr_name)); uint32 cookie = 0;
fSettings.AddItem(new Settings(interface->ifr_name));
}
interface = (ifreq*)((addr_t)interface + IF_NAMESIZE while (roster.GetNextInterface(&cookie, interface) == B_OK) {
+ interface->ifr_addr.sa_len); if (strncmp(interface.Name(), "loop", 4) && interface.Name()[0]) {
fInterfaces.AddItem(new BString(interface.Name()));
fSettings.AddItem(new Settings(interface.Name()));
}
} }
} }
+1
View File
@@ -10,6 +10,7 @@ Preference Network :
Settings.cpp Settings.cpp
: be $(HAIKU_NETWORK_LIBS) $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS) : be $(HAIKU_NETWORK_LIBS) $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS)
libbnetapi.so
: Network.rdef : Network.rdef
; ;