summaryrefslogtreecommitdiff
path: root/libopie2/examples/opienet
authormickeyl <mickeyl>2003-03-28 15:11:52 (UTC)
committer mickeyl <mickeyl>2003-03-28 15:11:52 (UTC)
commit11304d02942e9fa493e4e80943a828f9c65f6772 (patch) (side-by-side diff)
treea0223c10c067e1afc70d15c2b82be3f3c15e41ae /libopie2/examples/opienet
parentb271d575fa05cf570a1a829136517761bd47e69b (diff)
downloadopie-11304d02942e9fa493e4e80943a828f9c65f6772.zip
opie-11304d02942e9fa493e4e80943a828f9c65f6772.tar.gz
opie-11304d02942e9fa493e4e80943a828f9c65f6772.tar.bz2
skeleton and the start of libopie2, please read README, ROADMAP and STATUS and comment...
Diffstat (limited to 'libopie2/examples/opienet') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opienet/.cvsignore6
-rw-r--r--libopie2/examples/opienet/miniwellenreiter/.cvsignore6
-rw-r--r--libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp199
-rw-r--r--libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.pro13
-rw-r--r--libopie2/examples/opienet/onetworkdemo/.cvsignore6
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp35
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.pro12
-rw-r--r--libopie2/examples/opienet/opienet.pro3
8 files changed, 280 insertions, 0 deletions
diff --git a/libopie2/examples/opienet/.cvsignore b/libopie2/examples/opienet/.cvsignore
new file mode 100644
index 0000000..8f7300c
--- a/dev/null
+++ b/libopie2/examples/opienet/.cvsignore
@@ -0,0 +1,6 @@
+Makefile*
+moc*
+*moc
+*.o
+~*
+
diff --git a/libopie2/examples/opienet/miniwellenreiter/.cvsignore b/libopie2/examples/opienet/miniwellenreiter/.cvsignore
new file mode 100644
index 0000000..8f7300c
--- a/dev/null
+++ b/libopie2/examples/opienet/miniwellenreiter/.cvsignore
@@ -0,0 +1,6 @@
+Makefile*
+moc*
+*moc
+*.o
+~*
+
diff --git a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
new file mode 100644
index 0000000..aec9cc7
--- a/dev/null
+++ b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
@@ -0,0 +1,199 @@
+#include <qdict.h>
+#include <qsocketnotifier.h>
+#include <qstring.h>
+#include <opie2/onetwork.h>
+#include <qapplication.h>
+#include <opie2/opcap.h>
+#include <cerrno>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+//======================== Station help class ===============================
+
+class Station
+{
+ public:
+ Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {};
+ ~Station() {};
+
+ QString type;
+ int channel;
+ bool wep;
+ int beacons;
+};
+
+QDict<Station> stations;
+
+//======================== Application class ===============================
+
+class Wellenreiter : public QApplication
+{
+Q_OBJECT
+public:
+ Wellenreiter( int argc, char** argv ) : QApplication( argc, argv )
+ {
+
+ ONetwork* net = ONetwork::instance();
+
+ if ( argc < 3 )
+ {
+ printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] );
+ printf( "\n" );
+ printf( "Valid wireless interfaces (detected) are:\n" );
+
+ ONetwork::InterfaceIterator it = net->iterator();
+ while ( it.current() )
+ {
+ if ( it.current()->isWireless() )
+ {
+ printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(),
+ (const char*) it.current()->macAddress().toString(),
+ (const char*) it.current()->ipV4Address() );
+ }
+ ++it;
+ }
+ exit( -1 );
+ }
+
+ printf( "****************************************************\n" );
+ printf( "* Wellenreiter mini edition 1.0 (C) 2003 M-M-M *\n" );
+ printf( "****************************************************\n" );
+ printf( "\n\n" );
+
+ QString interface( argv[1] );
+ QString driver( argv[2] );
+
+ printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver );
+
+ // sanity checks before downcasting
+ ONetworkInterface* iface = net->interface( interface );
+ if ( !iface )
+ {
+ printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface );
+ exit( -1 );
+ }
+ if ( !iface->isWireless() )
+ {
+ printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface );
+ exit( -1 );
+ }
+
+ // downcast should be safe now
+ wiface = (OWirelessNetworkInterface*) iface;
+ printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() );
+
+ /*
+
+ // ifconfig down the interface - this enable more crash-proof
+ // scanning with drivers like spectrum_cs...
+ if ( wiface->isUp() )
+ {
+ printf( "Interface status is up... switching to down... " );
+ wiface->setUp( false );
+ if ( wiface->isUp() )
+ {
+ printf( "failed (%s). Exiting.\n", strerror( errno ) );
+ exit( -1 );
+ }
+ else
+ {
+ printf( "ok.\n" );
+ }
+ }
+ else
+ printf( "Interface status is already down - good.\n" );
+
+ */
+
+ // ifconfig +promisc the interface to receive all packets
+ if ( !wiface->promiscuousMode() )
+ {
+ printf( "Interface status is not promisc... switching to promisc... " );
+ wiface->setPromiscuousMode( true );
+ if ( !wiface->promiscuousMode() )
+ {
+ printf( "failed (%s). Exiting.\n", strerror( errno ) );
+ exit( -1 );
+ }
+ else
+ {
+ printf( "ok.\n" );
+ }
+ }
+ else
+ printf( "Interface status is already promisc - good.\n" );
+
+ // connect a monitoring strategy to the interface
+ if ( driver == "orinoco" )
+ new OOrinocoMonitoringInterface( wiface );
+ else
+ {
+ printf( "Unknown driver. Exiting\n" );
+ exit( -1 );
+ }
+
+ // enable monitoring mode
+ printf( "Enabling monitor mode...\n" );
+ wiface->setMonitorMode( true );
+
+ // open a packet capturer
+ cap = new OPacketCapturer();
+ cap->open( interface );
+ if ( !cap->isOpen() )
+ {
+ printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) );
+ exit( -1 );
+ }
+
+ // set capturer to non-blocking mode
+ cap->setBlocking( false );
+
+ // start channel hopper
+ wiface->setChannelHopping( 1000 );
+
+ // connect
+ connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
+
+ }
+
+ ~Wellenreiter() {};
+
+public slots:
+ void receivePacket(OPacket* p)
+ {
+ if (!p)
+ {
+ printf( "(empty packet received)\n" );
+ return;
+ }
+
+ OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" );
+
+ if ( beacon )
+ {
+ if ( stations.find( beacon->SSID() ) )
+ stations[beacon->SSID()]->beacons++;
+ else
+ {
+ printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) beacon->SSID() );
+ stations.insert( beacon->SSID(), new Station( "unknown", wiface->channel(),
+ ((OWaveLanPacket*) beacon->parent())->usesWep() ) );
+ }
+ }
+ }
+private:
+ OPacketCapturer* cap;
+ OWirelessNetworkInterface* wiface;
+};
+
+
+int main( int argc, char** argv )
+{
+ Wellenreiter w( argc, argv );
+ w.exec();
+ return 0;
+}
+
+#include "miniwellenreiter.moc"
+
diff --git a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.pro b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.pro
new file mode 100644
index 0000000..7ce535c
--- a/dev/null
+++ b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+CONFIG = qt warn_on debug
+HEADERS =
+SOURCES = miniwellenreiter.cpp
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+LIBS += -lopiecore2 -lopienet2
+TARGET = miniwellenreiter
+MOC_DIR = moc
+OBJECTS_DIR = obj
+
+include ( $(OPIEDIR)/include.pro )
+
diff --git a/libopie2/examples/opienet/onetworkdemo/.cvsignore b/libopie2/examples/opienet/onetworkdemo/.cvsignore
new file mode 100644
index 0000000..8f7300c
--- a/dev/null
+++ b/libopie2/examples/opienet/onetworkdemo/.cvsignore
@@ -0,0 +1,6 @@
+Makefile*
+moc*
+*moc
+*.o
+~*
+
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
new file mode 100644
index 0000000..7703b4c
--- a/dev/null
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -0,0 +1,35 @@
+#include <opie2/onetwork.h>
+
+int main( int argc, char** argv )
+{
+ qDebug( "OPIE Network Demo" );
+
+ ONetwork* net = ONetwork::instance();
+
+ ONetwork::InterfaceIterator it = net->iterator();
+
+ while ( it.current() )
+ {
+ qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() );
+ qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() );
+ qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() );
+ if ( it.current()->isWireless() )
+ {
+ OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() );
+ qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() );
+ qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() );
+ qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() );
+ qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() );
+
+ //if ( iface->mode() == OWirelessNetworkInterface::adhoc )
+ //{
+ qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP() );
+ //}
+
+ }
+ ++it;
+ }
+
+ return 0;
+
+}
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.pro b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.pro
new file mode 100644
index 0000000..2d71aa0
--- a/dev/null
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.pro
@@ -0,0 +1,12 @@
+TEMPLATE = app
+CONFIG = qt warn_on debug
+HEADERS =
+SOURCES = onetworkdemo.cpp
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+LIBS += -lopiecore2 -lopienet2
+TARGET = onetworkdemo
+MOC_DIR = moc
+OBJECTS_DIR = obj
+
+include ( $(OPIEDIR)/include.pro )
diff --git a/libopie2/examples/opienet/opienet.pro b/libopie2/examples/opienet/opienet.pro
new file mode 100644
index 0000000..c7800a9
--- a/dev/null
+++ b/libopie2/examples/opienet/opienet.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+SUBDIRS = miniwellenreiter onetworkdemo
+