Exemple #1
0
/* main:
 * Entry point. See usage(). */
int main(int argc, char **argv) {
    pthread_t thread;
    struct sigaction sa = {};

    setlocale(LC_ALL, "");

    /* TODO: tidy this up */
    /* read command line options and config file */   
    config_init();
    options_set_defaults();
    options_read_args(argc, argv);
    /* If a config was explicitly specified, whinge if it can't be found */
    read_config(options.config_file, options.config_file_specified);
    options_make();
    
    sa.sa_handler = finish;
    sigaction(SIGINT, &sa, NULL);

    pthread_mutex_init(&tick_mutex, NULL);

    packet_init();

    init_history();

    if (options.no_curses) {
      tui_init();
    }
    else {
      ui_init();
    }

    pthread_create(&thread, NULL, (void*)&packet_loop, NULL);

    /* Keep the starting time (used for timed termination) */
    first_timestamp = time(NULL);

    if (options.no_curses) {
      if (options.timed_output) {
        while(!foad) {
          sleep(1);
        }
      }
      else {
        tui_loop();
      }
    }
    else {
      ui_loop();
    }

    pthread_cancel(thread);

    ui_finish();
    
    return 0;
}
Exemple #2
0
options_t *options_new(gru_status_t *status) {
	options_t *ret = gru_alloc(sizeof(options_t), status);
	gru_alloc_check(ret, NULL);

	if (!options_set_defaults(ret, status)) {
		gru_dealloc((void **) &ret);

		return NULL;
	}

	return ret;
}
Exemple #3
0
/* main:
 * Entry point. See usage(). */
