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

📄 lan_ip_month.c

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

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

static const char *_Cn3 = "cur_w"; static _SQCURSOR *_SQ3 = 0;
static const char *_Cn2 = "cur_n"; static _SQCURSOR *_SQ2 = 0;
static const char *_Cn1 = "cur"; static _SQCURSOR *_SQ1 = 0;
#line 1 "lan_ip_month.ec"



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/msg.h>

#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>
#include <netinet/tcp.h>
#include <netinet/tcpip.h>
#include <signal.h>
/* 
 * $include sqlca;
 */
#line 24 "lan_ip_month.ec"
#line 1 "/opt/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 25 "lan_ip_month.ec"


#define K 1024
#define M 1048576

/*
 * $long sqlreturn;
 */
#line 30 "lan_ip_month.ec"
long sqlreturn;
/*
 * $float rn_in,rn_out,rw_in,rw_out;
 */
#line 31 "lan_ip_month.ec"
float rn_in, rn_out, rw_in, rw_out;

checksql(str)
char *str;
{
 if (sqlca.sqlcode < 0 )
    {  printf("%s failure , sqlcode=%d, isam=%d\n",str,sqlca.sqlcode,sqlca.sqlerrd[1]);  exit(-1); }
}


 cacu_ip()
 {
	int i;
/*
 * 	$char ip[20], group_id[20],login_name[20];
 */
#line 44 "lan_ip_month.ec"
char ip[20], group_id[20], login_name[20];
/*
 * 	$int account_id;
 */
#line 45 "lan_ip_month.ec"
int account_id;
/*
 * 	$double n_in,n_out,w_in,w_out;
 */
#line 46 "lan_ip_month.ec"
double n_in, n_out, w_in, w_out;
/*
 * 	$double fn_in,fn_out,fw_in,fw_out,fn_sum,fw_sum,f_total;
 */
#line 47 "lan_ip_month.ec"
double fn_in, fn_out, fw_in, fw_out, fn_sum, fw_sum, f_total;

/*
 * 	$declare cur cursor for
 * 	  select login_id,sum(n_in),sum(n_out),sum(w_in),sum(w_out)
 * 	  from lan_ip_day
 * 	  where fee_id=-1
 * 	  group by login_id;
 */
#line 49 "lan_ip_month.ec"
  {
#line 50 "lan_ip_month.ec"
  static const char *sqlcmdtxt[] =
#line 50 "lan_ip_month.ec"
    {
#line 50 "lan_ip_month.ec"
    " select login_id , sum ( n_in ) , sum ( n_out ) , sum ( w_in ) , sum ( w_out ) from lan_ip_day where fee_id = - 1 group by login_id",
    0
    };
#line 53 "lan_ip_month.ec"
#line 53 "lan_ip_month.ec"
  _SQ1 = _iqlocate_cursor(_Cn1, 0, 0);
#line 53 "lan_ip_month.ec"
  _iqcdcl(_SQ1, _Cn1, sqlcmdtxt, (struct sqlda *)0, (struct sqlda *)0, 0);
#line 53 "lan_ip_month.ec"
  }

/*
 * 	$open cur;
 */
#line 55 "lan_ip_month.ec"
  {
#line 55 "lan_ip_month.ec"
#line 55 "lan_ip_month.ec"
  _SQ1 = _iqlocate_cursor(_Cn1, 0, 0);
#line 55 "lan_ip_month.ec"
  _iqdcopen(_SQ1, (struct sqlda *)0, (char *)0, (char *)0, 0);
#line 55 "lan_ip_month.ec"
  }
	while(1)
	{
/*
 * 	 $fetch cur into $ip,$n_in,$n_out,$w_in,$w_out;
 */
#line 58 "lan_ip_month.ec"
  {
#line 58 "lan_ip_month.ec"
  static struct sqlvar_struct _sqobind[] = 
    {
      { 100, 20, 0, 0, 0, 0, 0, 0, 0 },
      { 105, sizeof(n_in), 0, 0, 0, 0, 0, 0, 0 },
      { 105, sizeof(n_out), 0, 0, 0, 0, 0, 0, 0 },
      { 105, sizeof(w_in), 0, 0, 0, 0, 0, 0, 0 },
      { 105, sizeof(w_out), 0, 0, 0, 0, 0, 0, 0 },
#line 58 "lan_ip_month.ec"
    };
  static struct sqlda _SD0 = { 5, _sqobind, 0, 5, 0 };
  static _FetchSpec _FS1 = { 0, 1, 0 };
#line 58 "lan_ip_month.ec"
  _sqobind[0].sqldata = ip;
#line 58 "lan_ip_month.ec"
  _sqobind[1].sqldata = (char *) &n_in;
#line 58 "lan_ip_month.ec"
  _sqobind[2].sqldata = (char *) &n_out;
#line 58 "lan_ip_month.ec"
  _sqobind[3].sqldata = (char *) &w_in;
#line 58 "lan_ip_month.ec"
  _sqobind[4].sqldata = (char *) &w_out;
#line 58 "lan_ip_month.ec"
  _SQ1 = _iqlocate_cursor(_Cn1, 0, 0);
#line 58 "lan_ip_month.ec"
  _iqcftch(_SQ1, (struct sqlda *)0, &_SD0, (char *)0, &_FS1);
#line 58 "lan_ip_month.ec"
  }
	 checksql("fetch cur error");
	 if (sqlca.sqlcode==100) break;

	 fn_in = n_in/M * rn_in;
	 fn_out = n_out/M * rn_out;
	 fw_in =  w_in/M * rw_in;
	 fw_out = w_out/M * rw_out;

	 fn_sum = fn_in + fw_in;
	 fw_sum = fn_out+ fw_out;
	 f_total = fn_sum + fw_sum;



/*
 * 	 $insert into lan_ip_fee(login_id,fee_id,f_date,fee_in,fee_out,fee_total)
 * 		  values($ip,0,today,$fn_sum,$fw_sum,$f_total);
 */
#line 73 "lan_ip_month.ec"
  {
#line 73 "lan_ip_month.ec"
  static const char *sqlcmdtxt[] =
#line 73 "lan_ip_month.ec"
    {
#line 73 "lan_ip_month.ec"
    " insert into lan_ip_fee ( login_id , fee_id , f_date , fee_in , fee_out , fee_total ) values ( ? , 0 , today , ? , ? , ? )",
    0
    };
#line 74 "lan_ip_month.ec"
  static _SQSTMT _SQ0 = {0};
  static struct sqlvar_struct _sqibind[] = 
    {
      { 100, 20, 0, 0, 0, 0, 0, 0, 0 },
      { 105, sizeof(fn_sum), 0, 0, 0, 0, 0, 0, 0 },
      { 105, sizeof(fw_sum), 0, 0, 0, 0, 0, 0, 0 },
      { 105, sizeof(f_total), 0, 0, 0, 0, 0, 0, 0 },
#line 74 "lan_ip_month.ec"
    };
#line 74 "lan_ip_month.ec"
#line 74 "lan_ip_month.ec"
  _sqibind[0].sqldata = ip;
#line 74 "lan_ip_month.ec"
  _sqibind[1].sqldata = (char *) &fn_sum;
#line 74 "lan_ip_month.ec"
  _sqibind[2].sqldata = (char *) &fw_sum;
#line 74 "lan_ip_month.ec"
  _sqibind[3].sqldata = (char *) &f_total;
  _iqstmnt(&_SQ0, sqlcmdtxt, 4, _sqibind, (char *)0);
#line 74 "lan_ip_month.ec"
  }
	 checksql("insert ip_fee");





/*
 * 	 $select account_id,name,group_id
 * 		into $account_id,$login_name,$group_id
 * 		from g_user_table
 * 		where login_id=$ip and services_type="E";
 */
#line 81 "lan_ip_month.ec"
  {
#line 81 "lan_ip_month.ec"
  static const char *sqlcmdtxt[] =
#line 81 "lan_ip_month.ec"
    {
#line 81 "lan_ip_month.ec"
    " select account_id , name , group_id from g_user_table where login_id = ? and services_type = 'E'",
    0
    };
#line 84 "lan_ip_month.ec"
  static _SQCURSOR _SQ0 = {0};
  static struct sqlvar_struct _sqibind[] = 
    {
      { 100, 20, 0, 0, 0, 0, 0, 0, 0 },
#line 84 "lan_ip_month.ec"
    };
  static struct sqlvar_struct _sqobind[] = 
    {
      { 102, sizeof(account_id), 0, 0, 0, 0, 0, 0, 0 },
      { 100, 20, 0, 0, 0, 0, 0, 0, 0 },
      { 100, 20, 0, 0, 0, 0, 0, 0, 0 },
#line 84 "lan_ip_month.ec"
    };
#line 84 "lan_ip_month.ec"
  _sqibind[0].sqldata = ip;
#line 84 "lan_ip_month.ec"
  _sqobind[0].sqldata = (char *) &account_id;
#line 84 "lan_ip_month.ec"
  _sqobind[1].sqldata = login_name;
#line 84 "lan_ip_month.ec"
  _sqobind[2].sqldata = group_id;
#line 84 "lan_ip_month.ec"
  _iqslct(&_SQ0, sqlcmdtxt, 1, _sqibind, 3, _sqobind, 0);
#line 84 "lan_ip_month.ec"
  }
	 checksql("select account from g_user_table");
	 if (sqlca.sqlcode ==100)
		continue;
/*
 * 	 $insert into z_fee_user_table
 * 	    (account_id,group_id,services_type,login_id,login_name,fee_id,fee_date,in_fee,out_fee,total_fee,fee_g_id)
 * 	    values($account_id,$group_id,"E",$ip,$login_name,0,today,$fn_sum,$fw_sum,$f_total,-1);
 */
#line 88 "lan_ip_month.ec"
  {
#line 88 "lan_ip_month.ec"
  static const char *sqlcmdtxt[] =
#line 88 "lan_ip_month.ec"
    {
#line 88 "lan_ip_month.ec"
    " insert into z_fee_user_table ( account_id , group_id , services_type , login_id , login_name , fee_id , fee_date , in_fee , out_fee , total_fee , fee_g_id ) values ( ? , ? , 'E' , ? , ? , 0 , today , ? , ? , ? , - 1 )",
    0
    };
#line 90 "lan_ip_month.ec"
  static _SQSTMT _SQ0 = {0};
  static struct sqlvar_struct _sqibind[] = 
    {
      { 102, sizeof(account_id), 0, 0, 0, 0, 0, 0, 0 },
      { 100, 20, 0, 0, 0, 0, 0, 0, 0 },
      { 100, 20, 0, 0, 0, 0, 0, 0, 0 },
      { 100, 20, 0, 0, 0, 0, 0, 0, 0 },
      { 105, sizeof(fn_sum), 0, 0, 0, 0, 0, 0, 0 },
      { 105, sizeof(fw_sum), 0, 0, 0, 0, 0, 0, 0 },
      { 105, sizeof(f_total), 0, 0, 0, 0, 0, 0, 0 },
#line 90 "lan_ip_month.ec"
    };
#line 90 "lan_ip_month.ec"
#line 90 "lan_ip_month.ec"
  _sqibind[0].sqldata = (char *) &account_id;
#line 90 "lan_ip_month.ec"
  _sqibind[1].sqldata = group_id;
#line 90 "lan_ip_month.ec"
  _sqibind[2].sqldata = ip;
#line 90 "lan_ip_month.ec"
  _sqibind[3].sqldata = login_name;
#line 90 "lan_ip_month.ec"
  _sqibind[4].sqldata = (char *) &fn_sum;
#line 90 "lan_ip_month.ec"
  _sqibind[5].sqldata = (char *) &fw_sum;
#line 90 "lan_ip_month.ec"
  _sqibind[6].sqldata = (char *) &f_total;
  _iqstmnt(&_SQ0, sqlcmdtxt, 7, _sqibind, (char *)0);
#line 90 "lan_ip_month.ec"
  }
	 checksql("insert z_fee_user_table");
	 sqlreturn=sqlca.sqlerrd[1];
/*
 * 	 $update lan_ip_day set fee_id = $sqlreturn
 * 	  where login_id=$ip and fee_id=-1;
 */
#line 93 "lan_ip_month.ec"
  {
#line 93 "lan_ip_month.ec"
  static const char *sqlcmdtxt[] =
#line 93 "lan_ip_month.ec"
    {
#line 93 "lan_ip_month.ec"
    " update lan_ip_day set fee_id = ? where login_id = ? and fee_id = - 1",
    0
    };
#line 94 "lan_ip_month.ec"
  static _SQSTMT _SQ0 = {0};
  static struct sqlvar_struct _sqibind[] = 
    {
      { 103, sizeof(sqlreturn), 0, 0, 0, 0, 0, 0, 0 },
      { 100, 20, 0, 0, 0, 0, 0, 0, 0 },
#line 94 "lan_ip_month.ec"
    };
#line 94 "lan_ip_month.ec"
#line 94 "lan_ip_month.ec"
  _sqibind[0].sqldata = (char *) &sqlreturn;
#line 94 "lan_ip_month.ec"
  _sqibind[1].sqldata = ip;
  _iqstmnt(&_SQ0, sqlcmdtxt, 2, _sqibind, (char *)0);
#line 94 "lan_ip_month.ec"
  }
	}
/*
 * 	$close cur;
 */
#line 96 "lan_ip_month.ec"
  {
#line 96 "lan_ip_month.ec"
#line 96 "lan_ip_month.ec"
  _SQ1 = _iqlocate_cursor(_Cn1, 0, 0);
#line 96 "lan_ip_month.ec"
  _iqclose(_SQ1);
#line 96 "lan_ip_month.ec"
  }
 printf("insert fee ok!\n");

 }


