author | mickeyl <mickeyl> | 2003-03-28 15:11:52 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-03-28 15:11:52 (UTC) |
commit | 11304d02942e9fa493e4e80943a828f9c65f6772 (patch) (unidiff) | |
tree | a0223c10c067e1afc70d15c2b82be3f3c15e41ae /libopie2/examples/opienet/miniwellenreiter | |
parent | b271d575fa05cf570a1a829136517761bd47e69b (diff) | |
download | opie-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/miniwellenreiter') (more/less context) (ignore whitespace changes)
3 files changed, 218 insertions, 0 deletions
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 @@ | |||
1 | Makefile* | ||
2 | moc* | ||
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 | |||
14 | class 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 | |||
26 | QDict<Station> stations; | ||
27 | |||
28 | //======================== Application class =============================== | ||
29 | |||
30 | class Wellenreiter : public QApplication | ||
31 | { | ||
32 | Q_OBJECT | ||
33 | public: | ||
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 | |||
162 | public 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 | } | ||
185 | private: | ||
186 | OPacketCapturer* cap; | ||
187 | OWirelessNetworkInterface* wiface; | ||
188 | }; | ||
189 | |||
190 | |||
191 | int 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 @@ | |||
1 | TEMPLATE = app | ||
2 | CONFIG = qt warn_on debug | ||
3 | HEADERS = | ||
4 | SOURCES = miniwellenreiter.cpp | ||
5 | INCLUDEPATH += $(OPIEDIR)/include | ||
6 | DEPENDPATH += $(OPIEDIR)/include | ||
7 | LIBS += -lopiecore2 -lopienet2 | ||
8 | TARGET = miniwellenreiter | ||
9 | MOC_DIR = moc | ||
10 | OBJECTS_DIR = obj | ||
11 | |||
12 | include ( $(OPIEDIR)/include.pro ) | ||
13 | |||