647c1761751c895a7f56ba0c5c9eaf36b8d7f722
[my-code/hdw-sniff.git] / parse.c
1 /*
2  * parse.c - parsing of pcap packages
3  *
4  * author: hackbard@hackdaworld.dyndns.org
5  *
6  */
7
8 #include "parse.h"
9 #include "main.h"
10
11 /* all the parsing stuff will go here
12  *
13  * different protocols should get to seperated files though ...
14  */
15
16 void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,const unsigned char *package) {
17
18   t_info *info;
19   int i;
20   t_sta new_sta;
21   t_frame4_hdr *f4hdr;
22   t_frame3_hdr *f3hdr;
23   t_frame2_hdr *f2hdr;
24   t_frame1_hdr *f1hdr;
25   t_beacon_fb *beacon_fb;
26   int ret;
27
28   info=(t_info *)ptr;
29
30   info->count++;
31
32   memset(&new_sta,0,sizeof(t_sta));
33
34   if(info->dump_fd!=0) {
35     ret=write(info->dump_fd,pcap_header,sizeof(struct pcap_pkthdr));
36     if(ret!=sizeof(struct pcap_pkthdr))
37       display_console(info,"warning, pcap header write failed!");
38     ret=write(info->dump_fd,package,pcap_header->caplen);
39     if(ret!=pcap_header->caplen)
40       display_console(info,"warning, package write failed!");
41   }
42   
43   /* maybe there is offset to the actual ieee802.11 frame,
44      for example prism header ... */
45
46   if(FCTL_TYPE(package[0])==FCTL_TYPE_MGMT) {
47     info->count_m++;
48     if(FCTL_STYPE(package[0])==FCTL_STYPE_BEACON) {
49       f3hdr=(t_frame3_hdr *)package;
50       beacon_fb=(t_beacon_fb *)(package+sizeof(t_frame3_hdr));
51       // new_sta.
52       /* debug output */
53       dprintf(info->log_fd,"beacon: ");
54       for(i=0;i<ADDR_LEN;i++) dprintf(info->log_fd,"%02x ",*((f3hdr->addr2)+i));
55         dprintf(info->log_fd,"  essid: (len=%x) ",beacon_fb->ssid_length);
56       for(i=0;i<beacon_fb->ssid_length;i++)
57         dprintf(info->log_fd,"%c ",*(u8 *)(beacon_fb->ssid+i));
58       dprintf(info->log_fd,"\n");
59     }
60   }
61   else if(FCTL_TYPE(package[0])==FCTL_TYPE_CTRL) {
62     info->count_c++;
63   }
64   else if(FCTL_TYPE(package[0])==FCTL_TYPE_DATA) {
65     info->count_d++;
66   }
67
68   display_console(info,"");
69
70 }