2 * hdw-sniff, sniffer using pcap lib
4 * author: hackbard@hackdaworld.dyndns.org
10 /* IEEE 802.3 stuff -- i will concentrate on .11 stuff before! */
11 #include <netinet/if_ether.h>
13 /* IEEE 802.11 stuff -- will become one include later ... */
14 #include "ieee80211.h" /* from hunz's aeolus, short hostap_wlan.h */
15 #include "ieee802_11.h" /* from pcmcia-cs */
17 #include "hdw-sniff.h" /* my functions */
19 int main(int argc, char *argv[]) {
22 char pcap_error[PCAP_ERRBUF_SIZE];
24 const u_char *package;
25 struct pcap_pkthdr pcap_header;
27 struct ieee802_11_hdr *w_hdr;
29 /* parse the arguments */
31 printf("usage: %s <interface> <logfile>\n",argv[0]);
35 printf("no logfile specified, writing to stdout ...\n");
38 /* start pcap session */
39 pcap_handle=pcap_open_live(argv[1],BUFSIZ,1,-1,pcap_error);
40 if(pcap_handle==NULL) {
41 printf("%s: %s\n",argv[0],pcap_error);
45 /* grab a package until user breaks */
49 printf("----| new package |----| hdw - sniff |----\n");
50 if((package=pcap_next(pcap_handle,&pcap_header))!=NULL) {
51 printf("package received at: %s",
52 ctime((const time_t*)&pcap_header.ts.tv_sec));
53 printf("pcap header: ");
54 printf("capture length=%d ",pcap_header.caplen);
55 printf("length(off wire)=%d\n",pcap_header.len);
58 /* 802.11 or 802.3 -- not quite sure about 'D' & '\0' */
60 printf("ieee802.11: ");
62 else if(*package=='\0') {
64 /* reading ethernet header */
65 e_hdr=(struct ethhdr *)package;
74 printf("dest_addr = ");
75 for(i=0;i<ETH_ALEN;i++)
76 printf("%x%s",*(e_hdr->h_dest+i),((i==ETH_ALEN-1)?" ":":"));
77 printf(" src_addr = ");
78 for(i=0;i<ETH_ALEN;i++)
79 printf("%x%s",*(e_hdr->h_source+i),((i==ETH_ALEN-1)?"\n":":"));
81 for(i=sizeof(struct ethhdr);i<pcap_header.caplen;i++)
82 printf("%x ",*(package+i));
87 /* print the whole package in hex */
88 for(i=0;i<=pcap_header.caplen;i++) printf("%x ",*(package+i));
90 printf("%c <- identifier for unknown!\n",*package);
93 printf("just beacon frames, ha? - wake up early! :)");