Example #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;
}
Example #2
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;
}