-rw-r--r-- | libopie2/opienet/opcap.cpp | 42 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 2 |
2 files changed, 35 insertions, 9 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 913d42e..6ddd457 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -43,107 +43,133 @@ | |||
43 | /*====================================================================================== | 43 | /*====================================================================================== |
44 | * OPacket | 44 | * OPacket |
45 | *======================================================================================*/ | 45 | *======================================================================================*/ |
46 | 46 | ||
47 | OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* parent ) | 47 | OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* parent ) |
48 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) | 48 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) |
49 | { | 49 | { |
50 | qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); | 50 | qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); |
51 | 51 | ||
52 | _end = (unsigned char*) data + header.len; | 52 | _end = (unsigned char*) data + header.len; |
53 | qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | 53 | qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); |
54 | 54 | ||
55 | if ( packetCapturer()->dataLink() == DLT_EN10MB ) | 55 | if ( packetCapturer()->dataLink() == DLT_EN10MB ) |
56 | { | 56 | { |
57 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); | 57 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); |
58 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); | 58 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); |
59 | } | 59 | } |
60 | else | 60 | else |
61 | { | 61 | { |
62 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); | 62 | qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); |
63 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); | 63 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); |
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | OPacket::~OPacket() | 68 | OPacket::~OPacket() |
69 | { | 69 | { |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | OPacketCapturer* OPacket::packetCapturer() const | 73 | OPacketCapturer* OPacket::packetCapturer() const |
74 | { | 74 | { |
75 | return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0; | 75 | return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0; |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | timevalstruct OPacket::timeval() const | 79 | timevalstruct OPacket::timeval() const |
80 | { | 80 | { |
81 | return _hdr.ts; | 81 | return _hdr.ts; |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | int OPacket::caplen() const | 85 | int OPacket::caplen() const |
86 | { | 86 | { |
87 | return _hdr.caplen; | 87 | return _hdr.caplen; |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | void OPacket::dump() const | 91 | QString OPacket::dump( int bpl ) const |
92 | { | 92 | { |
93 | printf( "OPacket::dump()\n" ); | 93 | static int index = 0; |
94 | printf( "----------------\n" ); | 94 | index++; |
95 | int len = _hdr.caplen; | ||
96 | QString str; | ||
97 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); | ||
98 | str.append( "0000: " ); | ||
99 | QString tmp; | ||
100 | QString bytes; | ||
101 | QString chars; | ||
102 | |||
103 | for ( int i = 0; i < len; ++i ) | ||
104 | { | ||
105 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | ||
106 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | ||
107 | else chars.append( '.' ); | ||
108 | |||
109 | if ( !((i+1) % bpl) ) | ||
110 | { | ||
111 | str.append( bytes ); | ||
112 | str.append( ' ' ); | ||
113 | str.append( chars ); | ||
114 | str.append( '\n' ); | ||
115 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); | ||
116 | bytes = ""; | ||
117 | chars = ""; | ||
118 | } | ||
95 | 119 | ||
96 | for ( int i = 0; i < _hdr.caplen; ++i ) | 120 | } |
121 | if ( (len % bpl) ) | ||
97 | { | 122 | { |
98 | printf( "%02x ", _data[i] ); | 123 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); |
99 | if ( !((i+1) % 32) ) printf( "\n" ); | 124 | str.append( chars ); |
100 | } | 125 | } |
101 | printf( "\n\n" ); | 126 | str.append( '\n' ); |
127 | return str; | ||
102 | } | 128 | } |
103 | 129 | ||
104 | 130 | ||
105 | 131 | ||
106 | int OPacket::len() const | 132 | int OPacket::len() const |
107 | { | 133 | { |
108 | return _hdr.len; | 134 | return _hdr.len; |
109 | } | 135 | } |
110 | 136 | ||
111 | /*====================================================================================== | 137 | /*====================================================================================== |
112 | * OEthernetPacket | 138 | * OEthernetPacket |
113 | *======================================================================================*/ | 139 | *======================================================================================*/ |
114 | 140 | ||
115 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) | 141 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
116 | :QObject( parent, "Ethernet" ), _ether( data ) | 142 | :QObject( parent, "Ethernet" ), _ether( data ) |
117 | 143 | ||
118 | { | 144 | { |
119 | 145 | ||
120 | qDebug( "Source = %s", (const char*) sourceAddress().toString() ); | 146 | qDebug( "Source = %s", (const char*) sourceAddress().toString() ); |
121 | qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); | 147 | qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); |
122 | 148 | ||
123 | if ( sourceAddress() == OMacAddress::broadcast ) | 149 | if ( sourceAddress() == OMacAddress::broadcast ) |
124 | qDebug( "Source is broadcast address" ); | 150 | qDebug( "Source is broadcast address" ); |
125 | if ( destinationAddress() == OMacAddress::broadcast ) | 151 | if ( destinationAddress() == OMacAddress::broadcast ) |
126 | qDebug( "Destination is broadcast address" ); | 152 | qDebug( "Destination is broadcast address" ); |
127 | 153 | ||
128 | switch ( type() ) | 154 | switch ( type() ) |
129 | { | 155 | { |
130 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 156 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
131 | case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } | 157 | case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } |
132 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } | 158 | case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } |
133 | default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); | 159 | default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); |
134 | } | 160 | } |
135 | 161 | ||
136 | } | 162 | } |
137 | 163 | ||
138 | 164 | ||
139 | OEthernetPacket::~OEthernetPacket() | 165 | OEthernetPacket::~OEthernetPacket() |
140 | { | 166 | { |
141 | } | 167 | } |
142 | 168 | ||
143 | 169 | ||
144 | OMacAddress OEthernetPacket::sourceAddress() const | 170 | OMacAddress OEthernetPacket::sourceAddress() const |
145 | { | 171 | { |
146 | return OMacAddress( _ether->ether_shost ); | 172 | return OMacAddress( _ether->ether_shost ); |
147 | } | 173 | } |
148 | 174 | ||
149 | 175 | ||
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 0b06572..04d22ff 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -35,97 +35,97 @@ | |||
35 | #define OPCAP_H | 35 | #define OPCAP_H |
36 | 36 | ||
37 | /* LINUX */ | 37 | /* LINUX */ |
38 | extern "C" // work around a bpf/pcap conflict in recent headers | 38 | extern "C" // work around a bpf/pcap conflict in recent headers |
39 | { | 39 | { |
40 | #include <pcap.h> | 40 | #include <pcap.h> |
41 | } | 41 | } |
42 | #include <netinet/ether.h> | 42 | #include <netinet/ether.h> |
43 | #include <netinet/ip.h> | 43 | #include <netinet/ip.h> |
44 | #include <netinet/udp.h> | 44 | #include <netinet/udp.h> |
45 | #include <netinet/tcp.h> | 45 | #include <netinet/tcp.h> |
46 | #include <time.h> | 46 | #include <time.h> |
47 | 47 | ||
48 | /* QT */ | 48 | /* QT */ |
49 | #include <qhostaddress.h> | 49 | #include <qhostaddress.h> |
50 | #include <qobject.h> | 50 | #include <qobject.h> |
51 | #include <qstring.h> | 51 | #include <qstring.h> |
52 | 52 | ||
53 | /* OPIE */ | 53 | /* OPIE */ |
54 | #include <opie2/onetutils.h> | 54 | #include <opie2/onetutils.h> |
55 | #include "802_11_user.h" | 55 | #include "802_11_user.h" |
56 | 56 | ||
57 | /* TYPEDEFS */ | 57 | /* TYPEDEFS */ |
58 | typedef struct timeval timevalstruct; | 58 | typedef struct timeval timevalstruct; |
59 | typedef struct pcap_pkthdr packetheaderstruct; | 59 | typedef struct pcap_pkthdr packetheaderstruct; |
60 | 60 | ||
61 | /* FORWARDS */ | 61 | /* FORWARDS */ |
62 | class OPacketCapturer; | 62 | class OPacketCapturer; |
63 | class QSocketNotifier; | 63 | class QSocketNotifier; |
64 | 64 | ||
65 | /*====================================================================================== | 65 | /*====================================================================================== |
66 | * OPacket - A frame on the wire | 66 | * OPacket - A frame on the wire |
67 | *======================================================================================*/ | 67 | *======================================================================================*/ |
68 | 68 | ||
69 | class OPacket : public QObject | 69 | class OPacket : public QObject |
70 | { | 70 | { |
71 | Q_OBJECT | 71 | Q_OBJECT |
72 | 72 | ||
73 | public: | 73 | public: |
74 | OPacket( packetheaderstruct, const unsigned char*, QObject* parent ); | 74 | OPacket( packetheaderstruct, const unsigned char*, QObject* parent ); |
75 | virtual ~OPacket(); | 75 | virtual ~OPacket(); |
76 | 76 | ||
77 | timevalstruct timeval() const; | 77 | timevalstruct timeval() const; |
78 | 78 | ||
79 | OPacketCapturer* packetCapturer() const; | 79 | OPacketCapturer* packetCapturer() const; |
80 | 80 | ||
81 | int caplen() const; | 81 | int caplen() const; |
82 | int len() const; | 82 | int len() const; |
83 | void dump() const; | 83 | QString dump( int = 32 ) const; |
84 | 84 | ||
85 | private: | 85 | private: |
86 | const packetheaderstruct _hdr; // pcap packet header | 86 | const packetheaderstruct _hdr; // pcap packet header |
87 | const unsigned char* _data; // pcap packet data | 87 | const unsigned char* _data; // pcap packet data |
88 | const unsigned char* _end; // end of pcap packet data | 88 | const unsigned char* _end; // end of pcap packet data |
89 | }; | 89 | }; |
90 | 90 | ||
91 | /*====================================================================================== | 91 | /*====================================================================================== |
92 | * OEthernetPacket - DLT_EN10MB frame | 92 | * OEthernetPacket - DLT_EN10MB frame |
93 | *======================================================================================*/ | 93 | *======================================================================================*/ |
94 | 94 | ||
95 | class OEthernetPacket : public QObject | 95 | class OEthernetPacket : public QObject |
96 | { | 96 | { |
97 | Q_OBJECT | 97 | Q_OBJECT |
98 | 98 | ||
99 | public: | 99 | public: |
100 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); | 100 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); |
101 | virtual ~OEthernetPacket(); | 101 | virtual ~OEthernetPacket(); |
102 | 102 | ||
103 | OMacAddress sourceAddress() const; | 103 | OMacAddress sourceAddress() const; |
104 | OMacAddress destinationAddress() const; | 104 | OMacAddress destinationAddress() const; |
105 | int type() const; | 105 | int type() const; |
106 | 106 | ||
107 | private: | 107 | private: |
108 | const struct ether_header* _ether; | 108 | const struct ether_header* _ether; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | 111 | ||
112 | /*====================================================================================== | 112 | /*====================================================================================== |
113 | * OWaveLanPacket - DLT_IEEE802_11 frame | 113 | * OWaveLanPacket - DLT_IEEE802_11 frame |
114 | *======================================================================================*/ | 114 | *======================================================================================*/ |
115 | 115 | ||
116 | class OWaveLanPacket : public QObject | 116 | class OWaveLanPacket : public QObject |
117 | { | 117 | { |
118 | Q_OBJECT | 118 | Q_OBJECT |
119 | 119 | ||
120 | public: | 120 | public: |
121 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); | 121 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); |
122 | virtual ~OWaveLanPacket(); | 122 | virtual ~OWaveLanPacket(); |
123 | 123 | ||
124 | int duration() const; | 124 | int duration() const; |
125 | bool fromDS() const; | 125 | bool fromDS() const; |
126 | bool toDS() const; | 126 | bool toDS() const; |
127 | virtual OMacAddress macAddress1() const; | 127 | virtual OMacAddress macAddress1() const; |
128 | virtual OMacAddress macAddress2() const; | 128 | virtual OMacAddress macAddress2() const; |
129 | virtual OMacAddress macAddress3() const; | 129 | virtual OMacAddress macAddress3() const; |
130 | virtual OMacAddress macAddress4() const; | 130 | virtual OMacAddress macAddress4() const; |
131 | bool usesPowerManagement() const; | 131 | bool usesPowerManagement() const; |