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

📄 iptraf.c

📁 一个网络流量分析的完整的程序
💻 C
📖 第 1 页 / 共 2 页
字号:
			servmon(ifname, ports, options, 0, &ofilter);		    break;		case 4:		    break;		}		tx_destroymenu(&break_menu);		break;	    case 5:		selectiface(ifname, WITHALL, &aborted);		if (!aborted) {		    if (strcmp(ifname, "") != 0)			ifptr = ifname;		    else			ifptr = NULL;		    hostmon(options, 0, ifptr);		}		break;	    case 7:		config_filters(&ofilter);		savefilters(&ofilter);		break;	    case 9:		setoptions(options, &ports);		saveoptions(options);		break;	    case 11:                tx_errbox("This will end your IPTraf session",                          "Press Enter to exit or any other key to resume", &resp);                if (resp == 13) 	/* Enter key to confirm exit */	        		    endloop = 1;		break;	    }	} while (!endloop);	tx_destroymenu(&menu);    } else {	switch (opt) {	case 'i':	    if ((strcmp(optarg, ALLSPEC) == 0)		|| (strcmp(optarg, "") == 0))		ifptr = NULL;	    else		ifptr = optarg;	    ipmon(options, &ofilter, facilitytime, ifptr);	    break;	case 'g':	    ifstats(options, &ofilter, facilitytime);	    break;	case 'd':	    detstats(optarg, options, facilitytime, &ofilter);	    break;	case 's':	    servmon(optarg, ports, options, facilitytime, &ofilter);	    break;	case 'z':	    packet_size_breakdown(options, optarg, facilitytime);	    break;	case 'l':	    if ((strcmp(optarg, ALLSPEC) == 0)		|| (strcmp(optarg, "") == 0))		ifptr = NULL;	    else		ifptr = optarg;	    hostmon(options, facilitytime, ifptr);	    break;	}    }    destroyporttab(ports);    erase();    update_panels();    doupdate();}/* * Command-line help facility. */void commandhelp(){    printf("\nSyntax:\n");    printf	("    iptraf [ -f ] [ { -i iface | -g | -d iface | -s iface | -z iface |\n");    printf("           -l iface } [ -t timeout ] [ -B [ -L logfile ] ] ]\n\n");    printf	("Issue the iptraf command with no parameters for menu-driven operation.\n");    printf("These options can also be supplied to the command:\n\n");    printf	("-i iface    - start the IP traffic monitor (use \"-i all\" for all interfaces)\n");    printf("-g          - start the general interface statistics\n");    printf	("-d iface    - start the detailed statistics facility on an interface\n");    printf	("-s iface    - start the TCP and UDP monitor on an interface\n");    printf("-z iface    - shows the packet size counts on an interface\n");    printf	("-l iface    - start the LAN station monitor (\"-l all\" for all LAN interfaces)\n");    printf	("-B          - run in background (use only with one of the above parameters)\n");    printf	("-t timeout  - when used with one of the above parameters, tells\n");    printf	("              the facility to run only for the specified number of\n");    printf("              minutes (timeout)\n");    printf        ("-L logfile  - when used with -B, allows you to specify an alternate\n");    printf        ("              log file.  The log is placed in %s if a path is not\n", LOGDIR);    printf        ("              specified.\n");     printf	("-f          - Clear all locks and counters.  Use with great caution.\n");    printf        ("              Normally used to recover from an abnormal termination.\n\n");    printf("IPTraf %s Copyright (c) Gerard Paul Java 1997-2002\n",	   VERSION);}int first_instance(){    int fd;    fd = open(IPTIDFILE, O_RDONLY);    if (fd < 0)	return !0;    else {	close(fd);	return 0;    }}void mark_first_instance(){    int fd;    fd = open(IPTIDFILE, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR);    if (fd < 0) {	fprintf(stderr, "\nWarning: unable to tag this process\r\n");        press_enter_to_continue();	return;    }    close(fd);}/* * Main routine */int main(int argc, char **argv){    struct OPTIONS options;    int opt = 0;    int command = 0;    char keyparm[12];    int facilitytime = 0;#ifndef ALLOWUSERS    if (getuid() != 0) {	fprintf(stderr, "\nIPTraf Version %s\n", VERSION);	fprintf(stderr, "Copyright (c) Gerard Paul Java 1997-2002l\n\n");	fprintf(stderr,		"This program can be run only by the system administrator\n\n");	exit(1);    }#endif    strcpy(current_logfile, "");        /*     * Parse command line     */    if (argc > 1) {	do {	    opterr = 0;	    opt = getopt(argc, argv, "i:gd:s:z:l:hfqt:BL:u");	    if (opt == 'h') {		commandhelp();		exit(0);	    } else if (opt == 'f') {		removetags();		remove_sockets();	    } else if (opt == 't') {		facilitytime = atoi(optarg);		if (facilitytime == 0) {		    fprintf(stderr, "\nInvalid time value\n\n");		    exit(1);		}	    } else if (opt == 'B') {		daemonized = 1;	    } else if (opt == 'L') {	        if (strchr(optarg, '/') != NULL)	            strncpy(current_logfile, optarg, 80);	        else	            strncpy(current_logfile, get_path(T_LOGDIR, optarg), 80);	    } else if (opt == 'q') {		/* -q parameter now ignored, maintained for compatibility */	    } else if (opt == 'u') {	        accept_unsupported_interfaces = 1;	    } else if (opt == '?') {		fprintf(stderr,			"\nInvalid option or missing parameter, use iptraf -h for help\n\n");		exit(1);	    } else if (opt != -1) {		if (optarg != 0) {		    bzero(keyparm, 12);		    strncpy(keyparm, optarg, 11);		} else		    strcpy(keyparm, "");		command = opt;	    }	} while ((opt != '?') && (opt != -1));    }    is_first_instance = first_instance();    if (getenv("TERM") == NULL) {	fprintf(stderr, "Your TERM variable is not set.\n");	fprintf(stderr, "Please set it to an appropriate value.\n");	exit(1);    }    loadoptions(&options);    /*     * If a facility is directly invoked from the command line, check for     * a daemonization request     */    if ((daemonized) && (command != 0)) {	switch (fork()) {	case 0:		/* child */	    setsid();	    freopen("/dev/null", "w", stdout);	/* redirect std output */	    freopen("/dev/null", "r", stdin);	/* redirect std input */	    freopen("/dev/null", "w", stderr);	/* redirect std error */	    signal(SIGUSR2, (void *) term_usr2_handler);	    options.logging = 1;	/* daemon mode implies logging */	    break;	case -1:		/* error */	    fprintf(stderr,		    "\nFork error, IPTraf cannot run in background\n\n");	    exit(1);	default:		/* parent */	    exit(0);	}    }#ifdef SIMDAEMON    daemonized = 1;    freopen("/dev/null", "w", stdout);	/* redirect std output */    freopen("/dev/null", "r", stdin);    freopen("/dev/null", "w", stderr);#endif    initscr();    if ((LINES < 24) || (COLS < 80)) {	endwin();	fprintf(stderr,		"\nThis program requires a screen size of at least 80 columns by 24 lines\n");	fprintf(stderr, "Please resize your window\n\n");	exit(1);    }    mark_first_instance();        signal(SIGTERM, (void *) term_signal_handler);    signal(SIGHUP, (void *) term_signal_handler);    signal(SIGSEGV, (void *) segvhandler);    signal(SIGTSTP, SIG_IGN);    signal(SIGINT, SIG_IGN);    signal(SIGUSR1, SIG_IGN);    start_color();    standardcolors(options.color);    noecho();    nonl();    cbreak();#ifndef DEBUG    curs_set(0);#endif    /*     * Set logfilename variable to an empty string in case -L was specified     * without -B.     */         if (!daemonized)        strcpy(current_logfile, "");            program_interface(&options, command, keyparm, facilitytime);    endwin();    if (is_first_instance)	unlink(IPTIDFILE);    return (0);}

⌨️ 快捷键说明

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