int display_console(t_info *info,char *string) {
- int x,y;
+ int x,y,size,count,cnt,i,s;
t_display *display;
+ t_sta *sta;
+ char help[32];
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,'-');
+ size=strlen(string);
+
+ if(info->view==VIEW_ALL) {
+ count=list_count(&(info->sniffed_sta));
+ cnt=((count>y-5)?y-5:count);
+
+ display_line(display,0,0,x,0,'-');
+ display_string(display,GUI_OFFSET_STA,1,"sta/ap",6);
+ display_string(display,GUI_OFFSET_SSID,1,"| ssid",6);
+ display_string(display,GUI_OFFSET_AP,1,"| ap",4);
+ display_string(display,GUI_OFFSET_WEP,1,"| wep",5);
+ display_string(display,GUI_OFFSET_MGMT,1,"| mgmt",6);
+ display_string(display,GUI_OFFSET_CTRL,1,"| ctrl",6);
+ display_string(display,GUI_OFFSET_DATA,1,"| data",6);
+ display_string(display,GUI_OFFSET_ACTIVE,1,"| act",5);
+ display_line(display,0,2,x,2,'-');
+
+ list_reset(&(info->sniffed_sta));
+
+ for(i=0;i<cnt;i++) {
+ sta=(t_sta *)info->sniffed_sta.current->data;
+ snprintf(help,32,"%02x:%02x:%02x:%02x:%02x:%02x",
+ sta->addr[0],sta->addr[1],sta->addr[2],
+ sta->addr[3],sta->addr[4],sta->addr[5]);
+ display_string(display,GUI_OFFSET_STA,3+i,help,17);
+ s=strlen(sta->ssid);
+ s=((s>=16)?16:s);
+ help[0]='|'; help[1]=' ';
+ memcpy(&help[2],sta->ssid,s);
+ display_string(display,GUI_OFFSET_SSID,3+i,help,s+2);
+ snprintf(help,4,"| %c",sta->ap?'y':'n');
+ display_string(display,GUI_OFFSET_AP,3+i,help,3);
+ snprintf(help,5,"| %c",sta->wep?'y':'n');
+ display_string(display,GUI_OFFSET_WEP,3+i,help,4);
+/*
+ snprintf(help,21,"| %04d | %04d | %04d",
+ sta->count_mgmt,sta->count_ctrl,
+ sta->count_data);
+*/
+ snprintf(help,21,"| %04d | n.a. | n.a.",
+ sta->count_mgmt);
+ display_string(display,GUI_OFFSET_MGMT,3+i,help,20);
+ snprintf(help,5,"| %c",sta->active);
+ display_string(display,GUI_OFFSET_ACTIVE,3+i,help,4);
+ list_next(&(info->sniffed_sta));
+ }
+ }
+
+ else if(info->view==VIEW_SINGLE) {
+ list_reset(&(info->sniffed_sta));
+ for(i=0;i<info->c_line;i++) list_next(&(info->sniffed_sta));
+ sta=(t_sta *)info->sniffed_sta.current->data;
+ display_line(display,0,0,x,0,'-');
+ snprintf(help,22,"sta %02x:%02x:%02x:%02x:%02x:%02x",
+ sta->addr[0],sta->addr[1],sta->addr[2],
+ sta->addr[3],sta->addr[4],sta->addr[5]);
+ display_string(display,1,1,help,21);
+ display_line(display,0,2,x,2,'-');
+ display_string(display,1,3,info->clean_line,x);
+ display_string(display,1,3,"ssid: ",6);
+ s=strlen(sta->ssid);
+ memcpy(help,sta->ssid,s);
+ display_string(display,7,3,help,s);
+ display_string(display,1,5,"more specific info soon ...",27);
+ }
+
+ /* footer */
+ display_line(display,0,y-3,x,y-3,'-');
- //display_line(display,0,0,0,y,'|');
- //display_line(display,x,0,x,y,'|');
+ snprintf(help,14,"total: %06d",info->count);
+ display_string(display,1,y-2,help,13);
+ snprintf(help,13,"mgmt: %06d",info->count_m);
+ display_string(display,15,y-2,help,12);
+ snprintf(help,12,"ctrl: %06d",info->count_c);
+ display_string(display,28,y-2,help,11);
+ snprintf(help,13,"data: %06d",info->count_d);
+ display_string(display,40,y-2,help,12);
display_line(display,0,y-1,x,y-1,'-');
+ if(size!=0) {
+ display_string(display,0,y,info->clean_line,x);
+ display_string(display,1,y,string,size);
+ }
+
display_draw(display);
+ if(info->view==VIEW_ALL)
+ display_set_cursor(display,0,3+info->c_line);
+
+
return 23;
}
int get_user_interaction(t_info *info) {
char *string;
+ int hlp=0;
string=(char *)malloc(info->display.max_x*sizeof(char));
event_stop(&(info->event));
display_console(info,"quit!");
}
-
+ else if(info->input.content[0]=='n') {
+ hlp=list_count(&(info->sniffed_sta));
+ if(info->c_line<hlp-1) info->c_line++;
+ }
+ else if(info->input.content[0]=='p') {
+ if(info->c_line>0) info->c_line--;
+ }
+ else if(info->input.content[0]==0x0d) {
+ display_clear_screen(&(info->display));
+ if(info->view==VIEW_ALL) info->view=VIEW_SINGLE;
+ else info->view=VIEW_ALL;
+ }
else {
snprintf(string,info->display.max_x,"unknown event (%x)",
info->input.content[0]);
info=(t_info *)ptr;
- if(info->current_channel>=CHANNEL_MAX) info->current_channel=1;
+ if((info->current_channel>CHANNEL_MAX)|(info->current_channel==0))
+ info->current_channel=1;
memset(&iwreq,0,sizeof(iwreq));
strcpy(iwreq.ifr_name,info->device);
iwreq.u.freq.e=0;
perror("ioctl");
return -23;
}
- ++(info->current_channel);
- 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(t_info));
-
+
/* parse arguments */
- for(i=1;i<argc;i++)
- {
- if(argv[i][0]=='-')
- {
- switch(argv[i][1])
- {
+ for(i=1;i<argc;i++) {
+ if(argv[i][0]=='-') {
+ switch(argv[i][1]) {
case 'h':
usage();
case 'm':
++i;
break;
case 'l':
- if((info.log_fd=open(argv[i+1],O_RDWR|O_CREAT))!=0)
+ if((info.log_fd=open(argv[i+1],O_RDWR|O_CREAT|O_APPEND))!=0)
printf("logfile -> %s\n",argv[i+1]);
else
puts("warning: can't write to logfile.");
system(sys_call);
if(info.log_fd==0) {
- if((info.log_fd=open("/tmp/hdw-sniff.log",O_RDWR|O_CREAT))!=0)
- puts("using logfile /tmp/hdw-sniff.log ...");
- else {
- puts("failed to open logfile ...");
- return -23;
+ if((info.log_fd=open("/tmp/hdw-sniff.log",O_RDWR|O_CREAT|O_APPEND))!=0)
+ puts("using logfile /tmp/hdw-sniff.log ...");
+ else {
+ puts("failed to open logfile ...");
+ return -23;
+ }
}
/* pcap */
info.channel_hop_fd=socket(AF_INET,SOCK_DGRAM,0);
display_init(&(info.display),info.log_fd);
+ if(info.display.max_x<HDW_SNIFF_MAX_WIDTH) {
+ display_shutdown(&(info.display));
+ puts("");
+ puts("");
+ puts("fatal! please increase your terminals width");
+ puts("");
+ return -23;
+ }
+ if(info.display.max_y<HDW_SNIFF_MAX_HEIGHT) {
+ display_shutdown(&(info.display));
+ puts("");
+ puts("");
+ puts("fatal! please increase your terminals width");
+ puts("");
+ return -23;
+ }
+ info.clean_line=(char *)malloc(info.display.max_x);
+ memset(info.clean_line,0x20,info.display.max_x);
+ info.view=VIEW_ALL;
+
+ display_console(&info,
+ "Welcome to hdw-sniff, Copyright (C) 2004/05 hackbard");
+ sleep(2);
input_init(&(info.input),info.log_fd);
- //input.mode=CONTENT_BUFFER;
input_ios_init(&info.input);
+ list_init(&(info.sniffed_sta),info.log_fd);
+
event_init(&(info.event),info.log_fd);
event_set_timeout(&(info.event),HOP_SEC,HOP_USEC);
event_math(0,&(info.event),READ,ADD);
event_math(pcap_fd,&(info.event),READ,ADD);
- list_init(&(info.sniffed_sta),info.log_fd);
-
- display_console(&info,"foo");
-
event_start(&(info.event),&info,react_on_event,hop_channel);
+ list_shutdown(&(info.sniffed_sta));
input_shutdown(&(info.input));
display_shutdown(&(info.display));
puts("bugreports: hackbard@hackdaworld.org");
return 23;
-
}