/* $Id: WLStumbler.cpp,v 1.1 2002/09/16 09:05:28 ghandi Exp $ */ /* * Simple command-line wireless stumbler as an example of the Viha WiFi API. * * To compile: c++ -framework WiFi -o Stumbler Stumbler.cpp * * (doesn't build w/ Jag Dev tools yet, I'll fix this soon, this is just * example source anyway, get the binary distro for the Stumbler binary) */ #include #include #include #include #include #include #include #include // Stupid C++ template crap struct eqstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) == 0; } }; static int quit = 0; static int quit_cc = 0; void* change_channels(void* packetSource) { unsigned short channel; WLDriverInterface* wldi = ((WLPacketSource*)packetSource)->getDriverInterface(); while (!quit_cc) { channel = wldi->getChannel(); channel = (channel % 11) + 1; wldi->stopCapture(); wldi->startCapture(channel); sleep(1); } return NULL; } void sigint(int sig) { quit = 1; printf("\nQuitting...\n"); } int main(int argc, char* argv[]) { /* I promise I'll ditch the STL soon ... */ hash_map, eqstr> networks; WLPacketSource* packetSource = new WLPacketSource(); WLFrame* frame; pthread_t channel_thread; signal(SIGINT, sigint); /* * Opening the packet source loads the driver and connects to it * via IOKit user client mechanism */ packetSource->open(); pthread_create(&channel_thread, NULL, change_channels, packetSource); printf("Channel | BSSID | AP/IBSS | PT/WEP | SSID\n"); for (int i = 0; i < 70; i++) printf("-"); printf("\n"); while (!quit && (frame = packetSource->readPacket()) != NULL) { IEEE80211Frame* f = new IEEE80211Frame(frame); if (f->getType() == 0 && f->getSubtype() == 8) { IEEE80211BeaconFrame* bf = new IEEE80211BeaconFrame(f->getFrameBody()); IEEE802Address* bssid = f->getBasicServiceSetIdentifier(); char* bssidStr = (char*)malloc(18); snprintf(bssidStr, 18, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", bssid->bytes[1], bssid->bytes[0], bssid->bytes[3], bssid->bytes[2], bssid->bytes[5], bssid->bytes[4]); /* * If it's not already in the hashmap, print out some info * about the network. * * If you want to be resistant against hacks like FakeAP, just * require two beacons before identifying it as a new network * and printing it out. */ if (!networks.count(bssidStr)) { networks[bssidStr] = bf; printf(" %.2d | %s |", bf->getChannel(), bssidStr); if (bf->isESS()) printf(" AP |"); else if (bf->isIBSS()) printf(" IBSS |"); else printf(" ???? |"); if (bf->isWEP()) printf(" WEP |"); else printf(" PT |"); printf(" '%s'\n", bf->getSSID()); } else { free(bssidStr); delete bf; } } } quit_cc = 1; /* * closing the packetsource unloads the WLanDriver and reloads the * AppleAirPort driver. */ packetSource->close(); delete packetSource; return 0; }