From: hackbard Date: Tue, 12 Nov 2002 16:05:02 +0000 (+0000) Subject: fixed and cached offsets - 1st try X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fhdw-sniff.git;a=commitdiff_plain;h=0819f943f6d301332559b998e67b8fbf13975f15 fixed and cached offsets - 1st try --- diff --git a/hdw-sniff.c b/hdw-sniff.c index 54e40db..94830b7 100644 --- a/hdw-sniff.c +++ b/hdw-sniff.c @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) { FD_ZERO(&pcap_fd_set); FD_SET(pcap_fd,&pcap_fd_set); fd_set_tv.tv_sec=0; - fd_set_tv.tv_usec=500000; + fd_set_tv.tv_usec=200000; if((select(pcap_fd+1,&pcap_fd_set,NULL,NULL,&fd_set_tv)) && (FD_ISSET(pcap_fd,&pcap_fd_set))) pcap_dispatch(pcap_handle,-1,pcap_process,(u_char *)&my_info_struct); else if((hop_channel(&my_info_struct,foo_fd))==-1) { @@ -125,7 +125,13 @@ void pcap_process(u_char *info,const struct pcap_pkthdr *pcap_header, struct ethhdr *e_hdr; struct ip *ip_hdr; struct info_struct *my_info_struct; - int i; + int i,p_o,w_o,e_o,i_o; + + /* cache offsets */ + p_o=sizeof(struct linux_wlan_ng_prism_hdr); + w_o=sizeof(struct ieee802_11_hdr); + e_o=sizeof(struct ethhdr); + i_o=sizeof(struct ip); my_info_struct=(struct info_struct *)info; ++(my_info_struct->count); @@ -140,16 +146,17 @@ void pcap_process(u_char *info,const struct pcap_pkthdr *pcap_header, /* prism wlan ng headers */ if((my_info_struct->mmode-0x30==1) && (strncmp(my_info_struct->dev,"wlan",4)==0)) { - printf("prism header:\n"); + printf("prism header: (%d bytes)\n",p_o); prism_hdr=(struct linux_wlan_ng_prism_hdr *)package; printf("message code/length: %d/%d\n",ntohs(prism_hdr->msgcode), ntohs(prism_hdr->msglen)); printf("device: %s\n",prism_hdr->devname); + /* skip wlan_ng_prism header */ + // package=package+p_o; /* ieee802.11 header */ - printf("ieee802.11 header:\n"); - package+=sizeof(struct linux_wlan_ng_prism_hdr); - w_hdr=(struct ieee802_11_hdr *)package; + printf("ieee802.11 header: (%d bytes)\n",w_o); + w_hdr=(struct ieee802_11_hdr *)(package+p_o); printf("debug:\n"); for(i=0;i<16;i++) { @@ -163,13 +170,13 @@ void pcap_process(u_char *info,const struct pcap_pkthdr *pcap_header, "ok":"unknown"); // printf("type: /* skip ieee802.11 header */ - package=package+sizeof(struct ieee802_11_hdr); + // package=package+w_o; } /* ieee802.3 */ /* ethernet */ printf("ethernet:\n"); - e_hdr=(struct ethhdr *)package; + e_hdr=(struct ethhdr *)(package+p_o+w_o); /* what types ? */ printf("type = "); printf("%x ",ntohs(e_hdr->h_proto)); @@ -182,7 +189,7 @@ void pcap_process(u_char *info,const struct pcap_pkthdr *pcap_header, /* IP ? */ if(ntohs(e_hdr->h_proto)==ETH_P_IP) { printf("ip protocol: "); - ip_hdr=(struct ip *)(package+sizeof(struct ethhdr)); + ip_hdr=(struct ip *)(package+p_o+w_o+e_o); printf("version = %x ",ntohs(ip_hdr->ip_v)); printf("header_length = %x \n",ntohs(ip_hdr->ip_hl)); printf("service = %x ",ntohs(ip_hdr->ip_tos)); @@ -196,8 +203,8 @@ void pcap_process(u_char *info,const struct pcap_pkthdr *pcap_header, ntohs(ip_hdr->ip_p)); printf("chksum: %x\n",ntohs(ip_hdr->ip_sum)); } - printf("all_hex_dump:\n"); - for(i=sizeof(struct ethhdr);icaplen;i++) + printf("all ethernet dump:\n"); + for(i=p_o+w_o+e_o;icaplen;i++) printf("%x ",*(package+i)); printf("\n"); }