X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=main.c;h=a0f557584e3a5ff19da5b02d5f67bd9dae20c95d;hb=ce967f4d1e3dc10cda58062bc21aaf264e1a0f81;hp=2926a7623e08586b1563dbf1515401fe1c7aab6d;hpb=1bc659fa450df2108ab59b085e75564b7ac19995;p=my-code%2Fhdw-sniff.git diff --git a/main.c b/main.c index 2926a76..a0f5575 100644 --- a/main.c +++ b/main.c @@ -1,62 +1,79 @@ /* * main.c - main hdw-sniff * - * author: hackbard@hackdaworld.dyndns.org + * Copyright (C) 2004 hackbard@hackdaworld.dyndns.org * */ -#include #include "main.h" +void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,const unsigned char *package); + /* functions */ -int usage(void) -{ - puts("usage: hdw-sniff "); - puts("\toptions:\t-m \t1 monitoring, 2 managed"); - puts("\t\t-d \twlan0,eth0"); - puts("\t\t-l "); - puts("\t\t-h \tdisplay this help message"); - return -23; + +int get_user_event(t_info *info) { + char event; + if(read(0,&event,1)!=1) { + perror("reading user interaction failed"); + return -23; + } + printf("user event: %c ",event); + if(event=='h') { + info->mode^=MODE_HEXOUT; + printf("- hex output: %c\n",info->mode&MODE_HEXOUT?'a':'n'); + } + if(event=='a') { + info->mode^=MODE_ASCIIOUT; + printf("- ascii output: %c\n",info->mode&MODE_ASCIIOUT?'a':'n'); + } + if(event=='q') { + info->mode|=MODE_QUIT; + printf("- shutting down!\n"); + } + + return 23; } -int hop_channel(info_struct *info) -{ - struct iwreq iwreq; - if(info->current_channel>=CHANNEL_MAX) info->current_channel=1; - memset(&iwreq,0,sizeof(iwreq)); - strcpy(iwreq.ifr_name,info->device); - iwreq.u.freq.e=0; - iwreq.u.freq.m=info->current_channel; - if(ioctl(info->channel_hop_fd,SIOCSIWFREQ,&iwreq)<0) - { - puts("unable to hop channel"); - perror("ioctl"); - return -23; - } - ++(info->current_channel; - return 23; +int usage(void) { + puts("usage: hdw-sniff "); + puts("\toptions:"); + puts("\t\t-m \tmonitor and/or wlanng"); + puts("\t\t-d \twlan0,eth0"); + puts("\t\t-l "); + puts("\t\t-k \t(string)"); + puts("\t\t-h \tdisplay this help message"); + puts(""); } -int main(int argc, char **argv) -{ - /* local variables */ - char pcap_error[PCAP_ERRBUF_SIZE]; - char sys_call[SYSCALL_MAX]; +int hop_channel(t_info *info) { - int pcap_fd,channel_hop_fd;; - int i; + struct iwreq iwreq; - fd_set pcap_fd_set; - struct timeval pcap_fd_set_tv; + if(info->current_channel>=CHANNEL_MAX) info->current_channel=1; + memset(&iwreq,0,sizeof(iwreq)); + strcpy(iwreq.ifr_name,info->device); + iwreq.u.freq.e=0; + iwreq.u.freq.m=info->current_channel; + if(ioctl(info->channel_hop_fd,SIOCSIWFREQ,&iwreq)<0) { + puts("unable to hop channel"); + perror("ioctl"); + return -23; + } + ++(info->current_channel); + return 23; +} - struct info_struct info; +int main(int argc, char **argv) { + t_info info; + int pcap_fd; + fd_set fds; + struct timeval hop_f; + int i; + char sys_call[MAX_SYSCALL_CHARS]; + char pcap_error[PCAP_ERRBUF_SIZE]; - memset(&info,0,sizeof(struct info_struct)); - /* default values */ - info.caps=0; - info.logfile_fd=0; - info.quit=0; + memset(&info,0,sizeof(t_info)); /* parse arguments */ for(i=1;i non blocking? */ - info.channel_hop_fd=socket(AF_INET,SOCK_DGRAM,0); /* socket fd for channel hopping */ - - /* watch pcap_fd for reading */ - FD_ZERO(&pcap_fd); - FD_SET(pcap_fd,&pcap_fd_set); - fd_set_tv.tv_sec=PCAP_SELECT_SEC; - pcap_fd_set_tv.tv_usec=PCAP_SELECT_USEC; + info.channel_hop_fd=socket(AF_INET,SOCK_DGRAM,0); /* parse packages until user breaks */ - while(!(info.caps&CAP_QUIT_MASK)) + while(!(info.mode&MODE_QUIT)) { - if(select(pcap_fd+1,&pcap_fd_set,NULL,NULL,&pcap_fd_set_tv)) - pcap_dispatch(pcap_handle,-1,parse_package,(unsigned char *)&info); - else - hop_channel(&info); + /* watch pcap_fd and stdin (reading) */ + FD_ZERO(&fds); + FD_SET(pcap_fd,&fds); + FD_SET(0,&fds); + hop_f.tv_sec=HOP_SEC; + hop_f.tv_usec=HOP_USEC; + + if(select(pcap_fd+1,&fds,NULL,NULL,&hop_f)) { + if(FD_ISSET(0,&fds)) + get_user_event(&info); + else if(FD_ISSET(pcap_fd,&fds)) + pcap_dispatch(info.pcap_handle,-1,parse_package,(unsigned char *)&info); + else + hop_channel(&info); + } } + puts(""); + puts(""); + puts("thanks for using hdw-sniff (C) 2005 hackbard"); + puts(""); puts("bugreports: hackbard@hackdaworld.dyndns.org"); + return 23; + }