-rw-r--r-- | libopie2/opienet/802_11_user.h | 4 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 2648 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 2 |
3 files changed, 1335 insertions, 1319 deletions
diff --git a/libopie2/opienet/802_11_user.h b/libopie2/opienet/802_11_user.h index ad84514..7ae27c5 100644 --- a/libopie2/opienet/802_11_user.h +++ b/libopie2/opienet/802_11_user.h | |||
@@ -1,458 +1,458 @@ | |||
1 | #ifndef IEEE_802_11 | 1 | #ifndef IEEE_802_11 |
2 | #define IEEE_802_11 | 2 | #define IEEE_802_11 |
3 | 3 | ||
4 | enum ieee_802_11_link_status_failure_reason { | 4 | enum ieee_802_11_link_status_failure_reason { |
5 | reserved0, Unspecified=1, Previous_not_valid, | 5 | reserved0, Unspecified=1, Previous_not_valid, |
6 | Sender_Quits_ESS_or_IBSS, | 6 | Sender_Quits_ESS_or_IBSS, |
7 | Due_Inactivity, AP_Overload, | 7 | Due_Inactivity, AP_Overload, |
8 | Class_2_from_NonAuth, | 8 | Class_2_from_NonAuth, |
9 | Class_3_from_NonAuth, | 9 | Class_3_from_NonAuth, |
10 | Sender_Quits_BSS, | 10 | Sender_Quits_BSS, |
11 | Association_requester_not_authenticated, | 11 | Association_requester_not_authenticated, |
12 | Reserved10 | 12 | Reserved10 |
13 | }; | 13 | }; |
14 | 14 | ||
15 | 15 | ||
16 | #define IEEE_802_11_LINK_STATUS_FAILURE_REASON_STRINGS \ | 16 | #define IEEE_802_11_LINK_STATUS_FAILURE_REASON_STRINGS \ |
17 | {\ | 17 | {\ |
18 | {reserved0, 0xff," Reserved reason "},\ | 18 | {reserved0, 0xff," Reserved reason "},\ |
19 | {Unspecified, 0xff," Unspecified Reason "},\ | 19 | {Unspecified, 0xff," Unspecified Reason "},\ |
20 | {Previous_not_valid,0xff," Previous Authentication no longer valid "},\ | 20 | {Previous_not_valid,0xff," Previous Authentication no longer valid "},\ |
21 | {Sender_Quits_ESS_or_IBSS,0xff," Deauthenticated because sending station is leaving (has left) IBSS or ESS "},\ | 21 | {Sender_Quits_ESS_or_IBSS,0xff," Deauthenticated because sending station is leaving (has left) IBSS or ESS "},\ |
22 | {Due_Inactivity,0xff," Disassociated due to inactivity "},\ | 22 | {Due_Inactivity,0xff," Disassociated due to inactivity "},\ |
23 | {AP_Overload, 0xff," Disassociated because AP is unable to handle all currently associated stations "},\ | 23 | {AP_Overload, 0xff," Disassociated because AP is unable to handle all currently associated stations "},\ |
24 | {Class_2_from_NonAuth,0xff," Class 2 frame received from non-Authenticated station"},\ | 24 | {Class_2_from_NonAuth,0xff," Class 2 frame received from non-Authenticated station"},\ |
25 | {Class_3_from_NonAuth,0xff," Class 3 frame received from nonAssociated station"},\ | 25 | {Class_3_from_NonAuth,0xff," Class 3 frame received from nonAssociated station"},\ |
26 | {Sender_Quits_BSS,0xff," Disassociated because sending station is leaving (has left) BSS"},\ | 26 | {Sender_Quits_BSS,0xff," Disassociated because sending station is leaving (has left) BSS"},\ |
27 | {Association_requester_not_authenticated,0xff," Station requesting (Re)Association is not Authenticated with responding station"},\ | 27 | {Association_requester_not_authenticated,0xff," Station requesting (Re)Association is not Authenticated with responding station"},\ |
28 | {Reserved10, 0xff," Reserved"},\ | 28 | {Reserved10, 0xff," Reserved"},\ |
29 | {0,0,NULL}\ | 29 | {0,0,NULL}\ |
30 | }; | 30 | }; |
31 | 31 | ||
32 | 32 | ||
33 | 33 | ||
34 | struct ieee_802_11_header { | 34 | struct ieee_802_11_header { |
35 | u_int16_tframe_control;// needs to be subtyped | 35 | u_int16_tframe_control;// needs to be subtyped |
36 | u_int16_tduration; | 36 | u_int16_tduration; |
37 | u_int8_tmac1[6]; | 37 | u_int8_tmac1[6]; |
38 | u_int8_tmac2[6]; | 38 | u_int8_tmac2[6]; |
39 | u_int8_tmac3[6]; | 39 | u_int8_tmac3[6]; |
40 | u_int16_tSeqCtl; | 40 | u_int16_tSeqCtl; |
41 | u_int8_tmac4[6]; | 41 | u_int8_tmac4[6]; |
42 | // u_int16_tgapLen; | 42 | // u_int16_tgapLen; |
43 | // u_int8_tgap[8]; | 43 | // u_int8_tgap[8]; |
44 | }; | 44 | }; |
45 | 45 | ||
46 | 46 | ||
47 | struct ieee_802_3_header { | 47 | struct ieee_802_3_header { |
48 | 48 | ||
49 | u_int16_tstatus; | 49 | u_int16_tstatus; |
50 | u_int16_tpayload_length; | 50 | u_int16_tpayload_length; |
51 | u_int8_tdst_mac[6]; | 51 | u_int8_tdst_mac[6]; |
52 | u_int8_tsrc_mac[6]; | 52 | u_int8_tsrc_mac[6]; |
53 | 53 | ||
54 | }; | 54 | }; |
55 | 55 | ||
56 | #define P80211_OUI_LEN 3 | 56 | #define P80211_OUI_LEN 3 |
57 | 57 | ||
58 | struct ieee_802_11_802_2_header { | 58 | struct ieee_802_11_802_2_header { |
59 | 59 | ||
60 | u_int8_t dsap; | 60 | u_int8_t dsap; |
61 | u_int8_t ssap; /* always 0xAA */ | 61 | u_int8_t ssap; /* always 0xAA */ |
62 | u_int8_t ctrl; /* always 0x03 */ | 62 | u_int8_t ctrl; /* always 0x03 */ |
63 | u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */ | 63 | u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */ |
64 | u_int16_t type; /* packet type ID field */ | 64 | u_int16_t type; /* packet type ID field */ |
65 | }; | 65 | }; |
66 | 66 | ||
67 | /* See RFC 826 for protocol description. ARP packets are variable | 67 | /* See RFC 826 for protocol description. ARP packets are variable |
68 | in size; the arphdr structure defines the fixed-length portion. | 68 | in size; the arphdr structure defines the fixed-length portion. |
69 | Protocol type values are the same as those for 10 Mb/s Ethernet. | 69 | Protocol type values are the same as those for 10 Mb/s Ethernet. |
70 | It is followed by the variable-sized fields ar_sha, arp_spa, | 70 | It is followed by the variable-sized fields ar_sha, arp_spa, |
71 | arp_tha and arp_tpa in that order, according to the lengths | 71 | arp_tha and arp_tpa in that order, according to the lengths |
72 | specified. Field names used correspond to RFC 826. */ | 72 | specified. Field names used correspond to RFC 826. */ |
73 | 73 | ||
74 | #define ETH_ALEN 6 | 74 | #define ETH_ALEN 6 |
75 | 75 | ||
76 | struct myarphdr | 76 | struct myarphdr |
77 | { | 77 | { |
78 | unsigned short int ar_hrd; /* Format of hardware address. */ | 78 | unsigned short int ar_hrd; /* Format of hardware address. */ |
79 | unsigned short int ar_pro; /* Format of protocol address. */ | 79 | unsigned short int ar_pro; /* Format of protocol address. */ |
80 | unsigned char ar_hln; /* Length of hardware address. */ | 80 | unsigned char ar_hln; /* Length of hardware address. */ |
81 | unsigned char ar_pln; /* Length of protocol address. */ | 81 | unsigned char ar_pln; /* Length of protocol address. */ |
82 | unsigned short int ar_op; /* ARP opcode (command). */ | 82 | unsigned short int ar_op; /* ARP opcode (command). */ |
83 | /* Ethernet looks like this : This bit is variable sized | 83 | /* Ethernet looks like this : This bit is variable sized |
84 | however... */ | 84 | however... */ |
85 | unsigned char ar_sha[ETH_ALEN]; /* Sender hardware address. */ | 85 | unsigned char ar_sha[ETH_ALEN]; /* Sender hardware address. */ |
86 | unsigned char ar_sip[4]; /* Sender IP address. */ | 86 | unsigned char ar_sip[4]; /* Sender IP address. */ |
87 | unsigned char ar_tha[ETH_ALEN]; /* Target hardware address. */ | 87 | unsigned char ar_tha[ETH_ALEN]; /* Target hardware address. */ |
88 | unsigned char ar_tip[4]; /* Target IP address. */ | 88 | unsigned char ar_tip[4]; /* Target IP address. */ |
89 | }; | 89 | }; |
90 | 90 | ||
91 | 91 | ||
92 | // following is incoplete and may be incorrect and need reorganization | 92 | // following is incoplete and may be incorrect and need reorganization |
93 | 93 | ||
94 | #define ieee_802_11_frame_type_Management0x00 | 94 | #define ieee_802_11_frame_type_Management0x00 |
95 | #define ieee_802_11_frame_type_Control 0x01 | 95 | #define ieee_802_11_frame_type_Control 0x01 |
96 | #define ieee_802_11_frame_type_Data 0x10 | 96 | #define ieee_802_11_frame_type_Data 0x10 |
97 | #define ieee_802_11_frame_type_Reserved 0x11 | 97 | #define ieee_802_11_frame_type_Reserved 0x11 |
98 | 98 | ||
99 | #define ieee_802_11_frame_subtype_Association_Req0x0 // Association Request | 99 | #define ieee_802_11_frame_subtype_Association_Req0x0 // Association Request |
100 | #define ieee_802_11_frame_subtype_Association_Resp0x1 // Association Response | 100 | #define ieee_802_11_frame_subtype_Association_Resp0x1 // Association Response |
101 | #define ieee_802_11_frame_subtype_Reassociation_Req0x2 // Reassociation Request | 101 | #define ieee_802_11_frame_subtype_Reassociation_Req0x2 // Reassociation Request |
102 | #define ieee_802_11_frame_subtype_Reassociation_Resp0x3 // Reassociation Response | 102 | #define ieee_802_11_frame_subtype_Reassociation_Resp0x3 // Reassociation Response |
103 | #define ieee_802_11_frame_subtype_Probe_Req 0x4 // Probe Request | 103 | #define ieee_802_11_frame_subtype_Probe_Req 0x4 // Probe Request |
104 | #define ieee_802_11_frame_subtype_Probe_Resp 0x5 // Probe Response | 104 | #define ieee_802_11_frame_subtype_Probe_Resp 0x5 // Probe Response |
105 | #define ieee_802_11_frame_subtype_Beacon 0x8 // Beacon | 105 | #define ieee_802_11_frame_subtype_Beacon 0x8 // Beacon |
106 | #define ieee_802_11_frame_subtype_ATIM 0x9 // ATIM | 106 | #define ieee_802_11_frame_subtype_ATIM 0x9 // ATIM |
107 | #define ieee_802_11_frame_subtype_Disassociation 0xA // Disassociation | 107 | #define ieee_802_11_frame_subtype_Disassociation 0xA // Disassociation |
108 | #define ieee_802_11_frame_subtype_Authentication 0xB // Authentication | 108 | #define ieee_802_11_frame_subtype_Authentication 0xB // Authentication |
109 | #define ieee_802_11_frame_subtype_Deauthentication 0xC // Deauthentication | 109 | #define ieee_802_11_frame_subtype_Deauthentication 0xC // Deauthentication |
110 | #define ieee_802_11_frame_subtype_PS_Poll 0xA // PS-Poll | 110 | #define ieee_802_11_frame_subtype_PS_Poll 0xA // PS-Poll |
111 | #define ieee_802_11_frame_subtype_RTS 0xB // RTS | 111 | #define ieee_802_11_frame_subtype_RTS 0xB // RTS |
112 | #define ieee_802_11_frame_subtype_CTS 0xC // CTS | 112 | #define ieee_802_11_frame_subtype_CTS 0xC // CTS |
113 | #define ieee_802_11_frame_subtype_ACK 0xD // ACK | 113 | #define ieee_802_11_frame_subtype_ACK 0xD // ACK |
114 | #define ieee_802_11_frame_subtype_CFEnd 0xE // CF-End | 114 | #define ieee_802_11_frame_subtype_CFEnd 0xE // CF-End |
115 | #define ieee_802_11_frame_subtype_CFEnd_CFAck 0xF // CF-End + CF-Ack | 115 | #define ieee_802_11_frame_subtype_CFEnd_CFAck 0xF // CF-End + CF-Ack |
116 | #define ieee_802_11_frame_subtype_Data 0x0 // Data | 116 | #define ieee_802_11_frame_subtype_Data 0x0 // Data |
117 | #define ieee_802_11_frame_subtype_Data_CFAck 0x1 // Data + CF-Ack | 117 | #define ieee_802_11_frame_subtype_Data_CFAck 0x1 // Data + CF-Ack |
118 | #define ieee_802_11_frame_subtype_Data_CF_Poll 0x2 // Data + CF-Poll | 118 | #define ieee_802_11_frame_subtype_Data_CF_Poll 0x2 // Data + CF-Poll |
119 | #define ieee_802_11_frame_subtype_Data_CF_AckCF_Poll 0x3 // Data + CF-Ack + CF-Poll | 119 | #define ieee_802_11_frame_subtype_Data_CF_AckCF_Poll 0x3 // Data + CF-Ack + CF-Poll |
120 | #define ieee_802_11_frame_subtype_NullFunction 0x4 // Null Function (no data) | 120 | #define ieee_802_11_frame_subtype_NullFunction 0x4 // Null Function (no data) |
121 | #define ieee_802_11_frame_subtype_CF_Ack 0x5 // CF-Ack (no data) | 121 | #define ieee_802_11_frame_subtype_CF_Ack 0x5 // CF-Ack (no data) |
122 | #define ieee_802_11_frame_subtype_CF_Poll 0x6 // CF-Poll (no data) | 122 | #define ieee_802_11_frame_subtype_CF_Poll 0x6 // CF-Poll (no data) |
123 | #define ieee_802_11_frame_subtype_CF_AckCF_Poll 0x7 // CF-Ack + CF-Poll (no data) | 123 | #define ieee_802_11_frame_subtype_CF_AckCF_Poll 0x7 // CF-Ack + CF-Poll (no data) |
124 | 124 | ||
125 | 125 | ||
126 | #define ieee_802_11_frame_subtype_strings {\ | 126 | #define ieee_802_11_frame_subtype_strings {\ |
127 | { ieee_802_11_frame_subtype_Association_Req,0xF,"f Association Request"},\ | 127 | { ieee_802_11_frame_subtype_Association_Req,0xF,"f Association Request"},\ |
128 | { ieee_802_11_frame_subtype_Association_Resp,0xF,"1 Association Response"},\ | 128 | { ieee_802_11_frame_subtype_Association_Resp,0xF,"1 Association Response"},\ |
129 | { ieee_802_11_frame_subtype_Reassociation_Req,0xF,"2 Reassociation Request"},\ | 129 | { ieee_802_11_frame_subtype_Reassociation_Req,0xF,"2 Reassociation Request"},\ |
130 | { ieee_802_11_frame_subtype_Reassociation_Resp,0xF,"3 Reassociation Response"},\ | 130 | { ieee_802_11_frame_subtype_Reassociation_Resp,0xF,"3 Reassociation Response"},\ |
131 | { ieee_802_11_frame_subtype_Probe_Req ,0xF,"4 Probe Request"},\ | 131 | { ieee_802_11_frame_subtype_Probe_Req ,0xF,"4 Probe Request"},\ |
132 | { ieee_802_11_frame_subtype_Probe_Resp ,0xF,"5 Probe Response"},\ | 132 | { ieee_802_11_frame_subtype_Probe_Resp ,0xF,"5 Probe Response"},\ |
133 | { ieee_802_11_frame_subtype_Beacon ,0xF,"8 Beacon"},\ | 133 | { ieee_802_11_frame_subtype_Beacon ,0xF,"8 Beacon"},\ |
134 | { ieee_802_11_frame_subtype_ATIM ,0xF,"9 ATIM"},\ | 134 | { ieee_802_11_frame_subtype_ATIM ,0xF,"9 ATIM"},\ |
135 | { ieee_802_11_frame_subtype_Disassociation,0xF,"A Disassociation"},\ | 135 | { ieee_802_11_frame_subtype_Disassociation,0xF,"A Disassociation"},\ |
136 | { ieee_802_11_frame_subtype_Authentication,0xF,"B Authentication"},\ | 136 | { ieee_802_11_frame_subtype_Authentication,0xF,"B Authentication"},\ |
137 | { ieee_802_11_frame_subtype_Deauthentication,0xF,"C Deauthentication"},\ | 137 | { ieee_802_11_frame_subtype_Deauthentication,0xF,"C Deauthentication"},\ |
138 | { ieee_802_11_frame_subtype_PS_Poll ,0xF,"A PS-Poll"},\ | 138 | { ieee_802_11_frame_subtype_PS_Poll ,0xF,"A PS-Poll"},\ |
139 | { ieee_802_11_frame_subtype_RTS ,0xF,"B RTS"},\ | 139 | { ieee_802_11_frame_subtype_RTS ,0xF,"B RTS"},\ |
140 | { ieee_802_11_frame_subtype_CTS ,0xF,"C CTS"},\ | 140 | { ieee_802_11_frame_subtype_CTS ,0xF,"C CTS"},\ |
141 | { ieee_802_11_frame_subtype_ACK ,0xF,"D ACK"},\ | 141 | { ieee_802_11_frame_subtype_ACK ,0xF,"D ACK"},\ |
142 | { ieee_802_11_frame_subtype_CFEnd ,0xF,"E CF-End"},\ | 142 | { ieee_802_11_frame_subtype_CFEnd ,0xF,"E CF-End"},\ |
143 | { ieee_802_11_frame_subtype_CFEnd_CFAck ,0xF,"F CF-End + CF-Ack"},\ | 143 | { ieee_802_11_frame_subtype_CFEnd_CFAck ,0xF,"F CF-End + CF-Ack"},\ |
144 | { ieee_802_11_frame_subtype_Data ,0xF,"0 Data"},\ | 144 | { ieee_802_11_frame_subtype_Data ,0xF,"0 Data"},\ |
145 | { ieee_802_11_frame_subtype_Data_CFAck ,0xF,"1 Data + CF-Ack"},\ | 145 | { ieee_802_11_frame_subtype_Data_CFAck ,0xF,"1 Data + CF-Ack"},\ |
146 | { ieee_802_11_frame_subtype_Data_CFPoll ,0xF,"2 Data + CF-Poll"},\ | 146 | { ieee_802_11_frame_subtype_Data_CFPoll ,0xF,"2 Data + CF-Poll"},\ |
147 | { ieee_802_11_frame_subtype_Data_CFAck_CFPoll,0xF,"3 Data + CF-Ack + CF-Poll"},\ | 147 | { ieee_802_11_frame_subtype_Data_CFAck_CFPoll,0xF,"3 Data + CF-Ack + CF-Poll"},\ |
148 | { ieee_802_11_frame_subtype_Null_Function ,0xF,"4 Null Function (no data)"},\ | 148 | { ieee_802_11_frame_subtype_Null_Function ,0xF,"4 Null Function (no data)"},\ |
149 | { ieee_802_11_frame_subtype_CFAck , 0xF,"5 CF-Ack (no data)"},\ | 149 | { ieee_802_11_frame_subtype_CFAck , 0xF,"5 CF-Ack (no data)"},\ |
150 | { ieee_802_11_frame_subtype_CFPoll , 0xF,"6 CF-Poll (no data)"},\ | 150 | { ieee_802_11_frame_subtype_CFPoll , 0xF,"6 CF-Poll (no data)"},\ |
151 | { ieee_802_11_frame_subtype_CFAck_CFPoll,0xF,"y7 CF-Ack + CF-Poll (no data)"},\ | 151 | { ieee_802_11_frame_subtype_CFAck_CFPoll,0xF,"y7 CF-Ack + CF-Poll (no data)"},\ |
152 | { 0,0,NULL}\ | 152 | { 0,0,NULL}\ |
153 | } | 153 | } |
154 | struct ieee_802_11_frame_subtype_class { | 154 | struct ieee_802_11_frame_subtype_class { |
155 | u_int8_tsubtype; | 155 | u_int8_tsubtype; |
156 | u_int8_tmask; | 156 | u_int8_tmask; |
157 | u_int8_tklass; | 157 | u_int8_tklass; |
158 | u_int8_ttype; | 158 | u_int8_ttype; |
159 | }; | 159 | }; |
160 | #define ieee_802_11_frame_subtype_classes {\ | 160 | #define ieee_802_11_frame_subtype_classes {\ |
161 | { ieee_802_11_frame_subtype_Association_Req,0xF,2,ieee_802_11_frame_type_Management},\ | 161 | { ieee_802_11_frame_subtype_Association_Req,0xF,2,ieee_802_11_frame_type_Management},\ |
162 | { ieee_802_11_frame_subtype_Association_Resp,0xF,2,ieee_802_11_frame_type_Management},\ | 162 | { ieee_802_11_frame_subtype_Association_Resp,0xF,2,ieee_802_11_frame_type_Management},\ |
163 | { ieee_802_11_frame_subtype_Reassociation_Req,0xF,2,ieee_802_11_frame_type_Management},\ | 163 | { ieee_802_11_frame_subtype_Reassociation_Req,0xF,2,ieee_802_11_frame_type_Management},\ |
164 | { ieee_802_11_frame_subtype_Reassociation_Resp,0xF,2,ieee_802_11_frame_type_Management},\ | 164 | { ieee_802_11_frame_subtype_Reassociation_Resp,0xF,2,ieee_802_11_frame_type_Management},\ |
165 | { ieee_802_11_frame_subtype_Probe_Req ,0xF,1,ieee_802_11_frame_type_Management},\ | 165 | { ieee_802_11_frame_subtype_Probe_Req ,0xF,1,ieee_802_11_frame_type_Management},\ |
166 | { ieee_802_11_frame_subtype_Probe_Resp ,0xF,1,ieee_802_11_frame_type_Management},\ | 166 | { ieee_802_11_frame_subtype_Probe_Resp ,0xF,1,ieee_802_11_frame_type_Management},\ |
167 | { ieee_802_11_frame_subtype_Beacon ,0xF,1,ieee_802_11_frame_type_Management},\ | 167 | { ieee_802_11_frame_subtype_Beacon ,0xF,1,ieee_802_11_frame_type_Management},\ |
168 | { ieee_802_11_frame_subtype_ATIM ,0xF,1,ieee_802_11_frame_type_Management},\ | 168 | { ieee_802_11_frame_subtype_ATIM ,0xF,1,ieee_802_11_frame_type_Management},\ |
169 | { ieee_802_11_frame_subtype_Disassociation,0xF,2,ieee_802_11_frame_type_Management},\ | 169 | { ieee_802_11_frame_subtype_Disassociation,0xF,2,ieee_802_11_frame_type_Management},\ |
170 | { ieee_802_11_frame_subtype_Authentication,0xF,1,ieee_802_11_frame_type_Management},\ | 170 | { ieee_802_11_frame_subtype_Authentication,0xF,1,ieee_802_11_frame_type_Management},\ |
171 | { ieee_802_11_frame_subtype_Deauthentication,0xF,3,ieee_802_11_frame_type_Management},\ | 171 | { ieee_802_11_frame_subtype_Deauthentication,0xF,3,ieee_802_11_frame_type_Management},\ |
172 | { ieee_802_11_frame_subtype_PS-Poll ,0xF,3,ieee_802_11_frame_type_Control},\ | 172 | { ieee_802_11_frame_subtype_PS-Poll ,0xF,3,ieee_802_11_frame_type_Control},\ |
173 | { ieee_802_11_frame_subtype_RTS ,0xF,1,ieee_802_11_frame_type_Control},\ | 173 | { ieee_802_11_frame_subtype_RTS ,0xF,1,ieee_802_11_frame_type_Control},\ |
174 | { ieee_802_11_frame_subtype_CTS ,0xF,1,ieee_802_11_frame_type_Control},\ | 174 | { ieee_802_11_frame_subtype_CTS ,0xF,1,ieee_802_11_frame_type_Control},\ |
175 | { ieee_802_11_frame_subtype_ACK ,0xF,1,ieee_802_11_frame_type_Control},\ | 175 | { ieee_802_11_frame_subtype_ACK ,0xF,1,ieee_802_11_frame_type_Control},\ |
176 | { ieee_802_11_frame_subtype_CFEnd ,0xF,1,ieee_802_11_frame_type_Control},\ | 176 | { ieee_802_11_frame_subtype_CFEnd ,0xF,1,ieee_802_11_frame_type_Control},\ |
177 | { ieee_802_11_frame_subtype_CFEnd_CFAck ,0xF,1,ieee_802_11_frame_type_Control},\ | 177 | { ieee_802_11_frame_subtype_CFEnd_CFAck ,0xF,1,ieee_802_11_frame_type_Control},\ |
178 | { ieee_802_11_frame_subtype_Data ,0xF,3,ieee_802_11_frame_type_Data},\ | 178 | { ieee_802_11_frame_subtype_Data ,0xF,3,ieee_802_11_frame_type_Data},\ |
179 | { ieee_802_11_frame_subtype_Data_CFAck ,0xF,3,ieee_802_11_frame_type_Data},\ | 179 | { ieee_802_11_frame_subtype_Data_CFAck ,0xF,3,ieee_802_11_frame_type_Data},\ |
180 | { ieee_802_11_frame_subtype_Data_CF_Poll 0xF,3,ieee_802_11_frame_type_Data},\ | 180 | { ieee_802_11_frame_subtype_Data_CF_Poll 0xF,3,ieee_802_11_frame_type_Data},\ |
181 | { ieee_802_11_frame_subtype_Data_CF_AckCF_Poll,0xF,3,ieee_802_11_frame_type_Data},\ | 181 | { ieee_802_11_frame_subtype_Data_CF_AckCF_Poll,0xF,3,ieee_802_11_frame_type_Data},\ |
182 | { ieee_802_11_frame_subtype_NullFunction 0xF,1,ieee_802_11_frame_type_Data},\ | 182 | { ieee_802_11_frame_subtype_NullFunction 0xF,1,ieee_802_11_frame_type_Data},\ |
183 | { ieee_802_11_frame_subtype_CF_Ack , 0xF,1,ieee_802_11_frame_type_Data},\ | 183 | { ieee_802_11_frame_subtype_CF_Ack , 0xF,1,ieee_802_11_frame_type_Data},\ |
184 | { ieee_802_11_frame_subtype_CF_Poll , 0xF,1,ieee_802_11_frame_type_Data},\ | 184 | { ieee_802_11_frame_subtype_CF_Poll , 0xF,1,ieee_802_11_frame_type_Data},\ |
185 | { ieee_802_11_frame_subtype_CF_AckCF_Poll,0xF,1,ieee_802_11_frame_type_Data},\ | 185 | { ieee_802_11_frame_subtype_CF_AckCF_Poll,0xF,1,ieee_802_11_frame_type_Data},\ |
186 | { 0,0,NULL}\ | 186 | { 0,0,NULL}\ |
187 | } | 187 | } |
188 | 188 | ||
189 | #define IEEE802_11_FC_LEN2 | 189 | #define IEEE802_11_FC_LEN2 |
190 | 190 | ||
191 | #define T_MGMT 0x0 /* management */ | 191 | #define T_MGMT 0x0 /* management */ |
192 | #define T_CTRL 0x1 /* control */ | 192 | #define T_CTRL 0x1 /* control */ |
193 | #define T_DATA 0x2 /* data */ | 193 | #define T_DATA 0x2 /* data */ |
194 | #define T_RESV 0x3 /* reserved */ | 194 | #define T_RESV 0x3 /* reserved */ |
195 | 195 | ||
196 | #define ST_ASSOC_REQUEST 0x0 | 196 | #define ST_ASSOC_REQUEST 0x0 |
197 | #define ST_ASSOC_RESPONSE 0x1 | 197 | #define ST_ASSOC_RESPONSE 0x1 |
198 | #define ST_REASSOC_REQUEST 0x2 | 198 | #define ST_REASSOC_REQUEST 0x2 |
199 | #define ST_REASSOC_RESPONSE 0x3 | 199 | #define ST_REASSOC_RESPONSE 0x3 |
200 | #define ST_PROBE_REQUEST 0x4 | 200 | #define ST_PROBE_REQUEST 0x4 |
201 | #define ST_PROBE_RESPONSE 0x5 | 201 | #define ST_PROBE_RESPONSE 0x5 |
202 | /* RESERVED 0x6 */ | 202 | /* RESERVED 0x6 */ |
203 | /* RESERVED 0x7 */ | 203 | /* RESERVED 0x7 */ |
204 | #define ST_BEACON 0x8 | 204 | #define ST_BEACON 0x8 |
205 | #define ST_ATIM 0x9 | 205 | #define ST_ATIM 0x9 |
206 | #define ST_DISASSOC 0xA | 206 | #define ST_DISASSOC 0xA |
207 | #define ST_AUTH 0xB | 207 | #define ST_AUTH 0xB |
208 | #define ST_DEAUTH 0xC | 208 | #define ST_DEAUTH 0xC |
209 | /* RESERVED 0xD */ | 209 | /* RESERVED 0xD */ |
210 | /* RESERVED 0xE */ | 210 | /* RESERVED 0xE */ |
211 | /* RESERVED 0xF */ | 211 | /* RESERVED 0xF */ |
212 | 212 | ||
213 | 213 | ||
214 | #define CTRL_PS_POLL0xA | 214 | #define CTRL_PS_POLL0xA |
215 | #define CTRL_RTS0xB | 215 | #define CTRL_RTS0xB |
216 | #define CTRL_CTS0xC | 216 | #define CTRL_CTS0xC |
217 | #define CTRL_ACK0xD | 217 | #define CTRL_ACK0xD |
218 | #define CTRL_CF_END0xE | 218 | #define CTRL_CF_END0xE |
219 | #define CTRL_END_ACK0xF | 219 | #define CTRL_END_ACK0xF |
220 | 220 | ||
221 | /* | 221 | /* |
222 | * Bits in the frame control field. | 222 | * Bits in the frame control field. |
223 | */ | 223 | */ |
224 | #define FC_VERSION(fc) ((fc) & 0x3) | 224 | #define FC_VERSION(fc) ((fc) & 0x3) |
225 | #define FC_TYPE(fc) (((fc) >> 2) & 0x3) | 225 | #define FC_TYPE(fc) (((fc) >> 2) & 0x3) |
226 | #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF) | 226 | #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF) |
227 | #define FC_TO_DS(fc) ((fc) & 0x0100) | 227 | #define FC_TO_DS(fc) ((fc) & 0x0100) |
228 | #define FC_FROM_DS(fc) ((fc) & 0x0200) | 228 | #define FC_FROM_DS(fc) ((fc) & 0x0200) |
229 | #define FC_MORE_FLAG(fc)((fc) & 0x0400) | 229 | #define FC_MORE_FLAG(fc)((fc) & 0x0400) |
230 | #define FC_RETRY(fc) ((fc) & 0x0800) | 230 | #define FC_RETRY(fc) ((fc) & 0x0800) |
231 | #define FC_POWER_MGMT(fc)((fc) & 0x1000) | 231 | #define FC_POWER_MGMT(fc)((fc) & 0x1000) |
232 | #define FC_MORE_DATA(fc)((fc) & 0x2000) | 232 | #define FC_MORE_DATA(fc)((fc) & 0x2000) |
233 | #define FC_WEP(fc) ((fc) & 0x4000) | 233 | #define FC_WEP(fc) ((fc) & 0x4000) |
234 | #define FC_ORDER(fc) ((fc) & 0x8000) | 234 | #define FC_ORDER(fc) ((fc) & 0x8000) |
235 | 235 | ||
236 | 236 | ||
237 | struct ieee_802_11_mgmt_header { | 237 | struct ieee_802_11_mgmt_header { |
238 | u_int16_t fc; | 238 | u_int16_t fc; |
239 | u_int16_t duration; | 239 | u_int16_t duration; |
240 | u_int8_t da[6]; | 240 | u_int8_t da[6]; |
241 | u_int8_t sa[6]; | 241 | u_int8_t sa[6]; |
242 | u_int8_t bssid[6]; | 242 | u_int8_t bssid[6]; |
243 | u_int16_t seq_ctrl; | 243 | u_int16_t seq_ctrl; |
244 | }; | 244 | }; |
245 | 245 | ||
246 | 246 | ||
247 | struct ieee_802_11_data_header { | 247 | struct ieee_802_11_data_header { |
248 | u_int16_tframe_control; | 248 | u_int16_tfc; |
249 | u_int16_tduration; | 249 | u_int16_tduration; |
250 | u_int8_tmac1[6]; | 250 | u_int8_tmac1[6]; |
251 | u_int8_tmac2[6]; | 251 | u_int8_tmac2[6]; |
252 | u_int8_tmac3[6]; | 252 | u_int8_tmac3[6]; |
253 | u_int16_tSeqCtl; | 253 | u_int16_tSeqCtl; |
254 | u_int8_tmac4[6]; | 254 | u_int8_tmac4[6]; |
255 | // u_int16_tgapLen; | 255 | // u_int16_tgapLen; |
256 | // u_int8_tgap[8]; | 256 | // u_int8_tgap[8]; |
257 | }; | 257 | }; |
258 | 258 | ||
259 | struct ieee_802_11_control_header { | 259 | struct ieee_802_11_control_header { |
260 | u_int16_tframe_control; | 260 | u_int16_tfc; |
261 | u_int16_tduration; | 261 | u_int16_tduration; |
262 | u_int8_tmac1[6]; | 262 | u_int8_tmac1[6]; |
263 | u_int8_tmac2[6]; | 263 | u_int8_tmac2[6]; |
264 | u_int8_tmac3[6]; | 264 | u_int8_tmac3[6]; |
265 | u_int16_tSeqCtl; | 265 | u_int16_tSeqCtl; |
266 | u_int8_tmac4[6]; | 266 | u_int8_tmac4[6]; |
267 | // u_int16_tgapLen; | 267 | // u_int16_tgapLen; |
268 | // u_int8_tgap[8]; | 268 | // u_int8_tgap[8]; |
269 | }; | 269 | }; |
270 | 270 | ||
271 | #define CAPABILITY_ESS(cap) ((cap) & 0x0001) | 271 | #define CAPABILITY_ESS(cap) ((cap) & 0x0001) |
272 | #define CAPABILITY_IBSS(cap) ((cap) & 0x0002) | 272 | #define CAPABILITY_IBSS(cap) ((cap) & 0x0002) |
273 | #define CAPABILITY_CFP(cap) ((cap) & 0x0004) | 273 | #define CAPABILITY_CFP(cap) ((cap) & 0x0004) |
274 | #define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008) | 274 | #define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008) |
275 | #define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010) | 275 | #define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010) |
276 | 276 | ||
277 | struct ssid_t { | 277 | struct ssid_t { |
278 | u_int8_telement_id; | 278 | u_int8_telement_id; |
279 | u_int8_tlength; | 279 | u_int8_tlength; |
280 | u_char ssid[33]; /* 32 + 1 for null */ | 280 | u_char ssid[33]; /* 32 + 1 for null */ |
281 | }; | 281 | }; |
282 | 282 | ||
283 | 283 | ||
284 | struct rates_t { | 284 | struct rates_t { |
285 | u_int8_telement_id; | 285 | u_int8_telement_id; |
286 | u_int8_tlength; | 286 | u_int8_tlength; |
287 | u_int8_trate[8]; | 287 | u_int8_trate[8]; |
288 | }; | 288 | }; |
289 | 289 | ||
290 | 290 | ||
291 | struct challenge_t { | 291 | struct challenge_t { |
292 | u_int8_telement_id; | 292 | u_int8_telement_id; |
293 | u_int8_tlength; | 293 | u_int8_tlength; |
294 | u_int8_ttext[254]; /* 1-253 + 1 for null */ | 294 | u_int8_ttext[254]; /* 1-253 + 1 for null */ |
295 | }; | 295 | }; |
296 | 296 | ||
297 | 297 | ||
298 | struct fh_t { | 298 | struct fh_t { |
299 | u_int8_telement_id; | 299 | u_int8_telement_id; |
300 | u_int8_tlength; | 300 | u_int8_tlength; |
301 | u_int16_tdwell_time; | 301 | u_int16_tdwell_time; |
302 | u_int8_thop_set; | 302 | u_int8_thop_set; |
303 | u_int8_t hop_pattern; | 303 | u_int8_t hop_pattern; |
304 | u_int8_thop_index; | 304 | u_int8_thop_index; |
305 | }; | 305 | }; |
306 | 306 | ||
307 | 307 | ||
308 | struct ds_t { | 308 | struct ds_t { |
309 | u_int8_telement_id; | 309 | u_int8_telement_id; |
310 | u_int8_tlength; | 310 | u_int8_tlength; |
311 | u_int8_tchannel; | 311 | u_int8_tchannel; |
312 | }; | 312 | }; |
313 | 313 | ||
314 | 314 | ||
315 | struct cf_t { | 315 | struct cf_t { |
316 | u_int8_telement_id; | 316 | u_int8_telement_id; |
317 | u_int8_tlength; | 317 | u_int8_tlength; |
318 | u_int8_tcount; | 318 | u_int8_tcount; |
319 | u_int8_tperiod; | 319 | u_int8_tperiod; |
320 | u_int16_tmax_duration; | 320 | u_int16_tmax_duration; |
321 | u_int16_tdur_remaing; | 321 | u_int16_tdur_remaing; |
322 | }; | 322 | }; |
323 | 323 | ||
324 | 324 | ||
325 | struct tim_t { | 325 | struct tim_t { |
326 | u_int8_telement_id; | 326 | u_int8_telement_id; |
327 | u_int8_tlength; | 327 | u_int8_tlength; |
328 | u_int8_tcount; | 328 | u_int8_tcount; |
329 | u_int8_tperiod; | 329 | u_int8_tperiod; |
330 | u_int8_tbitmap_control; | 330 | u_int8_tbitmap_control; |
331 | u_int8_tbitmap[251]; | 331 | u_int8_tbitmap[251]; |
332 | }; | 332 | }; |
333 | 333 | ||
334 | 334 | ||
335 | struct ibss_t { | 335 | struct ibss_t { |
336 | u_int8_telement_id; | 336 | u_int8_telement_id; |
337 | u_int8_tlength; | 337 | u_int8_tlength; |
338 | u_int16_tatim_window; | 338 | u_int16_tatim_window; |
339 | }; | 339 | }; |
340 | 340 | ||
341 | 341 | ||
342 | #define E_SSID 0 | 342 | #define E_SSID 0 |
343 | #define E_RATES 1 | 343 | #define E_RATES 1 |
344 | #define E_FH 2 | 344 | #define E_FH 2 |
345 | #define E_DS 3 | 345 | #define E_DS 3 |
346 | #define E_CF 4 | 346 | #define E_CF 4 |
347 | #define E_TIM 5 | 347 | #define E_TIM 5 |
348 | #define E_IBSS 6 | 348 | #define E_IBSS 6 |
349 | #define E_CHALLENGE 16 | 349 | #define E_CHALLENGE 16 |
350 | #define E_CISCO 133 | 350 | #define E_CISCO 133 |
351 | 351 | ||
352 | 352 | ||
353 | struct ieee_802_11_mgmt_body { | 353 | struct ieee_802_11_mgmt_body { |
354 | u_int8_t timestamp[8]; | 354 | u_int8_t timestamp[8]; |
355 | u_int16_t beacon_interval; | 355 | u_int16_t beacon_interval; |
356 | // u_int16_t listen_interval; | 356 | // u_int16_t listen_interval; |
357 | // u_int16_t status_code; | 357 | // u_int16_t status_code; |
358 | // u_int16_t aid; | 358 | // u_int16_t aid; |
359 | // u_char ap[6]; | 359 | // u_char ap[6]; |
360 | // u_int16_treason_code; | 360 | // u_int16_treason_code; |
361 | // u_int16_tauth_alg; | 361 | // u_int16_tauth_alg; |
362 | // u_int16_tauth_trans_seq_num; | 362 | // u_int16_tauth_trans_seq_num; |
363 | // struct challenge_t challenge; | 363 | // struct challenge_t challenge; |
364 | u_int16_t capability_info; | 364 | u_int16_t capability_info; |
365 | // struct ssid_tssid; | 365 | // struct ssid_tssid; |
366 | // struct rates_t rates; | 366 | // struct rates_t rates; |
367 | // struct ds_tds; | 367 | // struct ds_tds; |
368 | // struct cf_tcf; | 368 | // struct cf_tcf; |
369 | // struct fh_tfh; | 369 | // struct fh_tfh; |
370 | // struct tim_ttim; | 370 | // struct tim_ttim; |
371 | }; | 371 | }; |
372 | 372 | ||
373 | /* a 802.11 value */ | 373 | /* a 802.11 value */ |
374 | struct val_80211 { | 374 | struct val_80211 { |
375 | unsigned int did; | 375 | unsigned int did; |
376 | unsigned short status, len; | 376 | unsigned short status, len; |
377 | unsigned int data; | 377 | unsigned int data; |
378 | }; | 378 | }; |
379 | 379 | ||
380 | /* header attached during prism monitor mode */ | 380 | /* header attached during prism monitor mode */ |
381 | struct prism_hdr { | 381 | struct prism_hdr { |
382 | unsigned int msgcode, msglen; | 382 | unsigned int msgcode, msglen; |
383 | char devname[16]; | 383 | char devname[16]; |
384 | struct val_80211 hosttime, mactime, channel, rssi, sq, signal, | 384 | struct val_80211 hosttime, mactime, channel, rssi, sq, signal, |
385 | noise, rate, istx, frmlen; | 385 | noise, rate, istx, frmlen; |
386 | }; | 386 | }; |
387 | 387 | ||
388 | struct ieee_802_11_data_body { | 388 | struct ieee_802_11_data_body { |
389 | //FIXME | 389 | //FIXME |
390 | }; | 390 | }; |
391 | 391 | ||
392 | struct ieee_802_11_control_body { | 392 | struct ieee_802_11_control_body { |
393 | //FIXME | 393 | //FIXME |
394 | }; | 394 | }; |
395 | 395 | ||
396 | struct ctrl_rts_t { | 396 | struct ctrl_rts_t { |
397 | u_int16_tfc; | 397 | u_int16_tfc; |
398 | u_int16_tduration; | 398 | u_int16_tduration; |
399 | u_int8_tra[6]; | 399 | u_int8_tra[6]; |
400 | u_int8_tta[6]; | 400 | u_int8_tta[6]; |
401 | u_int8_tfcs[4]; | 401 | u_int8_tfcs[4]; |
402 | }; | 402 | }; |
403 | 403 | ||
404 | #define CTRL_RTS_LEN(2+2+6+6+4) | 404 | #define CTRL_RTS_LEN(2+2+6+6+4) |
405 | 405 | ||
406 | struct ctrl_cts_t { | 406 | struct ctrl_cts_t { |
407 | u_int16_tfc; | 407 | u_int16_tfc; |
408 | u_int16_tduration; | 408 | u_int16_tduration; |
409 | u_int8_tra[6]; | 409 | u_int8_tra[6]; |
410 | u_int8_tfcs[4]; | 410 | u_int8_tfcs[4]; |
411 | }; | 411 | }; |
412 | 412 | ||
413 | #define CTRL_CTS_LEN(2+2+6+4) | 413 | #define CTRL_CTS_LEN(2+2+6+4) |
414 | 414 | ||
415 | struct ctrl_ack_t { | 415 | struct ctrl_ack_t { |
416 | u_int16_tfc; | 416 | u_int16_tfc; |
417 | u_int16_tduration; | 417 | u_int16_tduration; |
418 | u_int8_tra[6]; | 418 | u_int8_tra[6]; |
419 | u_int8_tfcs[4]; | 419 | u_int8_tfcs[4]; |
420 | }; | 420 | }; |
421 | 421 | ||
422 | #define CTRL_ACK_LEN(2+2+6+4) | 422 | #define CTRL_ACK_LEN(2+2+6+4) |
423 | 423 | ||
424 | struct ctrl_ps_poll_t { | 424 | struct ctrl_ps_poll_t { |
425 | u_int16_tfc; | 425 | u_int16_tfc; |
426 | u_int16_taid; | 426 | u_int16_taid; |
427 | u_int8_tbssid[6]; | 427 | u_int8_tbssid[6]; |
428 | u_int8_tta[6]; | 428 | u_int8_tta[6]; |
429 | u_int8_tfcs[4]; | 429 | u_int8_tfcs[4]; |
430 | }; | 430 | }; |
431 | 431 | ||
432 | #define CTRL_PS_POLL_LEN(2+2+6+6+4) | 432 | #define CTRL_PS_POLL_LEN(2+2+6+6+4) |
433 | 433 | ||
434 | struct ctrl_end_t { | 434 | struct ctrl_end_t { |
435 | u_int16_tfc; | 435 | u_int16_tfc; |
436 | u_int16_tduration; | 436 | u_int16_tduration; |
437 | u_int8_tra[6]; | 437 | u_int8_tra[6]; |
438 | u_int8_tbssid[6]; | 438 | u_int8_tbssid[6]; |
439 | u_int8_tfcs[4]; | 439 | u_int8_tfcs[4]; |
440 | }; | 440 | }; |
441 | 441 | ||
442 | #define CTRL_END_LEN(2+2+6+6+4) | 442 | #define CTRL_END_LEN(2+2+6+6+4) |
443 | 443 | ||
444 | struct ctrl_end_ack_t { | 444 | struct ctrl_end_ack_t { |
445 | u_int16_tfc; | 445 | u_int16_tfc; |
446 | u_int16_tduration; | 446 | u_int16_tduration; |
447 | u_int8_tra[6]; | 447 | u_int8_tra[6]; |
448 | u_int8_tbssid[6]; | 448 | u_int8_tbssid[6]; |
449 | u_int8_tfcs[4]; | 449 | u_int8_tfcs[4]; |
450 | }; | 450 | }; |
451 | 451 | ||
452 | #define CTRL_END_ACK_LEN(2+2+6+6+4) | 452 | #define CTRL_END_ACK_LEN(2+2+6+6+4) |
453 | 453 | ||
454 | #define IV_IV(iv)((iv) & 0xFFFFFF) | 454 | #define IV_IV(iv)((iv) & 0xFFFFFF) |
455 | #define IV_PAD(iv)(((iv) >> 24) & 0x3F) | 455 | #define IV_PAD(iv)(((iv) >> 24) & 0x3F) |
456 | #define IV_KEYID(iv)(((iv) >> 30) & 0x03) | 456 | #define IV_KEYID(iv)(((iv) >> 30) & 0x03) |
457 | 457 | ||
458 | #endif | 458 | #endif |
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index e9b3b2c..012c0a3 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -1,1317 +1,1331 @@ | |||
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; 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 | /* 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 | /*====================================================================================== | 48 | /*====================================================================================== |
49 | * OPacket | 49 | * OPacket |
50 | *======================================================================================*/ | 50 | *======================================================================================*/ |
51 | 51 | ||
52 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) | 52 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) |
53 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) | 53 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) |
54 | { | 54 | { |
55 | //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); | 55 | //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); |
56 | 56 | ||
57 | _end = (unsigned char*) data + header.len; | 57 | _end = (unsigned char*) data + header.len; |
58 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | 58 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); |
59 | 59 | ||
60 | switch ( datalink ) | 60 | switch ( datalink ) |
61 | { | 61 | { |
62 | case DLT_EN10MB: | 62 | case DLT_EN10MB: |
63 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; | 63 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; |
64 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); | 64 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); |
65 | break; | 65 | break; |
66 | 66 | ||
67 | case DLT_IEEE802_11: | 67 | case DLT_IEEE802_11: |
68 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; | 68 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; |
69 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); | 69 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); |
70 | break; | 70 | break; |
71 | 71 | ||
72 | case DLT_PRISM_HEADER: | 72 | case DLT_PRISM_HEADER: |
73 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; | 73 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; |
74 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); | 74 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); |
75 | break; | 75 | break; |
76 | 76 | ||
77 | default: | 77 | default: |
78 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; | 78 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | OPacket::~OPacket() | 83 | OPacket::~OPacket() |
84 | { | 84 | { |
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | timevalstruct OPacket::timeval() const | 88 | timevalstruct OPacket::timeval() const |
89 | { | 89 | { |
90 | return _hdr.ts; | 90 | return _hdr.ts; |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | int OPacket::caplen() const | 94 | int OPacket::caplen() const |
95 | { | 95 | { |
96 | return _hdr.caplen; | 96 | return _hdr.caplen; |
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | 100 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) |
101 | { | 101 | { |
102 | if (!l) return; | 102 | if (!l) return; |
103 | QObject* o = l->first(); | 103 | QObject* o = l->first(); |
104 | while ( o ) | 104 | while ( o ) |
105 | { | 105 | { |
106 | stats[o->name()]++; | 106 | stats[o->name()]++; |
107 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); | 107 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); |
108 | o = l->next(); | 108 | o = l->next(); |
109 | } | 109 | } |
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
113 | void OPacket::dumpStructure( QObjectList* l ) | 113 | void OPacket::dumpStructure( QObjectList* l ) |
114 | { | 114 | { |
115 | QString packetString( "[ |" + _dumpStructure( l ) + " ]" ); | 115 | QString packetString( "[ |" + _dumpStructure( l ) + " ]" ); |
116 | odebug << "OPacket::dumpStructure: " << packetString << oendl; | 116 | odebug << "OPacket::dumpStructure: " << packetString << oendl; |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | QString OPacket::_dumpStructure( QObjectList* l ) | 120 | QString OPacket::_dumpStructure( QObjectList* l ) |
121 | { | 121 | { |
122 | if (!l) return QString::null; | 122 | if (!l) return QString::null; |
123 | QObject* o = l->first(); | 123 | QObject* o = l->first(); |
124 | QString str(" "); | 124 | QString str(" "); |
125 | 125 | ||
126 | while ( o ) | 126 | while ( o ) |
127 | { | 127 | { |
128 | str.append( o->name() ); | 128 | str.append( o->name() ); |
129 | str.append( " |" ); | 129 | str.append( " |" ); |
130 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); | 130 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); |
131 | o = l->next(); | 131 | o = l->next(); |
132 | } | 132 | } |
133 | return str; | 133 | return str; |
134 | } | 134 | } |
135 | 135 | ||
136 | QString OPacket::dump( int bpl ) const | 136 | QString OPacket::dump( int bpl ) const |
137 | { | 137 | { |
138 | static int index = 0; | 138 | static int index = 0; |
139 | index++; | 139 | index++; |
140 | int len = _hdr.caplen; | 140 | int len = _hdr.caplen; |
141 | QString str; | 141 | QString str; |
142 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); | 142 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); |
143 | str.append( "0000: " ); | 143 | str.append( "0000: " ); |
144 | QString tmp; | 144 | QString tmp; |
145 | QString bytes; | 145 | QString bytes; |
146 | QString chars; | 146 | QString chars; |
147 | 147 | ||
148 | for ( int i = 0; i < len; ++i ) | 148 | for ( int i = 0; i < len; ++i ) |
149 | { | 149 | { |
150 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | 150 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); |
151 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | 151 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); |
152 | else chars.append( '.' ); | 152 | else chars.append( '.' ); |
153 | 153 | ||
154 | if ( !((i+1) % bpl) ) | 154 | if ( !((i+1) % bpl) ) |
155 | { | 155 | { |
156 | str.append( bytes ); | 156 | str.append( bytes ); |
157 | str.append( ' ' ); | 157 | str.append( ' ' ); |
158 | str.append( chars ); | 158 | str.append( chars ); |
159 | str.append( '\n' ); | 159 | str.append( '\n' ); |
160 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); | 160 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); |
161 | bytes = ""; | 161 | bytes = ""; |
162 | chars = ""; | 162 | chars = ""; |
163 | } | 163 | } |
164 | 164 | ||
165 | } | 165 | } |
166 | if ( (len % bpl) ) | 166 | if ( (len % bpl) ) |
167 | { | 167 | { |
168 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); | 168 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); |
169 | str.append( chars ); | 169 | str.append( chars ); |
170 | } | 170 | } |
171 | str.append( '\n' ); | 171 | str.append( '\n' ); |
172 | return str; | 172 | return str; |
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
176 | int OPacket::len() const | 176 | int OPacket::len() const |
177 | { | 177 | { |
178 | return _hdr.len; | 178 | return _hdr.len; |
179 | } | 179 | } |
180 | 180 | ||
181 | 181 | ||
182 | /*====================================================================================== | 182 | /*====================================================================================== |
183 | * OEthernetPacket | 183 | * OEthernetPacket |
184 | *======================================================================================*/ | 184 | *======================================================================================*/ |
185 | 185 | ||
186 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) | 186 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
187 | :QObject( parent, "Ethernet" ), _ether( data ) | 187 | :QObject( parent, "Ethernet" ), _ether( data ) |
188 | { | 188 | { |
189 | 189 | ||
190 | odebug << "Source = " << sourceAddress().toString(); | 190 | odebug << "Source = " << sourceAddress().toString(); |
191 | odebug << "Destination = " << destinationAddress().toString(); | 191 | odebug << "Destination = " << destinationAddress().toString(); |
192 | 192 | ||
193 | if ( sourceAddress() == OMacAddress::broadcast ) | 193 | if ( sourceAddress() == OMacAddress::broadcast ) |
194 | odebug << "Source is broadcast address" << oendl; | 194 | odebug << "Source is broadcast address" << oendl; |
195 | if ( destinationAddress() == OMacAddress::broadcast ) | 195 | if ( destinationAddress() == OMacAddress::broadcast ) |
196 | odebug << "Destination is broadcast address" << oendl; | 196 | odebug << "Destination is broadcast address" << oendl; |
197 | 197 | ||
198 | switch ( type() ) | 198 | switch ( type() ) |
199 | { | 199 | { |
200 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 200 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
201 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 201 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
202 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } | 202 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } |
203 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; | 203 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; |
204 | } | 204 | } |
205 | 205 | ||
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | OEthernetPacket::~OEthernetPacket() | 209 | OEthernetPacket::~OEthernetPacket() |
210 | { | 210 | { |
211 | } | 211 | } |
212 | 212 | ||
213 | 213 | ||
214 | OMacAddress OEthernetPacket::sourceAddress() const | 214 | OMacAddress OEthernetPacket::sourceAddress() const |
215 | { | 215 | { |
216 | return OMacAddress( _ether->ether_shost ); | 216 | return OMacAddress( _ether->ether_shost ); |
217 | } | 217 | } |
218 | 218 | ||
219 | 219 | ||
220 | OMacAddress OEthernetPacket::destinationAddress() const | 220 | OMacAddress OEthernetPacket::destinationAddress() const |
221 | { | 221 | { |
222 | return OMacAddress( _ether->ether_dhost ); | 222 | return OMacAddress( _ether->ether_dhost ); |
223 | } | 223 | } |
224 | 224 | ||
225 | int OEthernetPacket::type() const | 225 | int OEthernetPacket::type() const |
226 | { | 226 | { |
227 | return ntohs( _ether->ether_type ); | 227 | return ntohs( _ether->ether_type ); |
228 | } | 228 | } |
229 | 229 | ||
230 | 230 | ||
231 | /*====================================================================================== | 231 | /*====================================================================================== |
232 | * OIPPacket | 232 | * OIPPacket |
233 | *======================================================================================*/ | 233 | *======================================================================================*/ |
234 | 234 | ||
235 | 235 | ||
236 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) | 236 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
237 | :QObject( parent, "IP" ), _iphdr( data ) | 237 | :QObject( parent, "IP" ), _iphdr( data ) |
238 | { | 238 | { |
239 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; | 239 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; |
240 | 240 | ||
241 | odebug << "FromAddress = " << fromIPAddress().toString(); | 241 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; |
242 | odebug << " toAddress = " << toIPAddress().toString(); | 242 | odebug << " toAddress = " << toIPAddress().toString() << oendl; |
243 | 243 | ||
244 | switch ( protocol() ) | 244 | switch ( protocol() ) |
245 | { | 245 | { |
246 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; | 246 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
247 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; | 247 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
248 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; | 248 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; |
249 | } | 249 | } |
250 | 250 | ||
251 | } | 251 | } |
252 | 252 | ||
253 | OIPPacket::~OIPPacket() | 253 | OIPPacket::~OIPPacket() |
254 | { | 254 | { |
255 | } | 255 | } |
256 | 256 | ||
257 | 257 | ||
258 | QHostAddress OIPPacket::fromIPAddress() const | 258 | QHostAddress OIPPacket::fromIPAddress() const |
259 | { | 259 | { |
260 | return EXTRACT_32BITS( &_iphdr->saddr ); | 260 | return EXTRACT_32BITS( &_iphdr->saddr ); |
261 | } | 261 | } |
262 | 262 | ||
263 | 263 | ||
264 | QHostAddress OIPPacket::toIPAddress() const | 264 | QHostAddress OIPPacket::toIPAddress() const |
265 | { | 265 | { |
266 | return EXTRACT_32BITS( &_iphdr->saddr ); | 266 | return EXTRACT_32BITS( &_iphdr->saddr ); |
267 | } | 267 | } |
268 | 268 | ||
269 | 269 | ||
270 | int OIPPacket::tos() const | 270 | int OIPPacket::tos() const |
271 | { | 271 | { |
272 | return _iphdr->tos; | 272 | return _iphdr->tos; |
273 | } | 273 | } |
274 | 274 | ||
275 | 275 | ||
276 | int OIPPacket::len() const | 276 | int OIPPacket::len() const |
277 | { | 277 | { |
278 | return EXTRACT_16BITS( &_iphdr->tot_len ); | 278 | return EXTRACT_16BITS( &_iphdr->tot_len ); |
279 | } | 279 | } |
280 | 280 | ||
281 | 281 | ||
282 | int OIPPacket::id() const | 282 | int OIPPacket::id() const |
283 | { | 283 | { |
284 | return EXTRACT_16BITS( &_iphdr->id ); | 284 | return EXTRACT_16BITS( &_iphdr->id ); |
285 | } | 285 | } |
286 | 286 | ||
287 | 287 | ||
288 | int OIPPacket::offset() const | 288 | int OIPPacket::offset() const |
289 | { | 289 | { |
290 | return EXTRACT_16BITS( &_iphdr->frag_off ); | 290 | return EXTRACT_16BITS( &_iphdr->frag_off ); |
291 | } | 291 | } |
292 | 292 | ||
293 | 293 | ||
294 | int OIPPacket::ttl() const | 294 | int OIPPacket::ttl() const |
295 | { | 295 | { |
296 | return _iphdr->ttl; | 296 | return _iphdr->ttl; |
297 | } | 297 | } |
298 | 298 | ||
299 | 299 | ||
300 | int OIPPacket::protocol() const | 300 | int OIPPacket::protocol() const |
301 | { | 301 | { |
302 | return _iphdr->protocol; | 302 | return _iphdr->protocol; |
303 | } | 303 | } |
304 | 304 | ||
305 | 305 | ||
306 | int OIPPacket::checksum() const | 306 | int OIPPacket::checksum() const |
307 | { | 307 | { |
308 | return EXTRACT_16BITS( &_iphdr->check ); | 308 | return EXTRACT_16BITS( &_iphdr->check ); |
309 | } | 309 | } |
310 | 310 | ||
311 | /*====================================================================================== | 311 | /*====================================================================================== |
312 | * OARPPacket | 312 | * OARPPacket |
313 | *======================================================================================*/ | 313 | *======================================================================================*/ |
314 | 314 | ||
315 | 315 | ||
316 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) | 316 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) |
317 | :QObject( parent, "ARP" ), _arphdr( data ) | 317 | :QObject( parent, "ARP" ), _arphdr( data ) |
318 | { | 318 | { |
319 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; | 319 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; |
320 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; | 320 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; |
321 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; | 321 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; |
322 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; | 322 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; |
323 | } | 323 | } |
324 | 324 | ||
325 | 325 | ||
326 | OARPPacket::~OARPPacket() | 326 | OARPPacket::~OARPPacket() |
327 | { | 327 | { |
328 | } | 328 | } |
329 | 329 | ||
330 | 330 | ||
331 | QString OARPPacket::type() const | 331 | QString OARPPacket::type() const |
332 | { | 332 | { |
333 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) | 333 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) |
334 | { | 334 | { |
335 | case 1: return "REQUEST"; | 335 | case 1: return "REQUEST"; |
336 | case 2: return "REPLY"; | 336 | case 2: return "REPLY"; |
337 | case 3: return "RREQUEST"; | 337 | case 3: return "RREQUEST"; |
338 | case 4: return "RREPLY"; | 338 | case 4: return "RREPLY"; |
339 | case 8: return "InREQUEST"; | 339 | case 8: return "InREQUEST"; |
340 | case 9: return "InREPLY"; | 340 | case 9: return "InREPLY"; |
341 | case 10: return "NAK"; | 341 | case 10: return "NAK"; |
342 | default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>"; | 342 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; |
343 | } | 343 | } |
344 | } | 344 | } |
345 | 345 | ||
346 | 346 | ||
347 | QHostAddress OARPPacket::senderIPV4Address() const | 347 | QHostAddress OARPPacket::senderIPV4Address() const |
348 | { | 348 | { |
349 | return EXTRACT_32BITS( &_arphdr->ar_sip ); | 349 | return EXTRACT_32BITS( &_arphdr->ar_sip ); |
350 | } | 350 | } |
351 | 351 | ||
352 | 352 | ||
353 | QHostAddress OARPPacket::targetIPV4Address() const | 353 | QHostAddress OARPPacket::targetIPV4Address() const |
354 | { | 354 | { |
355 | return EXTRACT_32BITS( &_arphdr->ar_tip ); | 355 | return EXTRACT_32BITS( &_arphdr->ar_tip ); |
356 | } | 356 | } |
357 | 357 | ||
358 | 358 | ||
359 | OMacAddress OARPPacket::senderMacAddress() const | 359 | OMacAddress OARPPacket::senderMacAddress() const |
360 | { | 360 | { |
361 | return OMacAddress( _arphdr->ar_sha ); | 361 | return OMacAddress( _arphdr->ar_sha ); |
362 | } | 362 | } |
363 | 363 | ||
364 | 364 | ||
365 | OMacAddress OARPPacket::targetMacAddress() const | 365 | OMacAddress OARPPacket::targetMacAddress() const |
366 | { | 366 | { |
367 | return OMacAddress( _arphdr->ar_tha ); | 367 | return OMacAddress( _arphdr->ar_tha ); |
368 | } | 368 | } |
369 | 369 | ||
370 | 370 | ||
371 | /*====================================================================================== | 371 | /*====================================================================================== |
372 | * OUDPPacket | 372 | * OUDPPacket |
373 | *======================================================================================*/ | 373 | *======================================================================================*/ |
374 | 374 | ||
375 | 375 | ||
376 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) | 376 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
377 | :QObject( parent, "UDP" ), _udphdr( data ) | 377 | :QObject( parent, "UDP" ), _udphdr( data ) |
378 | 378 | ||
379 | { | 379 | { |
380 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; | 380 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; |
381 | odebug << "fromPort = " << fromPort() << oendl; | 381 | odebug << "fromPort = " << fromPort() << oendl; |
382 | odebug << " toPort = " << toPort() << oendl; | 382 | odebug << " toPort = " << toPort() << oendl; |
383 | 383 | ||
384 | // TODO: Make this a case or a hash if we know more udp protocols | 384 | // TODO: Make this a case or a hash if we know more udp protocols |
385 | 385 | ||
386 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || | 386 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || |
387 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) | 387 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) |
388 | { | 388 | { |
389 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; | 389 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; |
390 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); | 390 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); |
391 | } | 391 | } |
392 | } | 392 | } |
393 | 393 | ||
394 | 394 | ||
395 | OUDPPacket::~OUDPPacket() | 395 | OUDPPacket::~OUDPPacket() |
396 | { | 396 | { |
397 | } | 397 | } |
398 | 398 | ||
399 | 399 | ||
400 | int OUDPPacket::fromPort() const | 400 | int OUDPPacket::fromPort() const |
401 | { | 401 | { |
402 | return EXTRACT_16BITS( &_udphdr->source ); | 402 | return EXTRACT_16BITS( &_udphdr->source ); |
403 | } | 403 | } |
404 | 404 | ||
405 | 405 | ||
406 | int OUDPPacket::toPort() const | 406 | int OUDPPacket::toPort() const |
407 | { | 407 | { |
408 | return EXTRACT_16BITS( &_udphdr->dest ); | 408 | return EXTRACT_16BITS( &_udphdr->dest ); |
409 | } | 409 | } |
410 | 410 | ||
411 | 411 | ||
412 | int OUDPPacket::length() const | 412 | int OUDPPacket::length() const |
413 | { | 413 | { |
414 | return EXTRACT_16BITS( &_udphdr->len ); | 414 | return EXTRACT_16BITS( &_udphdr->len ); |
415 | } | 415 | } |
416 | 416 | ||
417 | 417 | ||
418 | int OUDPPacket::checksum() const | 418 | int OUDPPacket::checksum() const |
419 | { | 419 | { |
420 | return EXTRACT_16BITS( &_udphdr->check ); | 420 | return EXTRACT_16BITS( &_udphdr->check ); |
421 | } | 421 | } |
422 | 422 | ||
423 | 423 | ||
424 | /*====================================================================================== | 424 | /*====================================================================================== |
425 | * ODHCPPacket | 425 | * ODHCPPacket |
426 | *======================================================================================*/ | 426 | *======================================================================================*/ |
427 | 427 | ||
428 | 428 | ||
429 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) | 429 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) |
430 | :QObject( parent, "DHCP" ), _dhcphdr( data ) | 430 | :QObject( parent, "DHCP" ), _dhcphdr( data ) |
431 | 431 | ||
432 | { | 432 | { |
433 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; | 433 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; |
434 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; | 434 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; |
435 | odebug << "clientAddress = " << clientAddress().toString() << oendl; | 435 | odebug << "clientAddress = " << clientAddress().toString() << oendl; |
436 | odebug << " yourAddress = " << yourAddress().toString() << oendl; | 436 | odebug << " yourAddress = " << yourAddress().toString() << oendl; |
437 | odebug << "serverAddress = " << serverAddress().toString() << oendl; | 437 | odebug << "serverAddress = " << serverAddress().toString() << oendl; |
438 | odebug << " relayAddress = " << relayAddress().toString() << oendl; | 438 | odebug << " relayAddress = " << relayAddress().toString() << oendl; |
439 | odebug << "parsing DHCP options..." << oendl; | 439 | odebug << "parsing DHCP options..." << oendl; |
440 | 440 | ||
441 | _type = 0; | 441 | _type = 0; |
442 | 442 | ||
443 | const unsigned char* option = &_dhcphdr->options[4]; | 443 | const unsigned char* option = &_dhcphdr->options[4]; |
444 | char tag = -1; | 444 | char tag = -1; |
445 | char len = -1; | 445 | char len = -1; |
446 | 446 | ||
447 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) | 447 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) |
448 | { | 448 | { |
449 | len = *option++; | 449 | len = *option++; |
450 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; | 450 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; |
451 | 451 | ||
452 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) | 452 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) |
453 | _type = *option; | 453 | _type = *option; |
454 | 454 | ||
455 | option += len; | 455 | option += len; |
456 | if ( option >= end ) | 456 | if ( option >= end ) |
457 | { | 457 | { |
458 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; | 458 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; |
459 | break; | 459 | break; |
460 | } | 460 | } |
461 | } | 461 | } |
462 | 462 | ||
463 | odebug << "DHCP type seems to be << " << type() << oendl; | 463 | odebug << "DHCP type seems to be << " << type() << oendl; |
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
467 | ODHCPPacket::~ODHCPPacket() | 467 | ODHCPPacket::~ODHCPPacket() |
468 | { | 468 | { |
469 | } | 469 | } |
470 | 470 | ||
471 | 471 | ||
472 | bool ODHCPPacket::isRequest() const | 472 | bool ODHCPPacket::isRequest() const |
473 | { | 473 | { |
474 | return ( _dhcphdr->op == 01 ); | 474 | return ( _dhcphdr->op == 01 ); |
475 | } | 475 | } |
476 | 476 | ||
477 | 477 | ||
478 | bool ODHCPPacket::isReply() const | 478 | bool ODHCPPacket::isReply() const |
479 | { | 479 | { |
480 | return ( _dhcphdr->op == 02 ); | 480 | return ( _dhcphdr->op == 02 ); |
481 | } | 481 | } |
482 | 482 | ||
483 | 483 | ||
484 | QString ODHCPPacket::type() const | 484 | QString ODHCPPacket::type() const |
485 | { | 485 | { |
486 | switch ( _type ) | 486 | switch ( _type ) |
487 | { | 487 | { |
488 | case 1: return "DISCOVER"; | 488 | case 1: return "DISCOVER"; |
489 | case 2: return "OFFER"; | 489 | case 2: return "OFFER"; |
490 | case 3: return "REQUEST"; | 490 | case 3: return "REQUEST"; |
491 | case 4: return "DECLINE"; | 491 | case 4: return "DECLINE"; |
492 | case 5: return "ACK"; | 492 | case 5: return "ACK"; |
493 | case 6: return "NAK"; | 493 | case 6: return "NAK"; |
494 | case 7: return "RELEASE"; | 494 | case 7: return "RELEASE"; |
495 | case 8: return "INFORM"; | 495 | case 8: return "INFORM"; |
496 | default: qWarning( "ODHCPPacket::type(): invalid DHCP type (%d) !", _dhcphdr->op ); return "<unknown>"; | 496 | default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>"; |
497 | } | 497 | } |
498 | } | 498 | } |
499 | 499 | ||
500 | 500 | ||
501 | QHostAddress ODHCPPacket::clientAddress() const | 501 | QHostAddress ODHCPPacket::clientAddress() const |
502 | { | 502 | { |
503 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); | 503 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); |
504 | } | 504 | } |
505 | 505 | ||
506 | 506 | ||
507 | QHostAddress ODHCPPacket::yourAddress() const | 507 | QHostAddress ODHCPPacket::yourAddress() const |
508 | { | 508 | { |
509 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); | 509 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); |
510 | } | 510 | } |
511 | 511 | ||
512 | 512 | ||
513 | QHostAddress ODHCPPacket::serverAddress() const | 513 | QHostAddress ODHCPPacket::serverAddress() const |
514 | { | 514 | { |
515 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); | 515 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); |
516 | } | 516 | } |
517 | 517 | ||
518 | 518 | ||
519 | QHostAddress ODHCPPacket::relayAddress() const | 519 | QHostAddress ODHCPPacket::relayAddress() const |
520 | { | 520 | { |
521 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); | 521 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); |
522 | } | 522 | } |
523 | 523 | ||
524 | 524 | ||
525 | OMacAddress ODHCPPacket::clientMacAddress() const | 525 | OMacAddress ODHCPPacket::clientMacAddress() const |
526 | { | 526 | { |
527 | return OMacAddress( _dhcphdr->chaddr ); | 527 | return OMacAddress( _dhcphdr->chaddr ); |
528 | } | 528 | } |
529 | 529 | ||
530 | 530 | ||
531 | /*====================================================================================== | 531 | /*====================================================================================== |
532 | * OTCPPacket | 532 | * OTCPPacket |
533 | *======================================================================================*/ | 533 | *======================================================================================*/ |
534 | 534 | ||
535 | 535 | ||
536 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) | 536 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) |
537 | :QObject( parent, "TCP" ), _tcphdr( data ) | 537 | :QObject( parent, "TCP" ), _tcphdr( data ) |
538 | 538 | ||
539 | { | 539 | { |
540 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; | 540 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; |
541 | } | 541 | } |
542 | 542 | ||
543 | 543 | ||
544 | OTCPPacket::~OTCPPacket() | 544 | OTCPPacket::~OTCPPacket() |
545 | { | 545 | { |
546 | } | 546 | } |
547 | 547 | ||
548 | 548 | ||
549 | int OTCPPacket::fromPort() const | 549 | int OTCPPacket::fromPort() const |
550 | { | 550 | { |
551 | return EXTRACT_16BITS( &_tcphdr->source ); | 551 | return EXTRACT_16BITS( &_tcphdr->source ); |
552 | } | 552 | } |
553 | 553 | ||
554 | 554 | ||
555 | int OTCPPacket::toPort() const | 555 | int OTCPPacket::toPort() const |
556 | { | 556 | { |
557 | return EXTRACT_16BITS( &_tcphdr->dest ); | 557 | return EXTRACT_16BITS( &_tcphdr->dest ); |
558 | } | 558 | } |
559 | 559 | ||
560 | 560 | ||
561 | int OTCPPacket::seq() const | 561 | int OTCPPacket::seq() const |
562 | { | 562 | { |
563 | return EXTRACT_16BITS( &_tcphdr->seq ); | 563 | return EXTRACT_16BITS( &_tcphdr->seq ); |
564 | } | 564 | } |
565 | 565 | ||
566 | 566 | ||
567 | int OTCPPacket::ack() const | 567 | int OTCPPacket::ack() const |
568 | { | 568 | { |
569 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); | 569 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); |
570 | } | 570 | } |
571 | 571 | ||
572 | 572 | ||
573 | int OTCPPacket::window() const | 573 | int OTCPPacket::window() const |
574 | { | 574 | { |
575 | return EXTRACT_16BITS( &_tcphdr->window ); | 575 | return EXTRACT_16BITS( &_tcphdr->window ); |
576 | } | 576 | } |
577 | 577 | ||
578 | 578 | ||
579 | int OTCPPacket::checksum() const | 579 | int OTCPPacket::checksum() const |
580 | { | 580 | { |
581 | return EXTRACT_16BITS( &_tcphdr->check ); | 581 | return EXTRACT_16BITS( &_tcphdr->check ); |
582 | } | 582 | } |
583 | 583 | ||
584 | /*====================================================================================== | 584 | /*====================================================================================== |
585 | * OPrismHeaderPacket | 585 | * OPrismHeaderPacket |
586 | *======================================================================================*/ | 586 | *======================================================================================*/ |
587 | 587 | ||
588 | 588 | ||
589 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) | 589 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) |
590 | :QObject( parent, "Prism" ), _header( data ) | 590 | :QObject( parent, "Prism" ), _header( data ) |
591 | 591 | ||
592 | { | 592 | { |
593 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; | 593 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; |
594 | 594 | ||
595 | odebug << "Signal Strength = " << data->signal.data << oendl; | 595 | odebug << "Signal Strength = " << data->signal.data << oendl; |
596 | 596 | ||
597 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); | 597 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); |
598 | } | 598 | } |
599 | 599 | ||
600 | OPrismHeaderPacket::~OPrismHeaderPacket() | 600 | OPrismHeaderPacket::~OPrismHeaderPacket() |
601 | { | 601 | { |
602 | } | 602 | } |
603 | 603 | ||
604 | 604 | ||
605 | unsigned int OPrismHeaderPacket::signalStrength() const | 605 | unsigned int OPrismHeaderPacket::signalStrength() const |
606 | { | 606 | { |
607 | return _header->signal.data; | 607 | return _header->signal.data; |
608 | } | 608 | } |
609 | 609 | ||
610 | /*====================================================================================== | 610 | /*====================================================================================== |
611 | * OWaveLanPacket | 611 | * OWaveLanPacket |
612 | *======================================================================================*/ | 612 | *======================================================================================*/ |
613 | 613 | ||
614 | 614 | ||
615 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) | 615 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) |
616 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 616 | :QObject( parent, "802.11" ), _wlanhdr( data ) |
617 | 617 | ||
618 | { | 618 | { |
619 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; | 619 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; |
620 | odebug << "type = " << type() << oendl; | 620 | odebug << "type = " << type() << oendl; |
621 | odebug << "subType = " << subType() << oendl; | 621 | odebug << "subType = " << subType() << oendl; |
622 | odebug << "duration = " << duration() << oendl; | 622 | odebug << "duration = " << duration() << oendl; |
623 | odebug << "powermanagement = " << usesPowerManagement() << oendl; | 623 | odebug << "powermanagement = " << usesPowerManagement() << oendl; |
624 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; | 624 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; |
625 | odebug << "MAC1 = " << macAddress1().toString() << oendl; | 625 | odebug << "MAC1 = " << macAddress1().toString() << oendl; |
626 | odebug << "MAC2 = " << macAddress2().toString() << oendl; | 626 | odebug << "MAC2 = " << macAddress2().toString() << oendl; |
627 | odebug << "MAC3 = " << macAddress3().toString() << oendl; | 627 | odebug << "MAC3 = " << macAddress3().toString() << oendl; |
628 | odebug << "MAC4 = " << macAddress4().toString() << oendl; | 628 | odebug << "MAC4 = " << macAddress4().toString() << oendl; |
629 | 629 | ||
630 | switch ( type() ) | 630 | switch ( type() ) |
631 | { | 631 | { |
632 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; | 632 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
633 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; | 633 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
634 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; | 634 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; |
635 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; | 635 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; |
636 | } | 636 | } |
637 | } | 637 | } |
638 | 638 | ||
639 | OWaveLanPacket::~OWaveLanPacket() | 639 | OWaveLanPacket::~OWaveLanPacket() |
640 | { | 640 | { |
641 | } | 641 | } |
642 | 642 | ||
643 | 643 | ||
644 | int OWaveLanPacket::duration() const | 644 | int OWaveLanPacket::duration() const |
645 | { | 645 | { |
646 | return _wlanhdr->duration; | 646 | return _wlanhdr->duration; |
647 | } | 647 | } |
648 | 648 | ||
649 | 649 | ||
650 | OMacAddress OWaveLanPacket::macAddress1() const | 650 | OMacAddress OWaveLanPacket::macAddress1() const |
651 | { | 651 | { |
652 | return OMacAddress( _wlanhdr->mac1 ); | 652 | return OMacAddress( _wlanhdr->mac1 ); |
653 | } | 653 | } |
654 | 654 | ||
655 | 655 | ||
656 | OMacAddress OWaveLanPacket::macAddress2() const | 656 | OMacAddress OWaveLanPacket::macAddress2() const |
657 | { | 657 | { |
658 | return OMacAddress( _wlanhdr->mac2 ); | 658 | return OMacAddress( _wlanhdr->mac2 ); |
659 | } | 659 | } |
660 | 660 | ||
661 | 661 | ||
662 | OMacAddress OWaveLanPacket::macAddress3() const | 662 | OMacAddress OWaveLanPacket::macAddress3() const |
663 | { | 663 | { |
664 | return OMacAddress( _wlanhdr->mac3 ); | 664 | return OMacAddress( _wlanhdr->mac3 ); |
665 | } | 665 | } |
666 | 666 | ||
667 | 667 | ||
668 | OMacAddress OWaveLanPacket::macAddress4() const | 668 | OMacAddress OWaveLanPacket::macAddress4() const |
669 | { | 669 | { |
670 | return OMacAddress( _wlanhdr->mac4 ); | 670 | return OMacAddress( _wlanhdr->mac4 ); |
671 | } | 671 | } |
672 | 672 | ||
673 | 673 | ||
674 | int OWaveLanPacket::subType() const | 674 | int OWaveLanPacket::subType() const |
675 | { | 675 | { |
676 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 676 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
677 | } | 677 | } |
678 | 678 | ||
679 | 679 | ||
680 | int OWaveLanPacket::type() const | 680 | int OWaveLanPacket::type() const |
681 | { | 681 | { |
682 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 682 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
683 | } | 683 | } |
684 | 684 | ||
685 | 685 | ||
686 | int OWaveLanPacket::version() const | 686 | int OWaveLanPacket::version() const |
687 | { | 687 | { |
688 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 688 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
689 | } | 689 | } |
690 | 690 | ||
691 | 691 | ||
692 | bool OWaveLanPacket::fromDS() const | 692 | bool OWaveLanPacket::fromDS() const |
693 | { | 693 | { |
694 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 694 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
695 | } | 695 | } |
696 | 696 | ||
697 | 697 | ||
698 | bool OWaveLanPacket::toDS() const | 698 | bool OWaveLanPacket::toDS() const |
699 | { | 699 | { |
700 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 700 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
701 | } | 701 | } |
702 | 702 | ||
703 | 703 | ||
704 | bool OWaveLanPacket::usesPowerManagement() const | 704 | bool OWaveLanPacket::usesPowerManagement() const |
705 | { | 705 | { |
706 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 706 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
707 | } | 707 | } |
708 | 708 | ||
709 | 709 | ||
710 | bool OWaveLanPacket::usesWep() const | 710 | bool OWaveLanPacket::usesWep() const |
711 | { | 711 | { |
712 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 712 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
713 | } | 713 | } |
714 | 714 | ||
715 | 715 | ||
716 | /*====================================================================================== | 716 | /*====================================================================================== |
717 | * OWaveLanManagementPacket | 717 | * OWaveLanManagementPacket |
718 | *======================================================================================*/ | 718 | *======================================================================================*/ |
719 | 719 | ||
720 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 720 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
721 | :QObject( parent, "802.11 Management" ), _header( data ), | 721 | :QObject( parent, "802.11 Management" ), _header( data ), |
722 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 722 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
723 | { | 723 | { |
724 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; | 724 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; |
725 | odebug << "Detected subtype is " << managementType() << oendl; | 725 | odebug << "Detected subtype is " << managementType() << oendl; |
726 | 726 | ||
727 | // grab tagged values | 727 | // grab tagged values |
728 | const unsigned char* ptr = (const unsigned char*) (_body+1); | 728 | const unsigned char* ptr = (const unsigned char*) (_body+1); |
729 | while (ptr < end) | 729 | while (ptr < end) |
730 | { | 730 | { |
731 | switch ( *ptr ) | 731 | switch ( *ptr ) |
732 | { | 732 | { |
733 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | 733 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; |
734 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | 734 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; |
735 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | 735 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; |
736 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | 736 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; |
737 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | 737 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; |
738 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | 738 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; |
739 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | 739 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; |
740 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | 740 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; |
741 | } | 741 | } |
742 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | 742 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value |
743 | ptr+= 2; // skip tag ID and length | 743 | ptr+= 2; // skip tag ID and length |
744 | } | 744 | } |
745 | } | 745 | } |
746 | 746 | ||
747 | 747 | ||
748 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | 748 | OWaveLanManagementPacket::~OWaveLanManagementPacket() |
749 | { | 749 | { |
750 | } | 750 | } |
751 | 751 | ||
752 | 752 | ||
753 | QString OWaveLanManagementPacket::managementType() const | 753 | QString OWaveLanManagementPacket::managementType() const |
754 | { | 754 | { |
755 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 755 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
756 | { | 756 | { |
757 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; | 757 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; |
758 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; | 758 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; |
759 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; | 759 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; |
760 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; | 760 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; |
761 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; | 761 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; |
762 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; | 762 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; |
763 | case ST_BEACON: return "Beacon"; break; | 763 | case ST_BEACON: return "Beacon"; break; |
764 | case ST_ATIM: return "Atim"; break; | 764 | case ST_ATIM: return "Atim"; break; |
765 | case ST_DISASSOC: return "Disassociation"; break; | 765 | case ST_DISASSOC: return "Disassociation"; break; |
766 | case ST_AUTH: return "Authentication"; break; | 766 | case ST_AUTH: return "Authentication"; break; |
767 | case ST_DEAUTH: return "Deathentication"; break; | 767 | case ST_DEAUTH: return "Deathentication"; break; |
768 | default: | 768 | default: owarn << "OWaveLanManagementPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; return "Unknown"; |
769 | qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); | 769 | } |
770 | return "Unknown"; | 770 | } |
771 | } | 771 | |
772 | } | 772 | |
773 | 773 | int OWaveLanManagementPacket::beaconInterval() const | |
774 | 774 | { | |
775 | int OWaveLanManagementPacket::beaconInterval() const | 775 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); |
776 | { | 776 | } |
777 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | 777 | |
778 | } | 778 | |
779 | 779 | int OWaveLanManagementPacket::capabilities() const | |
780 | 780 | { | |
781 | int OWaveLanManagementPacket::capabilities() const | 781 | return EXTRACT_LE_16BITS( &_body->capability_info ); |
782 | { | 782 | } |
783 | return EXTRACT_LE_16BITS( &_body->capability_info ); | 783 | |
784 | } | 784 | |
785 | 785 | bool OWaveLanManagementPacket::canESS() const | |
786 | 786 | { | |
787 | bool OWaveLanManagementPacket::canESS() const | 787 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
788 | { | 788 | } |
789 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 789 | |
790 | } | 790 | |
791 | 791 | bool OWaveLanManagementPacket::canIBSS() const | |
792 | 792 | { | |
793 | bool OWaveLanManagementPacket::canIBSS() const | 793 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
794 | { | 794 | } |
795 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 795 | |
796 | } | 796 | |
797 | 797 | bool OWaveLanManagementPacket::canCFP() const | |
798 | 798 | { | |
799 | bool OWaveLanManagementPacket::canCFP() const | 799 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
800 | { | 800 | } |
801 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 801 | |
802 | } | 802 | |
803 | 803 | bool OWaveLanManagementPacket::canCFP_REQ() const | |
804 | 804 | { | |
805 | bool OWaveLanManagementPacket::canCFP_REQ() const | 805 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
806 | { | 806 | } |
807 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 807 | |
808 | } | 808 | |
809 | 809 | bool OWaveLanManagementPacket::canPrivacy() const | |
810 | 810 | { | |
811 | bool OWaveLanManagementPacket::canPrivacy() const | 811 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
812 | { | 812 | } |
813 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 813 | |
814 | } | 814 | |
815 | 815 | /*====================================================================================== | |
816 | 816 | * OWaveLanManagementSSID | |
817 | /*====================================================================================== | 817 | *======================================================================================*/ |
818 | * OWaveLanManagementSSID | 818 | |
819 | *======================================================================================*/ | 819 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) |
820 | 820 | :QObject( parent, "802.11 SSID" ), _data( data ) | |
821 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) | 821 | { |
822 | :QObject( parent, "802.11 SSID" ), _data( data ) | 822 | odebug << "OWaveLanManagementSSID()" << oendl; |
823 | { | 823 | } |
824 | odebug << "OWaveLanManagementSSID()" << oendl; | 824 | |
825 | } | 825 | |
826 | 826 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | |
827 | 827 | { | |
828 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | 828 | } |
829 | { | 829 | |
830 | } | 830 | |
831 | 831 | QString OWaveLanManagementSSID::ID() const | |
832 | 832 | { | |
833 | QString OWaveLanManagementSSID::ID() const | 833 | int length = _data->length; |
834 | { | 834 | if ( length > 32 ) length = 32; |
835 | int length = _data->length; | 835 | char essid[length+1]; |
836 | if ( length > 32 ) length = 32; | 836 | memcpy( &essid, &_data->ssid, length ); |
837 | char essid[length+1]; | 837 | essid[length] = 0x0; |
838 | memcpy( &essid, &_data->ssid, length ); | 838 | return essid; |
839 | essid[length] = 0x0; | 839 | } |
840 | return essid; | 840 | |
841 | } | 841 | |
842 | 842 | /*====================================================================================== | |
843 | 843 | * OWaveLanManagementRates | |
844 | /*====================================================================================== | 844 | *======================================================================================*/ |
845 | * OWaveLanManagementRates | 845 | |
846 | *======================================================================================*/ | 846 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) |
847 | 847 | :QObject( parent, "802.11 Rates" ), _data( data ) | |
848 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) | 848 | { |
849 | :QObject( parent, "802.11 Rates" ), _data( data ) | 849 | odebug << "OWaveLanManagementRates()" << oendl; |
850 | { | 850 | } |
851 | odebug << "OWaveLanManagementRates()" << oendl; | 851 | |
852 | } | 852 | |
853 | 853 | OWaveLanManagementRates::~OWaveLanManagementRates() | |
854 | 854 | { | |
855 | OWaveLanManagementRates::~OWaveLanManagementRates() | 855 | } |
856 | { | 856 | |
857 | } | 857 | /*====================================================================================== |
858 | 858 | * OWaveLanManagementCF | |
859 | /*====================================================================================== | 859 | *======================================================================================*/ |
860 | * OWaveLanManagementCF | 860 | |
861 | *======================================================================================*/ | 861 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) |
862 | 862 | :QObject( parent, "802.11 CF" ), _data( data ) | |
863 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) | 863 | { |
864 | :QObject( parent, "802.11 CF" ), _data( data ) | 864 | odebug << "OWaveLanManagementCF()" << oendl; |
865 | { | 865 | } |
866 | odebug << "OWaveLanManagementCF()" << oendl; | 866 | |
867 | } | 867 | |
868 | 868 | OWaveLanManagementCF::~OWaveLanManagementCF() | |
869 | 869 | { | |
870 | OWaveLanManagementCF::~OWaveLanManagementCF() | 870 | } |
871 | { | 871 | |
872 | } | 872 | /*====================================================================================== |
873 | 873 | * OWaveLanManagementFH | |
874 | /*====================================================================================== | 874 | *======================================================================================*/ |
875 | * OWaveLanManagementFH | 875 | |
876 | *======================================================================================*/ | 876 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) |
877 | 877 | :QObject( parent, "802.11 FH" ), _data( data ) | |
878 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) | 878 | { |
879 | :QObject( parent, "802.11 FH" ), _data( data ) | 879 | odebug << "OWaveLanManagementFH()" << oendl; |
880 | { | 880 | } |
881 | odebug << "OWaveLanManagementFH()" << oendl; | 881 | |
882 | } | 882 | |
883 | 883 | OWaveLanManagementFH::~OWaveLanManagementFH() | |
884 | 884 | { | |
885 | OWaveLanManagementFH::~OWaveLanManagementFH() | 885 | } |
886 | { | 886 | |
887 | } | 887 | /*====================================================================================== |
888 | 888 | * OWaveLanManagementDS | |
889 | /*====================================================================================== | 889 | *======================================================================================*/ |
890 | * OWaveLanManagementDS | 890 | |
891 | *======================================================================================*/ | 891 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) |
892 | 892 | :QObject( parent, "802.11 DS" ), _data( data ) | |
893 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) | 893 | { |
894 | :QObject( parent, "802.11 DS" ), _data( data ) | 894 | odebug << "OWaveLanManagementDS()" << oendl; |
895 | { | 895 | } |
896 | odebug << "OWaveLanManagementDS()" << oendl; | 896 | |
897 | } | 897 | |
898 | 898 | OWaveLanManagementDS::~OWaveLanManagementDS() | |
899 | 899 | { | |
900 | OWaveLanManagementDS::~OWaveLanManagementDS() | 900 | } |
901 | { | 901 | |
902 | } | 902 | |
903 | 903 | int OWaveLanManagementDS::channel() const | |
904 | 904 | { | |
905 | int OWaveLanManagementDS::channel() const | 905 | return _data->channel; |
906 | { | 906 | } |
907 | return _data->channel; | 907 | |
908 | } | 908 | /*====================================================================================== |
909 | 909 | * OWaveLanManagementTim | |
910 | /*====================================================================================== | 910 | *======================================================================================*/ |
911 | * OWaveLanManagementTim | 911 | |
912 | *======================================================================================*/ | 912 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) |
913 | 913 | :QObject( parent, "802.11 Tim" ), _data( data ) | |
914 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) | 914 | { |
915 | :QObject( parent, "802.11 Tim" ), _data( data ) | 915 | odebug << "OWaveLanManagementTim()" << oendl; |
916 | { | 916 | } |
917 | odebug << "OWaveLanManagementTim()" << oendl; | 917 | |
918 | } | 918 | |
919 | 919 | OWaveLanManagementTim::~OWaveLanManagementTim() | |
920 | 920 | { | |
921 | OWaveLanManagementTim::~OWaveLanManagementTim() | 921 | } |
922 | { | 922 | |
923 | } | 923 | /*====================================================================================== |
924 | 924 | * OWaveLanManagementIBSS | |
925 | /*====================================================================================== | 925 | *======================================================================================*/ |
926 | * OWaveLanManagementIBSS | 926 | |
927 | *======================================================================================*/ | 927 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) |
928 | 928 | :QObject( parent, "802.11 IBSS" ), _data( data ) | |
929 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) | 929 | { |
930 | :QObject( parent, "802.11 IBSS" ), _data( data ) | 930 | odebug << "OWaveLanManagementIBSS()" << oendl; |
931 | { | 931 | } |
932 | odebug << "OWaveLanManagementIBSS()" << oendl; | 932 | |
933 | } | 933 | |
934 | 934 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | |
935 | 935 | { | |
936 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | 936 | } |
937 | { | 937 | |
938 | } | 938 | /*====================================================================================== |
939 | 939 | * OWaveLanManagementChallenge | |
940 | /*====================================================================================== | 940 | *======================================================================================*/ |
941 | * OWaveLanManagementChallenge | 941 | |
942 | *======================================================================================*/ | 942 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) |
943 | 943 | :QObject( parent, "802.11 Challenge" ), _data( data ) | |
944 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) | 944 | { |
945 | :QObject( parent, "802.11 Challenge" ), _data( data ) | 945 | odebug << "OWaveLanManagementChallenge()" << oendl; |
946 | { | 946 | } |
947 | odebug << "OWaveLanManagementChallenge()" << oendl; | 947 | |
948 | } | 948 | |
949 | 949 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | |
950 | 950 | { | |
951 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | 951 | } |
952 | { | 952 | |
953 | } | 953 | /*====================================================================================== |
954 | 954 | * OWaveLanDataPacket | |
955 | /*====================================================================================== | 955 | *======================================================================================*/ |
956 | * OWaveLanDataPacket | 956 | |
957 | *======================================================================================*/ | 957 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
958 | 958 | :QObject( parent, "802.11 Data" ), _header( data ) | |
959 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 959 | { |
960 | :QObject( parent, "802.11 Data" ), _header( data ) | 960 | odebug << "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." << oendl; |
961 | { | 961 | |
962 | odebug << "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." << oendl; | 962 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
963 | 963 | ||
964 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 964 | #warning The next line works for most cases, but can not be correct generally! |
965 | 965 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | |
966 | #warning The next line works for most cases, but can not be correct generally! | 966 | |
967 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 967 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
968 | 968 | } | |
969 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); | 969 | |
970 | } | 970 | |
971 | 971 | OWaveLanDataPacket::~OWaveLanDataPacket() | |
972 | 972 | { | |
973 | OWaveLanDataPacket::~OWaveLanDataPacket() | 973 | } |
974 | { | 974 | |
975 | } | 975 | |
976 | 976 | /*====================================================================================== | |
977 | 977 | * OLLCPacket | |
978 | /*====================================================================================== | 978 | *======================================================================================*/ |
979 | * OLLCPacket | 979 | |
980 | *======================================================================================*/ | 980 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
981 | 981 | :QObject( parent, "802.11 LLC" ), _header( data ) | |
982 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) | 982 | { |
983 | :QObject( parent, "802.11 LLC" ), _header( data ) | 983 | odebug << "OLLCPacket::OLLCPacket(): decoding frame..." << oendl; |
984 | { | 984 | |
985 | odebug << "OLLCPacket::OLLCPacket(): decoding frame..." << oendl; | 985 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) |
986 | 986 | { | |
987 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) | 987 | owarn << "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type = " << EXTRACT_16BITS( &_header->type ) << ")" << oendl; |
988 | { | 988 | |
989 | owarn << "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type = " << EXTRACT_16BITS( &_header->type ) << ")" << oendl; | 989 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
990 | 990 | { | |
991 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 991 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
992 | { | 992 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
993 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 993 | default: owarn << "OLLCPacket::OLLCPacket(): Unknown Encapsulation type = " << EXTRACT_16BITS( &_header->type ) << oendl; |
994 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 994 | } |
995 | default: owarn << "OLLCPacket::OLLCPacket(): Unknown Encapsulation type = " << EXTRACT_16BITS( &_header->type ) << oendl; | 995 | } |
996 | } | 996 | } |
997 | } | 997 | |
998 | } | 998 | |
999 | 999 | OLLCPacket::~OLLCPacket() | |
1000 | 1000 | { | |
1001 | OLLCPacket::~OLLCPacket() | 1001 | } |
1002 | { | 1002 | |
1003 | } | 1003 | |
1004 | 1004 | /*====================================================================================== | |
1005 | 1005 | * OWaveLanControlPacket | |
1006 | /*====================================================================================== | 1006 | *======================================================================================*/ |
1007 | * OWaveLanControlPacket | 1007 | |
1008 | *======================================================================================*/ | 1008 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) |
1009 | 1009 | :QObject( parent, "802.11 Control" ), _header( data ) | |
1010 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) | 1010 | { |
1011 | :QObject( parent, "802.11 Control" ), _header( data ) | 1011 | odebug << "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." << oendl; |
1012 | { | 1012 | odebug << "Detected subtype is " << controlType() << oendl; |
1013 | odebug << "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." << oendl; | 1013 | } |
1014 | //TODO: Implement this | 1014 | |
1015 | } | 1015 | |
1016 | 1016 | OWaveLanControlPacket::~OWaveLanControlPacket() | |
1017 | 1017 | { | |
1018 | OWaveLanControlPacket::~OWaveLanControlPacket() | 1018 | } |
1019 | { | 1019 | |
1020 | } | 1020 | |
1021 | 1021 | QString OWaveLanControlPacket::controlType() const | |
1022 | 1022 | { | |
1023 | /*====================================================================================== | 1023 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
1024 | * OPacketCapturer | 1024 | { |
1025 | *======================================================================================*/ | 1025 | case CTRL_PS_POLL: return "PowerSavePoll"; break; |
1026 | 1026 | case CTRL_RTS: return "RequestToSend"; break; | |
1027 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 1027 | case CTRL_CTS: return "ClearToSend"; break; |
1028 | :QObject( parent, name ), _name( QString::null ), _open( false ), | 1028 | case CTRL_ACK: return "Acknowledge"; break; |
1029 | _pch( 0 ), _pcd( 0 ), _sn( 0 ) | 1029 | case CTRL_CF_END: return "ContentionFreeEnd"; break; |
1030 | { | 1030 | case CTRL_END_ACK: return "AcknowledgeEnd"; break; |
1031 | } | 1031 | default: |
1032 | 1032 | owarn << "OWaveLanControlPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; | |
1033 | 1033 | return "Unknown"; | |
1034 | OPacketCapturer::~OPacketCapturer() | 1034 | } |
1035 | { | 1035 | } |
1036 | if ( _open ) | 1036 | |
1037 | { | 1037 | |
1038 | odebug << "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." << oendl; | 1038 | /*====================================================================================== |
1039 | close(); | 1039 | * OPacketCapturer |
1040 | } | 1040 | *======================================================================================*/ |
1041 | } | 1041 | |
1042 | 1042 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | |
1043 | 1043 | :QObject( parent, name ), _name( QString::null ), _open( false ), _pch( 0 ), _pcd( 0 ), _sn( 0 ) | |
1044 | void OPacketCapturer::setBlocking( bool b ) | 1044 | { |
1045 | { | 1045 | } |
1046 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) | 1046 | |
1047 | { | 1047 | |
1048 | odebug << "OPacketCapturer::setBlocking(): blocking mode changed successfully." << oendl; | 1048 | OPacketCapturer::~OPacketCapturer() |
1049 | } | 1049 | { |
1050 | else | 1050 | if ( _open ) |
1051 | { | 1051 | { |
1052 | odebug << "OPacketCapturer::setBlocking(): can't change blocking mode: " << _errbuf << oendl; | 1052 | odebug << "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." << oendl; |
1053 | } | 1053 | close(); |
1054 | } | 1054 | } |
1055 | 1055 | } | |
1056 | 1056 | ||
1057 | bool OPacketCapturer::blocking() const | 1057 | |
1058 | { | 1058 | void OPacketCapturer::setBlocking( bool b ) |
1059 | int b = pcap_getnonblock( _pch, _errbuf ); | 1059 | { |
1060 | if ( b == -1 ) | 1060 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) |
1061 | { | 1061 | { |
1062 | odebug << "OPacketCapturer::blocking(): can't get blocking mode: " << _errbuf << oendl; | 1062 | odebug << "OPacketCapturer::setBlocking(): blocking mode changed successfully." << oendl; |
1063 | return -1; | 1063 | } |
1064 | } | 1064 | else |
1065 | return !b; | 1065 | { |
1066 | } | 1066 | odebug << "OPacketCapturer::setBlocking(): can't change blocking mode: " << _errbuf << oendl; |
1067 | 1067 | } | |
1068 | 1068 | } | |
1069 | void OPacketCapturer::closeDumpFile() | 1069 | |
1070 | { | 1070 | |
1071 | if ( _pcd ) | 1071 | bool OPacketCapturer::blocking() const |
1072 | { | 1072 | { |
1073 | pcap_dump_close( _pcd ); | 1073 | int b = pcap_getnonblock( _pch, _errbuf ); |
1074 | _pcd = 0; | 1074 | if ( b == -1 ) |
1075 | } | 1075 | { |
1076 | pcap_close( _pch ); | 1076 | odebug << "OPacketCapturer::blocking(): can't get blocking mode: " << _errbuf << oendl; |
1077 | } | 1077 | return -1; |
1078 | 1078 | } | |
1079 | 1079 | return !b; | |
1080 | void OPacketCapturer::close() | 1080 | } |
1081 | { | 1081 | |
1082 | if ( _open ) | 1082 | |
1083 | { | 1083 | void OPacketCapturer::closeDumpFile() |
1084 | if ( _sn ) | 1084 | { |
1085 | { | 1085 | if ( _pcd ) |
1086 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1086 | { |
1087 | delete _sn; | 1087 | pcap_dump_close( _pcd ); |
1088 | } | 1088 | _pcd = 0; |
1089 | closeDumpFile(); | 1089 | } |
1090 | _open = false; | 1090 | pcap_close( _pch ); |
1091 | } | 1091 | } |
1092 | 1092 | ||
1093 | odebug << "OPacketCapturer::close() --- dumping capturing statistics..." << oendl; | 1093 | |
1094 | odebug << "--------------------------------------------------" << oendl; | 1094 | void OPacketCapturer::close() |
1095 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) | 1095 | { |
1096 | odebug << it.key() << " = " << it.data() << oendl; | 1096 | if ( _open ) |
1097 | odebug << "--------------------------------------------------" << oendl; | 1097 | { |
1098 | 1098 | if ( _sn ) | |
1099 | } | 1099 | { |
1100 | 1100 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | |
1101 | 1101 | delete _sn; | |
1102 | int OPacketCapturer::dataLink() const | 1102 | } |
1103 | { | 1103 | closeDumpFile(); |
1104 | return pcap_datalink( _pch ); | 1104 | _open = false; |
1105 | } | 1105 | } |
1106 | 1106 | ||
1107 | 1107 | odebug << "OPacketCapturer::close() --- dumping capturing statistics..." << oendl; | |
1108 | void OPacketCapturer::dump( OPacket* p ) | 1108 | odebug << "--------------------------------------------------" << oendl; |
1109 | { | 1109 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) |
1110 | if ( !_pcd ) | 1110 | odebug << it.key() << " = " << it.data() << oendl; |
1111 | { | 1111 | odebug << "--------------------------------------------------" << oendl; |
1112 | qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" ); | 1112 | |
1113 | return; | 1113 | } |
1114 | } | 1114 | |
1115 | pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); | 1115 | |
1116 | } | 1116 | int OPacketCapturer::dataLink() const |
1117 | 1117 | { | |
1118 | 1118 | return pcap_datalink( _pch ); | |
1119 | int OPacketCapturer::fileno() const | 1119 | } |
1120 | { | 1120 | |
1121 | if ( _open ) | 1121 | |
1122 | { | 1122 | void OPacketCapturer::dump( OPacket* p ) |
1123 | return pcap_fileno( _pch ); | 1123 | { |
1124 | } | 1124 | if ( !_pcd ) |
1125 | else | 1125 | { |
1126 | { | 1126 | owarn << "OPacketCapturer::dump() - cannot dump without open capture file!" << oendl; |
1127 | return -1; | 1127 | return; |
1128 | } | 1128 | } |
1129 | } | 1129 | pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); |
1130 | 1130 | } | |
1131 | 1131 | ||
1132 | OPacket* OPacketCapturer::next( int time ) | 1132 | |
1133 | { | 1133 | int OPacketCapturer::fileno() const |
1134 | fd_set fds; | 1134 | { |
1135 | struct timeval tv; | 1135 | if ( _open ) |
1136 | FD_ZERO( &fds ); | 1136 | { |
1137 | FD_SET( pcap_fileno( _pch ), &fds ); | 1137 | return pcap_fileno( _pch ); |
1138 | tv.tv_sec = time / 1000; | 1138 | } |
1139 | tv.tv_usec = time % 1000; | 1139 | else |
1140 | int retval = select( pcap_fileno( _pch )+1, &fds, NULL, NULL, &tv); | 1140 | { |
1141 | if ( retval > 0 ) // clear to read! | 1141 | return -1; |
1142 | return next(); | 1142 | } |
1143 | else | 1143 | } |
1144 | return 0; | 1144 | |
1145 | } | 1145 | |
1146 | 1146 | OPacket* OPacketCapturer::next( int time ) | |
1147 | 1147 | { | |
1148 | OPacket* OPacketCapturer::next() | 1148 | fd_set fds; |
1149 | { | 1149 | struct timeval tv; |
1150 | packetheaderstruct header; | 1150 | FD_ZERO( &fds ); |
1151 | odebug << "==> OPacketCapturer::next()" << oendl; | 1151 | FD_SET( pcap_fileno( _pch ), &fds ); |
1152 | const unsigned char* pdata = pcap_next( _pch, &header ); | 1152 | tv.tv_sec = time / 1000; |
1153 | odebug << "<== OPacketCapturer::next()" << oendl; | 1153 | tv.tv_usec = time % 1000; |
1154 | 1154 | int retval = select( pcap_fileno( _pch )+1, &fds, NULL, NULL, &tv); | |
1155 | if ( pdata && header.len ) | 1155 | if ( retval > 0 ) // clear to read! |
1156 | { | 1156 | return next(); |
1157 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); | 1157 | else |
1158 | // packets shouldn't be inserted in the QObject child-parent hierarchy, | 1158 | return 0; |
1159 | // because due to memory constraints they will be deleted as soon | 1159 | } |
1160 | // as possible - that is right after they have been processed | 1160 | |
1161 | // by emit() [ see below ] | 1161 | |
1162 | //TODO: make gathering statistics optional, because it takes time | 1162 | OPacket* OPacketCapturer::next() |
1163 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); | 1163 | { |
1164 | #ifndef NODEBUG | 1164 | packetheaderstruct header; |
1165 | p->dumpStructure( const_cast<QObjectList*>( p->children() ) ); | 1165 | odebug << "==> OPacketCapturer::next()" << oendl; |
1166 | #endif | 1166 | const unsigned char* pdata = pcap_next( _pch, &header ); |
1167 | return p; | 1167 | odebug << "<== OPacketCapturer::next()" << oendl; |
1168 | } | 1168 | |
1169 | else | 1169 | if ( pdata && header.len ) |
1170 | { | 1170 | { |
1171 | qWarning( "OPacketCapturer::next() - no packet received!" ); | 1171 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); |
1172 | return 0; | 1172 | // packets shouldn't be inserted in the QObject child-parent hierarchy, |
1173 | } | 1173 | // because due to memory constraints they will be deleted as soon |
1174 | } | 1174 | // as possible - that is right after they have been processed |
1175 | 1175 | // by emit() [ see below ] | |
1176 | 1176 | //TODO: make gathering statistics optional, because it takes time | |
1177 | bool OPacketCapturer::open( const QString& name ) | 1177 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); |
1178 | { | 1178 | #ifndef NODEBUG |
1179 | if ( _open ) | 1179 | p->dumpStructure( const_cast<QObjectList*>( p->children() ) ); |
1180 | { | 1180 | #endif |
1181 | if ( name == _name ) // ignore opening an already openend device | 1181 | return p; |
1182 | { | 1182 | } |
1183 | return true; | 1183 | else |
1184 | } | 1184 | { |
1185 | else // close the last opened device | 1185 | owarn << "OPacketCapturer::next() - no packet received!" << oendl; |
1186 | { | 1186 | return 0; |
1187 | close(); | 1187 | } |
1188 | } | 1188 | } |
1189 | } | 1189 | |
1190 | 1190 | ||
1191 | _name = name; | 1191 | bool OPacketCapturer::open( const QString& name ) |
1192 | 1192 | { | |
1193 | // open libpcap | 1193 | if ( _open ) |
1194 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); | 1194 | { |
1195 | 1195 | if ( name == _name ) // ignore opening an already openend device | |
1196 | if ( !handle ) | 1196 | { |
1197 | { | 1197 | return true; |
1198 | owarn << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; | 1198 | } |
1199 | return false; | 1199 | else // close the last opened device |
1200 | } | 1200 | { |
1201 | 1201 | close(); | |
1202 | odebug << "OPacketCapturer::open(): libpcap [" << name << "] opened successfully." << oendl; | 1202 | } |
1203 | _pch = handle; | 1203 | } |
1204 | _open = true; | 1204 | |
1205 | _stats.clear(); | 1205 | _name = name; |
1206 | 1206 | ||
1207 | // in case we have an application object, create a socket notifier | 1207 | // open libpcap |
1208 | if ( qApp ) //TODO: I don't like this here... | 1208 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); |
1209 | { | 1209 | |
1210 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 1210 | if ( !handle ) |
1211 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1211 | { |
1212 | } | 1212 | owarn << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; |
1213 | 1213 | return false; | |
1214 | return true; | 1214 | } |
1215 | } | 1215 | |
1216 | 1216 | odebug << "OPacketCapturer::open(): libpcap [" << name << "] opened successfully." << oendl; | |
1217 | 1217 | _pch = handle; | |
1218 | bool OPacketCapturer::openDumpFile( const QString& filename ) | 1218 | _open = true; |
1219 | { | 1219 | _stats.clear(); |
1220 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); | 1220 | |
1221 | if ( !dump ) | 1221 | // in case we have an application object, create a socket notifier |
1222 | { | 1222 | if ( qApp ) //TODO: I don't like this here... |
1223 | owarn << "OPacketCapturer::open(): can't open dump with '" << filename << "': " << _errbuf << oendl; | 1223 | { |
1224 | return false; | 1224 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
1225 | } | 1225 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1226 | odebug << "OPacketCapturer::open(): dump [" << filename << "] opened successfully." << oendl; | 1226 | } |
1227 | _pcd = dump; | 1227 | |
1228 | 1228 | return true; | |
1229 | return true; | 1229 | } |
1230 | } | 1230 | |
1231 | 1231 | ||
1232 | 1232 | bool OPacketCapturer::openDumpFile( const QString& filename ) | |
1233 | bool OPacketCapturer::open( const QFile& file ) | 1233 | { |
1234 | { | 1234 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); |
1235 | QString name = file.name(); | 1235 | if ( !dump ) |
1236 | 1236 | { | |
1237 | if ( _open ) | 1237 | owarn << "OPacketCapturer::open(): can't open dump with '" << filename << "': " << _errbuf << oendl; |
1238 | { | 1238 | return false; |
1239 | close(); | 1239 | } |
1240 | if ( name == _name ) // ignore opening an already openend device | 1240 | odebug << "OPacketCapturer::open(): dump [" << filename << "] opened successfully." << oendl; |
1241 | { | 1241 | _pcd = dump; |
1242 | return true; | 1242 | |
1243 | } | 1243 | return true; |
1244 | else // close the last opened device | 1244 | } |
1245 | { | 1245 | |
1246 | close(); | 1246 | |
1247 | } | 1247 | bool OPacketCapturer::open( const QFile& file ) |
1248 | } | 1248 | { |
1249 | 1249 | QString name = file.name(); | |
1250 | _name = name; | 1250 | |
1251 | 1251 | if ( _open ) | |
1252 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); | 1252 | { |
1253 | 1253 | close(); | |
1254 | if ( handle ) | 1254 | if ( name == _name ) // ignore opening an already openend device |
1255 | { | 1255 | { |
1256 | odebug << "OPacketCapturer::open(): libpcap opened successfully." << oendl; | 1256 | return true; |
1257 | _pch = handle; | 1257 | } |
1258 | _open = true; | 1258 | else // close the last opened device |
1259 | 1259 | { | |
1260 | // in case we have an application object, create a socket notifier | 1260 | close(); |
1261 | if ( qApp ) | 1261 | } |
1262 | { | 1262 | } |
1263 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 1263 | |
1264 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1264 | _name = name; |
1265 | } | 1265 | |
1266 | 1266 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); | |
1267 | return true; | 1267 | |
1268 | } | 1268 | if ( handle ) |
1269 | else | 1269 | { |
1270 | { | 1270 | odebug << "OPacketCapturer::open(): libpcap opened successfully." << oendl; |
1271 | odebug << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; | 1271 | _pch = handle; |
1272 | return false; | 1272 | _open = true; |
1273 | } | 1273 | |
1274 | 1274 | // in case we have an application object, create a socket notifier | |
1275 | } | 1275 | if ( qApp ) |
1276 | 1276 | { | |
1277 | 1277 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | |
1278 | bool OPacketCapturer::isOpen() const | 1278 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1279 | { | 1279 | } |
1280 | return _open; | 1280 | |
1281 | } | 1281 | return true; |
1282 | 1282 | } | |
1283 | 1283 | else | |
1284 | void OPacketCapturer::readyToReceive() | 1284 | { |
1285 | { | 1285 | odebug << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; |
1286 | odebug << "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" << oendl; | 1286 | return false; |
1287 | OPacket* p = next(); | 1287 | } |
1288 | emit receivedPacket( p ); | 1288 | |
1289 | // emit is synchronous - packet has been dealt with, now it's safe to delete | 1289 | } |
1290 | delete p; | 1290 | |
1291 | } | 1291 | |
1292 | 1292 | bool OPacketCapturer::isOpen() const | |
1293 | 1293 | { | |
1294 | const QMap<QString,int>& OPacketCapturer::statistics() const | 1294 | return _open; |
1295 | { | 1295 | } |
1296 | return _stats; | 1296 | |
1297 | } | 1297 | |
1298 | 1298 | void OPacketCapturer::readyToReceive() | |
1299 | 1299 | { | |
1300 | int OPacketCapturer::snapShot() const | 1300 | odebug << "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" << oendl; |
1301 | { | 1301 | OPacket* p = next(); |
1302 | return pcap_snapshot( _pch ); | 1302 | emit receivedPacket( p ); |
1303 | } | 1303 | // emit is synchronous - packet has been dealt with, now it's safe to delete |
1304 | 1304 | delete p; | |
1305 | 1305 | } | |
1306 | bool OPacketCapturer::swapped() const | 1306 | |
1307 | { | 1307 | |
1308 | return pcap_is_swapped( _pch ); | 1308 | const QMap<QString,int>& OPacketCapturer::statistics() const |
1309 | } | 1309 | { |
1310 | 1310 | return _stats; | |
1311 | 1311 | } | |
1312 | QString OPacketCapturer::version() const | 1312 | |
1313 | { | 1313 | |
1314 | return QString().sprintf( "%s.%s", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); | 1314 | int OPacketCapturer::snapShot() const |
1315 | } | 1315 | { |
1316 | 1316 | return pcap_snapshot( _pch ); | |
1317 | 1317 | } | |
1318 | |||
1319 | |||
1320 | bool OPacketCapturer::swapped() const | ||
1321 | { | ||
1322 | return pcap_is_swapped( _pch ); | ||
1323 | } | ||
1324 | |||
1325 | |||
1326 | QString OPacketCapturer::version() const | ||
1327 | { | ||
1328 | return QString().sprintf( "%s.%s", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); | ||
1329 | } | ||
1330 | |||
1331 | |||
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 497fd6b..b373c56 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -144,512 +144,514 @@ class OPacket : public QObject | |||
144 | * OEthernetPacket - DLT_EN10MB frame | 144 | * OEthernetPacket - DLT_EN10MB frame |
145 | *======================================================================================*/ | 145 | *======================================================================================*/ |
146 | 146 | ||
147 | class OEthernetPacket : public QObject | 147 | class OEthernetPacket : public QObject |
148 | { | 148 | { |
149 | Q_OBJECT | 149 | Q_OBJECT |
150 | 150 | ||
151 | public: | 151 | public: |
152 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); | 152 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); |
153 | virtual ~OEthernetPacket(); | 153 | virtual ~OEthernetPacket(); |
154 | 154 | ||
155 | OMacAddress sourceAddress() const; | 155 | OMacAddress sourceAddress() const; |
156 | OMacAddress destinationAddress() const; | 156 | OMacAddress destinationAddress() const; |
157 | int type() const; | 157 | int type() const; |
158 | 158 | ||
159 | private: | 159 | private: |
160 | const struct ether_header* _ether; | 160 | const struct ether_header* _ether; |
161 | }; | 161 | }; |
162 | 162 | ||
163 | /*====================================================================================== | 163 | /*====================================================================================== |
164 | * OPrismHeaderPacket - DLT_PRISM_HEADER frame | 164 | * OPrismHeaderPacket - DLT_PRISM_HEADER frame |
165 | *======================================================================================*/ | 165 | *======================================================================================*/ |
166 | 166 | ||
167 | class OPrismHeaderPacket : public QObject | 167 | class OPrismHeaderPacket : public QObject |
168 | { | 168 | { |
169 | Q_OBJECT | 169 | Q_OBJECT |
170 | 170 | ||
171 | public: | 171 | public: |
172 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); | 172 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); |
173 | virtual ~OPrismHeaderPacket(); | 173 | virtual ~OPrismHeaderPacket(); |
174 | 174 | ||
175 | unsigned int signalStrength() const; | 175 | unsigned int signalStrength() const; |
176 | 176 | ||
177 | private: | 177 | private: |
178 | const struct prism_hdr* _header; | 178 | const struct prism_hdr* _header; |
179 | }; | 179 | }; |
180 | 180 | ||
181 | /*====================================================================================== | 181 | /*====================================================================================== |
182 | * OWaveLanPacket - DLT_IEEE802_11 frame | 182 | * OWaveLanPacket - DLT_IEEE802_11 frame |
183 | *======================================================================================*/ | 183 | *======================================================================================*/ |
184 | 184 | ||
185 | class OWaveLanPacket : public QObject | 185 | class OWaveLanPacket : public QObject |
186 | { | 186 | { |
187 | Q_OBJECT | 187 | Q_OBJECT |
188 | 188 | ||
189 | public: | 189 | public: |
190 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); | 190 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); |
191 | virtual ~OWaveLanPacket(); | 191 | virtual ~OWaveLanPacket(); |
192 | 192 | ||
193 | int duration() const; | 193 | int duration() const; |
194 | bool fromDS() const; | 194 | bool fromDS() const; |
195 | bool toDS() const; | 195 | bool toDS() const; |
196 | virtual OMacAddress macAddress1() const; | 196 | virtual OMacAddress macAddress1() const; |
197 | virtual OMacAddress macAddress2() const; | 197 | virtual OMacAddress macAddress2() const; |
198 | virtual OMacAddress macAddress3() const; | 198 | virtual OMacAddress macAddress3() const; |
199 | virtual OMacAddress macAddress4() const; | 199 | virtual OMacAddress macAddress4() const; |
200 | bool usesPowerManagement() const; | 200 | bool usesPowerManagement() const; |
201 | int type() const; | 201 | int type() const; |
202 | int subType() const; | 202 | int subType() const; |
203 | int version() const; | 203 | int version() const; |
204 | bool usesWep() const; | 204 | bool usesWep() const; |
205 | 205 | ||
206 | private: | 206 | private: |
207 | const struct ieee_802_11_header* _wlanhdr; | 207 | const struct ieee_802_11_header* _wlanhdr; |
208 | }; | 208 | }; |
209 | 209 | ||
210 | 210 | ||
211 | /*====================================================================================== | 211 | /*====================================================================================== |
212 | * OWaveLanManagementPacket - type: management (T_MGMT) | 212 | * OWaveLanManagementPacket - type: management (T_MGMT) |
213 | *======================================================================================*/ | 213 | *======================================================================================*/ |
214 | 214 | ||
215 | class OWaveLanManagementPacket : public QObject | 215 | class OWaveLanManagementPacket : public QObject |
216 | { | 216 | { |
217 | Q_OBJECT | 217 | Q_OBJECT |
218 | 218 | ||
219 | public: | 219 | public: |
220 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); | 220 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); |
221 | virtual ~OWaveLanManagementPacket(); | 221 | virtual ~OWaveLanManagementPacket(); |
222 | 222 | ||
223 | QString managementType() const; | 223 | QString managementType() const; |
224 | 224 | ||
225 | int beaconInterval() const; | 225 | int beaconInterval() const; |
226 | int capabilities() const; // generic | 226 | int capabilities() const; // generic |
227 | 227 | ||
228 | bool canESS() const; | 228 | bool canESS() const; |
229 | bool canIBSS() const; | 229 | bool canIBSS() const; |
230 | bool canCFP() const; | 230 | bool canCFP() const; |
231 | bool canCFP_REQ() const; | 231 | bool canCFP_REQ() const; |
232 | bool canPrivacy() const; | 232 | bool canPrivacy() const; |
233 | 233 | ||
234 | private: | 234 | private: |
235 | const struct ieee_802_11_mgmt_header* _header; | 235 | const struct ieee_802_11_mgmt_header* _header; |
236 | const struct ieee_802_11_mgmt_body* _body; | 236 | const struct ieee_802_11_mgmt_body* _body; |
237 | }; | 237 | }; |
238 | 238 | ||
239 | 239 | ||
240 | /*====================================================================================== | 240 | /*====================================================================================== |
241 | * OWaveLanManagementSSID | 241 | * OWaveLanManagementSSID |
242 | *======================================================================================*/ | 242 | *======================================================================================*/ |
243 | 243 | ||
244 | class OWaveLanManagementSSID : public QObject | 244 | class OWaveLanManagementSSID : public QObject |
245 | { | 245 | { |
246 | Q_OBJECT | 246 | Q_OBJECT |
247 | 247 | ||
248 | public: | 248 | public: |
249 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); | 249 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); |
250 | virtual ~OWaveLanManagementSSID(); | 250 | virtual ~OWaveLanManagementSSID(); |
251 | 251 | ||
252 | QString ID() const; | 252 | QString ID() const; |
253 | 253 | ||
254 | private: | 254 | private: |
255 | const struct ssid_t* _data; | 255 | const struct ssid_t* _data; |
256 | }; | 256 | }; |
257 | 257 | ||
258 | /*====================================================================================== | 258 | /*====================================================================================== |
259 | * OWaveLanManagementRates | 259 | * OWaveLanManagementRates |
260 | *======================================================================================*/ | 260 | *======================================================================================*/ |
261 | 261 | ||
262 | class OWaveLanManagementRates : public QObject | 262 | class OWaveLanManagementRates : public QObject |
263 | { | 263 | { |
264 | Q_OBJECT | 264 | Q_OBJECT |
265 | 265 | ||
266 | public: | 266 | public: |
267 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); | 267 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); |
268 | virtual ~OWaveLanManagementRates(); | 268 | virtual ~OWaveLanManagementRates(); |
269 | 269 | ||
270 | private: | 270 | private: |
271 | const struct rates_t* _data; | 271 | const struct rates_t* _data; |
272 | }; | 272 | }; |
273 | 273 | ||
274 | /*====================================================================================== | 274 | /*====================================================================================== |
275 | * OWaveLanManagementCF | 275 | * OWaveLanManagementCF |
276 | *======================================================================================*/ | 276 | *======================================================================================*/ |
277 | 277 | ||
278 | class OWaveLanManagementCF : public QObject | 278 | class OWaveLanManagementCF : public QObject |
279 | { | 279 | { |
280 | Q_OBJECT | 280 | Q_OBJECT |
281 | 281 | ||
282 | public: | 282 | public: |
283 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); | 283 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); |
284 | virtual ~OWaveLanManagementCF(); | 284 | virtual ~OWaveLanManagementCF(); |
285 | 285 | ||
286 | private: | 286 | private: |
287 | const struct cf_t* _data; | 287 | const struct cf_t* _data; |
288 | }; | 288 | }; |
289 | 289 | ||
290 | /*====================================================================================== | 290 | /*====================================================================================== |
291 | * OWaveLanManagementFH | 291 | * OWaveLanManagementFH |
292 | *======================================================================================*/ | 292 | *======================================================================================*/ |
293 | 293 | ||
294 | class OWaveLanManagementFH : public QObject | 294 | class OWaveLanManagementFH : public QObject |
295 | { | 295 | { |
296 | Q_OBJECT | 296 | Q_OBJECT |
297 | 297 | ||
298 | public: | 298 | public: |
299 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); | 299 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); |
300 | virtual ~OWaveLanManagementFH(); | 300 | virtual ~OWaveLanManagementFH(); |
301 | 301 | ||
302 | private: | 302 | private: |
303 | const struct fh_t* _data; | 303 | const struct fh_t* _data; |
304 | }; | 304 | }; |
305 | 305 | ||
306 | /*====================================================================================== | 306 | /*====================================================================================== |
307 | * OWaveLanManagementDS | 307 | * OWaveLanManagementDS |
308 | *======================================================================================*/ | 308 | *======================================================================================*/ |
309 | 309 | ||
310 | class OWaveLanManagementDS : public QObject | 310 | class OWaveLanManagementDS : public QObject |
311 | { | 311 | { |
312 | Q_OBJECT | 312 | Q_OBJECT |
313 | 313 | ||
314 | public: | 314 | public: |
315 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); | 315 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); |
316 | virtual ~OWaveLanManagementDS(); | 316 | virtual ~OWaveLanManagementDS(); |
317 | 317 | ||
318 | int channel() const; | 318 | int channel() const; |
319 | 319 | ||
320 | private: | 320 | private: |
321 | const struct ds_t* _data; | 321 | const struct ds_t* _data; |
322 | }; | 322 | }; |
323 | 323 | ||
324 | /*====================================================================================== | 324 | /*====================================================================================== |
325 | * OWaveLanManagementTim | 325 | * OWaveLanManagementTim |
326 | *======================================================================================*/ | 326 | *======================================================================================*/ |
327 | 327 | ||
328 | class OWaveLanManagementTim : public QObject | 328 | class OWaveLanManagementTim : public QObject |
329 | { | 329 | { |
330 | Q_OBJECT | 330 | Q_OBJECT |
331 | 331 | ||
332 | public: | 332 | public: |
333 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); | 333 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); |
334 | virtual ~OWaveLanManagementTim(); | 334 | virtual ~OWaveLanManagementTim(); |
335 | 335 | ||
336 | private: | 336 | private: |
337 | const struct tim_t* _data; | 337 | const struct tim_t* _data; |
338 | }; | 338 | }; |
339 | 339 | ||
340 | /*====================================================================================== | 340 | /*====================================================================================== |
341 | * OWaveLanManagementIBSS | 341 | * OWaveLanManagementIBSS |
342 | *======================================================================================*/ | 342 | *======================================================================================*/ |
343 | 343 | ||
344 | class OWaveLanManagementIBSS : public QObject | 344 | class OWaveLanManagementIBSS : public QObject |
345 | { | 345 | { |
346 | Q_OBJECT | 346 | Q_OBJECT |
347 | 347 | ||
348 | public: | 348 | public: |
349 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); | 349 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); |
350 | virtual ~OWaveLanManagementIBSS(); | 350 | virtual ~OWaveLanManagementIBSS(); |
351 | 351 | ||
352 | private: | 352 | private: |
353 | const struct ibss_t* _data; | 353 | const struct ibss_t* _data; |
354 | }; | 354 | }; |
355 | 355 | ||
356 | /*====================================================================================== | 356 | /*====================================================================================== |
357 | * OWaveLanManagementChallenge | 357 | * OWaveLanManagementChallenge |
358 | *======================================================================================*/ | 358 | *======================================================================================*/ |
359 | 359 | ||
360 | class OWaveLanManagementChallenge : public QObject | 360 | class OWaveLanManagementChallenge : public QObject |
361 | { | 361 | { |
362 | Q_OBJECT | 362 | Q_OBJECT |
363 | 363 | ||
364 | public: | 364 | public: |
365 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); | 365 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); |
366 | virtual ~OWaveLanManagementChallenge(); | 366 | virtual ~OWaveLanManagementChallenge(); |
367 | 367 | ||
368 | private: | 368 | private: |
369 | const struct challenge_t* _data; | 369 | const struct challenge_t* _data; |
370 | }; | 370 | }; |
371 | 371 | ||
372 | /*====================================================================================== | 372 | /*====================================================================================== |
373 | * OWaveLanDataPacket - type: data (T_DATA) | 373 | * OWaveLanDataPacket - type: data (T_DATA) |
374 | *======================================================================================*/ | 374 | *======================================================================================*/ |
375 | 375 | ||
376 | class OWaveLanDataPacket : public QObject | 376 | class OWaveLanDataPacket : public QObject |
377 | { | 377 | { |
378 | Q_OBJECT | 378 | Q_OBJECT |
379 | 379 | ||
380 | public: | 380 | public: |
381 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); | 381 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); |
382 | virtual ~OWaveLanDataPacket(); | 382 | virtual ~OWaveLanDataPacket(); |
383 | 383 | ||
384 | private: | 384 | private: |
385 | const struct ieee_802_11_data_header* _header; | 385 | const struct ieee_802_11_data_header* _header; |
386 | }; | 386 | }; |
387 | 387 | ||
388 | /*====================================================================================== | 388 | /*====================================================================================== |
389 | * OWaveLanControlPacket - type: control (T_CTRL) | 389 | * OWaveLanControlPacket - type: control (T_CTRL) |
390 | *======================================================================================*/ | 390 | *======================================================================================*/ |
391 | 391 | ||
392 | class OWaveLanControlPacket : public QObject | 392 | class OWaveLanControlPacket : public QObject |
393 | { | 393 | { |
394 | Q_OBJECT | 394 | Q_OBJECT |
395 | 395 | ||
396 | public: | 396 | public: |
397 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); | 397 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); |
398 | virtual ~OWaveLanControlPacket(); | 398 | virtual ~OWaveLanControlPacket(); |
399 | 399 | ||
400 | QString controlType() const; | ||
401 | |||
400 | private: | 402 | private: |
401 | const struct ieee_802_11_control_header* _header; | 403 | const struct ieee_802_11_control_header* _header; |
402 | }; | 404 | }; |
403 | 405 | ||
404 | /*====================================================================================== | 406 | /*====================================================================================== |
405 | * OLLCPacket - IEEE 802.2 Link Level Control | 407 | * OLLCPacket - IEEE 802.2 Link Level Control |
406 | *======================================================================================*/ | 408 | *======================================================================================*/ |
407 | 409 | ||
408 | class OLLCPacket : public QObject | 410 | class OLLCPacket : public QObject |
409 | { | 411 | { |
410 | Q_OBJECT | 412 | Q_OBJECT |
411 | 413 | ||
412 | public: | 414 | public: |
413 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); | 415 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); |
414 | virtual ~OLLCPacket(); | 416 | virtual ~OLLCPacket(); |
415 | 417 | ||
416 | private: | 418 | private: |
417 | const struct ieee_802_11_802_2_header* _header; | 419 | const struct ieee_802_11_802_2_header* _header; |
418 | }; | 420 | }; |
419 | 421 | ||
420 | /*====================================================================================== | 422 | /*====================================================================================== |
421 | * OIPPacket | 423 | * OIPPacket |
422 | *======================================================================================*/ | 424 | *======================================================================================*/ |
423 | 425 | ||
424 | class OIPPacket : public QObject | 426 | class OIPPacket : public QObject |
425 | { | 427 | { |
426 | Q_OBJECT | 428 | Q_OBJECT |
427 | 429 | ||
428 | public: | 430 | public: |
429 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); | 431 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); |
430 | virtual ~OIPPacket(); | 432 | virtual ~OIPPacket(); |
431 | 433 | ||
432 | QHostAddress fromIPAddress() const; | 434 | QHostAddress fromIPAddress() const; |
433 | QHostAddress toIPAddress() const; | 435 | QHostAddress toIPAddress() const; |
434 | 436 | ||
435 | int tos() const; | 437 | int tos() const; |
436 | int len() const; | 438 | int len() const; |
437 | int id() const; | 439 | int id() const; |
438 | int offset() const; | 440 | int offset() const; |
439 | int ttl() const; | 441 | int ttl() const; |
440 | int protocol() const; | 442 | int protocol() const; |
441 | int checksum() const; | 443 | int checksum() const; |
442 | 444 | ||
443 | private: | 445 | private: |
444 | const struct iphdr* _iphdr; | 446 | const struct iphdr* _iphdr; |
445 | }; | 447 | }; |
446 | 448 | ||
447 | /*====================================================================================== | 449 | /*====================================================================================== |
448 | * OARPPacket | 450 | * OARPPacket |
449 | *======================================================================================*/ | 451 | *======================================================================================*/ |
450 | 452 | ||
451 | class OARPPacket : public QObject | 453 | class OARPPacket : public QObject |
452 | { | 454 | { |
453 | Q_OBJECT | 455 | Q_OBJECT |
454 | 456 | ||
455 | public: | 457 | public: |
456 | OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); | 458 | OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); |
457 | virtual ~OARPPacket(); | 459 | virtual ~OARPPacket(); |
458 | 460 | ||
459 | QHostAddress senderIPV4Address() const; | 461 | QHostAddress senderIPV4Address() const; |
460 | OMacAddress senderMacAddress() const; | 462 | OMacAddress senderMacAddress() const; |
461 | QHostAddress targetIPV4Address() const; | 463 | QHostAddress targetIPV4Address() const; |
462 | OMacAddress targetMacAddress() const; | 464 | OMacAddress targetMacAddress() const; |
463 | 465 | ||
464 | //int type() const; | 466 | //int type() const; |
465 | QString type() const; | 467 | QString type() const; |
466 | 468 | ||
467 | private: | 469 | private: |
468 | const struct myarphdr* _arphdr; | 470 | const struct myarphdr* _arphdr; |
469 | }; | 471 | }; |
470 | 472 | ||
471 | /*====================================================================================== | 473 | /*====================================================================================== |
472 | * OUDPPacket | 474 | * OUDPPacket |
473 | *======================================================================================*/ | 475 | *======================================================================================*/ |
474 | 476 | ||
475 | class OUDPPacket : public QObject | 477 | class OUDPPacket : public QObject |
476 | { | 478 | { |
477 | Q_OBJECT | 479 | Q_OBJECT |
478 | 480 | ||
479 | public: | 481 | public: |
480 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); | 482 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); |
481 | virtual ~OUDPPacket(); | 483 | virtual ~OUDPPacket(); |
482 | 484 | ||
483 | int fromPort() const; | 485 | int fromPort() const; |
484 | int toPort() const; | 486 | int toPort() const; |
485 | int length() const; | 487 | int length() const; |
486 | int checksum() const; | 488 | int checksum() const; |
487 | 489 | ||
488 | private: | 490 | private: |
489 | const struct udphdr* _udphdr; | 491 | const struct udphdr* _udphdr; |
490 | }; | 492 | }; |
491 | 493 | ||
492 | /*====================================================================================== | 494 | /*====================================================================================== |
493 | * ODHCPPacket | 495 | * ODHCPPacket |
494 | *======================================================================================*/ | 496 | *======================================================================================*/ |
495 | 497 | ||
496 | class ODHCPPacket : public QObject | 498 | class ODHCPPacket : public QObject |
497 | { | 499 | { |
498 | Q_OBJECT | 500 | Q_OBJECT |
499 | 501 | ||
500 | public: | 502 | public: |
501 | ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); | 503 | ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); |
502 | virtual ~ODHCPPacket(); | 504 | virtual ~ODHCPPacket(); |
503 | 505 | ||
504 | QHostAddress clientAddress() const; | 506 | QHostAddress clientAddress() const; |
505 | QHostAddress yourAddress() const; | 507 | QHostAddress yourAddress() const; |
506 | QHostAddress serverAddress() const; | 508 | QHostAddress serverAddress() const; |
507 | QHostAddress relayAddress() const; | 509 | QHostAddress relayAddress() const; |
508 | 510 | ||
509 | OMacAddress clientMacAddress() const; | 511 | OMacAddress clientMacAddress() const; |
510 | 512 | ||
511 | bool isRequest() const; | 513 | bool isRequest() const; |
512 | bool isReply() const; | 514 | bool isReply() const; |
513 | QString type() const; | 515 | QString type() const; |
514 | 516 | ||
515 | private: | 517 | private: |
516 | const struct dhcp_packet* _dhcphdr; | 518 | const struct dhcp_packet* _dhcphdr; |
517 | unsigned char _type; | 519 | unsigned char _type; |
518 | }; | 520 | }; |
519 | 521 | ||
520 | /*====================================================================================== | 522 | /*====================================================================================== |
521 | * OTCPPacket | 523 | * OTCPPacket |
522 | *======================================================================================*/ | 524 | *======================================================================================*/ |
523 | 525 | ||
524 | class OTCPPacket : public QObject | 526 | class OTCPPacket : public QObject |
525 | { | 527 | { |
526 | Q_OBJECT | 528 | Q_OBJECT |
527 | 529 | ||
528 | public: | 530 | public: |
529 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); | 531 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); |
530 | virtual ~OTCPPacket(); | 532 | virtual ~OTCPPacket(); |
531 | 533 | ||
532 | int fromPort() const; | 534 | int fromPort() const; |
533 | int toPort() const; | 535 | int toPort() const; |
534 | int seq() const; | 536 | int seq() const; |
535 | int ack() const; | 537 | int ack() const; |
536 | int window() const; | 538 | int window() const; |
537 | int checksum() const; | 539 | int checksum() const; |
538 | 540 | ||
539 | private: | 541 | private: |
540 | const struct tcphdr* _tcphdr; | 542 | const struct tcphdr* _tcphdr; |
541 | }; | 543 | }; |
542 | 544 | ||
543 | 545 | ||
544 | /*====================================================================================== | 546 | /*====================================================================================== |
545 | * OPacketCapturer | 547 | * OPacketCapturer |
546 | *======================================================================================*/ | 548 | *======================================================================================*/ |
547 | 549 | ||
548 | /** | 550 | /** |
549 | * @brief A class based wrapper for network packet capturing. | 551 | * @brief A class based wrapper for network packet capturing. |
550 | * | 552 | * |
551 | * This class is the base of a high-level interface to the well known packet capturing | 553 | * This class is the base of a high-level interface to the well known packet capturing |
552 | * library libpcap. | 554 | * library libpcap. |
553 | * @see http://tcpdump.org | 555 | * @see http://tcpdump.org |
554 | */ | 556 | */ |
555 | class OPacketCapturer : public QObject | 557 | class OPacketCapturer : public QObject |
556 | { | 558 | { |
557 | Q_OBJECT | 559 | Q_OBJECT |
558 | 560 | ||
559 | public: | 561 | public: |
560 | /** | 562 | /** |
561 | * Constructor. | 563 | * Constructor. |
562 | */ | 564 | */ |
563 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); | 565 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); |
564 | /** | 566 | /** |
565 | * Destructor. | 567 | * Destructor. |
566 | */ | 568 | */ |
567 | ~OPacketCapturer(); | 569 | ~OPacketCapturer(); |
568 | /** | 570 | /** |
569 | * Set the packet capturer to use blocking or non-blocking IO. This can be useful when | 571 | * Set the packet capturer to use blocking or non-blocking IO. This can be useful when |
570 | * not using the socket notifier, e.g. without an application object. | 572 | * not using the socket notifier, e.g. without an application object. |
571 | */ | 573 | */ |
572 | void setBlocking( bool ); | 574 | void setBlocking( bool ); |
573 | /** | 575 | /** |
574 | * @returns true if the packet capturer uses blocking IO calls. | 576 | * @returns true if the packet capturer uses blocking IO calls. |
575 | */ | 577 | */ |
576 | bool blocking() const; | 578 | bool blocking() const; |
577 | /** | 579 | /** |
578 | * Close the packet capturer. This is automatically done in the destructor. | 580 | * Close the packet capturer. This is automatically done in the destructor. |
579 | */ | 581 | */ |
580 | void close(); | 582 | void close(); |
581 | /** | 583 | /** |
582 | * Close the output capture file. | 584 | * Close the output capture file. |
583 | */ | 585 | */ |
584 | void closeDumpFile(); | 586 | void closeDumpFile(); |
585 | /** | 587 | /** |
586 | * @returns the data link type. | 588 | * @returns the data link type. |
587 | * @see <pcap.h> for possible values. | 589 | * @see <pcap.h> for possible values. |
588 | */ | 590 | */ |
589 | int dataLink() const; | 591 | int dataLink() const; |
590 | /** | 592 | /** |
591 | * Dump a packet to the output capture file. | 593 | * Dump a packet to the output capture file. |
592 | */ | 594 | */ |
593 | void dump( OPacket* ); | 595 | void dump( OPacket* ); |
594 | /** | 596 | /** |
595 | * @returns the file descriptor of the packet capturer. This is only useful, if | 597 | * @returns the file descriptor of the packet capturer. This is only useful, if |
596 | * not using the socket notifier, e.g. without an application object. | 598 | * not using the socket notifier, e.g. without an application object. |
597 | */ | 599 | */ |
598 | int fileno() const; | 600 | int fileno() const; |
599 | /** | 601 | /** |
600 | * @returns the next @ref OPacket from the packet capturer. | 602 | * @returns the next @ref OPacket from the packet capturer. |
601 | * @note If blocking mode is true then this call might block. | 603 | * @note If blocking mode is true then this call might block. |
602 | */ | 604 | */ |
603 | OPacket* next(); | 605 | OPacket* next(); |
604 | /** | 606 | /** |
605 | * @returns the next @ref OPacket from the packet capturer, if | 607 | * @returns the next @ref OPacket from the packet capturer, if |
606 | * one arrives within @a time milliseconds. | 608 | * one arrives within @a time milliseconds. |
607 | */ | 609 | */ |
608 | OPacket* next( int time ); | 610 | OPacket* next( int time ); |
609 | /** | 611 | /** |
610 | * Open the packet capturer to capture packets in live-mode from @a interface. | 612 | * Open the packet capturer to capture packets in live-mode from @a interface. |
611 | */ | 613 | */ |
612 | bool open( const QString& interface ); | 614 | bool open( const QString& interface ); |
613 | /** | 615 | /** |
614 | * Open the packet capturer to capture packets in offline-mode from @a file. | 616 | * Open the packet capturer to capture packets in offline-mode from @a file. |
615 | */ | 617 | */ |
616 | bool open( const QFile& file ); | 618 | bool open( const QFile& file ); |
617 | /** | 619 | /** |
618 | * Open a prerecorded tcpdump compatible capture file for use with @ref dump() | 620 | * Open a prerecorded tcpdump compatible capture file for use with @ref dump() |
619 | */ | 621 | */ |
620 | bool openDumpFile( const QString& filename ); | 622 | bool openDumpFile( const QString& filename ); |
621 | /** | 623 | /** |
622 | * @returns true if the packet capturer is open | 624 | * @returns true if the packet capturer is open |
623 | */ | 625 | */ |
624 | bool isOpen() const; | 626 | bool isOpen() const; |
625 | /** | 627 | /** |
626 | * @returns the snapshot length of this packet capturer | 628 | * @returns the snapshot length of this packet capturer |
627 | */ | 629 | */ |
628 | int snapShot() const; | 630 | int snapShot() const; |
629 | /** | 631 | /** |
630 | * @returns true if the input capture file has a different byte-order | 632 | * @returns true if the input capture file has a different byte-order |
631 | * than the byte-order of the running system. | 633 | * than the byte-order of the running system. |
632 | */ | 634 | */ |
633 | bool swapped() const; | 635 | bool swapped() const; |
634 | /** | 636 | /** |
635 | * @returns the libpcap version string used to write the input capture file. | 637 | * @returns the libpcap version string used to write the input capture file. |
636 | */ | 638 | */ |
637 | QString version() const; | 639 | QString version() const; |
638 | /** | 640 | /** |
639 | * @returns the packet statistic database. | 641 | * @returns the packet statistic database. |
640 | * @see QMap | 642 | * @see QMap |
641 | */ | 643 | */ |
642 | const QMap<QString,int>& statistics() const; | 644 | const QMap<QString,int>& statistics() const; |
643 | 645 | ||
644 | signals: | 646 | signals: |
645 | /** | 647 | /** |
646 | * This signal is emitted, when a packet has been received. | 648 | * This signal is emitted, when a packet has been received. |
647 | */ | 649 | */ |
648 | void receivedPacket( OPacket* ); | 650 | void receivedPacket( OPacket* ); |
649 | 651 | ||
650 | protected slots: | 652 | protected slots: |
651 | void readyToReceive(); | 653 | void readyToReceive(); |
652 | 654 | ||
653 | protected: | 655 | protected: |
654 | QString _name; // devicename | 656 | QString _name; // devicename |
655 | bool _open; // check this before doing pcap calls | 657 | bool _open; // check this before doing pcap calls |