author | max <max> | 2002-11-11 15:58:46 (UTC) |
---|---|---|
committer | max <max> | 2002-11-11 15:58:46 (UTC) |
commit | 2df7c2d998c4b15dba8cefea096cce248b774703 (patch) (unidiff) | |
tree | 84029e731fa0c2185dd48902f4fe230976d0ffd4 | |
parent | 2870d8cba649ab744d0e48a2bcc537ea753f842f (diff) | |
download | opie-2df7c2d998c4b15dba8cefea096cce248b774703.zip opie-2df7c2d998c4b15dba8cefea096cce248b774703.tar.gz opie-2df7c2d998c4b15dba8cefea096cce248b774703.tar.bz2 |
*** empty log message ***
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/sniffer.c | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.c b/noncore/net/wellenreiter/daemon/source/sniffer.c index 6f40503..31a5d13 100644 --- a/noncore/net/wellenreiter/daemon/source/sniffer.c +++ b/noncore/net/wellenreiter/daemon/source/sniffer.c | |||
@@ -1,437 +1,434 @@ | |||
1 | /* Its just a simple rfmon mode sniffer | 1 | /* Its just a simple rfmon mode sniffer |
2 | i hope my C is at last a bit better then in my | 2 | i hope my C is at last a bit better then in my |
3 | early days :-). | 3 | early days :-). |
4 | This works only with cisco wireless cards with an rfmon | 4 | This works only with cisco wireless cards with an rfmon |
5 | able driver and not with wifi stuff. | 5 | able driver and not with wifi stuff. |
6 | Btw. did i mention that i hate C? | 6 | Btw. did i mention that i hate C? |
7 | 7 | ||
8 | To compile use: | 8 | To compile use: |
9 | gcc wlan-sniffer.c -o wlan-sniffer -lpcap | 9 | gcc sniffer.c -o wlan-sniffer -lpcap |
10 | |||
11 | use it like this: | ||
12 | wlan-sniffer interface | ||
13 | 10 | ||
14 | */ | 11 | */ |
15 | #include "sniffer.h" | 12 | #include "sniffer.h" |
16 | 13 | ||
17 | int main(int argc, char **argv) | 14 | int main(int argc, char **argv) |
18 | { | 15 | { |
19 | int ret; /* return code */ | 16 | int ret; /* return code */ |
20 | ret = card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG); | 17 | ret = card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG); |
21 | if (ret == -1) | 18 | if (ret == -1) |
22 | { | 19 | { |
23 | exit(-1); | 20 | exit(-1); |
24 | } | 21 | } |
25 | start_sniffing (SNIFFER_DEVICE); | 22 | start_sniffing (SNIFFER_DEVICE); |
26 | 23 | ||
27 | return 0; | 24 | return 0; |
28 | } | 25 | } |
29 | 26 | ||
30 | int card_into_monitormode (char * device, int cardtype) | 27 | int card_into_monitormode (char * device, int cardtype) |
31 | { | 28 | { |
32 | int ret = -1; | 29 | int ret = -1; |
33 | int datalink; /* used for getting the pcap datalink type */ | 30 | int datalink; /* used for getting the pcap datalink type */ |
34 | char CiscoRFMON[35] = "/proc/driver/aironet/"; | 31 | char CiscoRFMON[35] = "/proc/driver/aironet/"; |
35 | FILE *CISCO_CONFIG_FILE; | 32 | FILE *CISCO_CONFIG_FILE; |
36 | char errbuf[PCAP_ERRBUF_SIZE]; | 33 | char errbuf[PCAP_ERRBUF_SIZE]; |
37 | pcap_t *handle; | 34 | pcap_t *handle; |
38 | 35 | ||
39 | /* Checks if we have a device to sniff on */ | 36 | /* Checks if we have a device to sniff on */ |
40 | if(device == NULL) | 37 | if(device == NULL) |
41 | { | 38 | { |
42 | printf ("Fatal error i did not have any interfaces to sniff on\n"); | 39 | printf ("Fatal error i did not have any interfaces to sniff on\n"); |
43 | exit(1); | 40 | exit(1); |
44 | } | 41 | } |
45 | 42 | ||
46 | /* Setting the prmiscous and up flag to the interface */ | 43 | /* Setting the prmiscous and up flag to the interface */ |
47 | if (card_set_promisc_up (device) == 0) | 44 | if (card_set_promisc_up (device) == 0) |
48 | { | 45 | { |
49 | printf ("Interface flags correctly set using ifconfig\n"); | 46 | printf ("Interface flags correctly set using ifconfig\n"); |
50 | } | 47 | } |
51 | 48 | ||
52 | /* Check the cardtype and executes the commands to go into monitor mode */ | 49 | /* Check the cardtype and executes the commands to go into monitor mode */ |
53 | if (cardtype == CARD_TYPE_CISCO) /* I got a cisco card */ | 50 | if (cardtype == CARD_TYPE_CISCO) /* I got a cisco card */ |
54 | { | 51 | { |
55 | /* bring the sniffer into rfmon mode */ | 52 | /* bring the sniffer into rfmon mode */ |
56 | snprintf(CiscoRFMON, sizeof(CiscoRFMON),DEFAULT_PATH, device); | 53 | snprintf(CiscoRFMON, sizeof(CiscoRFMON),DEFAULT_PATH, device); |
57 | CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w"); | 54 | CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w"); |
58 | fputs ("Mode: r",CISCO_CONFIG_FILE); | 55 | fputs ("Mode: r",CISCO_CONFIG_FILE); |
59 | fputs ("Mode: y",CISCO_CONFIG_FILE); | 56 | fputs ("Mode: y",CISCO_CONFIG_FILE); |
60 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); | 57 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); |
61 | fclose(CISCO_CONFIG_FILE); | 58 | fclose(CISCO_CONFIG_FILE); |
62 | } | 59 | } |
63 | else if (cardtype == CARD_TYPE_NG) | 60 | else if (cardtype == CARD_TYPE_NG) |
64 | { | 61 | { |
65 | char wlanngcmd[62]; | 62 | char wlanngcmd[62]; |
66 | snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device); | 63 | snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device); |
67 | if (ret = (system (wlanngcmd)) != 0) | 64 | if (ret = (system (wlanngcmd)) != 0) |
68 | { | 65 | { |
69 | printf ("\n Fatal error could not set %s in raw mode, check cardtype\n",device); | 66 | printf ("\n Fatal error could not set %s in raw mode, check cardtype\n",device); |
70 | exit(1); | 67 | exit(1); |
71 | } | 68 | } |
72 | } | 69 | } |
73 | else if (cardtype == CARD_TYPE_HOSTAP) | 70 | else if (cardtype == CARD_TYPE_HOSTAP) |
74 | { | 71 | { |
75 | printf ("Got a host-ap card, nothing is implemented now\n"); | 72 | printf ("Got a host-ap card, nothing is implemented now\n"); |
76 | } | 73 | } |
77 | 74 | ||
78 | 75 | ||
79 | /* Check the interface if it is in the correct raw mode */ | 76 | /* Check the interface if it is in the correct raw mode */ |
80 | handle = pcap_open_live(device, BUFSIZ, 1, 0, errbuf); | 77 | handle = pcap_open_live(device, BUFSIZ, 1, 0, errbuf); |
81 | 78 | ||
82 | /* getting the datalink type */ | 79 | /* getting the datalink type */ |
83 | datalink = pcap_datalink(handle); | 80 | datalink = pcap_datalink(handle); |
84 | 81 | ||
85 | if (datalink == DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ | 82 | if (datalink == DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ |
86 | { | 83 | { |
87 | printf ("Your successfully listen on %s in 802.11 raw mode\n",device); | 84 | printf ("Your successfully listen on %s in 802.11 raw mode\n",device); |
88 | pcap_close(handle); | 85 | pcap_close(handle); |
89 | return (0); | 86 | return (0); |
90 | 87 | ||
91 | } | 88 | } |
92 | else | 89 | else |
93 | { | 90 | { |
94 | printf ("Fatal error, cannot continue, your interface %s does not work in the correct 802.11 raw mode, check you driver please\n",device); | 91 | printf ("Fatal error, cannot continue, your interface %s does not work in the correct 802.11 raw mode, check you driver please\n",device); |
95 | pcap_close(handle); | 92 | pcap_close(handle); |
96 | exit(1); | 93 | exit(1); |
97 | } | 94 | } |
98 | } | 95 | } |
99 | 96 | ||
100 | int card_set_promisc_up (char * device) | 97 | int card_set_promisc_up (char * device) |
101 | { | 98 | { |
102 | int ret; | 99 | int ret; |
103 | char ifconfigcmd[32]; | 100 | char ifconfigcmd[32]; |
104 | snprintf(ifconfigcmd,sizeof(ifconfigcmd),SBIN_PATH, device); | 101 | snprintf(ifconfigcmd,sizeof(ifconfigcmd),SBIN_PATH, device); |
105 | ret = system (ifconfigcmd); | 102 | ret = system (ifconfigcmd); |
106 | if (ret > 0) | 103 | if (ret > 0) |
107 | { | 104 | { |
108 | printf ("\nFatal error, could not execute %s please check your card,binary location and permission\n",ifconfigcmd); | 105 | printf ("\nFatal error, could not execute %s please check your card,binary location and permission\n",ifconfigcmd); |
109 | exit(1); | 106 | exit(1); |
110 | } | 107 | } |
111 | return(0); | 108 | return(0); |
112 | } | 109 | } |
113 | 110 | ||
114 | int start_sniffing (char * device) | 111 | int start_sniffing (char * device) |
115 | { | 112 | { |
116 | int ret; /* return code */ | 113 | int ret; /* return code */ |
117 | pcap_t *handletopcap; | 114 | pcap_t *handletopcap; |
118 | char errbuf[PCAP_ERRBUF_SIZE]; | 115 | char errbuf[PCAP_ERRBUF_SIZE]; |
119 | struct pcap_pkthdr header; /* The header that pcap gives us */ | 116 | struct pcap_pkthdr header; /* The header that pcap gives us */ |
120 | const u_char *packet; /* The actual packet */ | 117 | const u_char *packet; /* The actual packet */ |
121 | 118 | ||
122 | /* opening the pcap for sniffing */ | 119 | /* opening the pcap for sniffing */ |
123 | handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf); | 120 | handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf); |
124 | 121 | ||
125 | /* Next few lines a taken out of kismet */ | 122 | /* Next few lines a taken out of kismet */ |
126 | #ifdef HAVE_PCAP_NONBLOCK | 123 | #ifdef HAVE_PCAP_NONBLOCK |
127 | pcap_setnonblock(handletopcap, 1, errstr); | 124 | pcap_setnonblock(handletopcap, 1, errstr); |
128 | #endif | 125 | #endif |
129 | 126 | ||
130 | /*start scanning */ | 127 | /*start scanning */ |
131 | pcap_loop(handletopcap,-1,process_packets,NULL); | 128 | pcap_loop(handletopcap,-1,process_packets,NULL); |
132 | 129 | ||
133 | printf("\nDone processing packets... wheew!\n"); | 130 | printf("\nDone processing packets... wheew!\n"); |
134 | return 0; | 131 | return 0; |
135 | } | 132 | } |
136 | 133 | ||
137 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) | 134 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) |
138 | { | 135 | { |
139 | u_int caplen = pkthdr->caplen; | 136 | u_int caplen = pkthdr->caplen; |
140 | u_int length = pkthdr->len; | 137 | u_int length = pkthdr->len; |
141 | u_int16_t fc; | 138 | u_int16_t fc; |
142 | u_int HEADER_LENGTH; | 139 | u_int HEADER_LENGTH; |
143 | u_short extracted_ethertype; | 140 | u_short extracted_ethertype; |
144 | int snapend; | 141 | int snapend; |
145 | int ret; | 142 | int ret; |
146 | /* pinfo holds all interresting information for us */ | 143 | /* pinfo holds all interresting information for us */ |
147 | struct packetinfo pinfo; | 144 | struct packetinfo pinfo; |
148 | struct packetinfo *pinfoptr; | 145 | struct packetinfo *pinfoptr; |
149 | pinfoptr=&pinfo; | 146 | pinfoptr=&pinfo; |
150 | 147 | ||
151 | pinfoptr->isvalid = 0; | 148 | pinfoptr->isvalid = 0; |
152 | pinfoptr->pktlen = pkthdr->len; | 149 | pinfoptr->pktlen = pkthdr->len; |
153 | if (caplen < IEEE802_11_FC_LEN) | 150 | if (caplen < IEEE802_11_FC_LEN) |
154 | { | 151 | { |
155 | /* This is a garbage packet, because is does not long enough | 152 | /* This is a garbage packet, because is does not long enough |
156 | to hold a 802.11b header */ | 153 | to hold a 802.11b header */ |
157 | pinfoptr->isvalid = 0; | 154 | pinfoptr->isvalid = 0; |
158 | return; | 155 | return; |
159 | } | 156 | } |
160 | 157 | ||
161 | /* Gets the framecontrol bits (2bytes long) */ | 158 | /* Gets the framecontrol bits (2bytes long) */ |
162 | fc = EXTRACT_LE_16BITS(packet); | 159 | fc = EXTRACT_LE_16BITS(packet); |
163 | 160 | ||
164 | HEADER_LENGTH = GetHeaderLength(fc); | 161 | HEADER_LENGTH = GetHeaderLength(fc); |
165 | 162 | ||
166 | if (caplen < HEADER_LENGTH) | 163 | if (caplen < HEADER_LENGTH) |
167 | { | 164 | { |
168 | /* This is a garbage packet, because it is not long enough | 165 | /* This is a garbage packet, because it is not long enough |
169 | to hold a correct header of its type */ | 166 | to hold a correct header of its type */ |
170 | pinfoptr->isvalid = 0; | 167 | pinfoptr->isvalid = 0; |
171 | return; | 168 | return; |
172 | } | 169 | } |
173 | 170 | ||
174 | /* Decode 802.11b header out of the packet */ | 171 | /* Decode 802.11b header out of the packet */ |
175 | if (decode_80211b_hdr(packet,pinfoptr) == 0) | 172 | if (decode_80211b_hdr(packet,pinfoptr) == 0) |
176 | { | 173 | { |
177 | /* Justification of the ofset to further process the packet */ | 174 | /* Justification of the ofset to further process the packet */ |
178 | length -= HEADER_LENGTH; | 175 | length -= HEADER_LENGTH; |
179 | caplen -= HEADER_LENGTH; | 176 | caplen -= HEADER_LENGTH; |
180 | packet += HEADER_LENGTH; | 177 | packet += HEADER_LENGTH; |
181 | } | 178 | } |
182 | else | 179 | else |
183 | { /* Something is wrong,could not be a correct packet */ | 180 | { /* Something is wrong,could not be a correct packet */ |
184 | return; | 181 | return; |
185 | } | 182 | } |
186 | 183 | ||
187 | switch (FC_TYPE(fc)) | 184 | switch (FC_TYPE(fc)) |
188 | { | 185 | { |
189 | /* Is it a managemnet frame? */ | 186 | /* Is it a managemnet frame? */ |
190 | case T_MGMT: | 187 | case T_MGMT: |
191 | switch (FC_SUBTYPE(fc)) | 188 | switch (FC_SUBTYPE(fc)) |
192 | { /* Is it a beacon frame? */ | 189 | { /* Is it a beacon frame? */ |
193 | case ST_BEACON: | 190 | case ST_BEACON: |
194 | if (handle_beacon(fc, packet,pinfoptr) ==0) | 191 | if (handle_beacon(fc, packet,pinfoptr) ==0) |
195 | { | 192 | { |
196 | if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) | 193 | if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) |
197 | { | 194 | { |
198 | /* Every beacon must have the broadcast as destination | 195 | /* Every beacon must have the broadcast as destination |
199 | so it must be a shitti packet */ | 196 | so it must be a shitti packet */ |
200 | pinfoptr->isvalid = 0; | 197 | pinfoptr->isvalid = 0; |
201 | return; | 198 | return; |
202 | } | 199 | } |
203 | if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) | 200 | if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) |
204 | { | 201 | { |
205 | /* Only one of both are possible, so must be | 202 | /* Only one of both are possible, so must be |
206 | a noise packet, if this comes up */ | 203 | a noise packet, if this comes up */ |
207 | pinfoptr->isvalid = 0; | 204 | pinfoptr->isvalid = 0; |
208 | return; | 205 | return; |
209 | } | 206 | } |
210 | if (pinfoptr->channel < 1 || pinfoptr->channel > 14) | 207 | if (pinfoptr->channel < 1 || pinfoptr->channel > 14) |
211 | { | 208 | { |
212 | /* Only channels between 1 and 14 are possible | 209 | /* Only channels between 1 and 14 are possible |
213 | others must be noise packets */ | 210 | others must be noise packets */ |
214 | pinfoptr->isvalid = 0; | 211 | pinfoptr->isvalid = 0; |
215 | return; | 212 | return; |
216 | } | 213 | } |
217 | 214 | ||
218 | /* Decoding successfull of beacon frame */ | 215 | /* Here should be the infos to the gui issued */ |
219 | if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) | 216 | if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) |
220 | { | 217 | { |
221 | printf ("\nHave found an accesspoint:"); | 218 | printf ("\nHave found an accesspoint:"); |
222 | } | 219 | } |
223 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 1) | 220 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 1) |
224 | { | 221 | { |
225 | printf ("\nHave found an AD-HOC station:"); | 222 | printf ("\nHave found an AD-HOC station:"); |
226 | 223 | ||
227 | } | 224 | } |
228 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) | 225 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) |
229 | { | 226 | { |
230 | printf ("\n\tOn a non-broadcasting network"); | 227 | printf ("\n\tOn a non-broadcasting network"); |
231 | } | 228 | } |
232 | else | 229 | else |
233 | { | 230 | { |
234 | printf ("\n\tOn network : %s",pinfoptr->ssid); | 231 | printf ("\n\tOn network : %s",pinfoptr->ssid); |
235 | } | 232 | } |
236 | printf ("\n\tLen SSID : %d",pinfoptr->ssid_len); | 233 | printf ("\n\tLen SSID : %d",pinfoptr->ssid_len); |
237 | printf ("\n\tOn Channel : %d",pinfoptr->channel); | 234 | printf ("\n\tOn Channel : %d",pinfoptr->channel); |
238 | printf ("\n\tEncryption : %s", pinfoptr->cap_WEP ? "ON" : "OFF"); | 235 | printf ("\n\tEncryption : %s", pinfoptr->cap_WEP ? "ON" : "OFF"); |
239 | printf ("\n\tMacaddress : %s",pinfoptr->sndhwaddr); | 236 | printf ("\n\tMacaddress : %s",pinfoptr->sndhwaddr); |
240 | printf ("\n\tBssid : %s",pinfoptr->bssid); | 237 | printf ("\n\tBssid : %s",pinfoptr->bssid); |
241 | printf ("\n\tDest : %s\n",pinfoptr->desthwaddr); | 238 | printf ("\n\tDest : %s\n",pinfoptr->desthwaddr); |
242 | } | 239 | } |
243 | break; | 240 | break; |
244 | default: | 241 | default: |
245 | printf("Unknown IEEE802.11 frame subtype (%d)",FC_SUBTYPE(fc)); | 242 | printf("Unknown IEEE802.11 frame subtype (%d)",FC_SUBTYPE(fc)); |
246 | break; | 243 | break; |
247 | } /* End of switch over different mgt frame types */ | 244 | } /* End of switch over different mgt frame types */ |
248 | 245 | ||
249 | break; | 246 | break; |
250 | case T_CTRL: | 247 | case T_CTRL: |
251 | //decode_control_frames(fc, packet); | 248 | //decode_control_frames(fc, packet); |
252 | printf ("Its a control frame"); | 249 | printf ("Its a control frame"); |
253 | break; | 250 | break; |
254 | case T_DATA: | 251 | case T_DATA: |
255 | //decode_data_frames(fc, packet); | 252 | //decode_data_frames(fc, packet); |
256 | printf ("Its a date frame"); | 253 | printf ("Its a date frame"); |
257 | break; | 254 | break; |
258 | default: | 255 | default: |
259 | printf("Unknown IEEE802.11 frame type (%d)",FC_TYPE(fc)); | 256 | printf("Unknown IEEE802.11 frame type (%d)",FC_TYPE(fc)); |
260 | break; | 257 | break; |
261 | } | 258 | } |
262 | } | 259 | } |
263 | 260 | ||
264 | 261 | ||
265 | /* This decodes the 802.11b frame header out of the 802.11b packet | 262 | /* This decodes the 802.11b frame header out of the 802.11b packet |
266 | all the infos is placed into the packetinfo structure */ | 263 | all the infos is placed into the packetinfo structure */ |
267 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) | 264 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) |
268 | { | 265 | { |
269 | char * ret; | 266 | char * ret; |
270 | char testme[16]; | 267 | char testme[16]; |
271 | const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; | 268 | const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; |
272 | ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); | 269 | ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); |
273 | 270 | ||
274 | /* Get the sender, bssid and dest mac address */ | 271 | /* Get the sender, bssid and dest mac address */ |
275 | etheraddr_string(mgthdr->bssid,ppinfo->bssid); | 272 | etheraddr_string(mgthdr->bssid,ppinfo->bssid); |
276 | etheraddr_string(mgthdr->da,ppinfo->desthwaddr); | 273 | etheraddr_string(mgthdr->da,ppinfo->desthwaddr); |
277 | etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); | 274 | etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); |
278 | ppinfo->fc_wep = FC_WEP(mgthdr->fc); | 275 | ppinfo->fc_wep = FC_WEP(mgthdr->fc); |
279 | return(0); | 276 | return(0); |
280 | } | 277 | } |
281 | 278 | ||
282 | 279 | ||
283 | void etheraddr_string(register const u_char *ep,char * text) | 280 | void etheraddr_string(register const u_char *ep,char * text) |
284 | { | 281 | { |
285 | static char hex[] = "0123456789abcdef"; | 282 | static char hex[] = "0123456789abcdef"; |
286 | register u_int i, j; | 283 | register u_int i, j; |
287 | register char *cp; | 284 | register char *cp; |
288 | char buf[sizeof("00:00:00:00:00:00")]; | 285 | char buf[sizeof("00:00:00:00:00:00")]; |
289 | cp = buf; | 286 | cp = buf; |
290 | if ((j = *ep >> 4) != 0) | 287 | if ((j = *ep >> 4) != 0) |
291 | *cp++ = hex[j]; | 288 | *cp++ = hex[j]; |
292 | *cp++ = hex[*ep++ & 0xf]; | 289 | *cp++ = hex[*ep++ & 0xf]; |
293 | for (i = 5; (int)--i >= 0;) { | 290 | for (i = 5; (int)--i >= 0;) { |
294 | *cp++ = ':'; | 291 | *cp++ = ':'; |
295 | if ((j = *ep >> 4) != 0) | 292 | if ((j = *ep >> 4) != 0) |
296 | *cp++ = hex[j]; | 293 | *cp++ = hex[j]; |
297 | *cp++ = hex[*ep++ & 0xf]; | 294 | *cp++ = hex[*ep++ & 0xf]; |
298 | } | 295 | } |
299 | *cp = '\0'; | 296 | *cp = '\0'; |
300 | strcpy(text,buf); | 297 | strcpy(text,buf); |
301 | return; | 298 | return; |
302 | } | 299 | } |
303 | 300 | ||
304 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | 301 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) |
305 | { | 302 | { |
306 | struct mgmt_body_t pbody; | 303 | struct mgmt_body_t pbody; |
307 | int offset = 0; | 304 | int offset = 0; |
308 | 305 | ||
309 | /* Get the static informations out of the packet */ | 306 | /* Get the static informations out of the packet */ |
310 | memset(&pbody, 0, sizeof(pbody)); | 307 | memset(&pbody, 0, sizeof(pbody)); |
311 | memcpy(&pbody.timestamp, p, 8); | 308 | memcpy(&pbody.timestamp, p, 8); |
312 | offset += 8; | 309 | offset += 8; |
313 | pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); | 310 | pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); |
314 | offset += 2; | 311 | offset += 2; |
315 | pbody.capability_info = EXTRACT_LE_16BITS(p+offset); | 312 | pbody.capability_info = EXTRACT_LE_16BITS(p+offset); |
316 | offset += 2; | 313 | offset += 2; |
317 | 314 | ||
318 | /* Gets the different flags out of the capabilities */ | 315 | /* Gets the different flags out of the capabilities */ |
319 | ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); | 316 | ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); |
320 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); | 317 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); |
321 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); | 318 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); |
322 | 319 | ||
323 | /* Gets the tagged elements out of the packets */ | 320 | /* Gets the tagged elements out of the packets */ |
324 | while (offset + 1 < ppinfo->pktlen) | 321 | while (offset + 1 < ppinfo->pktlen) |
325 | { | 322 | { |
326 | switch (*(p + offset)) | 323 | switch (*(p + offset)) |
327 | { | 324 | { |
328 | case E_SSID: | 325 | case E_SSID: |
329 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; | 326 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; |
330 | if (pbody.ssid.length > 0) | 327 | if (pbody.ssid.length > 0) |
331 | { | 328 | { |
332 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; | 329 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; |
333 | pbody.ssid.ssid[pbody.ssid.length]='\0'; | 330 | pbody.ssid.ssid[pbody.ssid.length]='\0'; |
334 | if (strcmp(pbody.ssid.ssid,"")==0) | 331 | if (strcmp(pbody.ssid.ssid,"")==0) |
335 | { | 332 | { |
336 | ppinfo->ssid = NONBROADCASTING; | 333 | ppinfo->ssid = NONBROADCASTING; |
337 | } | 334 | } |
338 | else | 335 | else |
339 | { | 336 | { |
340 | ppinfo->ssid = pbody.ssid.ssid; | 337 | ppinfo->ssid = pbody.ssid.ssid; |
341 | } | 338 | } |
342 | ppinfo->ssid_len = pbody.ssid.length; | 339 | ppinfo->ssid_len = pbody.ssid.length; |
343 | } | 340 | } |
344 | break; | 341 | break; |
345 | case E_CHALLENGE: | 342 | case E_CHALLENGE: |
346 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; | 343 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; |
347 | if (pbody.challenge.length > 0) | 344 | if (pbody.challenge.length > 0) |
348 | { | 345 | { |
349 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; | 346 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; |
350 | pbody.challenge.text[pbody.challenge.length]='\0'; | 347 | pbody.challenge.text[pbody.challenge.length]='\0'; |
351 | } | 348 | } |
352 | break; | 349 | break; |
353 | case E_RATES: | 350 | case E_RATES: |
354 | memcpy(&(pbody.rates),p+offset,2); offset += 2; | 351 | memcpy(&(pbody.rates),p+offset,2); offset += 2; |
355 | if (pbody.rates.length > 0) { | 352 | if (pbody.rates.length > 0) { |
356 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; | 353 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; |
357 | } | 354 | } |
358 | break; | 355 | break; |
359 | case E_DS: | 356 | case E_DS: |
360 | memcpy(&(pbody.ds),p+offset,3); offset +=3; | 357 | memcpy(&(pbody.ds),p+offset,3); offset +=3; |
361 | ppinfo->channel = pbody.ds.channel; | 358 | ppinfo->channel = pbody.ds.channel; |
362 | break; | 359 | break; |
363 | case E_CF: | 360 | case E_CF: |
364 | memcpy(&(pbody.cf),p+offset,8); offset +=8; | 361 | memcpy(&(pbody.cf),p+offset,8); offset +=8; |
365 | break; | 362 | break; |
366 | case E_TIM: | 363 | case E_TIM: |
367 | memcpy(&(pbody.tim),p+offset,2); offset +=2; | 364 | memcpy(&(pbody.tim),p+offset,2); offset +=2; |
368 | memcpy(&(pbody.tim.count),p+offset,3); offset +=3; | 365 | memcpy(&(pbody.tim.count),p+offset,3); offset +=3; |
369 | if ((pbody.tim.length -3) > 0) | 366 | if ((pbody.tim.length -3) > 0) |
370 | { | 367 | { |
371 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); | 368 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); |
372 | offset += pbody.tim.length -3; | 369 | offset += pbody.tim.length -3; |
373 | } | 370 | } |
374 | break; | 371 | break; |
375 | default: | 372 | default: |
376 | #if 0 | 373 | #if 0 |
377 | printf("(1) unhandled element_id (%d) ", *(p+offset) ); | 374 | printf("(1) unhandled element_id (%d) ", *(p+offset) ); |
378 | #endif | 375 | #endif |
379 | offset+= *(p+offset+1) + 2; | 376 | offset+= *(p+offset+1) + 2; |
380 | break; | 377 | break; |
381 | } /* end of switch*/ | 378 | } /* end of switch*/ |
382 | } /* end of for loop */ | 379 | } /* end of for loop */ |
383 | return(0); | 380 | return(0); |
384 | 381 | ||
385 | 382 | ||
386 | 383 | ||
387 | 384 | ||
388 | } /* End of handle_beacon */ | 385 | } /* End of handle_beacon */ |
389 | 386 | ||
390 | 387 | ||
391 | static int GetHeaderLength(u_int16_t fc) | 388 | static int GetHeaderLength(u_int16_t fc) |
392 | { | 389 | { |
393 | int iLength=0; | 390 | int iLength=0; |
394 | 391 | ||
395 | switch (FC_TYPE(fc)) { | 392 | switch (FC_TYPE(fc)) { |
396 | case T_MGMT: | 393 | case T_MGMT: |
397 | iLength = MGMT_HEADER_LEN; | 394 | iLength = MGMT_HEADER_LEN; |
398 | break; | 395 | break; |
399 | case T_CTRL: | 396 | case T_CTRL: |
400 | switch (FC_SUBTYPE(fc)) { | 397 | switch (FC_SUBTYPE(fc)) { |
401 | case CTRL_PS_POLL: | 398 | case CTRL_PS_POLL: |
402 | iLength = CTRL_PS_POLL_LEN; | 399 | iLength = CTRL_PS_POLL_LEN; |
403 | break; | 400 | break; |
404 | case CTRL_RTS: | 401 | case CTRL_RTS: |
405 | iLength = CTRL_RTS_LEN; | 402 | iLength = CTRL_RTS_LEN; |
406 | break; | 403 | break; |
407 | case CTRL_CTS: | 404 | case CTRL_CTS: |
408 | iLength = CTRL_CTS_LEN; | 405 | iLength = CTRL_CTS_LEN; |
409 | break; | 406 | break; |
410 | case CTRL_ACK: | 407 | case CTRL_ACK: |
411 | iLength = CTRL_ACK_LEN; | 408 | iLength = CTRL_ACK_LEN; |
412 | break; | 409 | break; |
413 | case CTRL_CF_END: | 410 | case CTRL_CF_END: |
414 | iLength = CTRL_END_LEN; | 411 | iLength = CTRL_END_LEN; |
415 | break; | 412 | break; |
416 | case CTRL_END_ACK: | 413 | case CTRL_END_ACK: |
417 | iLength = CTRL_END_ACK_LEN; | 414 | iLength = CTRL_END_ACK_LEN; |
418 | break; | 415 | break; |
419 | default: | 416 | default: |
420 | iLength = 0; | 417 | iLength = 0; |
421 | break; | 418 | break; |
422 | } | 419 | } |
423 | break; | 420 | break; |
424 | case T_DATA: | 421 | case T_DATA: |
425 | if (FC_TO_DS(fc) && FC_FROM_DS(fc)) | 422 | if (FC_TO_DS(fc) && FC_FROM_DS(fc)) |
426 | iLength = 30; | 423 | iLength = 30; |
427 | else | 424 | else |
428 | iLength = 24; | 425 | iLength = 24; |
429 | break; | 426 | break; |
430 | default: | 427 | default: |
431 | printf("unknown IEEE802.11 frame type (%d)", | 428 | printf("unknown IEEE802.11 frame type (%d)", |
432 | FC_TYPE(fc)); | 429 | FC_TYPE(fc)); |
433 | break; | 430 | break; |
434 | } | 431 | } |
435 | 432 | ||
436 | return iLength; | 433 | return iLength; |
437 | } | 434 | } |