author | mickeyl <mickeyl> | 2005-05-19 11:59:32 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-05-19 11:59:32 (UTC) |
commit | ed7ba8b228d3d0ffae9c9b68900b7f723d7ade4a (patch) (unidiff) | |
tree | 83b59755f58747cdb7e543a4c237e9e217b03fbd /libopie2/opienet | |
parent | cb243f00d12c5fc40de02e7f9f20009b52303a66 (diff) | |
download | opie-ed7ba8b228d3d0ffae9c9b68900b7f723d7ade4a.zip opie-ed7ba8b228d3d0ffae9c9b68900b7f723d7ade4a.tar.gz opie-ed7ba8b228d3d0ffae9c9b68900b7f723d7ade4a.tar.bz2 |
- add linux pcmcia subsystem wrapper: OPcmciaSystem and OPcmciaCard
- move linux-only subsystems in subdirectory linux
- minor header cleanups
-rw-r--r-- | libopie2/opienet/opcap.cpp | 2 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 1 |
2 files changed, 1 insertions, 2 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index eafbeea..c548356 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -1,268 +1,268 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; version 2 of the License. | 11 | - . .-<_> .<> Foundation; version 2 of the License. |
12 | ._= =} : | 12 | ._= =} : |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "udp_ports.h" | 31 | #include "udp_ports.h" |
32 | #include "opcap.h" | 32 | #include "opcap.h" |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/odebug.h> | 35 | #include <opie2/odebug.h> |
36 | using namespace Opie::Core; | 36 | using namespace Opie::Core; |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) | 39 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) |
40 | #include <qsocketnotifier.h> | 40 | #include <qsocketnotifier.h> |
41 | #include <qobjectlist.h> | 41 | #include <qobjectlist.h> |
42 | 42 | ||
43 | /* STD */ | 43 | /* STD */ |
44 | #include <sys/time.h> | 44 | #include <sys/time.h> |
45 | #include <sys/types.h> | 45 | #include <sys/types.h> |
46 | #include <assert.h> | 46 | #include <assert.h> |
47 | #include <unistd.h> | 47 | #include <unistd.h> |
48 | #include <string.h> | 48 | #include <string.h> |
49 | 49 | ||
50 | namespace Opie { | 50 | namespace Opie { |
51 | namespace Net { | 51 | namespace Net { |
52 | 52 | ||
53 | /*====================================================================================== | 53 | /*====================================================================================== |
54 | * OPacket | 54 | * OPacket |
55 | *======================================================================================*/ | 55 | *======================================================================================*/ |
56 | 56 | ||
57 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) | 57 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) |
58 | :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) | 58 | :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) |
59 | { | 59 | { |
60 | 60 | ||
61 | _data = new unsigned char[ header.len ]; | 61 | _data = new unsigned char[ header.len ]; |
62 | assert( _data ); | 62 | assert( _data ); |
63 | memcpy( const_cast<unsigned char*>(_data), data, header.len ); | 63 | memcpy( const_cast<unsigned char*>(_data), data, header.len ); |
64 | // We have to copy the data structure here, because the 'data' pointer handed by libpcap | 64 | // We have to copy the data structure here, because the 'data' pointer handed by libpcap |
65 | // points to an internal region which is reused by lipcap. | 65 | // points to an internal region which is reused by lipcap. |
66 | odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; | 66 | odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; |
67 | _end = (unsigned char*) _data + header.len; | 67 | _end = (unsigned char*) _data + header.len; |
68 | 68 | ||
69 | switch ( datalink ) | 69 | switch ( datalink ) |
70 | { | 70 | { |
71 | case DLT_EN10MB: | 71 | case DLT_EN10MB: |
72 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; | 72 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; |
73 | new OEthernetPacket( _end, (const struct ether_header*) _data, this ); | 73 | new OEthernetPacket( _end, (const struct ether_header*) _data, this ); |
74 | break; | 74 | break; |
75 | 75 | ||
76 | case DLT_IEEE802_11: | 76 | case DLT_IEEE802_11: |
77 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; | 77 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; |
78 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); | 78 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); |
79 | break; | 79 | break; |
80 | 80 | ||
81 | case DLT_PRISM_HEADER: | 81 | case DLT_PRISM_HEADER: |
82 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; | 82 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; |
83 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); | 83 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); |
84 | break; | 84 | break; |
85 | 85 | ||
86 | default: | 86 | default: |
87 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; | 87 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
92 | OPacket::~OPacket() | 92 | OPacket::~OPacket() |
93 | { | 93 | { |
94 | odebug << "~OPacket( " << name() << " )" << oendl; | 94 | odebug << "~OPacket( " << name() << " )" << oendl; |
95 | delete [] _data; | 95 | delete [] _data; |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
99 | timevalstruct OPacket::timeval() const | 99 | timevalstruct OPacket::timeval() const |
100 | { | 100 | { |
101 | return _hdr.ts; | 101 | return _hdr.ts; |
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
105 | int OPacket::caplen() const | 105 | int OPacket::caplen() const |
106 | { | 106 | { |
107 | return _hdr.caplen; | 107 | return _hdr.caplen; |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | 111 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) |
112 | { | 112 | { |
113 | if (!l) return; | 113 | if (!l) return; |
114 | QObject* o = l->first(); | 114 | QObject* o = l->first(); |
115 | while ( o ) | 115 | while ( o ) |
116 | { | 116 | { |
117 | stats[o->name()]++; | 117 | stats[o->name()]++; |
118 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); | 118 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); |
119 | o = l->next(); | 119 | o = l->next(); |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | QString OPacket::dumpStructure() const | 124 | QString OPacket::dumpStructure() const |
125 | { | 125 | { |
126 | return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; | 126 | return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | QString OPacket::_dumpStructure( QObjectList* l ) const | 130 | QString OPacket::_dumpStructure( QObjectList* l ) const |
131 | { | 131 | { |
132 | if (!l) return QString::null; | 132 | if (!l) return QString::null; |
133 | QObject* o = l->first(); | 133 | QObject* o = l->first(); |
134 | QString str(" "); | 134 | QString str(" "); |
135 | 135 | ||
136 | while ( o ) | 136 | while ( o ) |
137 | { | 137 | { |
138 | str.append( o->name() ); | 138 | str.append( o->name() ); |
139 | str.append( " |" ); | 139 | str.append( " |" ); |
140 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); | 140 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); |
141 | o = l->next(); | 141 | o = l->next(); |
142 | } | 142 | } |
143 | return str; | 143 | return str; |
144 | } | 144 | } |
145 | 145 | ||
146 | QString OPacket::dump( int bpl ) const | 146 | QString OPacket::dump( int bpl ) const |
147 | { | 147 | { |
148 | static int index = 0; | 148 | static int index = 0; |
149 | index++; | 149 | index++; |
150 | int len = _hdr.caplen; | 150 | int len = _hdr.caplen; |
151 | QString str( "000:" ); | 151 | QString str( "000:" ); |
152 | QString tmp; | 152 | QString tmp; |
153 | QString bytes; | 153 | QString bytes; |
154 | QString chars; | 154 | QString chars; |
155 | 155 | ||
156 | for ( int i = 0; i < len; ++i ) | 156 | for ( int i = 0; i < len; ++i ) |
157 | { | 157 | { |
158 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | 158 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); |
159 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | 159 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); |
160 | else chars.append( '.' ); | 160 | else chars.append( '.' ); |
161 | 161 | ||
162 | if ( !((i+1) % bpl) ) | 162 | if ( !((i+1) % bpl) ) |
163 | { | 163 | { |
164 | str.append( bytes ); | 164 | str.append( bytes ); |
165 | str.append( ' ' ); | 165 | str.append( ' ' ); |
166 | str.append( chars ); | 166 | str.append( chars ); |
167 | str.append( '\n' ); | 167 | str.append( '\n' ); |
168 | tmp.sprintf( "%03X:", i+1 ); str.append( tmp ); | 168 | tmp.sprintf( "%03X:", i+1 ); str.append( tmp ); |
169 | bytes = ""; | 169 | bytes = ""; |
170 | chars = ""; | 170 | chars = ""; |
171 | } | 171 | } |
172 | 172 | ||
173 | } | 173 | } |
174 | if ( (len % bpl) ) | 174 | if ( (len % bpl) ) |
175 | { | 175 | { |
176 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); | 176 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); |
177 | str.append( chars ); | 177 | str.append( chars ); |
178 | } | 178 | } |
179 | str.append( '\n' ); | 179 | str.append( '\n' ); |
180 | return str; | 180 | return str; |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | int OPacket::len() const | 184 | int OPacket::len() const |
185 | { | 185 | { |
186 | return _hdr.len; | 186 | return _hdr.len; |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) | 190 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) |
191 | { | 191 | { |
192 | s << p.dumpStructure(); | 192 | s << p.dumpStructure(); |
193 | return s; | 193 | return s; |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | /*====================================================================================== | 197 | /*====================================================================================== |
198 | * OEthernetPacket | 198 | * OEthernetPacket |
199 | *======================================================================================*/ | 199 | *======================================================================================*/ |
200 | 200 | ||
201 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) | 201 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
202 | :QObject( parent, "Ethernet" ), _ether( data ) | 202 | :QObject( parent, "Ethernet" ), _ether( data ) |
203 | { | 203 | { |
204 | 204 | ||
205 | odebug << "Source = " << sourceAddress().toString() << oendl; | 205 | odebug << "Source = " << sourceAddress().toString() << oendl; |
206 | odebug << "Destination = " << destinationAddress().toString() << oendl; | 206 | odebug << "Destination = " << destinationAddress().toString() << oendl; |
207 | 207 | ||
208 | if ( sourceAddress() == OMacAddress::broadcast ) | 208 | if ( sourceAddress() == OMacAddress::broadcast ) |
209 | odebug << "Source is broadcast address" << oendl; | 209 | odebug << "Source is broadcast address" << oendl; |
210 | if ( destinationAddress() == OMacAddress::broadcast ) | 210 | if ( destinationAddress() == OMacAddress::broadcast ) |
211 | odebug << "Destination is broadcast address" << oendl; | 211 | odebug << "Destination is broadcast address" << oendl; |
212 | 212 | ||
213 | switch ( type() ) | 213 | switch ( type() ) |
214 | { | 214 | { |
215 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 215 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
216 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 216 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
217 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } | 217 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } |
218 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; | 218 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; |
219 | } | 219 | } |
220 | 220 | ||
221 | } | 221 | } |
222 | 222 | ||
223 | 223 | ||
224 | OEthernetPacket::~OEthernetPacket() | 224 | OEthernetPacket::~OEthernetPacket() |
225 | { | 225 | { |
226 | } | 226 | } |
227 | 227 | ||
228 | 228 | ||
229 | OMacAddress OEthernetPacket::sourceAddress() const | 229 | OMacAddress OEthernetPacket::sourceAddress() const |
230 | { | 230 | { |
231 | return OMacAddress( _ether->ether_shost ); | 231 | return OMacAddress( _ether->ether_shost ); |
232 | } | 232 | } |
233 | 233 | ||
234 | 234 | ||
235 | OMacAddress OEthernetPacket::destinationAddress() const | 235 | OMacAddress OEthernetPacket::destinationAddress() const |
236 | { | 236 | { |
237 | return OMacAddress( _ether->ether_dhost ); | 237 | return OMacAddress( _ether->ether_dhost ); |
238 | } | 238 | } |
239 | 239 | ||
240 | int OEthernetPacket::type() const | 240 | int OEthernetPacket::type() const |
241 | { | 241 | { |
242 | return ntohs( _ether->ether_type ); | 242 | return ntohs( _ether->ether_type ); |
243 | } | 243 | } |
244 | 244 | ||
245 | 245 | ||
246 | /*====================================================================================== | 246 | /*====================================================================================== |
247 | * OIPPacket | 247 | * OIPPacket |
248 | *======================================================================================*/ | 248 | *======================================================================================*/ |
249 | 249 | ||
250 | 250 | ||
251 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) | 251 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
252 | :QObject( parent, "IP" ), _iphdr( data ) | 252 | :QObject( parent, "IP" ), _iphdr( data ) |
253 | { | 253 | { |
254 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; | 254 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; |
255 | 255 | ||
256 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; | 256 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; |
257 | odebug << " toAddress = " << toIPAddress().toString() << oendl; | 257 | odebug << " toAddress = " << toIPAddress().toString() << oendl; |
258 | 258 | ||
259 | switch ( protocol() ) | 259 | switch ( protocol() ) |
260 | { | 260 | { |
261 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; | 261 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
262 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; | 262 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
263 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; | 263 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; |
264 | } | 264 | } |
265 | 265 | ||
266 | } | 266 | } |
267 | 267 | ||
268 | OIPPacket::~OIPPacket() | 268 | OIPPacket::~OIPPacket() |
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 149e573..8b415a2 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -1,317 +1,316 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; version 2 of the License. | 11 | - . .-<_> .<> Foundation; version 2 of the License. |
12 | ._= =} : | 12 | ._= =} : |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifndef OPCAP_H | 31 | #ifndef OPCAP_H |
32 | #define OPCAP_H | 32 | #define OPCAP_H |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/onetutils.h> | 35 | #include <opie2/onetutils.h> |
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | #include <qevent.h> | 38 | #include <qevent.h> |
39 | #include <qfile.h> | 39 | #include <qfile.h> |
40 | #include <qhostaddress.h> | 40 | #include <qhostaddress.h> |
41 | #include <qobject.h> | 41 | #include <qobject.h> |
42 | #include <qstring.h> | 42 | #include <qstring.h> |
43 | #include <qtextstream.h> | 43 | #include <qtextstream.h> |
44 | #include <qmap.h> | 44 | #include <qmap.h> |
45 | 45 | ||
46 | /* STD */ | 46 | /* STD */ |
47 | extern "C" // work around a bpf/pcap conflict in recent headers | 47 | extern "C" // work around a bpf/pcap conflict in recent headers |
48 | { | 48 | { |
49 | #include <pcap.h> | 49 | #include <pcap.h> |
50 | } | 50 | } |
51 | #include <netinet/ether.h> | 51 | #include <netinet/ether.h> |
52 | #include <netinet/ip.h> | 52 | #include <netinet/ip.h> |
53 | #include <netinet/udp.h> | 53 | #include <netinet/udp.h> |
54 | #include <netinet/tcp.h> | 54 | #include <netinet/tcp.h> |
55 | #include <time.h> | 55 | #include <time.h> |
56 | 56 | ||
57 | /* Custom Network Includes (must go here, don't reorder!) */ | 57 | /* Custom Network Includes (must go here, don't reorder!) */ |
58 | #include "802_11_user.h" | 58 | #include "802_11_user.h" |
59 | #include "dhcp.h" | 59 | #include "dhcp.h" |
60 | 60 | ||
61 | |||
62 | /* TYPEDEFS */ | 61 | /* TYPEDEFS */ |
63 | typedef struct timeval timevalstruct; | 62 | typedef struct timeval timevalstruct; |
64 | typedef struct pcap_pkthdr packetheaderstruct; | 63 | typedef struct pcap_pkthdr packetheaderstruct; |
65 | 64 | ||
66 | /* FORWARDS */ | 65 | /* FORWARDS */ |
67 | class QSocketNotifier; | 66 | class QSocketNotifier; |
68 | namespace Opie { | 67 | namespace Opie { |
69 | namespace Net { | 68 | namespace Net { |
70 | class OPacketCapturer; | 69 | class OPacketCapturer; |
71 | 70 | ||
72 | /*====================================================================================== | 71 | /*====================================================================================== |
73 | * OPacket - A frame on the wire | 72 | * OPacket - A frame on the wire |
74 | *======================================================================================*/ | 73 | *======================================================================================*/ |
75 | 74 | ||
76 | /** @brief A class representing a data frame on the wire. | 75 | /** @brief A class representing a data frame on the wire. |
77 | * | 76 | * |
78 | * The whole family of the packet classes are used when capturing frames from a network. | 77 | * The whole family of the packet classes are used when capturing frames from a network. |
79 | * Most standard network protocols in use share a common architecture, which mostly is | 78 | * Most standard network protocols in use share a common architecture, which mostly is |
80 | * a packet header and then the packet payload. In layered architectures, each lower layer | 79 | * a packet header and then the packet payload. In layered architectures, each lower layer |
81 | * encapsulates data from its upper layer - that is it | 80 | * encapsulates data from its upper layer - that is it |
82 | * treats the data from its upper layer as payload and prepends an own header to the packet, | 81 | * treats the data from its upper layer as payload and prepends an own header to the packet, |
83 | * which - again - is treated as the payload for the layer below. The figure below is an | 82 | * which - again - is treated as the payload for the layer below. The figure below is an |
84 | * example for how such a data frame is composed out of packets, e.g. when sending a mail. | 83 | * example for how such a data frame is composed out of packets, e.g. when sending a mail. |
85 | * | 84 | * |
86 | * <pre> | 85 | * <pre> |
87 | * | User Data | == Mail Data | 86 | * | User Data | == Mail Data |
88 | * | SMTP Header | User Data | == SMTP | 87 | * | SMTP Header | User Data | == SMTP |
89 | * | TCP Header | SMTP Header | User Data | == TCP | 88 | * | TCP Header | SMTP Header | User Data | == TCP |
90 | * | IP Header | TCP Header | SMTP Header | User Data | == IP | 89 | * | IP Header | TCP Header | SMTP Header | User Data | == IP |
91 | * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC | 90 | * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC |
92 | * | 91 | * |
93 | * </pre> | 92 | * </pre> |
94 | * | 93 | * |
95 | * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer | 94 | * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer |
96 | * also contains a few more levels of encapsulation. | 95 | * also contains a few more levels of encapsulation. |
97 | * Since the type of the payload is more or less independent from the encapsulating protocol, | 96 | * Since the type of the payload is more or less independent from the encapsulating protocol, |
98 | * the header must be inspected before attempting to decode the payload. Hence, the | 97 | * the header must be inspected before attempting to decode the payload. Hence, the |
99 | * encapsulation level varies and can't be deduced without actually looking into the packets. | 98 | * encapsulation level varies and can't be deduced without actually looking into the packets. |
100 | * | 99 | * |
101 | * For actually working with captured frames, it's useful to identify the packets via names and | 100 | * For actually working with captured frames, it's useful to identify the packets via names and |
102 | * insert them into a parent/child - relationship based on the encapsulation. This is why | 101 | * insert them into a parent/child - relationship based on the encapsulation. This is why |
103 | * all packet classes derive from QObject. The amount of overhead caused by the QObject is | 102 | * all packet classes derive from QObject. The amount of overhead caused by the QObject is |
104 | * not a problem in this case, because we're talking about a theoratical maximum of about | 103 | * not a problem in this case, because we're talking about a theoratical maximum of about |
105 | * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the | 104 | * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the |
106 | * QObject also cares about destroying the sub-, (child-) packets. | 105 | * QObject also cares about destroying the sub-, (child-) packets. |
107 | * | 106 | * |
108 | * This enables us to perform a simple look for packets of a certain type: | 107 | * This enables us to perform a simple look for packets of a certain type: |
109 | * @code | 108 | * @code |
110 | * OPacketCapturer* pcap = new OPacketCapturer(); | 109 | * OPacketCapturer* pcap = new OPacketCapturer(); |
111 | * pcap->open( "eth0" ); | 110 | * pcap->open( "eth0" ); |
112 | * OPacket* p = pcap->next(); | 111 | * OPacket* p = pcap->next(); |
113 | * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists | 112 | * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists |
114 | * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; | 113 | * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; |
115 | * | 114 | * |
116 | */ | 115 | */ |
117 | 116 | ||
118 | class OPacket : public QObject | 117 | class OPacket : public QObject |
119 | { | 118 | { |
120 | Q_OBJECT | 119 | Q_OBJECT |
121 | 120 | ||
122 | friend class OPacketCapturer; | 121 | friend class OPacketCapturer; |
123 | friend QTextStream& operator<<( QTextStream& s, const OPacket& p ); | 122 | friend QTextStream& operator<<( QTextStream& s, const OPacket& p ); |
124 | 123 | ||
125 | public: | 124 | public: |
126 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); | 125 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); |
127 | virtual ~OPacket(); | 126 | virtual ~OPacket(); |
128 | 127 | ||
129 | timevalstruct timeval() const; | 128 | timevalstruct timeval() const; |
130 | 129 | ||
131 | int caplen() const; | 130 | int caplen() const; |
132 | int len() const; | 131 | int len() const; |
133 | QString dump( int = 32 ) const; //FIXME: remove that | 132 | QString dump( int = 32 ) const; //FIXME: remove that |
134 | 133 | ||
135 | void updateStats( QMap<QString,int>&, QObjectList* ); //FIXME: Revise | 134 | void updateStats( QMap<QString,int>&, QObjectList* ); //FIXME: Revise |
136 | 135 | ||
137 | QString dumpStructure() const; //FIXME: Revise | 136 | QString dumpStructure() const; //FIXME: Revise |
138 | private: | 137 | private: |
139 | QString _dumpStructure( QObjectList* ) const; //FIXME: Revise | 138 | QString _dumpStructure( QObjectList* ) const; //FIXME: Revise |
140 | 139 | ||
141 | private: | 140 | private: |
142 | const packetheaderstruct _hdr; // pcap packet header | 141 | const packetheaderstruct _hdr; // pcap packet header |
143 | const unsigned char* _data; // pcap packet data | 142 | const unsigned char* _data; // pcap packet data |
144 | const unsigned char* _end; // end of pcap packet data | 143 | const unsigned char* _end; // end of pcap packet data |
145 | private: | 144 | private: |
146 | class Private; | 145 | class Private; |
147 | Private *d; | 146 | Private *d; |
148 | }; | 147 | }; |
149 | 148 | ||
150 | QTextStream& operator<<( QTextStream& s, const OPacket& p ); //FIXME: Revise | 149 | QTextStream& operator<<( QTextStream& s, const OPacket& p ); //FIXME: Revise |
151 | 150 | ||
152 | /*====================================================================================== | 151 | /*====================================================================================== |
153 | * OEthernetPacket - DLT_EN10MB frame | 152 | * OEthernetPacket - DLT_EN10MB frame |
154 | *======================================================================================*/ | 153 | *======================================================================================*/ |
155 | 154 | ||
156 | class OEthernetPacket : public QObject | 155 | class OEthernetPacket : public QObject |
157 | { | 156 | { |
158 | Q_OBJECT | 157 | Q_OBJECT |
159 | 158 | ||
160 | public: | 159 | public: |
161 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); | 160 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); |
162 | virtual ~OEthernetPacket(); | 161 | virtual ~OEthernetPacket(); |
163 | 162 | ||
164 | OMacAddress sourceAddress() const; | 163 | OMacAddress sourceAddress() const; |
165 | OMacAddress destinationAddress() const; | 164 | OMacAddress destinationAddress() const; |
166 | int type() const; | 165 | int type() const; |
167 | 166 | ||
168 | private: | 167 | private: |
169 | const struct ether_header* _ether; | 168 | const struct ether_header* _ether; |
170 | private: | 169 | private: |
171 | class Private; | 170 | class Private; |
172 | Private *d; | 171 | Private *d; |
173 | }; | 172 | }; |
174 | 173 | ||
175 | /*====================================================================================== | 174 | /*====================================================================================== |
176 | * OPrismHeaderPacket - DLT_PRISM_HEADER frame | 175 | * OPrismHeaderPacket - DLT_PRISM_HEADER frame |
177 | *======================================================================================*/ | 176 | *======================================================================================*/ |
178 | 177 | ||
179 | class OPrismHeaderPacket : public QObject | 178 | class OPrismHeaderPacket : public QObject |
180 | { | 179 | { |
181 | Q_OBJECT | 180 | Q_OBJECT |
182 | 181 | ||
183 | public: | 182 | public: |
184 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); | 183 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); |
185 | virtual ~OPrismHeaderPacket(); | 184 | virtual ~OPrismHeaderPacket(); |
186 | 185 | ||
187 | unsigned int signalStrength() const; | 186 | unsigned int signalStrength() const; |
188 | 187 | ||
189 | private: | 188 | private: |
190 | const struct prism_hdr* _header; | 189 | const struct prism_hdr* _header; |
191 | class Private; | 190 | class Private; |
192 | Private *d; | 191 | Private *d; |
193 | }; | 192 | }; |
194 | 193 | ||
195 | /*====================================================================================== | 194 | /*====================================================================================== |
196 | * OWaveLanPacket - DLT_IEEE802_11 frame | 195 | * OWaveLanPacket - DLT_IEEE802_11 frame |
197 | *======================================================================================*/ | 196 | *======================================================================================*/ |
198 | 197 | ||
199 | class OWaveLanPacket : public QObject | 198 | class OWaveLanPacket : public QObject |
200 | { | 199 | { |
201 | Q_OBJECT | 200 | Q_OBJECT |
202 | 201 | ||
203 | public: | 202 | public: |
204 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); | 203 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); |
205 | virtual ~OWaveLanPacket(); | 204 | virtual ~OWaveLanPacket(); |
206 | 205 | ||
207 | int duration() const; | 206 | int duration() const; |
208 | bool fromDS() const; | 207 | bool fromDS() const; |
209 | bool toDS() const; | 208 | bool toDS() const; |
210 | virtual OMacAddress macAddress1() const; | 209 | virtual OMacAddress macAddress1() const; |
211 | virtual OMacAddress macAddress2() const; | 210 | virtual OMacAddress macAddress2() const; |
212 | virtual OMacAddress macAddress3() const; | 211 | virtual OMacAddress macAddress3() const; |
213 | virtual OMacAddress macAddress4() const; | 212 | virtual OMacAddress macAddress4() const; |
214 | bool usesPowerManagement() const; | 213 | bool usesPowerManagement() const; |
215 | int type() const; | 214 | int type() const; |
216 | int subType() const; | 215 | int subType() const; |
217 | int version() const; | 216 | int version() const; |
218 | bool usesWep() const; | 217 | bool usesWep() const; |
219 | 218 | ||
220 | private: | 219 | private: |
221 | const struct ieee_802_11_header* _wlanhdr; | 220 | const struct ieee_802_11_header* _wlanhdr; |
222 | class Private; | 221 | class Private; |
223 | Private *d; | 222 | Private *d; |
224 | }; | 223 | }; |
225 | 224 | ||
226 | 225 | ||
227 | /*====================================================================================== | 226 | /*====================================================================================== |
228 | * OWaveLanManagementPacket - type: management (T_MGMT) | 227 | * OWaveLanManagementPacket - type: management (T_MGMT) |
229 | *======================================================================================*/ | 228 | *======================================================================================*/ |
230 | 229 | ||
231 | class OWaveLanManagementPacket : public QObject | 230 | class OWaveLanManagementPacket : public QObject |
232 | { | 231 | { |
233 | Q_OBJECT | 232 | Q_OBJECT |
234 | 233 | ||
235 | public: | 234 | public: |
236 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); | 235 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); |
237 | virtual ~OWaveLanManagementPacket(); | 236 | virtual ~OWaveLanManagementPacket(); |
238 | 237 | ||
239 | QString managementType() const; | 238 | QString managementType() const; |
240 | 239 | ||
241 | int beaconInterval() const; | 240 | int beaconInterval() const; |
242 | int capabilities() const; // generic | 241 | int capabilities() const; // generic |
243 | 242 | ||
244 | bool canESS() const; | 243 | bool canESS() const; |
245 | bool canIBSS() const; | 244 | bool canIBSS() const; |
246 | bool canCFP() const; | 245 | bool canCFP() const; |
247 | bool canCFP_REQ() const; | 246 | bool canCFP_REQ() const; |
248 | bool canPrivacy() const; | 247 | bool canPrivacy() const; |
249 | 248 | ||
250 | private: | 249 | private: |
251 | const struct ieee_802_11_mgmt_header* _header; | 250 | const struct ieee_802_11_mgmt_header* _header; |
252 | const struct ieee_802_11_mgmt_body* _body; | 251 | const struct ieee_802_11_mgmt_body* _body; |
253 | class Private; | 252 | class Private; |
254 | Private *d; | 253 | Private *d; |
255 | }; | 254 | }; |
256 | 255 | ||
257 | 256 | ||
258 | /*====================================================================================== | 257 | /*====================================================================================== |
259 | * OWaveLanManagementSSID | 258 | * OWaveLanManagementSSID |
260 | *======================================================================================*/ | 259 | *======================================================================================*/ |
261 | 260 | ||
262 | class OWaveLanManagementSSID : public QObject | 261 | class OWaveLanManagementSSID : public QObject |
263 | { | 262 | { |
264 | Q_OBJECT | 263 | Q_OBJECT |
265 | 264 | ||
266 | public: | 265 | public: |
267 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); | 266 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); |
268 | virtual ~OWaveLanManagementSSID(); | 267 | virtual ~OWaveLanManagementSSID(); |
269 | 268 | ||
270 | QString ID( bool decloak = false ) const; | 269 | QString ID( bool decloak = false ) const; |
271 | 270 | ||
272 | private: | 271 | private: |
273 | const struct ssid_t* _data; | 272 | const struct ssid_t* _data; |
274 | class Private; | 273 | class Private; |
275 | Private *d; | 274 | Private *d; |
276 | }; | 275 | }; |
277 | 276 | ||
278 | /*====================================================================================== | 277 | /*====================================================================================== |
279 | * OWaveLanManagementRates | 278 | * OWaveLanManagementRates |
280 | *======================================================================================*/ | 279 | *======================================================================================*/ |
281 | 280 | ||
282 | class OWaveLanManagementRates : public QObject | 281 | class OWaveLanManagementRates : public QObject |
283 | { | 282 | { |
284 | Q_OBJECT | 283 | Q_OBJECT |
285 | 284 | ||
286 | public: | 285 | public: |
287 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); | 286 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); |
288 | virtual ~OWaveLanManagementRates(); | 287 | virtual ~OWaveLanManagementRates(); |
289 | 288 | ||
290 | private: | 289 | private: |
291 | const struct rates_t* _data; | 290 | const struct rates_t* _data; |
292 | class Private; | 291 | class Private; |
293 | Private *d; | 292 | Private *d; |
294 | }; | 293 | }; |
295 | 294 | ||
296 | /*====================================================================================== | 295 | /*====================================================================================== |
297 | * OWaveLanManagementCF | 296 | * OWaveLanManagementCF |
298 | *======================================================================================*/ | 297 | *======================================================================================*/ |
299 | 298 | ||
300 | class OWaveLanManagementCF : public QObject | 299 | class OWaveLanManagementCF : public QObject |
301 | { | 300 | { |
302 | Q_OBJECT | 301 | Q_OBJECT |
303 | 302 | ||
304 | public: | 303 | public: |
305 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); | 304 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); |
306 | virtual ~OWaveLanManagementCF(); | 305 | virtual ~OWaveLanManagementCF(); |
307 | 306 | ||
308 | private: | 307 | private: |
309 | const struct cf_t* _data; | 308 | const struct cf_t* _data; |
310 | class Private; | 309 | class Private; |
311 | Private *d; | 310 | Private *d; |
312 | }; | 311 | }; |
313 | 312 | ||
314 | /*====================================================================================== | 313 | /*====================================================================================== |
315 | * OWaveLanManagementFH | 314 | * OWaveLanManagementFH |
316 | *======================================================================================*/ | 315 | *======================================================================================*/ |
317 | 316 | ||