/* IfMan.cpp Interface Manager for Aladin Copyright (C) 2003 Mike Saywell Southampton Open Wireless Network, http://www.sown.org.uk ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ This class controls which interfaces Aladin runs on, in particular it will dynmaically add and remove entries for HostAP WDS interfaces. It is responsible for creating, starting and stopping the RevArpDaemon processes. ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "IfMan.h" IfMan::IfMan(AddressManager* addrMan) { this->addrMan = NULL; this->addrMan = addrMan; } void* IfMan::dowdsMonitor(struct Wrapper* wrap) { char* hostap_dev = wrap->dev; if (DEBUG) { cout << "Monitoring hostap device " << hostap_dev << endl; } char line[256]; char wdsPath[128]; wdsPath[0] = '\0'; strcat(wdsPath, "/proc/net/hostap/"); strcat(wdsPath, hostap_dev); strcat(wdsPath, "/wds"); ifstream wdsFile; if (!wdsFile) { cerr << "FATAL: Failed to open " << wdsPath << " for reading.\n"; exit(1); } while(wrap->run) { wdsFile.open(wdsPath); // Poll for changes in link status // Return pointer to beginning wdsFile.clear(); wdsFile.seekg(0, ios::beg); if (DEBUG) { cout << endl; cout << "Polling interfaces..." << endl; } while (wdsFile.getline(line, 256)) { string interface(strtok(line, " \t")); // Drop remaining tokens on the line while(strtok(NULL, " \t")); if(ifmap[interface] && ifmap[interface]->rARPd->isRunning()) { continue; } else { this->enable((char *) interface.c_str()); } } wdsFile.close(); sleep(5); } delete wrap; } void IfMan::enable(char* if_name) { if (DEBUG) { cout << "Enabling aladin on interface " << if_name << endl; } string iface(if_name); if(ifmap[iface] && ifmap[iface]->rARPd->isRunning()) { cerr << "Interface manager already running on " << if_name << "!"; return; } ifmap[iface] = new struct Interface; ifmap[iface]->if_index = if_nametoindex(if_name); ifmap[if_name]->rARPd = new RevArpDaemon(this->addrMan, ifmap[iface]->if_index); ifmap[if_name]->rARPd->start(); } void IfMan::disable(char* if_name) { if (DEBUG) { cout << "Disabling aladin on interface " << if_name << endl; } cout << "Not implemented!" << endl; } void IfMan::wdsMonitor(char* if_name) { struct Wrapper* wrap = new struct Wrapper; strncpy(wrap->dev, if_name, 256); wrap->ifman = this; wrap->run = true; pthread_create(&wrap->thread, NULL, &imLauncher, wrap); } void* imLauncher(void *obj) { struct Wrapper* foo = (struct Wrapper*) obj; return static_cast(foo->ifman)->dowdsMonitor(foo); }