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

📄 lan_ip_night.c

📁 计费部分源程序。我认为该软件极好
💻 C
字号:
#include <sqlhdr.h>
extern _SQCURSOR *_iqnprep();

#if !defined(__STDC__)
#define const 
#endif

#line 1 "lan_ip_night.ec"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <time.h>
/* 
 * $include  sqlca;
 */
#line 11 "lan_ip_night.ec"
#line 1 "/opt/usr/informix/incl/esql/sqlca.h"

#ifndef SQLCA_INCL

#define SQLCA_INCL

struct sqlca_s
    {
    long sqlcode;
    char sqlerrm[72];
    char sqlerrp[8];
    long sqlerrd[6];
	
    struct sqlcaw_s
	{
	char sqlwarn0;
	char sqlwarn1;

	char sqlwarn2;

	char sqlwarn3;

	char sqlwarn4;

	char sqlwarn5;
	char sqlwarn6;
	char sqlwarn7;
	} sqlwarn;
    };


#ifdef VMS
noshare
#endif
extern struct sqlca_s sqlca;

extern long SQLCODE;

#define SQLNOTFOUND 100

#endif
#line 12 "lan_ip_night.ec"

struct tm s;
struct tm *t;

#define K 1024
#define IP_NUM 1000
struct {
   char ip[20];
   long n_in, n_out, w_in, w_out;
   double n_sum, w_sum, nw_sum;
} ip_list[IP_NUM];