int main(int argc, char **argv) {
    pthread_t thread;
    struct sigaction sa = {};

    setlocale(LC_ALL, "");

    /* TODO: tidy this up */
    /* read command line options and config file */   
    config_init();
    options_set_defaults();
    options_read_args(argc, argv);
    /* If a config was explicitly specified, whinge if it can't be found */
    read_config(options.config_file, options.config_file_specified);
    options_make();
    
    sa.sa_handler = finish;
    sigaction(SIGINT, &sa, NULL);

    pthread_mutex_init(&tick_mutex, NULL);

    packet_init();

    init_history();

    ui_init();

    pthread_create(&thread, NULL, (void*)&packet_loop, NULL);

    ui_loop();

    //pthread_cancel(thread); // bionic c have no pthread_cancel, by dove

    ui_finish();
    
    return 0;
}
Exemple #4
0
int main(int argc, char **argv) {
    pthread_t thread;
    struct sigaction sa = {};
	time_t timer_log;//time_t就是long int 类
	struct tm *tblock =NULL;/*定义一个变量*/

#if 1 

	if(daemon(0, 0) < 0)
	{
		perror("error daemon...\n");
		exit(1);
	}
#endif

    setlocale(LC_ALL, "");


#if 1
		//FILE *fp_log;				 /*定义一个文件指针*/
		int i_log;
		fp_log=fopen("/var/log/iftopd.log", "a+");	
		if(fp_log==NULL)				 /*判断文件是否打开成功*/
		   printf("File open error");  /*提示打开不成功*/
		else
		{  

			//time_t timer_log;//time_t就是long int 类
			//struct tm *tblock =NULL;		
			timer_log = time(NULL);//这一句也可以改成time(&timer);	
			tblock = localtime(&timer_log); 
			fprintf(fp_log,"start iftop time is: %s\n",asctime(tblock));				
	
		}


#endif 

    /* TODO: tidy this up */
    /* read command line options and config file */   
    config_init();
    options_set_defaults();
    options_read_args(argc, argv);
    /* If a config was explicitly specified, whinge if it can't be found */
    read_config(options.config_file, options.config_file_specified);
    options_make();
/*  修正参数 */
	correction_parameter();
    
    sa.sa_handler = finish;
    sigaction(SIGINT, &sa, NULL);

    pthread_mutex_init(&tick_mutex, NULL);

    packet_init();

    init_history();

    if (options.no_curses) {
      tui_init();
    }
    else {
      ui_init();
    }

    pthread_create(&thread, NULL, (void*)&packet_loop, NULL);

    /* Keep the starting time (used for timed termination) */
    first_timestamp = time(NULL);

    if (options.no_curses) {
      if (options.timed_output) {
        while(!foad) {
          sleep(1);
        }
      }
      else {
        tui_loop();
      }
    }
    else {
      ui_loop();
    }

    pthread_cancel(thread);

#if 1

#if  1
fprintf(fp_log," interface***** = %s \n",options.interface);
fprintf(fp_log," speed_second_time = %d \n",options.speed_second_time);
fprintf(fp_log," num_lines = %d \n",options.num_lines);

#endif


#if 1
	if( NULL != fp_log)
	{
		time(&timer_log);
		tblock = localtime(&timer_log);	
		fprintf(fp_log,"close iftop time is: %s\n",asctime(tblock));	
	}
	
#endif
	i_log = fclose(fp_log); 		   /*关闭打开的文件*/
	if(i_log!=0) 				/*判断文件是否关闭成功*/
		printf("File close error"); 		/*提示关闭	失败提示*/
	
#endif
    ui_finish();
    
    return 0;
}
Exemple #5
0
void options_process(int argc, char** argv)
{
    memset(&options, 0, sizeof(options));

    options_set_defaults();

    extern char* optarg;
    extern int optind;
    struct option long_options[] = {
	{ "nodaemon",    0, 0, 'D' },
	{ "debug",       0, 0, 'd' },
	{ "help",        0, 0, 'h' },
	{ "ignorenodev", 0, 0,  1  },
	{ "dmi",         0, 0,  2  },
	{ "filter",      0, 0,  3  },
	{ "user",        1, 0,  4  },
	{ "password",    1, 0,  5  },
	{ "ip",          1, 0,  6  },
	{ "decode",      1, 0, 'e' },
	{ "seltest",     1, 0, 't' },
	{ "params",      0, 0,  7  },
	{ "setparam",    1, 0,  8  },
	{ "single",      0, 0, 's' },
	{ "noserdfiltering", 0, 0, 'f' },
	{ 0, 0, 0, 0 }
    };
	
    int opt;

    while ((opt = getopt_long(argc, argv, "Ddhe:t:sf",
			      long_options, &optind)) != -1) {
	switch (opt) {
	case 'D':
	    options.no_daemon_flag = 1;
	    break;
	case 'd':
	    options.debug_mode++;
	    options.nosyslog_mode = 1;
	    break;
        case 'e':
            options.decode_mode = 1;
            options.nosyslog_mode = 1;
            options.decode_address = strtoll(optarg, NULL, 16);
	    {
		char* colon = strchr(optarg, ':');
		if (colon)
		    options.decode_syndrome = strtol(colon+1, NULL, 16);
		else
		    options.decode_syndrome = 0;
	    }
            break;
        case 't':
            options.seltest_mode = 1;
	    options.debug_mode++;
            options.nosyslog_mode = 1;
	    options.no_daemon_flag = 1;
            options.seltest_address = strtoll(optarg, NULL, 16);
	    {
		char* colon = strchr(optarg, ':');
		if (colon)
		    options.decode_syndrome = strtol(colon+1, NULL, 16);
		else
		    options.decode_syndrome = 0;
            }

            break;
	case 's':
	    options.singleiter_mode = 1;
	    options.no_daemon_flag = 1;
	    break;
	case 'f':
	    options.no_serd_filter = 1;
	    break;
	case 1:
	    options.ignore_no_dev = 1;
	    break;
	case 2:
	    options.dmi_decode = 1;
	    break;
	case 3:
	    options.filter_bogus = 1;
	    break;
	case 4:
	    options.i_user = optarg;
	    break;
	case 5:
	    options.i_password = optarg;
	    break;
	case 6:
	    options.i_ip = optarg;
	    break;
	case 7:
	    options_print_parameters();
	    exit(0);
	case 8:
	    options_add_parameter(optarg);
	    break;
	case 'h':
	    options_usage(argv);
	    exit(0);
	default:
	    options_usage(argv);
	    exit(1);
	}
    }
}