summaryrefslogtreecommitdiff
path: root/libopie2/examples/opienet
Unidiff
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 @@
1Makefile*
2moc*
3*moc
4*.o
5~*
6
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 @@
1Makefile*
2moc*
3*moc
4*.o
5~*
6
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 @@
1#include <qdict.h>
2#include <qsocketnotifier.h>
3#include <qstring.h>
4#include <opie2/onetwork.h>
5#include <qapplication.h>
6#include <opie2/opcap.h>
7#include <cerrno>
8#include <cstdio>
9#include <cstdlib>
10#include <cstring>
11
12//======================== Station help class ===============================
13
14class Station
15{
16 public:
17 Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {};
18 ~Station() {};
19
20 QString type;
21 int channel;
22 bool wep;
23 int beacons;
24};
25
26QDict<Station> stations;
27
28//======================== Application class ===============================
29
30class Wellenreiter : public QApplication
31{
32Q_OBJECT
33public:
34 Wellenreiter( int argc, char** argv ) : QApplication( argc, argv )
35 {
36
37 ONetwork* net = ONetwork::instance();
38
39 if ( argc < 3 )
40 {
41 printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] );
42 printf( "\n" );
43 printf( "Valid wireless interfaces (detected) are:\n" );
44
45 ONetwork::InterfaceIterator it = net->iterator();
46 while ( it.current() )
47 {
48 if ( it.current()->isWireless() )
49 {
50 printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(),
51 (const char*) it.current()->macAddress().toString(),
52 (const char*) it.current()->ipV4Address() );
53 }
54 ++it;
55 }
56 exit( -1 );
57 }
58
59 printf( "****************************************************\n" );
60 printf( "* Wellenreiter mini edition 1.0 (C) 2003 M-M-M *\n" );
61 printf( "****************************************************\n" );
62 printf( "\n\n" );
63
64 QString interface( argv[1] );
65 QString driver( argv[2] );
66
67 printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver );
68
69 // sanity checks before downcasting
70 ONetworkInterface* iface = net->interface( interface );
71 if ( !iface )
72 {
73 printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface );
74 exit( -1 );
75 }
76 if ( !iface->isWireless() )
77 {
78 printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface );
79 exit( -1 );
80 }
81
82 // downcast should be safe now
83 wiface = (OWirelessNetworkInterface*) iface;
84 printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() );
85
86 /*
87
88 // ifconfig down the interface - this enable more crash-proof
89 // scanning with drivers like spectrum_cs...
90 if ( wiface->isUp() )
91 {
92 printf( "Interface status is up... switching to down... " );
93 wiface->setUp( false );
94 if ( wiface->isUp() )
95 {
96 printf( "failed (%s). Exiting.\n", strerror( errno ) );
97 exit( -1 );
98 }
99 else
100 {
101 printf( "ok.\n" );
102 }
103 }
104 else
105 printf( "Interface status is already down - good.\n" );
106
107 */
108
109 // ifconfig +promisc the interface to receive all packets
110 if ( !wiface->promiscuousMode() )
111 {
112 printf( "Interface status is not promisc... switching to promisc... " );
113 wiface->setPromiscuousMode( true );
114 if ( !wiface->promiscuousMode() )
115 {
116 printf( "failed (%s). Exiting.\n", strerror( errno ) );
117 exit( -1 );
118 }
119 else
120 {
121 printf( "ok.\n" );
122 }
123 }
124 else
125 printf( "Interface status is already promisc - good.\n" );
126
127 // connect a monitoring strategy to the interface
128 if ( driver == "orinoco" )
129 new OOrinocoMonitoringInterface( wiface );
130 else
131 {
132 printf( "Unknown driver. Exiting\n" );
133 exit( -1 );
134 }
135
136 // enable monitoring mode
137 printf( "Enabling monitor mode...\n" );
138 wiface->setMonitorMode( true );
139
140 // open a packet capturer
141 cap = new OPacketCapturer();
142 cap->open( interface );
143 if ( !cap->isOpen() )
144 {
145 printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) );
146 exit( -1 );
147 }
148
149 // set capturer to non-blocking mode
150 cap->setBlocking( false );
151
152 // start channel hopper
153 wiface->setChannelHopping( 1000 );
154
155 // connect
156 connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
157
158 }
159
160 ~Wellenreiter() {};
161
162public slots:
163 void receivePacket(OPacket* p)
164 {
165 if (!p)
166 {
167 printf( "(empty packet received)\n" );
168 return;
169 }
170
171 OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" );
172
173 if ( beacon )
174 {
175 if ( stations.find( beacon->SSID() ) )
176 stations[beacon->SSID()]->beacons++;
177 else
178 {
179 printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) beacon->SSID() );
180 stations.insert( beacon->SSID(), new Station( "unknown", wiface->channel(),
181 ((OWaveLanPacket*) beacon->parent())->usesWep() ) );
182 }
183 }
184 }
185private:
186 OPacketCapturer* cap;
187 OWirelessNetworkInterface* wiface;
188};
189
190
191int main( int argc, char** argv )
192{
193 Wellenreiter w( argc, argv );
194 w.exec();
195 return 0;
196}
197
198#include "miniwellenreiter.moc"
199
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 @@
1TEMPLATE = app
2CONFIG = qt warn_on debug
3HEADERS =
4SOURCES = miniwellenreiter.cpp
5INCLUDEPATH += $(OPIEDIR)/include
6DEPENDPATH += $(OPIEDIR)/include
7LIBS += -lopiecore2 -lopienet2
8TARGET = miniwellenreiter
9MOC_DIR = moc
10OBJECTS_DIR = obj
11
12include ( $(OPIEDIR)/include.pro )
13
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 @@
1Makefile*
2moc*
3*moc
4*.o
5~*
6
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 @@
1#include <opie2/onetwork.h>
2
3int main( int argc, char** argv )
4{
5 qDebug( "OPIE Network Demo" );
6
7 ONetwork* net = ONetwork::instance();
8
9 ONetwork::InterfaceIterator it = net->iterator();
10
11 while ( it.current() )
12 {
13 qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() );
14 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() );
15 qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() );
16 if ( it.current()->isWireless() )
17 {
18 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() );
19 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() );
20 qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() );
21 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() );
22 qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() );
23
24 //if ( iface->mode() == OWirelessNetworkInterface::adhoc )
25 //{
26 qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP() );
27 //}
28
29 }
30 ++it;
31 }
32
33 return 0;
34
35}
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 @@
1TEMPLATE = app
2CONFIG = qt warn_on debug
3HEADERS =
4SOURCES = onetworkdemo.cpp
5INCLUDEPATH += $(OPIEDIR)/include
6DEPENDPATH += $(OPIEDIR)/include
7LIBS += -lopiecore2 -lopienet2
8TARGET = onetworkdemo
9MOC_DIR = moc
10OBJECTS_DIR = obj
11
12include ( $(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 @@
1TEMPLATE = subdirs
2SUBDIRS = miniwellenreiter onetworkdemo
3