X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fhdw-sniff.git;a=blobdiff_plain;f=main.c;h=2c5a41f7e437928566cd4a02b10878b235084f46;hp=9e8258fe74c48b69481f68c03d981a673660e205;hb=c9575c4e105d074120e573587cbf7e7de9a0b5ab;hpb=728bc5f9cd9f3ded02efba8352fffef843095ee2 diff --git a/main.c b/main.c index 9e8258f..2c5a41f 100644 --- a/main.c +++ b/main.c @@ -1,62 +1,145 @@ /* * main.c - main hdw-sniff * - * author: hackbard@hackdaworld.dyndns.org + * Copyright (C) 2004/05 hackbard@hackdaworld.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 display_console(t_info *info,char *string) { + + int x,y; + t_display *display; + + display=(t_display *)&(info->display); + + x=display->max_x-1; + y=display->max_y-1; + + display_line(display,0,0,2,0,'-'); + display_string(display,4,0,"essid",5); + display_line(display,10,0,x,0,'-'); + + //display_line(display,0,0,0,y,'|'); + //display_line(display,x,0,x,y,'|'); + + display_line(display,0,y-1,x,y-1,'-'); + + display_draw(display); + + 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 noop(t_input *input,void *ptr) { + + return 23; +} + +int get_user_interaction(t_info *info) { + + char *string; + + string=(char *)malloc(info->display.max_x*sizeof(char)); + + input_get_event(&(info->input),noop,info); + + /* + if(info->input.content[0]=='h') { + display_console(info,"hdw-sniff help:"); + display_console(info,"h - print this help"); + display_console(info,"x - enable/disable hex output"); + display_console(info,"a - enable/disable ascii output"); + display_console(info,"q - quit"); + display_console(info,"console navigation: arrow up/down"); + display_console(info,"network list navigation: page up/down"); + } + */ + + if(info->input.content[0]=='x') { + info->mode^=MODE_HEXOUT; + display_console(info,"toggled hex output"); + } + + else if(info->input.content[0]=='a') { + info->mode^=MODE_ASCIIOUT; + display_console(info,"toggled ascii output"); + } + + else if(info->input.content[0]=='q') { + event_stop(&(info->event)); + display_console(info,"quit!"); + } + + else { + snprintf(string,info->display.max_x,"unknown event (%x)", + info->input.content[0]); + display_console(info,string); + } + + return 23; } -int main(int argc, char **argv) -{ - /* local variables */ - char pcap_error[PCAP_ERRBUF_SIZE]; - char sys_call[SYSCALL_MAX]; +int react_on_event(t_event *event,void *ptr) { + + t_info *info; + + info=(t_info *)ptr; + + if(event_check(event,0)==E_FD_YES) get_user_interaction(info); + else pcap_dispatch(info->pcap_handle,-1,parse_package,(u_char *)ptr); + + 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(""); + + return 23; +} + +int hop_channel(t_event *event,void *ptr) { - int pcap_fd,channel_hop_fd;; - int i; + struct iwreq iwreq; + t_info *info; - fd_set pcap_fd_set; - struct timeval pcap_fd_set_tv; + info=(t_info *)ptr; - struct info_struct info; + 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 main(int argc, char **argv) { + t_info info; + int pcap_fd; + int logfd; + 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 */ + info.channel_hop_fd=socket(AF_INET,SOCK_DGRAM,0); + + display_init(&(info.display),logfd); + + input_init(&(info.input),logfd); + //input.mode=CONTENT_BUFFER; + input_ios_init(&info.input); + + event_init(&(info.event),logfd); + event_set_timeout(&(info.event),HOP_SEC,HOP_USEC); + + event_math(0,&(info.event),READ,ADD); + event_math(pcap_fd,&(info.event),READ,ADD); + + display_console(&info,"foo"); + + event_start(&(info.event),&info,react_on_event,hop_channel); + + input_shutdown(&(info.input)); + display_shutdown(&(info.display)); - /* 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; - - /* parse packages until user breaks */ - while(!(info.caps&CAP_QUIT_MASK)) - { - 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); - } + puts(""); + puts(""); + puts("thanks for using hdw-sniff (C) 2004/05 hackbard"); + puts(""); + puts("bugreports: hackbard@hackdaworld.org"); - puts("bugreports: hackbard@hackdaworld.dyndns.org"); return 23; + }