-rw-r--r-- | libopie2/opienet/opcap.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 93176c0..067d6b7 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -1,140 +1,143 @@ | |||
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-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" | ||
32 | #include "opcap.h" | ||
33 | |||
31 | /* OPIE */ | 34 | /* OPIE */ |
32 | #include <opie2/opcap.h> | ||
33 | #include <opie2/odebug.h> | 35 | #include <opie2/odebug.h> |
36 | using namespace Opie::Core; | ||
34 | 37 | ||
35 | /* QT */ | 38 | /* QT */ |
36 | #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) |
37 | #include <qsocketnotifier.h> | 40 | #include <qsocketnotifier.h> |
38 | #include <qobjectlist.h> | 41 | #include <qobjectlist.h> |
39 | 42 | ||
40 | /* SYSTEM */ | 43 | /* STD */ |
41 | #include <sys/time.h> | 44 | #include <sys/time.h> |
42 | #include <sys/types.h> | 45 | #include <sys/types.h> |
46 | #include <assert.h> | ||
43 | #include <unistd.h> | 47 | #include <unistd.h> |
44 | 48 | #include <string.h> | |
45 | /* LOCAL */ | ||
46 | #include "udp_ports.h" | ||
47 | |||
48 | using namespace Opie::Core; | ||
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( data ) | 58 | :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) |
59 | { | 59 | { |
60 | //FIXME: Copy the data structure here, because it isn't persistent. Check that. | ||
61 | |||
62 | qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); | ||
63 | 60 | ||
64 | _end = (unsigned char*) data + header.len; | 61 | _data = new unsigned char[sizeof data]; |
65 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | 62 | assert( _data ); |
63 | memcpy( const_cast<unsigned char*>(_data), data, sizeof data ); | ||
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. | ||
66 | odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; | ||
67 | _end = (unsigned char*) _data + header.len; | ||
66 | 68 | ||
67 | switch ( datalink ) | 69 | switch ( datalink ) |
68 | { | 70 | { |
69 | case DLT_EN10MB: | 71 | case DLT_EN10MB: |
70 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; | 72 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; |
71 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); | 73 | new OEthernetPacket( _end, (const struct ether_header*) _data, this ); |
72 | break; | 74 | break; |
73 | 75 | ||
74 | case DLT_IEEE802_11: | 76 | case DLT_IEEE802_11: |
75 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; | 77 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; |
76 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); | 78 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); |
77 | break; | 79 | break; |
78 | 80 | ||
79 | case DLT_PRISM_HEADER: | 81 | case DLT_PRISM_HEADER: |
80 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; | 82 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; |
81 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); | 83 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); |
82 | break; | 84 | break; |
83 | 85 | ||
84 | default: | 86 | default: |
85 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; | 87 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; |
86 | } | 88 | } |
87 | } | 89 | } |
88 | 90 | ||
89 | 91 | ||
90 | OPacket::~OPacket() | 92 | OPacket::~OPacket() |
91 | { | 93 | { |
92 | qDebug( "OPacket::~OPacket( %s )", name() ); | 94 | odebug << "~OPacket( " << name() << " )" << oendl; |
95 | delete _data; | ||
93 | } | 96 | } |
94 | 97 | ||
95 | 98 | ||
96 | timevalstruct OPacket::timeval() const | 99 | timevalstruct OPacket::timeval() const |
97 | { | 100 | { |
98 | return _hdr.ts; | 101 | return _hdr.ts; |
99 | } | 102 | } |
100 | 103 | ||
101 | 104 | ||
102 | int OPacket::caplen() const | 105 | int OPacket::caplen() const |
103 | { | 106 | { |
104 | return _hdr.caplen; | 107 | return _hdr.caplen; |
105 | } | 108 | } |
106 | 109 | ||
107 | 110 | ||
108 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | 111 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) |
109 | { | 112 | { |
110 | if (!l) return; | 113 | if (!l) return; |
111 | QObject* o = l->first(); | 114 | QObject* o = l->first(); |
112 | while ( o ) | 115 | while ( o ) |
113 | { | 116 | { |
114 | stats[o->name()]++; | 117 | stats[o->name()]++; |
115 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); | 118 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); |
116 | o = l->next(); | 119 | o = l->next(); |
117 | } | 120 | } |
118 | } | 121 | } |
119 | 122 | ||
120 | 123 | ||
121 | QString OPacket::dumpStructure() const | 124 | QString OPacket::dumpStructure() const |
122 | { | 125 | { |
123 | return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; | 126 | return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; |
124 | } | 127 | } |
125 | 128 | ||
126 | 129 | ||
127 | QString OPacket::_dumpStructure( QObjectList* l ) const | 130 | QString OPacket::_dumpStructure( QObjectList* l ) const |
128 | { | 131 | { |
129 | if (!l) return QString::null; | 132 | if (!l) return QString::null; |
130 | QObject* o = l->first(); | 133 | QObject* o = l->first(); |
131 | QString str(" "); | 134 | QString str(" "); |
132 | 135 | ||
133 | while ( o ) | 136 | while ( o ) |
134 | { | 137 | { |
135 | str.append( o->name() ); | 138 | str.append( o->name() ); |
136 | str.append( " |" ); | 139 | str.append( " |" ); |
137 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); | 140 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); |
138 | o = l->next(); | 141 | o = l->next(); |
139 | } | 142 | } |
140 | return str; | 143 | return str; |