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 #define MAX_PACKAGES 3
21 int main(int argc, char *argv[]) {
24 char pcap_error[PCAP_ERRBUF_SIZE];
26 const u_char *package;
27 struct pcap_pkthdr pcap_header;
29 struct ieee802_11_hdr *w_hdr;
31 /* parse the arguments */
33 printf("usage: %s <interface> <logfile>\n",argv[0]);
37 printf("no logfile specified, writing to stdout ...\n");
40 /* start pcap session */
41 pcap_handle=pcap_open_live(argv[1],BUFSIZ,1,-1,pcap_error);
42 if(pcap_handle==NULL) {
43 printf("%s: %s\n",argv[0],pcap_error);
47 /* grab a package until user breaks */
49 while (count<MAX_PACKAGES) {
52 if((package=pcap_next(pcap_handle,&pcap_header))!=NULL) {
53 printf("---> package %d ---- %s",count,
54 ctime((const time_t*)&pcap_header.ts.tv_sec));
55 printf("pcap header: ");
56 printf("capture length=%d ",pcap_header.caplen);
57 printf("length(off wire)=%d\n",pcap_header.len);
60 /* is ieee802.11 ? -- we assume yes :) */
64 e_hdr=(struct ethhdr *)package;
67 printf("%x ",ntohs(e_hdr->h_proto));
68 printf("dest_addr = ");
69 for(i=0;i<ETH_ALEN;i++)
70 printf("%x%s",*(e_hdr->h_dest+i),((i==ETH_ALEN-1)?" ":":"));
71 printf(" src_addr = ");
72 for(i=0;i<ETH_ALEN;i++)
73 printf("%x%s",*(e_hdr->h_source+i),((i==ETH_ALEN-1)?"\n":":"));
74 if(ntohs(e_hdr->h_proto)==ETH_P_IP) {
75 printf("ip protocol: ");
79 for(i=sizeof(struct ethhdr);i<pcap_header.caplen;i++)
80 printf("%x ",*(package+i));
84 printf("just beacon frames, ha? - wake up early! :)\n");