author | mickeyl <mickeyl> | 2004-03-28 17:32:44 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-03-28 17:32:44 (UTC) |
commit | 1c151bedaa6cfcc8f10c7b5aa549de3e6628d271 (patch) (unidiff) | |
tree | 23cb7abf06ff3092e629095546f1171761321716 | |
parent | e2368b92a101437f7ed289d5ae62f7e7e2466344 (diff) | |
download | opie-1c151bedaa6cfcc8f10c7b5aa549de3e6628d271.zip opie-1c151bedaa6cfcc8f10c7b5aa549de3e6628d271.tar.gz opie-1c151bedaa6cfcc8f10c7b5aa549de3e6628d271.tar.bz2 |
add some FIXMEs for later API revisions
-rw-r--r-- | libopie2/opienet/opcap.cpp | 2 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 10 |
2 files changed, 7 insertions, 5 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index c5df041..93176c0 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -12,96 +12,98 @@ | |||
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 | /* OPIE */ | 31 | /* OPIE */ |
32 | #include <opie2/opcap.h> | 32 | #include <opie2/opcap.h> |
33 | #include <opie2/odebug.h> | 33 | #include <opie2/odebug.h> |
34 | 34 | ||
35 | /* QT */ | 35 | /* QT */ |
36 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) | 36 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) |
37 | #include <qsocketnotifier.h> | 37 | #include <qsocketnotifier.h> |
38 | #include <qobjectlist.h> | 38 | #include <qobjectlist.h> |
39 | 39 | ||
40 | /* SYSTEM */ | 40 | /* SYSTEM */ |
41 | #include <sys/time.h> | 41 | #include <sys/time.h> |
42 | #include <sys/types.h> | 42 | #include <sys/types.h> |
43 | #include <unistd.h> | 43 | #include <unistd.h> |
44 | 44 | ||
45 | /* LOCAL */ | 45 | /* LOCAL */ |
46 | #include "udp_ports.h" | 46 | #include "udp_ports.h" |
47 | 47 | ||
48 | using namespace Opie::Core; | 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( data ) |
59 | { | 59 | { |
60 | //FIXME: Copy the data structure here, because it isn't persistent. Check that. | ||
61 | |||
60 | qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); | 62 | qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); |
61 | 63 | ||
62 | _end = (unsigned char*) data + header.len; | 64 | _end = (unsigned char*) data + header.len; |
63 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | 65 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); |
64 | 66 | ||
65 | switch ( datalink ) | 67 | switch ( datalink ) |
66 | { | 68 | { |
67 | case DLT_EN10MB: | 69 | case DLT_EN10MB: |
68 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; | 70 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; |
69 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); | 71 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); |
70 | break; | 72 | break; |
71 | 73 | ||
72 | case DLT_IEEE802_11: | 74 | case DLT_IEEE802_11: |
73 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; | 75 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; |
74 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); | 76 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); |
75 | break; | 77 | break; |
76 | 78 | ||
77 | case DLT_PRISM_HEADER: | 79 | case DLT_PRISM_HEADER: |
78 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; | 80 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; |
79 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); | 81 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); |
80 | break; | 82 | break; |
81 | 83 | ||
82 | default: | 84 | default: |
83 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; | 85 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; |
84 | } | 86 | } |
85 | } | 87 | } |
86 | 88 | ||
87 | 89 | ||
88 | OPacket::~OPacket() | 90 | OPacket::~OPacket() |
89 | { | 91 | { |
90 | qDebug( "OPacket::~OPacket( %s )", name() ); | 92 | qDebug( "OPacket::~OPacket( %s )", name() ); |
91 | } | 93 | } |
92 | 94 | ||
93 | 95 | ||
94 | timevalstruct OPacket::timeval() const | 96 | timevalstruct OPacket::timeval() const |
95 | { | 97 | { |
96 | return _hdr.ts; | 98 | return _hdr.ts; |
97 | } | 99 | } |
98 | 100 | ||
99 | 101 | ||
100 | int OPacket::caplen() const | 102 | int OPacket::caplen() const |
101 | { | 103 | { |
102 | return _hdr.caplen; | 104 | return _hdr.caplen; |
103 | } | 105 | } |
104 | 106 | ||
105 | 107 | ||
106 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | 108 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) |
107 | { | 109 | { |
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 4ff8495..2dbe030 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -85,114 +85,114 @@ class OPacketCapturer; | |||
85 | * | 85 | * |
86 | * <pre> | 86 | * <pre> |
87 | * | User Data | == Mail Data | 87 | * | User Data | == Mail Data |
88 | * | SMTP Header | User Data | == SMTP | 88 | * | SMTP Header | User Data | == SMTP |
89 | * | TCP Header | SMTP Header | User Data | == TCP | 89 | * | TCP Header | SMTP Header | User Data | == TCP |
90 | * | IP Header | TCP Header | SMTP Header | User Data | == IP | 90 | * | IP Header | TCP Header | SMTP Header | User Data | == IP |
91 | * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC | 91 | * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC |
92 | * | 92 | * |
93 | * </pre> | 93 | * </pre> |
94 | * | 94 | * |
95 | * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer | 95 | * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer |
96 | * also contains a few more levels of encapsulation. | 96 | * also contains a few more levels of encapsulation. |
97 | * Since the type of the payload is more or less independent from the encapsulating protocol, | 97 | * 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 | 98 | * 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. | 99 | * encapsulation level varies and can't be deduced without actually looking into the packets. |
100 | * | 100 | * |
101 | * For actually working with captured frames, it's useful to identify the packets via names and | 101 | * 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 | 102 | * 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 | 103 | * 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 | 104 | * 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 | 105 | * 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. | 106 | * QObject also cares about destroying the sub-, (child-) packets. |
107 | * | 107 | * |
108 | * This enables us to perform a simple look for packets of a certain type: | 108 | * This enables us to perform a simple look for packets of a certain type: |
109 | * @code | 109 | * @code |
110 | * OPacketCapturer* pcap = new OPacketCapturer(); | 110 | * OPacketCapturer* pcap = new OPacketCapturer(); |
111 | * pcap->open( "eth0" ); | 111 | * pcap->open( "eth0" ); |
112 | * OPacket* p = pcap->next(); | 112 | * OPacket* p = pcap->next(); |
113 | * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists | 113 | * 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; | 114 | * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; |
115 | * | 115 | * |
116 | */ | 116 | */ |
117 | 117 | ||
118 | class OPacket : public QObject | 118 | class OPacket : public QObject |
119 | { | 119 | { |
120 | Q_OBJECT | 120 | Q_OBJECT |
121 | 121 | ||
122 | friend class OPacketCapturer; | 122 | friend class OPacketCapturer; |
123 | friend QTextStream& operator<<( QTextStream& s, const OPacket& p ); | 123 | friend QTextStream& operator<<( QTextStream& s, const OPacket& p ); |
124 | 124 | ||
125 | public: | 125 | public: |
126 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); | 126 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); |
127 | virtual ~OPacket(); | 127 | virtual ~OPacket(); |
128 | 128 | ||
129 | timevalstruct timeval() const; | 129 | timevalstruct timeval() const; |
130 | 130 | ||
131 | int caplen() const; | 131 | int caplen() const; |
132 | int len() const; | 132 | int len() const; |
133 | QString dump( int = 32 ) const; | 133 | QString dump( int = 32 ) const; //FIXME: remove that |
134 | 134 | ||
135 | void updateStats( QMap<QString,int>&, QObjectList* ); | 135 | void updateStats( QMap<QString,int>&, QObjectList* ); //FIXME: Revise |
136 | 136 | ||
137 | QString dumpStructure() const; | 137 | QString dumpStructure() const; //FIXME: Revise |
138 | private: | 138 | private: |
139 | QString _dumpStructure( QObjectList* ) const; | 139 | QString _dumpStructure( QObjectList* ) const; //FIXME: Revise |
140 | 140 | ||
141 | private: | 141 | private: |
142 | const packetheaderstruct _hdr; // pcap packet header | 142 | const packetheaderstruct _hdr; // pcap packet header |
143 | const unsigned char* _data; // pcap packet data | 143 | const unsigned char* _data; // pcap packet data |
144 | const unsigned char* _end; // end of pcap packet data | 144 | const unsigned char* _end; // end of pcap packet data |
145 | private: | 145 | private: |
146 | class Private; | 146 | class Private; |
147 | Private *d; | 147 | Private *d; |
148 | }; | 148 | }; |
149 | 149 | ||
150 | QTextStream& operator<<( QTextStream& s, const OPacket& p ); | 150 | QTextStream& operator<<( QTextStream& s, const OPacket& p ); //FIXME: Revise |
151 | 151 | ||
152 | /*====================================================================================== | 152 | /*====================================================================================== |
153 | * OEthernetPacket - DLT_EN10MB frame | 153 | * OEthernetPacket - DLT_EN10MB frame |
154 | *======================================================================================*/ | 154 | *======================================================================================*/ |
155 | 155 | ||
156 | class OEthernetPacket : public QObject | 156 | class OEthernetPacket : public QObject |
157 | { | 157 | { |
158 | Q_OBJECT | 158 | Q_OBJECT |
159 | 159 | ||
160 | public: | 160 | public: |
161 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); | 161 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); |
162 | virtual ~OEthernetPacket(); | 162 | virtual ~OEthernetPacket(); |
163 | 163 | ||
164 | OMacAddress sourceAddress() const; | 164 | OMacAddress sourceAddress() const; |
165 | OMacAddress destinationAddress() const; | 165 | OMacAddress destinationAddress() const; |
166 | int type() const; | 166 | int type() const; |
167 | 167 | ||
168 | private: | 168 | private: |
169 | const struct ether_header* _ether; | 169 | const struct ether_header* _ether; |
170 | private: | 170 | private: |
171 | class Private; | 171 | class Private; |
172 | Private *d; | 172 | Private *d; |
173 | }; | 173 | }; |
174 | 174 | ||
175 | /*====================================================================================== | 175 | /*====================================================================================== |
176 | * OPrismHeaderPacket - DLT_PRISM_HEADER frame | 176 | * OPrismHeaderPacket - DLT_PRISM_HEADER frame |
177 | *======================================================================================*/ | 177 | *======================================================================================*/ |
178 | 178 | ||
179 | class OPrismHeaderPacket : public QObject | 179 | class OPrismHeaderPacket : public QObject |
180 | { | 180 | { |
181 | Q_OBJECT | 181 | Q_OBJECT |
182 | 182 | ||
183 | public: | 183 | public: |
184 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); | 184 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); |
185 | virtual ~OPrismHeaderPacket(); | 185 | virtual ~OPrismHeaderPacket(); |
186 | 186 | ||
187 | unsigned int signalStrength() const; | 187 | unsigned int signalStrength() const; |
188 | 188 | ||
189 | private: | 189 | private: |
190 | const struct prism_hdr* _header; | 190 | const struct prism_hdr* _header; |
191 | class Private; | 191 | class Private; |
192 | Private *d; | 192 | Private *d; |
193 | }; | 193 | }; |
194 | 194 | ||
195 | /*====================================================================================== | 195 | /*====================================================================================== |
196 | * OWaveLanPacket - DLT_IEEE802_11 frame | 196 | * OWaveLanPacket - DLT_IEEE802_11 frame |
197 | *======================================================================================*/ | 197 | *======================================================================================*/ |
198 | 198 | ||