From 0b604ab6443a24d4a07ec6d4ea33ed5224baa83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sat, 12 Dec 2009 20:22:10 +0000 Subject: [PATCH] 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 --- src/servers/net/NetServer.cpp | 62 +++++------------------------------ 1 file changed, 9 insertions(+), 53 deletions(-) diff --git a/src/servers/net/NetServer.cpp b/src/servers/net/NetServer.cpp index 6808a3f6f9..35bac9fdd2 100644 --- a/src/servers/net/NetServer.cpp +++ b/src/servers/net/NetServer.cpp @@ -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); - - }