get_rate()
{

/*
 *  $declare cur_n scroll cursor for
 * 	select rate_in,rate_out from ip_net where name="n";
 */
#line 105 "lan_ip_month.ec"
  {
#line 106 "lan_ip_month.ec"
  static const char *sqlcmdtxt[] =
#line 106 "lan_ip_month.ec"
    {
#line 106 "lan_ip_month.ec"
    " select rate_in , rate_out from ip_net where name = 'n'",
    0
    };
#line 106 "lan_ip_month.ec"
#line 106 "lan_ip_month.ec"
  _SQ2 = _iqlocate_cursor(_Cn2, 0, 0);
#line 106 "lan_ip_month.ec"
  _iqcdcl(_SQ2, _Cn2, sqlcmdtxt, (struct sqlda *)0, (struct sqlda *)0, 32);
#line 106 "lan_ip_month.ec"
  }
/*
 *  $declare cur_w scroll cursor for
 * 	select rate_in,rate_out from ip_net where name="w";
 */
#line 107 "lan_ip_month.ec"
  {
#line 108 "lan_ip_month.ec"
  static const char *sqlcmdtxt[] =
#line 108 "lan_ip_month.ec"
    {
#line 108 "lan_ip_month.ec"
    " select rate_in , rate_out from ip_net where name = 'w'",
    0
    };
#line 108 "lan_ip_month.ec"
#line 108 "lan_ip_month.ec"
  _SQ3 = _iqlocate_cursor(_Cn3, 0, 0);
#line 108 "lan_ip_month.ec"
  _iqcdcl(_SQ3, _Cn3, sqlcmdtxt, (struct sqlda *)0, (struct sqlda *)0, 32);
#line 108 "lan_ip_month.ec"
  }

/*
 *  $open cur_n;
 */
#line 110 "lan_ip_month.ec"
  {
#line 110 "lan_ip_month.ec"
#line 110 "lan_ip_month.ec"
  _SQ2 = _iqlocate_cursor(_Cn2, 0, 0);
#line 110 "lan_ip_month.ec"
  _iqdcopen(_SQ2, (struct sqlda *)0, (char *)0, (char *)0, 0);
#line 110 "lan_ip_month.ec"
  }
/*
 *    $fetch first cur_n into $rn_in,$rn_out;
 */
#line 111 "lan_ip_month.ec"
  {
#line 111 "lan_ip_month.ec"
  static struct sqlvar_struct _sqobind[] = 
    {
      { 104, sizeof(rn_in), 0, 0, 0, 0, 0, 0, 0 },
      { 104, sizeof(rn_out), 0, 0, 0, 0, 0, 0, 0 },
#line 111 "lan_ip_month.ec"
    };
  static struct sqlda _SD0 = { 2, _sqobind, 0, 2, 0 };
  static _FetchSpec _FS1 = { 0, 3, 0 };
#line 111 "lan_ip_month.ec"
  _sqobind[0].sqldata = (char *) &rn_in;
#line 111 "lan_ip_month.ec"
  _sqobind[1].sqldata = (char *) &rn_out;
#line 111 "lan_ip_month.ec"
  _SQ2 = _iqlocate_cursor(_Cn2, 0, 0);
#line 111 "lan_ip_month.ec"
  _iqcftch(_SQ2, (struct sqlda *)0, &_SD0, (char *)0, &_FS1);
#line 111 "lan_ip_month.ec"
  }
   if (sqlca.sqlcode==100)
	{
	 printf("read n_rate error!\n");
/*
 * 	 $close cur_n;
 */
#line 115 "lan_ip_month.ec"
  {
#line 115 "lan_ip_month.ec"
#line 115 "lan_ip_month.ec"
  _SQ2 = _iqlocate_cursor(_Cn2, 0, 0);
#line 115 "lan_ip_month.ec"
  _iqclose(_SQ2);
#line 115 "lan_ip_month.ec"
  }
	 exit(-1);
	}
/*
 *  $close cur_n;
 */
#line 118 "lan_ip_month.ec"
  {
#line 118 "lan_ip_month.ec"
#line 118 "lan_ip_month.ec"
  _SQ2 = _iqlocate_cursor(_Cn2, 0, 0);
#line 118 "lan_ip_month.ec"
  _iqclose(_SQ2);
#line 118 "lan_ip_month.ec"
  }

/*
 *  $open cur_w;
 */
#line 120 "lan_ip_month.ec"
  {
#line 120 "lan_ip_month.ec"
#line 120 "lan_ip_month.ec"
  _SQ3 = _iqlocate_cursor(_Cn3, 0, 0);
#line 120 "lan_ip_month.ec"
  _iqdcopen(_SQ3, (struct sqlda *)0, (char *)0, (char *)0, 0);
#line 120 "lan_ip_month.ec"
  }
/*
 *    $fetch first cur_w into $rw_in,$rw_out;
 */
#line 121 "lan_ip_month.ec"
  {
#line 121 "lan_ip_month.ec"
  static struct sqlvar_struct _sqobind[] = 
    {
      { 104, sizeof(rw_in), 0, 0, 0, 0, 0, 0, 0 },
      { 104, sizeof(rw_out), 0, 0, 0, 0, 0, 0, 0 },
#line 121 "lan_ip_month.ec"
    };
  static struct sqlda _SD0 = { 2, _sqobind, 0, 2, 0 };
  static _FetchSpec _FS1 = { 0, 3, 0 };
#line 121 "lan_ip_month.ec"
  _sqobind[0].sqldata = (char *) &rw_in;
#line 121 "lan_ip_month.ec"
  _sqobind[1].sqldata = (char *) &rw_out;
#line 121 "lan_ip_month.ec"
  _SQ3 = _iqlocate_cursor(_Cn3, 0, 0);
#line 121 "lan_ip_month.ec"
  _iqcftch(_SQ3, (struct sqlda *)0, &_SD0, (char *)0, &_FS1);
#line 121 "lan_ip_month.ec"
  }
   if (sqlca.sqlcode==100)
	{
	 printf("read w_rate error!\n");
/*
 * 	 $close cur_w;
 */
#line 125 "lan_ip_month.ec"
  {
#line 125 "lan_ip_month.ec"
#line 125 "lan_ip_month.ec"
  _SQ3 = _iqlocate_cursor(_Cn3, 0, 0);
#line 125 "lan_ip_month.ec"
  _iqclose(_SQ3);
#line 125 "lan_ip_month.ec"
  }
	 exit(-1);
	}
/*
 *  $close cur_w;
 */
#line 128 "lan_ip_month.ec"
  {
#line 128 "lan_ip_month.ec"
#line 128 "lan_ip_month.ec"
  _SQ3 = _iqlocate_cursor(_Cn3, 0, 0);
#line 128 "lan_ip_month.ec"
  _iqclose(_SQ3);
#line 128 "lan_ip_month.ec"
  }
 printf(" get rate ok! \n<n_in=%5.1f n_out=%5.1f w_in=%5.1f w_out%5.1f>\n",rn_in,rn_out,rw_in,rw_out);
}

main(int argc, char *argv[])
{
	char command[150];
	long i1,i2,j;

	if (argc > 1)
	{
	 printf("get arg <%s>\n",argv[1]);
	 if (strcmp(argv[1],"m")==0)
	 {
	 }
	}

/*
 *  $database scs_internet@ONLINE;
 */
#line 145 "lan_ip_month.ec"
  {
#line 145 "lan_ip_month.ec"
  _iqdbase("scs_internet@ONLINE", 0);
#line 145 "lan_ip_month.ec"
  }
 checksql("database connect error!");

	get_rate();
	cacu_ip();	
}

⌨️ 快捷键说明

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