void NetServer::_ConfigureDevices(int socket, const char* startPath, BMessage* suggestedInterface) { BDirectory directory(startPath); BEntry entry; while (directory.GetNextEntry(&entry) == B_OK) { char name[B_FILE_NAME_LENGTH]; struct stat stat; BPath path; if (entry.GetName(name) != B_OK || !strcmp(name, "stack") || entry.GetPath(&path) != B_OK || entry.GetStat(&stat) != B_OK) continue; if (S_ISBLK(stat.st_mode) || S_ISCHR(stat.st_mode)) { if (suggestedInterface != NULL && suggestedInterface->RemoveName("device") == B_OK && suggestedInterface->AddString("device", path.Path()) == B_OK && _ConfigureInterface(socket, *suggestedInterface) == B_OK) suggestedInterface = NULL; else _ConfigureDevice(socket, path.Path()); } else if (entry.IsDirectory()) _ConfigureDevices(socket, path.Path(), suggestedInterface); } }
void NetServer::_HandleDeviceMonitor(int socket, BMessage* message) { int32 opcode; if (message->FindInt32("opcode", &opcode) != B_OK || (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) _ConfigureDevice(socket, path); else { ifreq request; 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(), path, strerror(errno)); } } }
void NetServer::_HandleDeviceMonitor(int socket, BMessage* message) { int32 opcode; if (message->FindInt32("opcode", &opcode) != B_OK || (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) _ConfigureDevice(socket, path); else _RemoveInterface(socket, path); }