Some simplifications (thanks Axel):

* Don't watch for moved entries
* Ask the network stack to delete the named interface 


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34648 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2009-12-12 20:22:10 +00:00
parent a195cce7b5
commit 0b604ab644
1 changed files with 9 additions and 53 deletions

View File

@ -280,8 +280,7 @@ NetServer::ReadyToRun()
_StartServices();
BPrivate::BPathMonitor::StartWatching("/dev/net", B_ENTRY_CREATED
| B_ENTRY_REMOVED | B_ENTRY_MOVED | B_WATCH_FILES_ONLY
| B_WATCH_RECURSIVELY, this);
| B_ENTRY_REMOVED | B_WATCH_FILES_ONLY | B_WATCH_RECURSIVELY, this);
}
@ -879,71 +878,28 @@ void
NetServer::_HandleDeviceMonitor(int socket, BMessage* message)
{
int32 opcode;
if (message->FindInt32("opcode", &opcode) != B_OK)
if (message->FindInt32("opcode", &opcode) != B_OK
|| (opcode != B_ENTRY_CREATED && opcode != B_ENTRY_REMOVED))
return;
if (opcode != B_ENTRY_CREATED && opcode != B_ENTRY_REMOVED)
return;
const char* path;
const char* watchedPath;
if (message->FindString("watched_path", &watchedPath) != B_OK
|| message->FindString("path", &path) != B_OK)
return;
if (opcode == B_ENTRY_CREATED) {
if (opcode == B_ENTRY_CREATED)
_ConfigureDevice(socket, path);
return;
}
ifconf config;
config.ifc_len = sizeof(config.ifc_value);
if (ioctl(socket, SIOCGIFCOUNT, &config, sizeof(struct ifconf)) < 0)
return;
uint32 count = (uint32)config.ifc_value;
if (count == 0) {
// there are no interfaces yet
return;
}
void *buffer = malloc(count * sizeof(struct ifreq));
if (buffer == NULL) {
fprintf(stderr, "%s: Out of memory.\n", Name());
return;
}
config.ifc_len = count * sizeof(struct ifreq);
config.ifc_buf = buffer;
if (ioctl(socket, SIOCGIFCONF, &config, sizeof(struct ifconf)) < 0) {
free(buffer);
return;
}
ifreq *interface = (ifreq *)buffer;
int32 pathLength = strlen(path);
for (uint32 i = 0; i < count; i++) {
if (strncmp(interface->ifr_name, path, pathLength)) {
interface = (ifreq *)((addr_t)interface + IF_NAMESIZE
+ interface->ifr_addr.sa_len);
continue;
}
else {
ifreq request;
if (!prepare_request(request, interface->ifr_name))
break;
if (!prepare_request(request, path))
return;
if (ioctl(socket, SIOCDIFADDR, &request, sizeof(request)) < 0) {
fprintf(stderr, "%s: Could not delete interface %s: %s\n",
Name(), interface->ifr_name, strerror(errno));
Name(), path, strerror(errno));
}
break;
}
free(buffer);
}