author | mickeyl <mickeyl> | 2004-05-02 19:17:27 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-05-02 19:17:27 (UTC) |
commit | 8602449caa5a055bd5f033e3792d0a59a0b41bfa (patch) (unidiff) | |
tree | 17f60677ff09e89eb270f1e6cc837687b0eab871 | |
parent | 3e8fab5fddb3a38d93eaca1a8d69d8f668c7cd99 (diff) | |
download | opie-8602449caa5a055bd5f033e3792d0a59a0b41bfa.zip opie-8602449caa5a055bd5f033e3792d0a59a0b41bfa.tar.gz opie-8602449caa5a055bd5f033e3792d0a59a0b41bfa.tar.bz2 |
dump takes less space now
NOTE: I think dump really doesn't belong here
-rw-r--r-- | libopie2/opienet/opcap.cpp | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 8ec4f47..8184f21 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -1,426 +1,424 @@ | |||
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; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
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; | 151 | QString str( "000:" ); |
152 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); | ||
153 | str.append( "0000: " ); | ||
154 | QString tmp; | 152 | QString tmp; |
155 | QString bytes; | 153 | QString bytes; |
156 | QString chars; | 154 | QString chars; |
157 | 155 | ||
158 | for ( int i = 0; i < len; ++i ) | 156 | for ( int i = 0; i < len; ++i ) |
159 | { | 157 | { |
160 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | 158 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); |
161 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | 159 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); |
162 | else chars.append( '.' ); | 160 | else chars.append( '.' ); |
163 | 161 | ||
164 | if ( !((i+1) % bpl) ) | 162 | if ( !((i+1) % bpl) ) |
165 | { | 163 | { |
166 | str.append( bytes ); | 164 | str.append( bytes ); |
167 | str.append( ' ' ); | 165 | str.append( ' ' ); |
168 | str.append( chars ); | 166 | str.append( chars ); |
169 | str.append( '\n' ); | 167 | str.append( '\n' ); |
170 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); | 168 | tmp.sprintf( "%03X:", i+1 ); str.append( tmp ); |
171 | bytes = ""; | 169 | bytes = ""; |
172 | chars = ""; | 170 | chars = ""; |
173 | } | 171 | } |
174 | 172 | ||
175 | } | 173 | } |
176 | if ( (len % bpl) ) | 174 | if ( (len % bpl) ) |
177 | { | 175 | { |
178 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); | 176 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); |
179 | str.append( chars ); | 177 | str.append( chars ); |
180 | } | 178 | } |
181 | str.append( '\n' ); | 179 | str.append( '\n' ); |
182 | return str; | 180 | return str; |
183 | } | 181 | } |
184 | 182 | ||
185 | 183 | ||
186 | int OPacket::len() const | 184 | int OPacket::len() const |
187 | { | 185 | { |
188 | return _hdr.len; | 186 | return _hdr.len; |
189 | } | 187 | } |
190 | 188 | ||
191 | 189 | ||
192 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) | 190 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) |
193 | { | 191 | { |
194 | s << p.dumpStructure(); | 192 | s << p.dumpStructure(); |
195 | } | 193 | } |
196 | 194 | ||
197 | 195 | ||
198 | /*====================================================================================== | 196 | /*====================================================================================== |
199 | * OEthernetPacket | 197 | * OEthernetPacket |
200 | *======================================================================================*/ | 198 | *======================================================================================*/ |
201 | 199 | ||
202 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) | 200 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
203 | :QObject( parent, "Ethernet" ), _ether( data ) | 201 | :QObject( parent, "Ethernet" ), _ether( data ) |
204 | { | 202 | { |
205 | 203 | ||
206 | odebug << "Source = " << sourceAddress().toString() << oendl; | 204 | odebug << "Source = " << sourceAddress().toString() << oendl; |
207 | odebug << "Destination = " << destinationAddress().toString() << oendl; | 205 | odebug << "Destination = " << destinationAddress().toString() << oendl; |
208 | 206 | ||
209 | if ( sourceAddress() == OMacAddress::broadcast ) | 207 | if ( sourceAddress() == OMacAddress::broadcast ) |
210 | odebug << "Source is broadcast address" << oendl; | 208 | odebug << "Source is broadcast address" << oendl; |
211 | if ( destinationAddress() == OMacAddress::broadcast ) | 209 | if ( destinationAddress() == OMacAddress::broadcast ) |
212 | odebug << "Destination is broadcast address" << oendl; | 210 | odebug << "Destination is broadcast address" << oendl; |
213 | 211 | ||
214 | switch ( type() ) | 212 | switch ( type() ) |
215 | { | 213 | { |
216 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 214 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
217 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 215 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
218 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } | 216 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } |
219 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; | 217 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; |
220 | } | 218 | } |
221 | 219 | ||
222 | } | 220 | } |
223 | 221 | ||
224 | 222 | ||
225 | OEthernetPacket::~OEthernetPacket() | 223 | OEthernetPacket::~OEthernetPacket() |
226 | { | 224 | { |
227 | } | 225 | } |
228 | 226 | ||
229 | 227 | ||
230 | OMacAddress OEthernetPacket::sourceAddress() const | 228 | OMacAddress OEthernetPacket::sourceAddress() const |
231 | { | 229 | { |
232 | return OMacAddress( _ether->ether_shost ); | 230 | return OMacAddress( _ether->ether_shost ); |
233 | } | 231 | } |
234 | 232 | ||
235 | 233 | ||
236 | OMacAddress OEthernetPacket::destinationAddress() const | 234 | OMacAddress OEthernetPacket::destinationAddress() const |
237 | { | 235 | { |
238 | return OMacAddress( _ether->ether_dhost ); | 236 | return OMacAddress( _ether->ether_dhost ); |
239 | } | 237 | } |
240 | 238 | ||
241 | int OEthernetPacket::type() const | 239 | int OEthernetPacket::type() const |
242 | { | 240 | { |
243 | return ntohs( _ether->ether_type ); | 241 | return ntohs( _ether->ether_type ); |
244 | } | 242 | } |
245 | 243 | ||
246 | 244 | ||
247 | /*====================================================================================== | 245 | /*====================================================================================== |
248 | * OIPPacket | 246 | * OIPPacket |
249 | *======================================================================================*/ | 247 | *======================================================================================*/ |
250 | 248 | ||
251 | 249 | ||
252 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) | 250 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
253 | :QObject( parent, "IP" ), _iphdr( data ) | 251 | :QObject( parent, "IP" ), _iphdr( data ) |
254 | { | 252 | { |
255 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; | 253 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; |
256 | 254 | ||
257 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; | 255 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; |
258 | odebug << " toAddress = " << toIPAddress().toString() << oendl; | 256 | odebug << " toAddress = " << toIPAddress().toString() << oendl; |
259 | 257 | ||
260 | switch ( protocol() ) | 258 | switch ( protocol() ) |
261 | { | 259 | { |
262 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; | 260 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
263 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; | 261 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
264 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; | 262 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; |
265 | } | 263 | } |
266 | 264 | ||
267 | } | 265 | } |
268 | 266 | ||
269 | OIPPacket::~OIPPacket() | 267 | OIPPacket::~OIPPacket() |
270 | { | 268 | { |
271 | } | 269 | } |
272 | 270 | ||
273 | 271 | ||
274 | QHostAddress OIPPacket::fromIPAddress() const | 272 | QHostAddress OIPPacket::fromIPAddress() const |
275 | { | 273 | { |
276 | return EXTRACT_32BITS( &_iphdr->saddr ); | 274 | return EXTRACT_32BITS( &_iphdr->saddr ); |
277 | } | 275 | } |
278 | 276 | ||
279 | 277 | ||
280 | QHostAddress OIPPacket::toIPAddress() const | 278 | QHostAddress OIPPacket::toIPAddress() const |
281 | { | 279 | { |
282 | return EXTRACT_32BITS( &_iphdr->saddr ); | 280 | return EXTRACT_32BITS( &_iphdr->saddr ); |
283 | } | 281 | } |
284 | 282 | ||
285 | 283 | ||
286 | int OIPPacket::tos() const | 284 | int OIPPacket::tos() const |
287 | { | 285 | { |
288 | return _iphdr->tos; | 286 | return _iphdr->tos; |
289 | } | 287 | } |
290 | 288 | ||
291 | 289 | ||
292 | int OIPPacket::len() const | 290 | int OIPPacket::len() const |
293 | { | 291 | { |
294 | return EXTRACT_16BITS( &_iphdr->tot_len ); | 292 | return EXTRACT_16BITS( &_iphdr->tot_len ); |
295 | } | 293 | } |
296 | 294 | ||
297 | 295 | ||
298 | int OIPPacket::id() const | 296 | int OIPPacket::id() const |
299 | { | 297 | { |
300 | return EXTRACT_16BITS( &_iphdr->id ); | 298 | return EXTRACT_16BITS( &_iphdr->id ); |
301 | } | 299 | } |
302 | 300 | ||
303 | 301 | ||
304 | int OIPPacket::offset() const | 302 | int OIPPacket::offset() const |
305 | { | 303 | { |
306 | return EXTRACT_16BITS( &_iphdr->frag_off ); | 304 | return EXTRACT_16BITS( &_iphdr->frag_off ); |
307 | } | 305 | } |
308 | 306 | ||
309 | 307 | ||
310 | int OIPPacket::ttl() const | 308 | int OIPPacket::ttl() const |
311 | { | 309 | { |
312 | return _iphdr->ttl; | 310 | return _iphdr->ttl; |
313 | } | 311 | } |
314 | 312 | ||
315 | 313 | ||
316 | int OIPPacket::protocol() const | 314 | int OIPPacket::protocol() const |
317 | { | 315 | { |
318 | return _iphdr->protocol; | 316 | return _iphdr->protocol; |
319 | } | 317 | } |
320 | 318 | ||
321 | 319 | ||
322 | int OIPPacket::checksum() const | 320 | int OIPPacket::checksum() const |
323 | { | 321 | { |
324 | return EXTRACT_16BITS( &_iphdr->check ); | 322 | return EXTRACT_16BITS( &_iphdr->check ); |
325 | } | 323 | } |
326 | 324 | ||
327 | /*====================================================================================== | 325 | /*====================================================================================== |
328 | * OARPPacket | 326 | * OARPPacket |
329 | *======================================================================================*/ | 327 | *======================================================================================*/ |
330 | 328 | ||
331 | 329 | ||
332 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) | 330 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) |
333 | :QObject( parent, "ARP" ), _arphdr( data ) | 331 | :QObject( parent, "ARP" ), _arphdr( data ) |
334 | { | 332 | { |
335 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; | 333 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; |
336 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; | 334 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; |
337 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; | 335 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; |
338 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; | 336 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; |
339 | } | 337 | } |
340 | 338 | ||
341 | 339 | ||
342 | OARPPacket::~OARPPacket() | 340 | OARPPacket::~OARPPacket() |
343 | { | 341 | { |
344 | } | 342 | } |
345 | 343 | ||
346 | 344 | ||
347 | QString OARPPacket::type() const | 345 | QString OARPPacket::type() const |
348 | { | 346 | { |
349 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) | 347 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) |
350 | { | 348 | { |
351 | case 1: return "REQUEST"; | 349 | case 1: return "REQUEST"; |
352 | case 2: return "REPLY"; | 350 | case 2: return "REPLY"; |
353 | case 3: return "RREQUEST"; | 351 | case 3: return "RREQUEST"; |
354 | case 4: return "RREPLY"; | 352 | case 4: return "RREPLY"; |
355 | case 8: return "InREQUEST"; | 353 | case 8: return "InREQUEST"; |
356 | case 9: return "InREPLY"; | 354 | case 9: return "InREPLY"; |
357 | case 10: return "NAK"; | 355 | case 10: return "NAK"; |
358 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; | 356 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; |
359 | } | 357 | } |
360 | } | 358 | } |
361 | 359 | ||
362 | 360 | ||
363 | QHostAddress OARPPacket::senderIPV4Address() const | 361 | QHostAddress OARPPacket::senderIPV4Address() const |
364 | { | 362 | { |
365 | return EXTRACT_32BITS( &_arphdr->ar_sip ); | 363 | return EXTRACT_32BITS( &_arphdr->ar_sip ); |
366 | } | 364 | } |
367 | 365 | ||
368 | 366 | ||
369 | QHostAddress OARPPacket::targetIPV4Address() const | 367 | QHostAddress OARPPacket::targetIPV4Address() const |
370 | { | 368 | { |
371 | return EXTRACT_32BITS( &_arphdr->ar_tip ); | 369 | return EXTRACT_32BITS( &_arphdr->ar_tip ); |
372 | } | 370 | } |
373 | 371 | ||
374 | 372 | ||
375 | OMacAddress OARPPacket::senderMacAddress() const | 373 | OMacAddress OARPPacket::senderMacAddress() const |
376 | { | 374 | { |
377 | return OMacAddress( _arphdr->ar_sha ); | 375 | return OMacAddress( _arphdr->ar_sha ); |
378 | } | 376 | } |
379 | 377 | ||
380 | 378 | ||
381 | OMacAddress OARPPacket::targetMacAddress() const | 379 | OMacAddress OARPPacket::targetMacAddress() const |
382 | { | 380 | { |
383 | return OMacAddress( _arphdr->ar_tha ); | 381 | return OMacAddress( _arphdr->ar_tha ); |
384 | } | 382 | } |
385 | 383 | ||
386 | 384 | ||
387 | /*====================================================================================== | 385 | /*====================================================================================== |
388 | * OUDPPacket | 386 | * OUDPPacket |
389 | *======================================================================================*/ | 387 | *======================================================================================*/ |
390 | 388 | ||
391 | 389 | ||
392 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) | 390 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
393 | :QObject( parent, "UDP" ), _udphdr( data ) | 391 | :QObject( parent, "UDP" ), _udphdr( data ) |
394 | 392 | ||
395 | { | 393 | { |
396 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; | 394 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; |
397 | odebug << "fromPort = " << fromPort() << oendl; | 395 | odebug << "fromPort = " << fromPort() << oendl; |
398 | odebug << " toPort = " << toPort() << oendl; | 396 | odebug << " toPort = " << toPort() << oendl; |
399 | 397 | ||
400 | // TODO: Make this a case or a hash if we know more udp protocols | 398 | // TODO: Make this a case or a hash if we know more udp protocols |
401 | 399 | ||
402 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || | 400 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || |
403 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) | 401 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) |
404 | { | 402 | { |
405 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; | 403 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; |
406 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); | 404 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); |
407 | } | 405 | } |
408 | } | 406 | } |
409 | 407 | ||
410 | 408 | ||
411 | OUDPPacket::~OUDPPacket() | 409 | OUDPPacket::~OUDPPacket() |
412 | { | 410 | { |
413 | } | 411 | } |
414 | 412 | ||
415 | 413 | ||
416 | int OUDPPacket::fromPort() const | 414 | int OUDPPacket::fromPort() const |
417 | { | 415 | { |
418 | return EXTRACT_16BITS( &_udphdr->source ); | 416 | return EXTRACT_16BITS( &_udphdr->source ); |
419 | } | 417 | } |
420 | 418 | ||
421 | 419 | ||
422 | int OUDPPacket::toPort() const | 420 | int OUDPPacket::toPort() const |
423 | { | 421 | { |
424 | return EXTRACT_16BITS( &_udphdr->dest ); | 422 | return EXTRACT_16BITS( &_udphdr->dest ); |
425 | } | 423 | } |
426 | 424 | ||