main()
{

  char filename[80], buff[400], s_today[100];
/*
 *   $char ip[20],temp[100];
 */
#line 28 "lan_ip_night.ec"
char ip[20], temp[100];
/*
 *   $long n_in, n_out, w_in, w_out;
 */
#line 29 "lan_ip_night.ec"
long n_in, n_out, w_in, w_out;
  double n_in_sum=0, n_out_sum=0, w_in_sum=0, w_out_sum=0,
	 n_total=0, w_total=0, total=0;
  char *ptr;
  int i,j,ip_list_up=0;
  FILE *fp,*fw,*fi;
  time_t t_stru;

/*
 *  $database scs_internet@ONLINE;
 */
#line 37 "lan_ip_night.ec"
  {
#line 37 "lan_ip_night.ec"
  _iqdbase("scs_internet@ONLINE", 0);
#line 37 "lan_ip_night.ec"
  }

  if (sqlca.sqlcode<0 ) {
      printf("open database is error! %d \n",sqlca.sqlcode);
      exit (-1);
    }

 time(&t_stru);
 t = localtime(&t_stru);

	system("date >> l_night.log");
	system("echo l_night start >> l_night.log");

 sprintf(s_today,"%04d%02d%02d",(1900+t->tm_year),t->tm_mon+1,t->tm_mday);

      strcpy(filename,"a_tmp");
      if((fp=fopen(filename,"r")) == NULL)
      {
         printf("not found %s \n",filename);
         exit(-1);
      }

      strcpy(filename,"data.dat");
      if((fw=fopen(filename,"a+")) == NULL)
      {
         printf("can't write %s \n",filename);
         exit(-1);
      }
	sprintf(temp,"DATE=%s\n",s_today);
	fputs(temp,fw);


      while ( ! feof(fp))
      {
         fgets(buff,200,fp);



	 ptr = strtok(buff," ");
	 if (ptr == NULL) continue;
	 strcpy(ip,ptr);


	 ptr = strtok(NULL," ");
	 if (ptr == NULL) continue;
	 strcpy(temp,ptr);
	 n_in = atol(temp);


	 ptr = strtok(NULL," ");
	 if (ptr == NULL) continue;
	 strcpy(temp,ptr);
	 n_out = atol(temp);

	 ptr = strtok(NULL," ");
	 if (ptr == NULL) continue;
	 strcpy(temp,ptr);
	 w_in = atol(temp);

	 ptr = strtok(NULL," ");
	 if (ptr == NULL) continue;
	 strcpy(temp,ptr);
	 w_out = atol(temp);


         for(j=0; j<ip_list_up;j++)
         if (!strcmp(ip_list[j].ip,ip))
	 {
		ip_list[j].n_in += n_in;	
		ip_list[j].n_out += n_out;	
		ip_list[j].w_in += w_in;	
		ip_list[j].w_out += w_out;	
		break;
	 }

         if (j==ip_list_up)
	 {
	        strcpy(ip_list[j].ip,ip);
                ip_list_up++;
		ip_list[j].n_in = n_in;	
		ip_list[j].n_out = n_out;	
		ip_list[j].w_in = w_in;	
		ip_list[j].w_out = w_out;	
         }
      }

      for(j=0; j< ip_list_up;j++)
      {
	ip_list[j].n_sum = (ip_list[j].n_in+ip_list[j].n_out)/K;
	ip_list[j].w_sum = (ip_list[j].w_in+ip_list[j].w_out)/K;
	ip_list[j].nw_sum = (ip_list[j].n_sum+ip_list[j].w_sum);

	n_in_sum += (ip_list[j].n_in);
	n_out_sum += (ip_list[j].n_out);
	w_in_sum += (ip_list[j].w_in);
	w_out_sum += (ip_list[j].w_out);

	
		strcpy(ip,ip_list[j].ip);
		n_in = ip_list[j].n_in;
		n_out = ip_list[j].n_out;
		w_in = ip_list[j].w_in;
		w_out = ip_list[j].w_out;
/*
 * 	$insert into lan_ip_day(login_id,d_date,n_in,n_out,w_in,w_out,fee_id)
 * 	  values($ip,today,$n_in,$n_out,$w_in,$w_out,-1);
 */
#line 140 "lan_ip_night.ec"
  {
#line 140 "lan_ip_night.ec"
  static const char *sqlcmdtxt[] =
#line 140 "lan_ip_night.ec"
    {
#line 140 "lan_ip_night.ec"
    " insert into lan_ip_day ( login_id , d_date , n_in , n_out , w_in , w_out , fee_id ) values ( ? , today , ? , ? , ? , ? , - 1 )",
    0
    };
#line 141 "lan_ip_night.ec"
  static _SQSTMT _SQ0 = {0};
  static struct sqlvar_struct _sqibind[] = 
    {
      { 100, 20, 0, 0, 0, 0, 0, 0, 0 },
      { 103, sizeof(n_in), 0, 0, 0, 0, 0, 0, 0 },
      { 103, sizeof(n_out), 0, 0, 0, 0, 0, 0, 0 },
      { 103, sizeof(w_in), 0, 0, 0, 0, 0, 0, 0 },
      { 103, sizeof(w_out), 0, 0, 0, 0, 0, 0, 0 },
#line 141 "lan_ip_night.ec"
    };
#line 141 "lan_ip_night.ec"
#line 141 "lan_ip_night.ec"
  _sqibind[0].sqldata = ip;
#line 141 "lan_ip_night.ec"
  _sqibind[1].sqldata = (char *) &n_in;
#line 141 "lan_ip_night.ec"
  _sqibind[2].sqldata = (char *) &n_out;
#line 141 "lan_ip_night.ec"
  _sqibind[3].sqldata = (char *) &w_in;
#line 141 "lan_ip_night.ec"
  _sqibind[4].sqldata = (char *) &w_out;
  _iqstmnt(&_SQ0, sqlcmdtxt, 5, _sqibind, (char *)0);
#line 141 "lan_ip_night.ec"
  }

	printf("IP=%s,国内流入=%ld(K),国内流出=%ld(K),国外流入=%ld(K),国外流出=%ld(K)\n",ip_list[j].ip,
		  ip_list[j].n_in/K, ip_list[j].n_out/K,
		  ip_list[j].w_in/K, ip_list[j].w_out/K);

	
	sprintf(buff,"%s %10ld %10ld %10ld %10ld\n",ip_list[j].ip,
		  ip_list[j].n_in/K, ip_list[j].n_out/K,
		  ip_list[j].w_in/K, ip_list[j].w_out/K);
	fputs(buff,fw);

	
        strcpy(filename,ip_list[j].ip);
        if((fi=fopen(filename,"a+")) == NULL)
        {
         printf("can't write %s \n",filename);
         exit(-1);
        }
	sprintf(temp,"DATE=%s\n",s_today);
	fputs(temp,fi);
	fputs(buff,fi);
	fclose(fi);

      }

	n_in_sum = n_in_sum/K/K;
	n_out_sum = n_out_sum/K/K;
	w_in_sum = w_in_sum/K/K;
	w_out_sum = w_out_sum/K/K;
	n_total = n_in_sum + n_out_sum;
	w_total = w_in_sum + w_out_sum;
	total = n_total + w_total;

	printf("\n		流量合计:\n");
	printf("\n 国内流入=%10.2f(M),国内流出=%10.2f(M),国外流入=%10.2f(M),国外流出=%10.2f(M),\n 国内总计=%15.2f(M),国外总计=%15.2f(M), 全部合计= %15.2f(M)\n\n\n",
		n_in_sum,n_out_sum,w_in_sum,w_out_sum,n_total,w_total,total);





  	fclose(fw);

	fclose(fp);

	printf("	处理成功结束 \n");

	system("date >> l_night.log");
	system("echo l_night stop >> l_night.log");

/*
 * 	$close database;
 */
#line 192 "lan_ip_night.ec"
  {
#line 192 "lan_ip_night.ec"
  _iqdbclose();
#line 192 "lan_ip_night.ec"
  }
}

⌨️ 快捷键说明

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