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

📄 get_net.c

📁 UNIX环境下资源监控程序(包含对CPUMEMDISKIOPS等资源的监控)
💻 C
字号:
#include  "public.h"
//#include  "monitor.h"
//#include  "msgqueue.h"
#include "sysmoni.h"
#include  "standdb.h"
/************************************************/
/*FILE NAME:	get_net.c						*/
/*DESCRIPTION:	use system command get net info,
 **		decompose and analysis the data			*/
/*INCLUDE:										*/
/*FUNCTION:	get_net(char * acz_device),
/*AUTHOR:	genius.xuyong						*/
/*CREATE DATE:	2002-08-16						*/
/************************************************/
extern	long	gl_qmsgsend;


/*void main()*/
int	get_net( char *acz_device,
               char *acz_machine_code,
                char *acz_module_code,
                char *acz_object_code,
                char *acz_create_time)
{
	FILE	*lh_file;		
	char	lcz_buf[LEN];	
	int		i=0;
	
/**	init the msgqueue **/
/*
	if ( InitQueue(&gl_qmsgsend,QUEUESEND)<0 )
	{
		printf("init queue error!");
		exit(-1);
	}
*/
	system("netstat -arn >out/net.dat");

	lh_file = fopen("./out/net.dat","r");	/*open a cpu info text*/
	if ( NULL == lh_file )
	{
		printf("open file net.dat error!\n");
		fclose( lh_file );
		return;
	}
	
	memset(lcz_buf,0x00,LEN);	/*set lcz_buf string is null*/
	i=0;

	while (NULL != fgets(lcz_buf,sizeof(lcz_buf),lh_file))
	/*read a line from file,if is eof then break the while cycle*/
	{
		
		/*if the line include char '0' then deal the line ,
		 *else continue the cycle*/
		if (NULL==strstr(lcz_buf,"."))
		{
			continue;
		}
		else
		{
			decompose_net(lcz_buf,acz_machine_code,acz_module_code,acz_object_code,acz_create_time); /*deal data function*/
			i++;
		}
	}
	fclose( lh_file );

	/* deal_net(&ls_net,i,acz_device,acz_unusualfile,acz_lckfile,acz_procname);	*/
}

/************************************************************/
/*decompose a data string,change some char to long type data,
 *and send them to a struct. the in_parameter are a string and 
 *a cpuinfo struct
 ************************************************************/

int decompose_net(char *acz_buf,char* acz_machine_code,char* acz_module_code,char* acz_object_code,char * create_time)
{
	int		i,j,k;
	char	lc_char;
	char	lcz_tmp[8][18+1];
	char    complete_time[20]="";
	long	ll_pos;
	char            lc_state[10];    /*网络属性状态*/
	char            lc_code[10][10];  /*网络属性编码*/
	char gcz_net[6][20]={"Destination","Gateway","Flags","Refs","Use","Interface"};/* 网络模块属性数组*/
	
	memset(lcz_tmp,0x00,sizeof(lcz_tmp));/*set the lcz_tmp is null*/
	j=0;	/*set the first position is lcz_tmp[0]*/
	k=0;	/*set the first position is ll_array[0]*/
	
	for (i=0;;i++)/*this cycle is read a char from the buffer char*/
	{
		lc_char=acz_buf[i];/*put the buffer char to lc_char*/
		if (lc_char=='\n')/*if the char is the end of the buffer*/
		{
			if (j>0)	/*if counter j >0,mean lcz_tmp not null*/
			{
				lcz_tmp[k][j]='\0';
				if (lc_state[k]=='1')
				{      
					get_format_time(complete_time,sizeof(complete_time));
					Write_MonitorInfo(lc_code[k], acz_object_code,lcz_tmp[k],create_time,complete_time );
				}	
			}	
			break;	/* the exit of the cycle*/
		}

		if (lc_char!=0x20)	/*if the char is not null*/
		{
			lcz_tmp[k][j]=lc_char;	
			j++;	/*the value of lc_char append to lcz_tmp */			
		}
		else
		{
			if (j>0)
			{
				lcz_tmp[k][j]='\0';
				 memset(lc_state,0x00,strlen(lc_state));
				 memset(lc_code,0x00,10);
				if (k==0)
				{      
					Read_Property(gcz_net,acz_module_code,lc_state,lc_code);	
					if  ( Read_Object(lcz_tmp[k], acz_module_code,acz_object_code)==0)
				         break;
				}
				
				if (lc_state[k]=='1')
				{       get_format_time(complete_time,sizeof(complete_time));
					Write_MonitorInfo(lc_code[k], acz_object_code,lcz_tmp[k],create_time,complete_time  );
				}		
				k++;
			}
			memset(lcz_tmp,0x00,10);	
			j=0;	/*set the first position is lcz_tmp[0]*/
		}
	}
	
	return ( 0 );

}

⌨️ 快捷键说明

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