summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/sniff.cc41
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/sniff.hh10
2 files changed, 31 insertions, 20 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc
index fedd8fc..66299d1 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc
@@ -1,303 +1,314 @@
1/* 1/*
2 * rfmon mode sniffer 2 * rfmon mode sniffer
3 * 3 *
4 * $Id$ 4 * $Id$
5 */ 5 */
6 6
7#include "sniff.hh" 7#include "sniff.hh"
8#include "ieee802_11.hh" 8#include "ieee802_11.hh"
9#include "extract.hh" 9#include "extract.hh"
10#include "log.hh" 10#include "log.hh"
11#include "proto.hh"
11 12
12/* Main function, checks packets */ 13/* Main function, checks packets */
13void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet) 14void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet, char *guihost, int guiport)
14{ 15{
15 unsigned int caplen = pkthdr->caplen; 16 unsigned int caplen = pkthdr->caplen;
16 unsigned int length = pkthdr->len; 17 unsigned int length = pkthdr->len;
17 u_int16_t fc; 18 u_int16_t fc;
18 unsigned int HEADER_LENGTH; 19 unsigned int HEADER_LENGTH;
19 20
20 /* pinfo holds all interresting information for us */ 21 /* pinfo holds all interresting information for us */
21 struct packetinfo pinfo; 22 struct packetinfo pinfo;
22 struct packetinfo *pinfoptr; 23 struct packetinfo *pinfoptr;
24
25 /* wl_network_t will finally be set and send to the ui */
26 wl_network_t wl_net;
27
23 pinfoptr=&pinfo; 28 pinfoptr=&pinfo;
24 29
25 pinfoptr->isvalid = 0; 30 pinfoptr->isvalid = 0;
26 pinfoptr->pktlen = pkthdr->len; 31 pinfoptr->pktlen = pkthdr->len;
27 32
28 if (caplen < IEEE802_11_FC_LEN) 33 if (caplen < IEEE802_11_FC_LEN)
29 { 34 {
30 /* This is a garbage packet, because is does not long enough 35 /* This is a garbage packet, because is does not long enough
31 to hold a 802.11b header */ 36 to hold a 802.11b header */
32 pinfoptr->isvalid = 0; 37 pinfoptr->isvalid = 0;
33 return; 38 return;
34 } 39 }
35 40
36 /* Gets the framecontrol bits (2bytes long) */ 41 /* Gets the framecontrol bits (2bytes long) */
37 fc = EXTRACT_LE_16BITS(packet); 42 fc = EXTRACT_LE_16BITS(packet);
38 43
39 HEADER_LENGTH = GetHeaderLength(fc); 44 HEADER_LENGTH = GetHeaderLength(fc);
40 45
41 if (caplen < HEADER_LENGTH) 46 if (caplen < HEADER_LENGTH)
42 { 47 {
43 /* This is a garbage packet, because it is not long enough 48 /* This is a garbage packet, because it is not long enough
44 to hold a correct header of its type */ 49 to hold a correct header of its type */
45 pinfoptr->isvalid = 0; 50 pinfoptr->isvalid = 0;
46 return; 51 return;
47 } 52 }
48 53
49 /* Decode 802.11b header out of the packet */ 54 /* Decode 802.11b header out of the packet */
50 if (decode_80211b_hdr(packet,pinfoptr) == 0) 55 if (decode_80211b_hdr(packet,pinfoptr) == 0)
51 { 56 {
52 /* Justification of the ofset to further process the packet */ 57 /* Justification of the ofset to further process the packet */
53 length -= HEADER_LENGTH; 58 length -= HEADER_LENGTH;
54 caplen -= HEADER_LENGTH; 59 caplen -= HEADER_LENGTH;
55 packet += HEADER_LENGTH; 60 packet += HEADER_LENGTH;
56 } 61 }
57 else /* Something is wrong,could not be a correct packet */ 62 else /* Something is wrong,could not be a correct packet */
58 return; 63 return;
59 64
60 switch (FC_TYPE(fc)) 65 switch (FC_TYPE(fc))
61 { 66 {
62 /* Is it a managemnet frame? */ 67 /* Is it a managemnet frame? */
63 case T_MGMT: 68 case T_MGMT:
64 switch (FC_SUBTYPE(fc)) 69 switch (FC_SUBTYPE(fc))
65 { 70 {
66 case ST_BEACON: 71 case ST_BEACON:
67 if (handle_beacon(fc, packet,pinfoptr) ==0) 72 if (handle_beacon(fc, packet,pinfoptr) ==0)
68 { 73 {
69 if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) 74 if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0)
70 { 75 {
71 /* Every beacon must have the broadcast as destination 76 /* Every beacon must have the broadcast as destination
72 so it must be a shitti packet */ 77 so it must be a shitti packet */
73 pinfoptr->isvalid = 0; 78 pinfoptr->isvalid = 0;
74 return; 79 return;
75 } 80 }
76 81
77 if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) 82 if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS)
78 { 83 {
79 /* Only one of both are possible, so must be 84 /* Only one of both are possible, so must be
80 a noise packet, if this comes up */ 85 a noise packet, if this comes up */
81 pinfoptr->isvalid = 0; 86 pinfoptr->isvalid = 0;
82 return; 87 return;
83 } 88 }
84 if (pinfoptr->channel < 1 || pinfoptr->channel > 14) 89 if (pinfoptr->channel < 1 || pinfoptr->channel > 14)
85 { 90 {
86 /* Only channels between 1 and 14 are possible 91 /* Only channels between 1 and 14 are possible
87 others must be noise packets */ 92 others must be noise packets */
88 pinfoptr->isvalid = 0; 93 pinfoptr->isvalid = 0;
89 return; 94 return;
90 } 95 }
91 96
92 97
93 /* Here should be the infos to the gui issued */ 98 /* Here should be the infos to the gui issued */
94 if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) 99 if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0)
95 { 100 {
96 printf ("\nHave found an accesspoint:"); 101 wl_loginfo("Found an access point");
102 wl_net.net_type=1;
97 } 103 }
98 else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 1) 104 else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 1)
99 { 105 {
100 printf ("\nHave found an AD-HOC station:"); 106 wl_loginfo("Found an ad-hoc network");
101 107 wl_net.net_type=2;
102 } 108 }
103 if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) 109 if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0)
104 { 110 {
105 printf ("\n\tOn a non-broadcasting network"); 111 wl_loginfo("Net is a non-broadcasting network");
106 } 112 }
107 else 113 else
108 { 114 {
109 printf ("\n\tOn network : %s",pinfoptr->ssid); 115 wl_loginfo("SSID is: %s", pinfoptr->ssid);
116 // wl_net.bssid=pinfoptr->ssid;
110 } 117 }
111 printf ("\n\tLen SSID : %d",pinfoptr->ssid_len); 118
112 printf ("\n\tOn Channel : %d",pinfoptr->channel); 119 wl_net.ssid_len=pinfoptr->ssid_len;
113 printf ("\n\tEncryption : %s", pinfoptr->cap_WEP ? "ON" : "OFF"); 120 wl_net.channel=pinfoptr->channel;
114 printf ("\n\tMacaddress : %s",pinfoptr->sndhwaddr); 121 wl_net.wep=pinfoptr->cap_WEP;
115 printf ("\n\tBssid : %s",pinfoptr->bssid); 122 memcpy(wl_net.mac, pinfoptr->sndhwaddr, sizeof(wl_net.mac));;
116 printf ("\n\tDest : %s\n",pinfoptr->desthwaddr); 123 memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid));
124
125 // printf ("\n\tDest : %s\n",pinfoptr->desthwaddr);
126 send_network_found((char *)guihost, guiport, &wl_net);
127 wl_loginfo("Sent network to GUI '%s:%d'", guihost, guiport);
117 } 128 }
118 break; 129 break;
119 default: 130 default:
120 wl_logerr("Unknown IEEE802.11 frame subtype (%d)", FC_SUBTYPE(fc)); 131 wl_logerr("Unknown IEEE802.11 frame subtype (%d)", FC_SUBTYPE(fc));
121 break; 132 break;
122 } /* End of switch over different mgt frame types */ 133 } /* End of switch over different mgt frame types */
123 134
124 break; 135 break;
125 136
126 case T_CTRL: 137 case T_CTRL:
127 wl_loginfo("Received control frame, not implemented yet"); 138 wl_loginfo("Received control frame, not implemented yet");
128 break; 139 break;
129 140
130 case T_DATA: 141 case T_DATA:
131 wl_loginfo("Received date frame, not implemented yet"); 142 wl_loginfo("Received date frame, not implemented yet");
132 break; 143 break;
133 144
134 default: 145 default:
135 wl_logerr("Unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); 146 wl_logerr("Unknown IEEE802.11 frame type (%d)", FC_TYPE(fc));
136 break; 147 break;
137 } 148 }
138} 149}
139 150
140/* This decodes the 802.11b frame header out of the 802.11b packet 151/* This decodes the 802.11b frame header out of the 802.11b packet
141 all the infos is placed into the packetinfo structure */ 152 all the infos is placed into the packetinfo structure */
142int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) 153int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo)
143{ 154{
144 const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; 155 const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p;
145 ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); 156 ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc);
146 157
147 /* Get the sender, bssid and dest mac address */ 158 /* Get the sender, bssid and dest mac address */
148 etheraddr_string(mgthdr->bssid,ppinfo->bssid); 159 etheraddr_string(mgthdr->bssid,ppinfo->bssid);
149 etheraddr_string(mgthdr->da,ppinfo->desthwaddr); 160 etheraddr_string(mgthdr->da,ppinfo->desthwaddr);
150 etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); 161 etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr);
151 ppinfo->fc_wep = FC_WEP(mgthdr->fc); 162 ppinfo->fc_wep = FC_WEP(mgthdr->fc);
152 return 0; 163 return 0;
153} 164}
154 165
155 166
156void etheraddr_string(register const u_char *ep, char *text) 167void etheraddr_string(register const u_char *ep, char *text)
157{ 168{
158 static char hex[] = "0123456789abcdef"; 169 static char hex[] = "0123456789abcdef";
159 register unsigned int i, j; 170 register unsigned int i, j;
160 register char *cp; 171 register char *cp;
161 char buf[sizeof("00:00:00:00:00:00")]; 172 char buf[sizeof("00:00:00:00:00:00")];
162 cp = buf; 173 cp = buf;
163 if ((j = *ep >> 4) != 0) 174 if ((j = *ep >> 4) != 0)
164 *cp++ = hex[j]; 175 *cp++ = hex[j];
165 *cp++ = hex[*ep++ & 0xf]; 176 *cp++ = hex[*ep++ & 0xf];
166 for (i = 5; (int)--i >= 0;) { 177 for (i = 5; (int)--i >= 0;) {
167 *cp++ = ':'; 178 *cp++ = ':';
168 if ((j = *ep >> 4) != 0) 179 if ((j = *ep >> 4) != 0)
169 *cp++ = hex[j]; 180 *cp++ = hex[j];
170 *cp++ = hex[*ep++ & 0xf]; 181 *cp++ = hex[*ep++ & 0xf];
171 } 182 }
172 *cp = '\0'; 183 *cp = '\0';
173 strcpy(text,buf); 184 strcpy(text,buf);
174} 185}
175 186
176/* beacon handler */ 187/* beacon handler */
177int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) 188int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo)
178{ 189{
179 struct mgmt_body_t pbody; 190 struct mgmt_body_t pbody;
180 int offset = 0; 191 int offset = 0;
181 192
182 /* Get the static informations out of the packet */ 193 /* Get the static informations out of the packet */
183 memset(&pbody, 0, sizeof(pbody)); 194 memset(&pbody, 0, sizeof(pbody));
184 memcpy(&pbody.timestamp, p, 8); 195 memcpy(&pbody.timestamp, p, 8);
185 offset += 8; 196 offset += 8;
186 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); 197 pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
187 offset += 2; 198 offset += 2;
188 pbody.capability_info = EXTRACT_LE_16BITS(p+offset); 199 pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
189 offset += 2; 200 offset += 2;
190 201
191 /* Gets the different flags out of the capabilities */ 202 /* Gets the different flags out of the capabilities */
192 ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); 203 ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info);
193 ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); 204 ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info);
194 ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); 205 ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info);
195 206
196 /* Gets the tagged elements out of the packets */ 207 /* Gets the tagged elements out of the packets */
197 while (offset + 1 < ppinfo->pktlen) 208 while (offset + 1 < ppinfo->pktlen)
198 { 209 {
199 switch (*(p + offset)) 210 switch (*(p + offset))
200 { 211 {
201 case E_SSID: 212 case E_SSID:
202 memcpy(&(pbody.ssid),p+offset,2); offset += 2; 213 memcpy(&(pbody.ssid),p+offset,2); offset += 2;
203 if (pbody.ssid.length > 0) 214 if (pbody.ssid.length > 0)
204 { 215 {
205 memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; 216 memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length;
206 pbody.ssid.ssid[pbody.ssid.length]='\0'; 217 pbody.ssid.ssid[pbody.ssid.length]='\0';
207 if (strcmp((char *)pbody.ssid.ssid,"")==0) 218 if (strcmp((char *)pbody.ssid.ssid,"")==0)
208 ppinfo->ssid = NONBROADCASTING; 219 memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid));
209 else 220 else
210 ppinfo->ssid = (char *)pbody.ssid.ssid; 221 memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid));
211 ppinfo->ssid_len = pbody.ssid.length; 222 ppinfo->ssid_len = pbody.ssid.length;
212 } 223 }
213 break; 224 break;
214 225
215 case E_CHALLENGE: 226 case E_CHALLENGE:
216 memcpy(&(pbody.challenge),p+offset,2); offset += 2; 227 memcpy(&(pbody.challenge),p+offset,2); offset += 2;
217 if (pbody.challenge.length > 0) 228 if (pbody.challenge.length > 0)
218 { 229 {
219 memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; 230 memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length;
220 pbody.challenge.text[pbody.challenge.length]='\0'; 231 pbody.challenge.text[pbody.challenge.length]='\0';
221 } 232 }
222 break; 233 break;
223 case E_RATES: 234 case E_RATES:
224 memcpy(&(pbody.rates),p+offset,2); offset += 2; 235 memcpy(&(pbody.rates),p+offset,2); offset += 2;
225 if (pbody.rates.length > 0) 236 if (pbody.rates.length > 0)
226 { 237 {
227 memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; 238 memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length;
228 } 239 }
229 break; 240 break;
230 case E_DS: 241 case E_DS:
231 memcpy(&(pbody.ds),p+offset,3); offset +=3; 242 memcpy(&(pbody.ds),p+offset,3); offset +=3;
232 ppinfo->channel = pbody.ds.channel; 243 ppinfo->channel = pbody.ds.channel;
233 break; 244 break;
234 case E_CF: 245 case E_CF:
235 memcpy(&(pbody.cf),p+offset,8); offset +=8; 246 memcpy(&(pbody.cf),p+offset,8); offset +=8;
236 break; 247 break;
237 case E_TIM: 248 case E_TIM:
238 memcpy(&(pbody.tim),p+offset,2); offset +=2; 249 memcpy(&(pbody.tim),p+offset,2); offset +=2;
239 memcpy(&(pbody.tim.count),p+offset,3); offset +=3; 250 memcpy(&(pbody.tim.count),p+offset,3); offset +=3;
240 if ((pbody.tim.length -3) > 0) 251 if ((pbody.tim.length -3) > 0)
241 { 252 {
242 memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); 253 memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3));
243 offset += pbody.tim.length -3; 254 offset += pbody.tim.length -3;
244 } 255 }
245 break; 256 break;
246 default: 257 default:
247 258
248 offset+= *(p+offset+1) + 2; 259 offset+= *(p+offset+1) + 2;
249 break; 260 break;
250 } /* end of switch*/ 261 } /* end of switch*/
251 } /* end of for loop */ 262 } /* end of for loop */
252 return 0; 263 return 0;
253 264
254} /* End of handle_beacon */ 265} /* End of handle_beacon */
255 266
256 267
257int GetHeaderLength(u_int16_t fc) 268int GetHeaderLength(u_int16_t fc)
258{ 269{
259 int iLength=0; 270 int iLength=0;
260 271
261 switch (FC_TYPE(fc)) 272 switch (FC_TYPE(fc))
262 { 273 {
263 case T_MGMT: 274 case T_MGMT:
264 iLength = MGMT_HEADER_LEN; 275 iLength = MGMT_HEADER_LEN;
265 break; 276 break;
266 case T_CTRL: 277 case T_CTRL:
267 switch (FC_SUBTYPE(fc)) 278 switch (FC_SUBTYPE(fc))
268 { 279 {
269 case CTRL_PS_POLL: 280 case CTRL_PS_POLL:
270 iLength = CTRL_PS_POLL_LEN; 281 iLength = CTRL_PS_POLL_LEN;
271 break; 282 break;
272 case CTRL_RTS: 283 case CTRL_RTS:
273 iLength = CTRL_RTS_LEN; 284 iLength = CTRL_RTS_LEN;
274 break; 285 break;
275 case CTRL_CTS: 286 case CTRL_CTS:
276 iLength = CTRL_CTS_LEN; 287 iLength = CTRL_CTS_LEN;
277 break; 288 break;
278 case CTRL_ACK: 289 case CTRL_ACK:
279 iLength = CTRL_ACK_LEN; 290 iLength = CTRL_ACK_LEN;
280 break; 291 break;
281 case CTRL_CF_END: 292 case CTRL_CF_END:
282 iLength = CTRL_END_LEN; 293 iLength = CTRL_END_LEN;
283 break; 294 break;
284 case CTRL_END_ACK: 295 case CTRL_END_ACK:
285 iLength = CTRL_END_ACK_LEN; 296 iLength = CTRL_END_ACK_LEN;
286 break; 297 break;
287 default: 298 default:
288 iLength = 0; 299 iLength = 0;
289 break; 300 break;
290 } 301 }
291 break; 302 break;
292 case T_DATA: 303 case T_DATA:
293 if (FC_TO_DS(fc) && FC_FROM_DS(fc)) 304 if (FC_TO_DS(fc) && FC_FROM_DS(fc))
294 iLength = 30; 305 iLength = 30;
295 else 306 else
296 iLength = 24; 307 iLength = 24;
297 break; 308 break;
298 default: 309 default:
299 wl_logerr("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); 310 wl_logerr("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc));
300 break; 311 break;
301 } 312 }
302 return iLength; 313 return iLength;
303} 314}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh b/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh
index fa8519b..60cdc43 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh
@@ -1,64 +1,64 @@
1/* $Id$ */ 1/* $Id$ */
2 2
3#ifndef SNIFF_HH 3#ifndef SNIFF_HH
4#define SNIFF_HH 4#define SNIFF_HH
5 5
6#include <string.h> 6#include <string.h>
7#include <stdio.h> 7#include <stdio.h>
8#include <stdlib.h> 8#include <stdlib.h>
9#include <pcap.h> 9#include <pcap.h>
10#include <errno.h> 10#include <errno.h>
11#include <sys/socket.h> 11#include <sys/socket.h>
12#include <netinet/in.h> 12#include <netinet/in.h>
13#include <arpa/inet.h> 13#include <arpa/inet.h>
14#include <net/bpf.h> 14#include <net/bpf.h>
15 15
16#define NONBROADCASTING "non-broadcasting" 16#define NONBROADCASTING "non-broadcasting"
17 17
18/* holds all the interresting data */ 18/* holds all the interresting data */
19struct packetinfo 19struct packetinfo
20{ 20{
21 int isvalid; 21 int isvalid;
22 int pktlen; 22 int pktlen;
23 int fctype; 23 int fctype;
24 int fcsubtype; 24 int fcsubtype;
25 int fc_wep; 25 int fc_wep;
26 int cap_WEP; 26 int cap_WEP;
27 int cap_IBSS; 27 int cap_IBSS;
28 int cap_ESS; 28 int cap_ESS;
29 int channel; 29 int channel;
30 char bssid[sizeof("00:00:00:00:00:00")]; 30 char bssid[sizeof("00:00:00:00:00:00") + 1];
31 char desthwaddr[sizeof("00:00:00:00:00:00")]; 31 char desthwaddr[sizeof("00:00:00:00:00:00") + 1];
32 char sndhwaddr[sizeof("00:00:00:00:00:00")]; 32 char sndhwaddr[sizeof("00:00:00:00:00:00") + 1];
33 char *ssid; 33 char ssid[128];
34 int ssid_len; 34 int ssid_len;
35}; 35};
36 36
37void process_packets(const struct pcap_pkthdr* pkthdr,const u_char* packet); 37void process_packets(const struct pcap_pkthdr* pkthdr,const u_char* packet, char *, int);
38int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); 38int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo);
39void etheraddr_string(register const u_char *ep,char * text); 39void etheraddr_string(register const u_char *ep,char * text);
40int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); 40int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo);
41 41
42int GetHeaderLength(u_int16_t fc); 42int GetHeaderLength(u_int16_t fc);
43 43
44/* 44/*
45 * True if "l" bytes of "var" were captured. 45 * True if "l" bytes of "var" were captured.
46 * 46 *
47 * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large 47 * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large
48 * that "snapend - (l)" underflows. 48 * that "snapend - (l)" underflows.
49 * 49 *
50 * The check is for <= rather than < because "l" might be 0. 50 * The check is for <= rather than < because "l" might be 0.
51 */ 51 */
52#define TTEST2(var, l) (snapend - (l) <= snapend && \ 52#define TTEST2(var, l) (snapend - (l) <= snapend && \
53 (const u_char *)&(var) <= snapend - (l)) 53 (const u_char *)&(var) <= snapend - (l))
54 54
55/* True if "var" was captured */ 55/* True if "var" was captured */
56#define TTEST(var) TTEST2(var, sizeof(var)) 56#define TTEST(var) TTEST2(var, sizeof(var))
57 57
58/* Bail if "l" bytes of "var" were not captured */ 58/* Bail if "l" bytes of "var" were not captured */
59#define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc 59#define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc
60 60
61/* Bail if "var" was not captured */ 61/* Bail if "var" was not captured */
62#define TCHECK(var) TCHECK2(var, sizeof(var)) 62#define TCHECK(var) TCHECK2(var, sizeof(var))
63 63
64#endif /* SNIFF_HH */ 64#endif /* SNIFF_HH */