⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui_main.c

📁 * A ncurses user interface. * Network statistics to view the amount of packets and data in many
💻 C
字号:
/*  This file is part of sniffer, a packet capture utility and  network moniter  The author can be contacted at <mistral@stev.org>  the lastest version is avilable from   http://stev.org  This program is free software; you can redistribute it and/or modify  it under the terms of the GNU General Public License as published by  the Free Software Foundation; either version 2 of the License, or  (at your option) any later version.  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License for more details.  You should have received a copy of the GNU General Public License  along with this program; if not, write to the Free Software  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include <pthread.h>#include <unistd.h>#include <sys/time.h>#include <sys/types.h>#include <errno.h>#include <string.h>#include <ncurses.h>#include "config.h"#include "locks.h"#include "list.h"#include "log.h"#include "arp.h"#include "arp_gui.h"#include "if.h"#include "tcp.h"#include "udp.h"#include "icmp.h"#include "lookup_gui.h"#include "gui_main.h"pthread_mutex_t gui_mutex =  PTHREAD_MUTEX_INITIALIZER;int gui_ready = 0;struct gui_t *gui;struct gui_menu_t gui_menu_main[] = {	{"Stats",	"View general stats",			GUI_MENU_FUNC,	&gui_stats},#ifdef ARP	{"Arp"	,	"View arp addresses",			GUI_MENU_SUB,	&arp_gui},#endif	{"IP v4" ,	"View IP Version 4 Protocols",	GUI_MENU_SUB,	&gui_ipv4},	{"Hosts" ,	"View Host tables",				GUI_MENU_SUB,	&lookup_gui},	{NULL    , NULL,							GUI_MENU_END,	NULL}};struct gui_menu_t gui_menu_ipv4[] = {	{"TCP"		, "View TCP Packets",		GUI_MENU_FUNC, &tcp_gui},	{"TCP Conn"	, "View TCP Connections",	GUI_MENU_FUNC, &tcp_gui_conn},	{"UDP"		, "View UDP Packets",		GUI_MENU_FUNC, &udp_gui},	{"UDP Conn"	, "View UDP Connections",	GUI_MENU_FUNC, &udp_gui_conn},	{"ICMP"		, "View ICMP Packets",		GUI_MENU_FUNC, &icmp_gui},	{NULL		, NULL,						GUI_MENU_END,  NULL}};void *gui_main(void *arg) {	SLOCK(&gui_mutex);	gui = gui_setup();	if (!gui) {		printf("Cannot start gui\n");		exit(0);	}		/* we can now unlock this we have set */	/* up now people can print to us */	gui_ready = 1; /* we are ready */	SUNLOCK(&gui_mutex); /* unlock before we start looping */	while(gui_ready == 1)		sleep(1);	if (gui_wait(0, 5) == 1)		getch();	werase(gui->twin);	box(gui->twin, 0, 0);	wrefresh(gui->twin);	while(1)		gui_menu(gui, gui_menu_main, 1, 1, 10, 15);	gui_end(gui);	return 0;}void gui_ipv4(struct gui_t *p, int y, int x) {	gui_menu(p, gui_menu_ipv4, y, x, 7, 10);	return;}void gui_stats(struct gui_t *p, int y, int x) {	WINDOW *draw;	int cury, i, max;	char *foot_back;	/* form a list of stats we use */	struct gen_stat *tstat[] = {&stat_global, &ip_stat, &tcp_stat, &udp_stat,				&icmp_stat, &arp_stat, NULL};	struct if_stat *tmp_if;	draw = newwin(p->twin->_maxy - 1, p->twin->_maxx - 1, 1, 1);	if (!draw)		return;	wbkgd(draw, COLOR_PAIR(COL_BACK));	while(1) {		cury = 0;		werase(draw);		foot_back = p->footer;		gui_footer(p, "General Stats");		i = 0;		mvwprintw(draw, cury++, 0, "Desc\tCurrent\t\tAverage\t\t\tTotal\t (Packet/Data Pairs)");		while(tstat[i] != NULL) {			stat_process(tstat[i]);			mvwprintw(draw, cury++, 0, "%s\t%.2f:%.2f KB\t%.3f:%.3f KB  \t%llu:%llu %s",					tstat[i]->title,					tstat[i]->rate_packets, tstat[i]->rate_kb,					tstat[i]->avg_packets, tstat[i]->avg_kb,					tstat[i]->packets, tstat[i]->readable, tstat[i]->messure);			i++;		}		cury++;		mvwprintw(draw, cury++, 0, "Interfaces");		SLOCK(&if_mutex);		max = list_length(if_list);		for(i=0;i<max && cury < draw->_maxy;i++) {			tmp_if = list_get(if_list, i);			stat_process(&tmp_if->all_stat);			mvwprintw(draw, cury++, 0, "%s\t%.2f:%.2f KB\t%.3f:%.3f KB  \t%llu:%llu %s",					tmp_if->if_name,					tmp_if->all_stat.rate_packets, tmp_if->all_stat.rate_kb,					tmp_if->all_stat.avg_packets, tmp_if->all_stat.avg_kb,					tmp_if->all_stat.packets, tmp_if->all_stat.readable, 					tmp_if->all_stat.messure);		}		SUNLOCK(&if_mutex);		wrefresh(draw);		if (gui_wait(250, 0) == 1) {			getch();			goto get_out;		}	} /* end while(1) */get_out:	gui_footer(p, foot_back);	werase(draw);	wrefresh(draw);	delwin(draw);	return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -