Changeset 157 for trunk

Show
Ignore:
Timestamp:
10/18/11 16:40:41 (11 years ago)
Author:
andreu
Message:

renetcol mib update

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/renetcolAgg.c

    r154 r157  
    11/* 
    22 * File: renetcolAgg.c 
    3  *  
    4  * Authors: ANDREU Francois-Xavier  
    53 * 
    6  * Copyright (C) 2007-2011 GIP RENATER  
     4 * Authors: ANDREU Francois-Xavier 
     5 * 
     6 * Copyright (C) 2007-2011 GIP RENATER 
    77 */ 
    88 
    9 /*  This file is part of renetcol.  
     9/*  This file is part of renetcol. 
    1010 * 
    1111 *  renetcol is free software; you can redistribute it and/or modify 
     
    2828 * the rrd files which contain the statistique for each subnet. 
    2929 * When your system is too fast and the number of your subnet too big 
    30  * (> 1024), the create and update process can be too fast and before the  
     30 * (> 1024), the create and update process can be too fast and before the 
    3131 * end of creation. So the maximum number of files which can be opened for one 
    3232 * process in the same time is reached and we must temporize. 
     
    4040main(int argc, char *argv[]) 
    4141{ 
    42   int shmid; 
    43   int i, j, k = 0; 
    44   int index = 1; 
    45   int rrd_update_er_ct = 0; 
    46   int rrd_update_ok_ct = 0; 
    47   int rrd_already_created_ct = 0; 
    48   int rrd_create_er_ct = 0; 
    49   int rrd_create_ok_ct = 0; 
    50   int isFirstUpdate = 1; 
    51   key_t key; 
    52   static char buf[2048]; 
    53   static char name[2048]; 
    54   static char ipStr[24]; 
     42    int shmid; 
     43    int i, j, k = 0; 
     44    int index = 1; 
     45    int rrd_update_er_ct = 0; 
     46    int rrd_update_ok_ct = 0; 
     47    int rrd_already_created_ct = 0; 
     48    int rrd_create_er_ct = 0; 
     49    int rrd_create_ok_ct = 0; 
     50    int isFirstUpdate = 1; 
     51    key_t key; 
     52    static char buf[2048]; 
     53    static char name[2048]; 
     54    static char ipStr[24]; 
    5555#ifdef IPV6LINKAGG 
    56   static char ipv6LinkStr[40]; /* 10_0_0_1_20_136 <router address> + <sampling> + <SNMP index> */ 
     56    static char ipv6LinkStr[40]; /* 10_0_0_1_20_136 <router address> + <sampling> + <SNMP index> */ 
    5757#endif 
    5858#if defined(MATRIX) && defined(IPV4AGGIDR) 
    59   static char indexStr[24]; 
     59    static char indexStr[24]; 
    6060#endif 
    61   static char asStr[7]; 
    62   static char createstr[2048]; 
    63   char *opt[27]; 
    64   char *optUpdate[3]; 
    65   FILE *fp; 
    66   static time_t now, now2; 
    67    
    68   key = 8765; 
    69   if ((shmid = shmget(key, SHMSIZE, 0666)) < 0) { 
    70     perror("shmget"); 
    71     exit(1); 
    72   } 
    73   if ((shmForAgg = (struct SHMForAgg *)shmat(shmid, (void *)0, 0)) == (void *) -1) { 
    74     perror("shmat"); 
    75     exit(1); 
    76   } 
    77    
    78   fprintf(stderr, "renetcolAgg: I become a deamon, next messages via syslogd. Bye.\n"); 
    79   if (fork () != 0) 
    80     exit (0); 
    81   if (setsid() == -1){ 
    82     exit(4); 
    83   } 
    84    
    85   do { 
    86     if (shmForAgg->readed == 1) { 
    87       shmForAgg->readed = 0; 
    88       if (shmForAgg->currentTable == 0) { 
    89         index = 1; 
    90       }else{ 
    91         index = 0; 
    92       } 
    93       now = time((time_t *)NULL); 
    94       if (isFirstUpdate == 0) { 
    95         /* RRD ACCOUNTING for prefixV4Tab */ 
    96         for (i=0; i<shmForAgg->v4PrefixNb; i++){ 
    97           /* HERE create or update RRD FILE */ 
    98           if (shmForAgg->prefixV4Tab[index][i].sampling != 0) { 
    99             for (j=0; j<strlen(name); j++) {name[j] = '\0';} 
    100             for (j=0; j<strlen(createstr); j++) {createstr[j] = '\0';} 
    101             for (j=0; j<strlen(ipStr); j++) {ipStr[j] = '\0';} 
    102             for (j=0; j<strlen(buf); j++) {buf[j] = '\0';} 
    103             strcat(name, PREFIX_RRD_LOCATION); 
    104             sprintf(ipStr, "%lu_%lu_%lu_%lu_%hu_%lu",  
    105                     shmForAgg->prefixV4Tab[index][i].beginning>>24, 
    106                     shmForAgg->prefixV4Tab[index][i].beginning<<8>>24, 
    107                     shmForAgg->prefixV4Tab[index][i].beginning<<16>>24, 
    108                     shmForAgg->prefixV4Tab[index][i].beginning<<24>>24, 
    109                     shmForAgg->prefixV4Tab[index][i].mask, 
    110                     shmForAgg->prefixV4Tab[index][i].sampling 
    111                     );  
    112             strcat(name, ipStr); 
    113             strcat(name, RRD_EXTENSION); 
    114             if ( (fp=fopen(name,"r")) == NULL ){ 
    115               opt[0]= (char *) malloc((strlen(RRD_PARAM_PREFIX_0) + 1) * sizeof(char)); 
    116               strcpy(opt[0], RRD_PARAM_PREFIX_0); 
    117               opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
    118               strcpy(opt[1], name); 
    119               opt[2]= (char *) malloc((strlen(RRD_PARAM_PREFIX_1) + 1) * sizeof(char)); 
    120               strcpy(opt[2], RRD_PARAM_PREFIX_1); 
    121               opt[3]= (char *) malloc((strlen(RRD_PARAM_PREFIX_2) + 1) * sizeof(char)); 
    122               strcpy(opt[3], RRD_PARAM_PREFIX_2); 
    123               opt[4]= (char *) malloc((strlen(RRD_PARAM_PREFIX_3) + 1) * sizeof(char)); 
    124               strcpy(opt[4], RRD_PARAM_PREFIX_3); 
    125               opt[5]= (char *) malloc((strlen(RRD_PARAM_PREFIX_4) + 1) * sizeof(char)); 
    126               strcpy(opt[5], RRD_PARAM_PREFIX_4); 
    127               opt[6]= (char *) malloc((strlen(RRD_PARAM_PREFIX_5) + 1) * sizeof(char)); 
    128               strcpy(opt[6], RRD_PARAM_PREFIX_5); 
    129               opt[7]= (char *) malloc((strlen(RRD_PARAM_PREFIX_6) + 1) * sizeof(char)); 
    130               strcpy(opt[7], RRD_PARAM_PREFIX_6); 
    131               opt[8]= (char *) malloc((strlen(RRD_PARAM_PREFIX_7) + 1) * sizeof(char)); 
    132               strcpy(opt[8], RRD_PARAM_PREFIX_7); 
    133               opt[9]= (char *) malloc((strlen(RRD_PARAM_PREFIX_8) + 1) * sizeof(char)); 
    134               strcpy(opt[9], RRD_PARAM_PREFIX_8); 
    135               opt[10]= (char *) malloc((strlen(RRD_PARAM_PREFIX_9) + 1) * sizeof(char)); 
    136               strcpy(opt[10], RRD_PARAM_PREFIX_9); 
    137               opt[11]= (char *) malloc((strlen(RRD_PARAM_PREFIX_10) + 1) * sizeof(char)); 
    138               strcpy(opt[11], RRD_PARAM_PREFIX_10); 
    139               opt[12]= (char *) malloc((strlen(RRD_PARAM_PREFIX_11) + 1) * sizeof(char)); 
    140               strcpy(opt[12], RRD_PARAM_PREFIX_11); 
    141               opt[13]= (char *) malloc((strlen(RRD_PARAM_PREFIX_12) + 1) * sizeof(char)); 
    142               strcpy(opt[13], RRD_PARAM_PREFIX_12); 
    143               opt[14]= (char *) malloc((strlen(RRD_PARAM_PREFIX_13) + 1) * sizeof(char)); 
    144               strcpy(opt[14], RRD_PARAM_PREFIX_13); 
    145               opt[15]= (char *) malloc((strlen(RRD_PARAM_PREFIX_14) + 1) * sizeof(char)); 
    146               strcpy(opt[15], RRD_PARAM_PREFIX_14); 
    147               opt[16]= (char *) malloc((strlen(RRD_PARAM_PREFIX_15) + 1) * sizeof(char)); 
    148               strcpy(opt[16], RRD_PARAM_PREFIX_15); 
    149               opt[17]= (char *) malloc((strlen(RRD_PARAM_PREFIX_16) + 1) * sizeof(char)); 
    150               strcpy(opt[17], RRD_PARAM_PREFIX_16); 
    151               opt[18]= (char *) malloc((strlen(RRD_PARAM_PREFIX_17) + 1) * sizeof(char)); 
    152               strcpy(opt[18], RRD_PARAM_PREFIX_17); 
    153               opt[19]= (char *) malloc((strlen(RRD_PARAM_PREFIX_18) + 1) * sizeof(char)); 
    154               strcpy(opt[19], RRD_PARAM_PREFIX_18); 
    155               opt[20]= (char *) malloc((strlen(RRD_PARAM_PREFIX_19) + 1) * sizeof(char)); 
    156               strcpy(opt[20], RRD_PARAM_PREFIX_19); 
    157               opt[21]= (char *) malloc((strlen(RRD_PARAM_PREFIX_20) + 1) * sizeof(char)); 
    158               strcpy(opt[21], RRD_PARAM_PREFIX_20); 
    159               opt[22]= (char *) malloc((strlen(RRD_PARAM_PREFIX_21) + 1) * sizeof(char)); 
    160               strcpy(opt[22], RRD_PARAM_PREFIX_21); 
    161               opt[23]= (char *) malloc((strlen(RRD_PARAM_PREFIX_22) + 1) * sizeof(char)); 
    162               strcpy(opt[23], RRD_PARAM_PREFIX_22); 
    163               opt[24]= (char *) malloc((strlen(RRD_PARAM_PREFIX_23) + 1) * sizeof(char)); 
    164               strcpy(opt[24], RRD_PARAM_PREFIX_23); 
    165               opt[25]= (char *) malloc((strlen(RRD_PARAM_PREFIX_24) + 1) * sizeof(char)); 
    166               strcpy(opt[25], RRD_PARAM_PREFIX_24); 
    167               opt[26]= (char *) malloc((strlen(RRD_PARAM_PREFIX_25) + 1) * sizeof(char)); 
    168               strcpy(opt[26], RRD_PARAM_PREFIX_25); 
    169               optind = opterr = 0; 
    170               rrd_clear_error(); 
    171               if ( rrd_create(27,opt) < 0) { 
    172                 syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
    173                 rrd_create_er_ct++; 
    174               } else { 
    175                 rrd_create_ok_ct++; 
    176               } 
    177               for ( j=0; j<27; j++) { 
    178                 free(opt[j]); 
    179                 opt[j] = NULL; 
    180               } 
    181             }else{  
    182               fclose(fp); 
    183               rrd_already_created_ct++; 
    184               snprintf(buf,  
    185                        2048,  
    186                        "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",   
    187                        now-300,  /* or ctime(&now) with %s */ 
    188                        shmForAgg->prefixV4Tab[index][i].flowNbIN,  /* 1 */ 
    189                        shmForAgg->prefixV4Tab[index][i].flowNbOUT, 
    190                        shmForAgg->prefixV4Tab[index][i].bytesNbIN, 
    191                        shmForAgg->prefixV4Tab[index][i].bytesNbOUT, 
    192                        shmForAgg->prefixV4Tab[index][i].pktsNbIN,  /* 5 */ 
    193                        shmForAgg->prefixV4Tab[index][i].pktsNbOUT, 
    194                        shmForAgg->prefixV4Tab[index][i].firstCoSIN, 
    195                        shmForAgg->prefixV4Tab[index][i].firstCoSOUT, 
    196                        shmForAgg->prefixV4Tab[index][i].secondCoSIN, 
    197                        shmForAgg->prefixV4Tab[index][i].secondCoSOUT, 
    198                        shmForAgg->prefixV4Tab[index][i].thirdCoSIN, 
    199                        shmForAgg->prefixV4Tab[index][i].thirdCoSOUT, 
    200                        shmForAgg->prefixV4Tab[index][i].fourthCoSIN, 
    201                        shmForAgg->prefixV4Tab[index][i].fourthCoSOUT 
    202                        ); 
    203               optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
    204               strcpy(optUpdate[0], RRD_UPDATE_0); 
    205               optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
    206               strcpy(optUpdate[1], name); 
    207               optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
    208               strcpy(optUpdate[2], buf); 
    209               optind = opterr = 0;  
    210               rrd_clear_error(); 
    211               if ( rrd_update(3, optUpdate) < 0 ) {  
    212                 syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
    213                 rrd_update_er_ct++; 
    214               } else { 
    215                 rrd_update_ok_ct++; 
    216               } 
    217               for ( j=0; j<3; j++) { 
    218                 free(optUpdate[j]); 
    219                 optUpdate[j] = NULL; 
    220               } 
    221             } 
    222             /* Reinit the shared tables */ 
    223             shmForAgg->prefixV4Tab[index][i].flowNbIN = 0; 
    224             shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0; 
    225             shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0; 
    226             shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0; 
    227             shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0; 
    228             shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0; 
    229             shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0; 
    230             shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0; 
    231             shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0; 
    232             shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0; 
    233             shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0; 
    234             shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0; 
    235             shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0; 
    236             shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0; 
    237           } 
    238         } 
    239         /* ACCOUNTING for prefixV4SubnetTab */ 
    240         for (i=0; i<shmForAgg->v4SubnetNb; i++){ 
    241           /* HERE create or update RRD FILE */ 
    242           if (shmForAgg->prefixV4SubnetTab[index][i].sampling != 0) { 
    243             for (j=0; j<strlen(name); j++) {name[j] = '\0';} 
    244             for (j=0; j<strlen(createstr); j++) {createstr[j] = '\0';} 
    245             for (j=0; j<strlen(ipStr); j++) {ipStr[j] = '\0';} 
    246             for (j=0; j<strlen(buf); j++) {buf[j] = '\0';} 
    247             strcat(name, PREFIX_RRD_LOCATION); 
    248             sprintf(ipStr, "%lu_%lu_%lu_%lu_%hu_%lu",  
    249                     shmForAgg->prefixV4SubnetTab[index][i].beginning>>24, 
    250                     shmForAgg->prefixV4SubnetTab[index][i].beginning<<8>>24, 
    251                     shmForAgg->prefixV4SubnetTab[index][i].beginning<<16>>24, 
    252                     shmForAgg->prefixV4SubnetTab[index][i].beginning<<24>>24, 
    253                     shmForAgg->prefixV4SubnetTab[index][i].mask, 
    254                     shmForAgg->prefixV4SubnetTab[index][i].sampling 
    255                     );  
    256             strcat(name, ipStr); 
    257             strcat(name, RRD_EXTENSION); 
    258             if ( (fp=fopen(name,"r")) == NULL ){ 
    259               opt[0]= (char *) malloc((strlen(RRD_PARAM_PREFIX_0) + 1) * sizeof(char)); 
    260               strcpy(opt[0], RRD_PARAM_PREFIX_0); 
    261               opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
    262               strcpy(opt[1], name); 
    263               opt[2]= (char *) malloc((strlen(RRD_PARAM_PREFIX_1) + 1) * sizeof(char)); 
    264               strcpy(opt[2], RRD_PARAM_PREFIX_1); 
    265               opt[3]= (char *) malloc((strlen(RRD_PARAM_PREFIX_2) + 1) * sizeof(char)); 
    266               strcpy(opt[3], RRD_PARAM_PREFIX_2); 
    267               opt[4]= (char *) malloc((strlen(RRD_PARAM_PREFIX_3) + 1) * sizeof(char)); 
    268               strcpy(opt[4], RRD_PARAM_PREFIX_3); 
    269               opt[5]= (char *) malloc((strlen(RRD_PARAM_PREFIX_4) + 1) * sizeof(char)); 
    270               strcpy(opt[5], RRD_PARAM_PREFIX_4); 
    271               opt[6]= (char *) malloc((strlen(RRD_PARAM_PREFIX_5) + 1) * sizeof(char)); 
    272               strcpy(opt[6], RRD_PARAM_PREFIX_5); 
    273               opt[7]= (char *) malloc((strlen(RRD_PARAM_PREFIX_6) + 1) * sizeof(char)); 
    274               strcpy(opt[7], RRD_PARAM_PREFIX_6); 
    275               opt[8]= (char *) malloc((strlen(RRD_PARAM_PREFIX_7) + 1) * sizeof(char)); 
    276               strcpy(opt[8], RRD_PARAM_PREFIX_7); 
    277               opt[9]= (char *) malloc((strlen(RRD_PARAM_PREFIX_8) + 1) * sizeof(char)); 
    278               strcpy(opt[9], RRD_PARAM_PREFIX_8); 
    279               opt[10]= (char *) malloc((strlen(RRD_PARAM_PREFIX_9) + 1) * sizeof(char)); 
    280               strcpy(opt[10], RRD_PARAM_PREFIX_9); 
    281               opt[11]= (char *) malloc((strlen(RRD_PARAM_PREFIX_10) + 1) * sizeof(char)); 
    282               strcpy(opt[11], RRD_PARAM_PREFIX_10); 
    283               opt[12]= (char *) malloc((strlen(RRD_PARAM_PREFIX_11) + 1) * sizeof(char)); 
    284               strcpy(opt[12], RRD_PARAM_PREFIX_11); 
    285               opt[13]= (char *) malloc((strlen(RRD_PARAM_PREFIX_12) + 1) * sizeof(char)); 
    286               strcpy(opt[13], RRD_PARAM_PREFIX_12); 
    287               opt[14]= (char *) malloc((strlen(RRD_PARAM_PREFIX_13) + 1) * sizeof(char)); 
    288               strcpy(opt[14], RRD_PARAM_PREFIX_13); 
    289               opt[15]= (char *) malloc((strlen(RRD_PARAM_PREFIX_14) + 1) * sizeof(char)); 
    290               strcpy(opt[15], RRD_PARAM_PREFIX_14); 
    291               opt[16]= (char *) malloc((strlen(RRD_PARAM_PREFIX_15) + 1) * sizeof(char)); 
    292               strcpy(opt[16], RRD_PARAM_PREFIX_15); 
    293               opt[17]= (char *) malloc((strlen(RRD_PARAM_PREFIX_16) + 1) * sizeof(char)); 
    294               strcpy(opt[17], RRD_PARAM_PREFIX_16); 
    295               opt[18]= (char *) malloc((strlen(RRD_PARAM_PREFIX_17) + 1) * sizeof(char)); 
    296               strcpy(opt[18], RRD_PARAM_PREFIX_17); 
    297               opt[19]= (char *) malloc((strlen(RRD_PARAM_PREFIX_18) + 1) * sizeof(char)); 
    298               strcpy(opt[19], RRD_PARAM_PREFIX_18); 
    299               opt[20]= (char *) malloc((strlen(RRD_PARAM_PREFIX_19) + 1) * sizeof(char)); 
    300               strcpy(opt[20], RRD_PARAM_PREFIX_19); 
    301               opt[21]= (char *) malloc((strlen(RRD_PARAM_PREFIX_20) + 1) * sizeof(char)); 
    302               strcpy(opt[21], RRD_PARAM_PREFIX_20); 
    303               opt[22]= (char *) malloc((strlen(RRD_PARAM_PREFIX_21) + 1) * sizeof(char)); 
    304               strcpy(opt[22], RRD_PARAM_PREFIX_21); 
    305               opt[23]= (char *) malloc((strlen(RRD_PARAM_PREFIX_22) + 1) * sizeof(char)); 
    306               strcpy(opt[23], RRD_PARAM_PREFIX_22); 
    307               opt[24]= (char *) malloc((strlen(RRD_PARAM_PREFIX_23) + 1) * sizeof(char)); 
    308               strcpy(opt[24], RRD_PARAM_PREFIX_23); 
    309               opt[25]= (char *) malloc((strlen(RRD_PARAM_PREFIX_24) + 1) * sizeof(char)); 
    310               strcpy(opt[25], RRD_PARAM_PREFIX_24); 
    311               opt[26]= (char *) malloc((strlen(RRD_PARAM_PREFIX_25) + 1) * sizeof(char)); 
    312               strcpy(opt[26], RRD_PARAM_PREFIX_25); 
    313               optind = opterr = 0; 
    314               rrd_clear_error(); 
    315               if ( rrd_create(27,opt) < 0) { 
    316                 syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
    317                 rrd_create_er_ct++; 
    318               } else { 
    319                 rrd_create_ok_ct++; 
    320               } 
    321               for ( j=0; j<27; j++) { 
    322                 free(opt[j]); 
    323                 opt[j] = NULL; 
    324               } 
    325             }else{  
    326               fclose(fp); 
    327               rrd_already_created_ct++; 
    328               snprintf(buf,  
    329                        2048,  
    330                        "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",   
    331                        now-300,  /* or ctime(&now) with %s */ 
    332                        shmForAgg->prefixV4SubnetTab[index][i].flowNbIN,  /* 1 */ 
    333                        shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT, 
    334                        shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN, 
    335                        shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT, 
    336                        shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN,  /* 5 */ 
    337                        shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT, 
    338                        shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN, 
    339                        shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT, 
    340                        shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN, 
    341                        shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT, 
    342                        shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN, 
    343                        shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT, 
    344                        shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN, 
    345                        shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT 
    346                        ); 
    347               optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
    348               strcpy(optUpdate[0], RRD_UPDATE_0); 
    349               optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
    350               strcpy(optUpdate[1], name); 
    351               optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
    352               strcpy(optUpdate[2], buf); 
    353               optind = opterr = 0;  
    354               rrd_clear_error(); 
    355               if ( rrd_update(3, optUpdate) < 0 ) {  
    356                 syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
    357                 rrd_update_er_ct++; 
    358               } else { 
    359                 rrd_update_ok_ct++; 
    360               } 
    361               for ( j=0; j<3; j++) { 
    362                 free(optUpdate[j]); 
    363                 optUpdate[j] = NULL; 
    364               } 
    365             } 
    366             /* Reinit the shared tables */ 
    367             shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0; 
    368             shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0; 
    369             shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0; 
    370             shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0; 
    371             shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0; 
    372             shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0; 
    373             shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0; 
    374             shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0; 
    375             shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0; 
    376             shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0; 
    377             shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0; 
    378             shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0; 
    379             shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0; 
    380             shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0; 
    381           } 
    382         } 
     61    static char asStr[7]; 
     62    static char createstr[2048]; 
     63    char *opt[27]; 
     64    char *optUpdate[3]; 
     65    FILE *fp; 
     66    static time_t now, now2; 
     67 
     68    key = 8765; 
     69    if ((shmid = shmget(key, SHMSIZE, 0666)) < 0) 
     70    { 
     71        perror("shmget"); 
     72        exit(1); 
     73    } 
     74    if ((shmForAgg = (struct SHMForAgg *)shmat(shmid, (void *)0, 0)) == (void *) -1) 
     75    { 
     76        perror("shmat"); 
     77        exit(1); 
     78    } 
     79 
     80    fprintf(stderr, "renetcolAgg: I become a deamon, next messages via syslogd. Bye.\n"); 
     81    if (fork () != 0) 
     82        exit (0); 
     83    if (setsid() == -1) 
     84    { 
     85        exit(4); 
     86    } 
     87 
     88    do 
     89    { 
     90        if (shmForAgg->readed == 1) 
     91        { 
     92            shmForAgg->readed = 0; 
     93            if (shmForAgg->currentTable == 0) 
     94            { 
     95                index = 1; 
     96            } 
     97            else 
     98            { 
     99                index = 0; 
     100            } 
     101            now = time((time_t *)NULL); 
     102            if (isFirstUpdate == 0) 
     103            { 
     104                /* RRD ACCOUNTING for prefixV4Tab */ 
     105                for (i=0; i<shmForAgg->v4PrefixNb; i++) 
     106                { 
     107                    /* HERE create or update RRD FILE */ 
     108                    if (shmForAgg->prefixV4Tab[index][i].sampling != 0) 
     109                    { 
     110                        for (j=0; j<strlen(name); j++) 
     111                        { 
     112                            name[j] = '\0'; 
     113                        } 
     114                        for (j=0; j<strlen(createstr); j++) 
     115                        { 
     116                            createstr[j] = '\0'; 
     117                        } 
     118                        for (j=0; j<strlen(ipStr); j++) 
     119                        { 
     120                            ipStr[j] = '\0'; 
     121                        } 
     122                        for (j=0; j<strlen(buf); j++) 
     123                        { 
     124                            buf[j] = '\0'; 
     125                        } 
     126                        strcat(name, PREFIX_RRD_LOCATION); 
     127                        sprintf(ipStr, "%lu_%lu_%lu_%lu_%hu_%lu", 
     128                                shmForAgg->prefixV4Tab[index][i].beginning>>24, 
     129                                shmForAgg->prefixV4Tab[index][i].beginning<<8>>24, 
     130                                shmForAgg->prefixV4Tab[index][i].beginning<<16>>24, 
     131                                shmForAgg->prefixV4Tab[index][i].beginning<<24>>24, 
     132                                shmForAgg->prefixV4Tab[index][i].mask, 
     133                                shmForAgg->prefixV4Tab[index][i].sampling 
     134                               ); 
     135                        strcat(name, ipStr); 
     136                        strcat(name, RRD_EXTENSION); 
     137                        if ( (fp=fopen(name,"r")) == NULL ) 
     138                        { 
     139                            opt[0]= (char *) malloc((strlen(RRD_PARAM_PREFIX_0) + 1) * sizeof(char)); 
     140                            strcpy(opt[0], RRD_PARAM_PREFIX_0); 
     141                            opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     142                            strcpy(opt[1], name); 
     143                            opt[2]= (char *) malloc((strlen(RRD_PARAM_PREFIX_1) + 1) * sizeof(char)); 
     144                            strcpy(opt[2], RRD_PARAM_PREFIX_1); 
     145                            opt[3]= (char *) malloc((strlen(RRD_PARAM_PREFIX_2) + 1) * sizeof(char)); 
     146                            strcpy(opt[3], RRD_PARAM_PREFIX_2); 
     147                            opt[4]= (char *) malloc((strlen(RRD_PARAM_PREFIX_3) + 1) * sizeof(char)); 
     148                            strcpy(opt[4], RRD_PARAM_PREFIX_3); 
     149                            opt[5]= (char *) malloc((strlen(RRD_PARAM_PREFIX_4) + 1) * sizeof(char)); 
     150                            strcpy(opt[5], RRD_PARAM_PREFIX_4); 
     151                            opt[6]= (char *) malloc((strlen(RRD_PARAM_PREFIX_5) + 1) * sizeof(char)); 
     152                            strcpy(opt[6], RRD_PARAM_PREFIX_5); 
     153                            opt[7]= (char *) malloc((strlen(RRD_PARAM_PREFIX_6) + 1) * sizeof(char)); 
     154                            strcpy(opt[7], RRD_PARAM_PREFIX_6); 
     155                            opt[8]= (char *) malloc((strlen(RRD_PARAM_PREFIX_7) + 1) * sizeof(char)); 
     156                            strcpy(opt[8], RRD_PARAM_PREFIX_7); 
     157                            opt[9]= (char *) malloc((strlen(RRD_PARAM_PREFIX_8) + 1) * sizeof(char)); 
     158                            strcpy(opt[9], RRD_PARAM_PREFIX_8); 
     159                            opt[10]= (char *) malloc((strlen(RRD_PARAM_PREFIX_9) + 1) * sizeof(char)); 
     160                            strcpy(opt[10], RRD_PARAM_PREFIX_9); 
     161                            opt[11]= (char *) malloc((strlen(RRD_PARAM_PREFIX_10) + 1) * sizeof(char)); 
     162                            strcpy(opt[11], RRD_PARAM_PREFIX_10); 
     163                            opt[12]= (char *) malloc((strlen(RRD_PARAM_PREFIX_11) + 1) * sizeof(char)); 
     164                            strcpy(opt[12], RRD_PARAM_PREFIX_11); 
     165                            opt[13]= (char *) malloc((strlen(RRD_PARAM_PREFIX_12) + 1) * sizeof(char)); 
     166                            strcpy(opt[13], RRD_PARAM_PREFIX_12); 
     167                            opt[14]= (char *) malloc((strlen(RRD_PARAM_PREFIX_13) + 1) * sizeof(char)); 
     168                            strcpy(opt[14], RRD_PARAM_PREFIX_13); 
     169                            opt[15]= (char *) malloc((strlen(RRD_PARAM_PREFIX_14) + 1) * sizeof(char)); 
     170                            strcpy(opt[15], RRD_PARAM_PREFIX_14); 
     171                            opt[16]= (char *) malloc((strlen(RRD_PARAM_PREFIX_15) + 1) * sizeof(char)); 
     172                            strcpy(opt[16], RRD_PARAM_PREFIX_15); 
     173                            opt[17]= (char *) malloc((strlen(RRD_PARAM_PREFIX_16) + 1) * sizeof(char)); 
     174                            strcpy(opt[17], RRD_PARAM_PREFIX_16); 
     175                            opt[18]= (char *) malloc((strlen(RRD_PARAM_PREFIX_17) + 1) * sizeof(char)); 
     176                            strcpy(opt[18], RRD_PARAM_PREFIX_17); 
     177                            opt[19]= (char *) malloc((strlen(RRD_PARAM_PREFIX_18) + 1) * sizeof(char)); 
     178                            strcpy(opt[19], RRD_PARAM_PREFIX_18); 
     179                            opt[20]= (char *) malloc((strlen(RRD_PARAM_PREFIX_19) + 1) * sizeof(char)); 
     180                            strcpy(opt[20], RRD_PARAM_PREFIX_19); 
     181                            opt[21]= (char *) malloc((strlen(RRD_PARAM_PREFIX_20) + 1) * sizeof(char)); 
     182                            strcpy(opt[21], RRD_PARAM_PREFIX_20); 
     183                            opt[22]= (char *) malloc((strlen(RRD_PARAM_PREFIX_21) + 1) * sizeof(char)); 
     184                            strcpy(opt[22], RRD_PARAM_PREFIX_21); 
     185                            opt[23]= (char *) malloc((strlen(RRD_PARAM_PREFIX_22) + 1) * sizeof(char)); 
     186                            strcpy(opt[23], RRD_PARAM_PREFIX_22); 
     187                            opt[24]= (char *) malloc((strlen(RRD_PARAM_PREFIX_23) + 1) * sizeof(char)); 
     188                            strcpy(opt[24], RRD_PARAM_PREFIX_23); 
     189                            opt[25]= (char *) malloc((strlen(RRD_PARAM_PREFIX_24) + 1) * sizeof(char)); 
     190                            strcpy(opt[25], RRD_PARAM_PREFIX_24); 
     191                            opt[26]= (char *) malloc((strlen(RRD_PARAM_PREFIX_25) + 1) * sizeof(char)); 
     192                            strcpy(opt[26], RRD_PARAM_PREFIX_25); 
     193                            optind = opterr = 0; 
     194                            rrd_clear_error(); 
     195                            if ( rrd_create(27,opt) < 0) 
     196                            { 
     197                                syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
     198                                rrd_create_er_ct++; 
     199                            } 
     200                            else 
     201                            { 
     202                                rrd_create_ok_ct++; 
     203                            } 
     204                            for ( j=0; j<27; j++) 
     205                            { 
     206                                free(opt[j]); 
     207                                opt[j] = NULL; 
     208                            } 
     209                        } 
     210                        else 
     211                        { 
     212                            fclose(fp); 
     213                            rrd_already_created_ct++; 
     214                            snprintf(buf, 
     215                                     2048, 
     216                                     "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu", 
     217                                     now-300,  /* or ctime(&now) with %s */ 
     218                                     shmForAgg->prefixV4Tab[index][i].flowNbIN,  /* 1 */ 
     219                                     shmForAgg->prefixV4Tab[index][i].flowNbOUT, 
     220                                     shmForAgg->prefixV4Tab[index][i].bytesNbIN, 
     221                                     shmForAgg->prefixV4Tab[index][i].bytesNbOUT, 
     222                                     shmForAgg->prefixV4Tab[index][i].pktsNbIN,  /* 5 */ 
     223                                     shmForAgg->prefixV4Tab[index][i].pktsNbOUT, 
     224                                     shmForAgg->prefixV4Tab[index][i].firstCoSIN, 
     225                                     shmForAgg->prefixV4Tab[index][i].firstCoSOUT, 
     226                                     shmForAgg->prefixV4Tab[index][i].secondCoSIN, 
     227                                     shmForAgg->prefixV4Tab[index][i].secondCoSOUT, 
     228                                     shmForAgg->prefixV4Tab[index][i].thirdCoSIN, 
     229                                     shmForAgg->prefixV4Tab[index][i].thirdCoSOUT, 
     230                                     shmForAgg->prefixV4Tab[index][i].fourthCoSIN, 
     231                                     shmForAgg->prefixV4Tab[index][i].fourthCoSOUT 
     232                                    ); 
     233                            optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
     234                            strcpy(optUpdate[0], RRD_UPDATE_0); 
     235                            optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     236                            strcpy(optUpdate[1], name); 
     237                            optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
     238                            strcpy(optUpdate[2], buf); 
     239                            optind = opterr = 0; 
     240                            rrd_clear_error(); 
     241                            if ( rrd_update(3, optUpdate) < 0 ) 
     242                            { 
     243                                syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
     244                                rrd_update_er_ct++; 
     245                            } 
     246                            else 
     247                            { 
     248                                rrd_update_ok_ct++; 
     249                            } 
     250                            for ( j=0; j<3; j++) 
     251                            { 
     252                                free(optUpdate[j]); 
     253                                optUpdate[j] = NULL; 
     254                            } 
     255                        } 
     256                        /* Reinit the shared tables */ 
     257                        shmForAgg->prefixV4Tab[index][i].flowNbIN = 0; 
     258                        shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0; 
     259                        shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0; 
     260                        shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0; 
     261                        shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0; 
     262                        shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0; 
     263                        shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0; 
     264                        shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0; 
     265                        shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0; 
     266                        shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0; 
     267                        shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0; 
     268                        shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0; 
     269                        shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0; 
     270                        shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0; 
     271                    } 
     272                } 
     273                /* ACCOUNTING for prefixV4SubnetTab */ 
     274                for (i=0; i<shmForAgg->v4SubnetNb; i++) 
     275                { 
     276                    /* HERE create or update RRD FILE */ 
     277                    if (shmForAgg->prefixV4SubnetTab[index][i].sampling != 0) 
     278                    { 
     279                        for (j=0; j<strlen(name); j++) 
     280                        { 
     281                            name[j] = '\0'; 
     282                        } 
     283                        for (j=0; j<strlen(createstr); j++) 
     284                        { 
     285                            createstr[j] = '\0'; 
     286                        } 
     287                        for (j=0; j<strlen(ipStr); j++) 
     288                        { 
     289                            ipStr[j] = '\0'; 
     290                        } 
     291                        for (j=0; j<strlen(buf); j++) 
     292                        { 
     293                            buf[j] = '\0'; 
     294                        } 
     295                        strcat(name, PREFIX_RRD_LOCATION); 
     296                        sprintf(ipStr, "%lu_%lu_%lu_%lu_%hu_%lu", 
     297                                shmForAgg->prefixV4SubnetTab[index][i].beginning>>24, 
     298                                shmForAgg->prefixV4SubnetTab[index][i].beginning<<8>>24, 
     299                                shmForAgg->prefixV4SubnetTab[index][i].beginning<<16>>24, 
     300                                shmForAgg->prefixV4SubnetTab[index][i].beginning<<24>>24, 
     301                                shmForAgg->prefixV4SubnetTab[index][i].mask, 
     302                                shmForAgg->prefixV4SubnetTab[index][i].sampling 
     303                               ); 
     304                        strcat(name, ipStr); 
     305                        strcat(name, RRD_EXTENSION); 
     306                        if ( (fp=fopen(name,"r")) == NULL ) 
     307                        { 
     308                            opt[0]= (char *) malloc((strlen(RRD_PARAM_PREFIX_0) + 1) * sizeof(char)); 
     309                            strcpy(opt[0], RRD_PARAM_PREFIX_0); 
     310                            opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     311                            strcpy(opt[1], name); 
     312                            opt[2]= (char *) malloc((strlen(RRD_PARAM_PREFIX_1) + 1) * sizeof(char)); 
     313                            strcpy(opt[2], RRD_PARAM_PREFIX_1); 
     314                            opt[3]= (char *) malloc((strlen(RRD_PARAM_PREFIX_2) + 1) * sizeof(char)); 
     315                            strcpy(opt[3], RRD_PARAM_PREFIX_2); 
     316                            opt[4]= (char *) malloc((strlen(RRD_PARAM_PREFIX_3) + 1) * sizeof(char)); 
     317                            strcpy(opt[4], RRD_PARAM_PREFIX_3); 
     318                            opt[5]= (char *) malloc((strlen(RRD_PARAM_PREFIX_4) + 1) * sizeof(char)); 
     319                            strcpy(opt[5], RRD_PARAM_PREFIX_4); 
     320                            opt[6]= (char *) malloc((strlen(RRD_PARAM_PREFIX_5) + 1) * sizeof(char)); 
     321                            strcpy(opt[6], RRD_PARAM_PREFIX_5); 
     322                            opt[7]= (char *) malloc((strlen(RRD_PARAM_PREFIX_6) + 1) * sizeof(char)); 
     323                            strcpy(opt[7], RRD_PARAM_PREFIX_6); 
     324                            opt[8]= (char *) malloc((strlen(RRD_PARAM_PREFIX_7) + 1) * sizeof(char)); 
     325                            strcpy(opt[8], RRD_PARAM_PREFIX_7); 
     326                            opt[9]= (char *) malloc((strlen(RRD_PARAM_PREFIX_8) + 1) * sizeof(char)); 
     327                            strcpy(opt[9], RRD_PARAM_PREFIX_8); 
     328                            opt[10]= (char *) malloc((strlen(RRD_PARAM_PREFIX_9) + 1) * sizeof(char)); 
     329                            strcpy(opt[10], RRD_PARAM_PREFIX_9); 
     330                            opt[11]= (char *) malloc((strlen(RRD_PARAM_PREFIX_10) + 1) * sizeof(char)); 
     331                            strcpy(opt[11], RRD_PARAM_PREFIX_10); 
     332                            opt[12]= (char *) malloc((strlen(RRD_PARAM_PREFIX_11) + 1) * sizeof(char)); 
     333                            strcpy(opt[12], RRD_PARAM_PREFIX_11); 
     334                            opt[13]= (char *) malloc((strlen(RRD_PARAM_PREFIX_12) + 1) * sizeof(char)); 
     335                            strcpy(opt[13], RRD_PARAM_PREFIX_12); 
     336                            opt[14]= (char *) malloc((strlen(RRD_PARAM_PREFIX_13) + 1) * sizeof(char)); 
     337                            strcpy(opt[14], RRD_PARAM_PREFIX_13); 
     338                            opt[15]= (char *) malloc((strlen(RRD_PARAM_PREFIX_14) + 1) * sizeof(char)); 
     339                            strcpy(opt[15], RRD_PARAM_PREFIX_14); 
     340                            opt[16]= (char *) malloc((strlen(RRD_PARAM_PREFIX_15) + 1) * sizeof(char)); 
     341                            strcpy(opt[16], RRD_PARAM_PREFIX_15); 
     342                            opt[17]= (char *) malloc((strlen(RRD_PARAM_PREFIX_16) + 1) * sizeof(char)); 
     343                            strcpy(opt[17], RRD_PARAM_PREFIX_16); 
     344                            opt[18]= (char *) malloc((strlen(RRD_PARAM_PREFIX_17) + 1) * sizeof(char)); 
     345                            strcpy(opt[18], RRD_PARAM_PREFIX_17); 
     346                            opt[19]= (char *) malloc((strlen(RRD_PARAM_PREFIX_18) + 1) * sizeof(char)); 
     347                            strcpy(opt[19], RRD_PARAM_PREFIX_18); 
     348                            opt[20]= (char *) malloc((strlen(RRD_PARAM_PREFIX_19) + 1) * sizeof(char)); 
     349                            strcpy(opt[20], RRD_PARAM_PREFIX_19); 
     350                            opt[21]= (char *) malloc((strlen(RRD_PARAM_PREFIX_20) + 1) * sizeof(char)); 
     351                            strcpy(opt[21], RRD_PARAM_PREFIX_20); 
     352                            opt[22]= (char *) malloc((strlen(RRD_PARAM_PREFIX_21) + 1) * sizeof(char)); 
     353                            strcpy(opt[22], RRD_PARAM_PREFIX_21); 
     354                            opt[23]= (char *) malloc((strlen(RRD_PARAM_PREFIX_22) + 1) * sizeof(char)); 
     355                            strcpy(opt[23], RRD_PARAM_PREFIX_22); 
     356                            opt[24]= (char *) malloc((strlen(RRD_PARAM_PREFIX_23) + 1) * sizeof(char)); 
     357                            strcpy(opt[24], RRD_PARAM_PREFIX_23); 
     358                            opt[25]= (char *) malloc((strlen(RRD_PARAM_PREFIX_24) + 1) * sizeof(char)); 
     359                            strcpy(opt[25], RRD_PARAM_PREFIX_24); 
     360                            opt[26]= (char *) malloc((strlen(RRD_PARAM_PREFIX_25) + 1) * sizeof(char)); 
     361                            strcpy(opt[26], RRD_PARAM_PREFIX_25); 
     362                            optind = opterr = 0; 
     363                            rrd_clear_error(); 
     364                            if ( rrd_create(27,opt) < 0) 
     365                            { 
     366                                syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
     367                                rrd_create_er_ct++; 
     368                            } 
     369                            else 
     370                            { 
     371                                rrd_create_ok_ct++; 
     372                            } 
     373                            for ( j=0; j<27; j++) 
     374                            { 
     375                                free(opt[j]); 
     376                                opt[j] = NULL; 
     377                            } 
     378                        } 
     379                        else 
     380                        { 
     381                            fclose(fp); 
     382                            rrd_already_created_ct++; 
     383                            snprintf(buf, 
     384                                     2048, 
     385                                     "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu", 
     386                                     now-300,  /* or ctime(&now) with %s */ 
     387                                     shmForAgg->prefixV4SubnetTab[index][i].flowNbIN,  /* 1 */ 
     388                                     shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT, 
     389                                     shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN, 
     390                                     shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT, 
     391                                     shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN,  /* 5 */ 
     392                                     shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT, 
     393                                     shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN, 
     394                                     shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT, 
     395                                     shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN, 
     396                                     shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT, 
     397                                     shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN, 
     398                                     shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT, 
     399                                     shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN, 
     400                                     shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT 
     401                                    ); 
     402                            optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
     403                            strcpy(optUpdate[0], RRD_UPDATE_0); 
     404                            optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     405                            strcpy(optUpdate[1], name); 
     406                            optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
     407                            strcpy(optUpdate[2], buf); 
     408                            optind = opterr = 0; 
     409                            rrd_clear_error(); 
     410                            if ( rrd_update(3, optUpdate) < 0 ) 
     411                            { 
     412                                syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
     413                                rrd_update_er_ct++; 
     414                            } 
     415                            else 
     416                            { 
     417                                rrd_update_ok_ct++; 
     418                            } 
     419                            for ( j=0; j<3; j++) 
     420                            { 
     421                                free(optUpdate[j]); 
     422                                optUpdate[j] = NULL; 
     423                            } 
     424                        } 
     425                        /* Reinit the shared tables */ 
     426                        shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0; 
     427                        shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0; 
     428                        shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0; 
     429                        shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0; 
     430                        shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0; 
     431                        shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0; 
     432                        shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0; 
     433                        shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0; 
     434                        shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0; 
     435                        shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0; 
     436                        shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0; 
     437                        shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0; 
     438                        shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0; 
     439                        shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0; 
     440                    } 
     441                } 
    383442#if defined(MATRIX) && defined(IPV4AGGIDR) 
    384         /* MATRIX INTER POP ACCOUNTING */ 
    385         /* rrd */ 
    386         for (i=0; i<ROUTER_INDEX_MAX; i++){ 
    387           for (j=0; j<ROUTER_INDEX_MAX; j++){ 
    388             /* HERE create or update RRD FILE */ 
    389             for (k=0; k<strlen(name); k++) {name[k] = '\0';} 
    390             for (k=0; k<strlen(createstr); k++) {createstr[k] = '\0';} 
    391             for (k=0; k<strlen(indexStr); k++) {indexStr[k] = '\0';} 
    392             for (k=0; k<strlen(buf); k++) {buf[k] = '\0';} 
    393             strcat(name, MATRIX_RRD_LOCATION); 
    394             sprintf(indexStr, "%d_%d",  
    395                     i, 
    396                     j 
    397                     );  
    398             strcat(name, indexStr); 
    399             strcat(name, RRD_EXTENSION); 
    400             if ( (fp=fopen(name,"r")) == NULL ){ 
    401               opt[0]= (char *) malloc((strlen(RRD_PARAM_MATRIX_0) + 1) * sizeof(char)); 
    402               strcpy(opt[0], RRD_PARAM_MATRIX_0); 
    403               opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
    404               strcpy(opt[1], name); 
    405               opt[2]= (char *) malloc((strlen(RRD_PARAM_MATRIX_1) + 1) * sizeof(char)); 
    406               strcpy(opt[2], RRD_PARAM_MATRIX_1); 
    407               opt[3]= (char *) malloc((strlen(RRD_PARAM_MATRIX_2) + 1) * sizeof(char)); 
    408               strcpy(opt[3], RRD_PARAM_MATRIX_2); 
    409               opt[4]= (char *) malloc((strlen(RRD_PARAM_MATRIX_3) + 1) * sizeof(char)); 
    410               strcpy(opt[4], RRD_PARAM_MATRIX_3); 
    411               opt[5]= (char *) malloc((strlen(RRD_PARAM_MATRIX_4) + 1) * sizeof(char)); 
    412               strcpy(opt[5], RRD_PARAM_MATRIX_4); 
    413               opt[6]= (char *) malloc((strlen(RRD_PARAM_MATRIX_5) + 1) * sizeof(char)); 
    414               strcpy(opt[6], RRD_PARAM_MATRIX_5); 
    415               opt[7]= (char *) malloc((strlen(RRD_PARAM_MATRIX_6) + 1) * sizeof(char)); 
    416               strcpy(opt[7], RRD_PARAM_MATRIX_6); 
    417               opt[8]= (char *) malloc((strlen(RRD_PARAM_MATRIX_7) + 1) * sizeof(char)); 
    418               strcpy(opt[8], RRD_PARAM_MATRIX_7); 
    419               opt[9]= (char *) malloc((strlen(RRD_PARAM_MATRIX_8) + 1) * sizeof(char)); 
    420               strcpy(opt[9], RRD_PARAM_MATRIX_8); 
    421               opt[10]= (char *) malloc((strlen(RRD_PARAM_MATRIX_9) + 1) * sizeof(char)); 
    422               strcpy(opt[10], RRD_PARAM_MATRIX_9); 
    423               opt[11]= (char *) malloc((strlen(RRD_PARAM_MATRIX_10) + 1) * sizeof(char)); 
    424               strcpy(opt[11], RRD_PARAM_MATRIX_10); 
    425               opt[12]= (char *) malloc((strlen(RRD_PARAM_MATRIX_11) + 1) * sizeof(char)); 
    426               strcpy(opt[12], RRD_PARAM_MATRIX_11); 
    427               opt[13]= (char *) malloc((strlen(RRD_PARAM_MATRIX_12) + 1) * sizeof(char)); 
    428               strcpy(opt[13], RRD_PARAM_MATRIX_12); 
    429               opt[14]= (char *) malloc((strlen(RRD_PARAM_MATRIX_13) + 1) * sizeof(char)); 
    430               strcpy(opt[14], RRD_PARAM_MATRIX_13); 
    431               opt[15]= (char *) malloc((strlen(RRD_PARAM_MATRIX_14) + 1) * sizeof(char)); 
    432               strcpy(opt[15], RRD_PARAM_MATRIX_14); 
    433               optind = opterr = 0; 
    434               rrd_clear_error(); 
    435               if ( rrd_create(16,opt) < 0) { 
    436                 syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
    437                 rrd_create_er_ct++; 
    438               } else { 
    439                 rrd_create_ok_ct++; 
    440               } 
    441               for ( k=0; k<16; k++) { 
    442                 free(opt[k]); 
    443                 opt[k] = NULL; 
    444               } 
    445             }else{  
    446               fclose(fp); 
    447               rrd_already_created_ct++; 
    448               snprintf(buf,  
    449                        2048,  
    450                        "%lu:%llu:%llu:%llu",   
    451                        now-300,  /* or ctime(&now) with %s */ 
    452                        shmForAgg->matrixPOP[index][i][j].flowNb, 
    453                        shmForAgg->matrixPOP[index][i][j].bytesNb, 
    454                        shmForAgg->matrixPOP[index][i][j].pktsNb 
    455                        ); 
    456               optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
    457               strcpy(optUpdate[0], RRD_UPDATE_0); 
    458               optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
    459               strcpy(optUpdate[1], name); 
    460               optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
    461               strcpy(optUpdate[2], buf); 
    462               optind = opterr = 0;  
    463               rrd_clear_error(); 
    464               if ( rrd_update(3, optUpdate) < 0 ) {  
    465                 syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
    466                 rrd_update_er_ct++; 
    467               } else { 
    468                 rrd_update_ok_ct++; 
    469               } 
    470               for ( k=0; k<3; k++) { 
    471                 free(optUpdate[k]); 
    472                 optUpdate[k] = NULL; 
    473               } 
    474             } 
    475  
    476           } 
    477         } 
    478         /* reinit */ 
    479         for (i=0; i<ROUTER_INDEX_MAX; i++){ 
    480           for (j=0; j<ROUTER_INDEX_MAX; j++) { 
    481             shmForAgg->matrixPOP[index][i][j].bytesNb = 0; 
    482             shmForAgg->matrixPOP[index][i][j].pktsNb = 0; 
    483             shmForAgg->matrixPOP[index][i][j].flowNb = 0; 
    484           } 
    485         } 
    486         /* END MATRIX INTER POP ACC */ 
     443                /* MATRIX INTER POP ACCOUNTING */ 
     444                /* rrd */ 
     445                for (i=0; i<ROUTER_INDEX_MAX; i++) 
     446                { 
     447                    for (j=0; j<ROUTER_INDEX_MAX; j++) 
     448                    { 
     449                        /* HERE create or update RRD FILE */ 
     450                        for (k=0; k<strlen(name); k++) 
     451                        { 
     452                            name[k] = '\0'; 
     453                        } 
     454                        for (k=0; k<strlen(createstr); k++) 
     455                        { 
     456                            createstr[k] = '\0'; 
     457                        } 
     458                        for (k=0; k<strlen(indexStr); k++) 
     459                        { 
     460                            indexStr[k] = '\0'; 
     461                        } 
     462                        for (k=0; k<strlen(buf); k++) 
     463                        { 
     464                            buf[k] = '\0'; 
     465                        } 
     466                        strcat(name, MATRIX_RRD_LOCATION); 
     467                        sprintf(indexStr, "%d_%d", 
     468                                i, 
     469                                j 
     470                               ); 
     471                        strcat(name, indexStr); 
     472                        strcat(name, RRD_EXTENSION); 
     473                        if ( (fp=fopen(name,"r")) == NULL ) 
     474                        { 
     475                            opt[0]= (char *) malloc((strlen(RRD_PARAM_MATRIX_0) + 1) * sizeof(char)); 
     476                            strcpy(opt[0], RRD_PARAM_MATRIX_0); 
     477                            opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     478                            strcpy(opt[1], name); 
     479                            opt[2]= (char *) malloc((strlen(RRD_PARAM_MATRIX_1) + 1) * sizeof(char)); 
     480                            strcpy(opt[2], RRD_PARAM_MATRIX_1); 
     481                            opt[3]= (char *) malloc((strlen(RRD_PARAM_MATRIX_2) + 1) * sizeof(char)); 
     482                            strcpy(opt[3], RRD_PARAM_MATRIX_2); 
     483                            opt[4]= (char *) malloc((strlen(RRD_PARAM_MATRIX_3) + 1) * sizeof(char)); 
     484                            strcpy(opt[4], RRD_PARAM_MATRIX_3); 
     485                            opt[5]= (char *) malloc((strlen(RRD_PARAM_MATRIX_4) + 1) * sizeof(char)); 
     486                            strcpy(opt[5], RRD_PARAM_MATRIX_4); 
     487                            opt[6]= (char *) malloc((strlen(RRD_PARAM_MATRIX_5) + 1) * sizeof(char)); 
     488                            strcpy(opt[6], RRD_PARAM_MATRIX_5); 
     489                            opt[7]= (char *) malloc((strlen(RRD_PARAM_MATRIX_6) + 1) * sizeof(char)); 
     490                            strcpy(opt[7], RRD_PARAM_MATRIX_6); 
     491                            opt[8]= (char *) malloc((strlen(RRD_PARAM_MATRIX_7) + 1) * sizeof(char)); 
     492                            strcpy(opt[8], RRD_PARAM_MATRIX_7); 
     493                            opt[9]= (char *) malloc((strlen(RRD_PARAM_MATRIX_8) + 1) * sizeof(char)); 
     494                            strcpy(opt[9], RRD_PARAM_MATRIX_8); 
     495                            opt[10]= (char *) malloc((strlen(RRD_PARAM_MATRIX_9) + 1) * sizeof(char)); 
     496                            strcpy(opt[10], RRD_PARAM_MATRIX_9); 
     497                            opt[11]= (char *) malloc((strlen(RRD_PARAM_MATRIX_10) + 1) * sizeof(char)); 
     498                            strcpy(opt[11], RRD_PARAM_MATRIX_10); 
     499                            opt[12]= (char *) malloc((strlen(RRD_PARAM_MATRIX_11) + 1) * sizeof(char)); 
     500                            strcpy(opt[12], RRD_PARAM_MATRIX_11); 
     501                            opt[13]= (char *) malloc((strlen(RRD_PARAM_MATRIX_12) + 1) * sizeof(char)); 
     502                            strcpy(opt[13], RRD_PARAM_MATRIX_12); 
     503                            opt[14]= (char *) malloc((strlen(RRD_PARAM_MATRIX_13) + 1) * sizeof(char)); 
     504                            strcpy(opt[14], RRD_PARAM_MATRIX_13); 
     505                            opt[15]= (char *) malloc((strlen(RRD_PARAM_MATRIX_14) + 1) * sizeof(char)); 
     506                            strcpy(opt[15], RRD_PARAM_MATRIX_14); 
     507                            optind = opterr = 0; 
     508                            rrd_clear_error(); 
     509                            if ( rrd_create(16,opt) < 0) 
     510                            { 
     511                                syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
     512                                rrd_create_er_ct++; 
     513                            } 
     514                            else 
     515                            { 
     516                                rrd_create_ok_ct++; 
     517                            } 
     518                            for ( k=0; k<16; k++) 
     519                            { 
     520                                free(opt[k]); 
     521                                opt[k] = NULL; 
     522                            } 
     523                        } 
     524                        else 
     525                        { 
     526                            fclose(fp); 
     527                            rrd_already_created_ct++; 
     528                            snprintf(buf, 
     529                                     2048, 
     530                                     "%lu:%llu:%llu:%llu", 
     531                                     now-300,  /* or ctime(&now) with %s */ 
     532                                     shmForAgg->matrixPOP[index][i][j].flowNb, 
     533                                     shmForAgg->matrixPOP[index][i][j].bytesNb, 
     534                                     shmForAgg->matrixPOP[index][i][j].pktsNb 
     535                                    ); 
     536                            optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
     537                            strcpy(optUpdate[0], RRD_UPDATE_0); 
     538                            optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     539                            strcpy(optUpdate[1], name); 
     540                            optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
     541                            strcpy(optUpdate[2], buf); 
     542                            optind = opterr = 0; 
     543                            rrd_clear_error(); 
     544                            if ( rrd_update(3, optUpdate) < 0 ) 
     545                            { 
     546                                syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
     547                                rrd_update_er_ct++; 
     548                            } 
     549                            else 
     550                            { 
     551                                rrd_update_ok_ct++; 
     552                            } 
     553                            for ( k=0; k<3; k++) 
     554                            { 
     555                                free(optUpdate[k]); 
     556                                optUpdate[k] = NULL; 
     557                            } 
     558                        } 
     559 
     560                    } 
     561                } 
     562                /* reinit */ 
     563                for (i=0; i<ROUTER_INDEX_MAX; i++) 
     564                { 
     565                    for (j=0; j<ROUTER_INDEX_MAX; j++) 
     566                    { 
     567                        shmForAgg->matrixPOP[index][i][j].bytesNb = 0; 
     568                        shmForAgg->matrixPOP[index][i][j].pktsNb = 0; 
     569                        shmForAgg->matrixPOP[index][i][j].flowNb = 0; 
     570                    } 
     571                } 
     572                /* END MATRIX INTER POP ACC */ 
    487573#endif /* MATRIX */ 
    488574#ifdef ASACC 
    489         /*  
    490          * 
    491          * AS ACCOUNTING  
    492          * 
    493          */ 
    494         for (i=0; i<shmForAgg->ASNb; i++){ 
    495           /* HERE create or update RRD FILE */ 
    496           if (shmForAgg->ASTab[index][i].sampling != 0) { 
    497             for (j=0; j<strlen(name); j++) {name[j] = '\0';} 
    498             for (j=0; j<strlen(createstr); j++) {createstr[j] = '\0';} 
    499             for (j=0; j<strlen(asStr); j++) {asStr[j] = '\0';} 
    500             for (j=0; j<strlen(buf); j++) {buf[j] = '\0';} 
    501             strcat(name, AS_RRD_LOCATION); 
    502             sprintf(asStr, "%hu_%lu",  
    503                     shmForAgg->ASTab[index][i].as, 
    504                     shmForAgg->ASTab[index][i].sampling 
    505                     );  
    506             strcat(name, asStr); 
    507             strcat(name, RRD_EXTENSION); 
    508             if ( (fp=fopen(name,"r")) == NULL ){ 
    509               opt[0]= (char *) malloc((strlen(RRD_PARAM_AS_0) + 1) * sizeof(char)); 
    510               strcpy(opt[0], RRD_PARAM_AS_0); 
    511               opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
    512               strcpy(opt[1], name); 
    513               opt[2]= (char *) malloc((strlen(RRD_PARAM_AS_1) + 1) * sizeof(char)); 
    514               strcpy(opt[2], RRD_PARAM_AS_1); 
    515               opt[3]= (char *) malloc((strlen(RRD_PARAM_AS_2) + 1) * sizeof(char)); 
    516               strcpy(opt[3], RRD_PARAM_AS_2); 
    517               opt[4]= (char *) malloc((strlen(RRD_PARAM_AS_3) + 1) * sizeof(char)); 
    518               strcpy(opt[4], RRD_PARAM_AS_3); 
    519               opt[5]= (char *) malloc((strlen(RRD_PARAM_AS_4) + 1) * sizeof(char)); 
    520               strcpy(opt[5], RRD_PARAM_AS_4); 
    521               opt[6]= (char *) malloc((strlen(RRD_PARAM_AS_5) + 1) * sizeof(char)); 
    522               strcpy(opt[6], RRD_PARAM_AS_5); 
    523               opt[7]= (char *) malloc((strlen(RRD_PARAM_AS_6) + 1) * sizeof(char)); 
    524               strcpy(opt[7], RRD_PARAM_AS_6); 
    525               opt[8]= (char *) malloc((strlen(RRD_PARAM_AS_7) + 1) * sizeof(char)); 
    526               strcpy(opt[8], RRD_PARAM_AS_7); 
    527               opt[9]= (char *) malloc((strlen(RRD_PARAM_AS_8) + 1) * sizeof(char)); 
    528               strcpy(opt[9], RRD_PARAM_AS_8); 
    529               opt[10]= (char *) malloc((strlen(RRD_PARAM_AS_9) + 1) * sizeof(char)); 
    530               strcpy(opt[10], RRD_PARAM_AS_9); 
    531               opt[11]= (char *) malloc((strlen(RRD_PARAM_AS_10) + 1) * sizeof(char)); 
    532               strcpy(opt[11], RRD_PARAM_AS_10); 
    533               opt[12]= (char *) malloc((strlen(RRD_PARAM_AS_11) + 1) * sizeof(char)); 
    534               strcpy(opt[12], RRD_PARAM_AS_11); 
    535               opt[13]= (char *) malloc((strlen(RRD_PARAM_AS_12) + 1) * sizeof(char)); 
    536               strcpy(opt[13], RRD_PARAM_AS_12); 
    537               opt[14]= (char *) malloc((strlen(RRD_PARAM_AS_13) + 1) * sizeof(char)); 
    538               strcpy(opt[14], RRD_PARAM_AS_13); 
    539               opt[15]= (char *) malloc((strlen(RRD_PARAM_AS_14) + 1) * sizeof(char)); 
    540               strcpy(opt[15], RRD_PARAM_AS_14); 
    541               opt[16]= (char *) malloc((strlen(RRD_PARAM_AS_15) + 1) * sizeof(char)); 
    542               strcpy(opt[16], RRD_PARAM_AS_15); 
    543               opt[17]= (char *) malloc((strlen(RRD_PARAM_AS_16) + 1) * sizeof(char)); 
    544               strcpy(opt[17], RRD_PARAM_AS_16); 
    545               opt[18]= (char *) malloc((strlen(RRD_PARAM_AS_17) + 1) * sizeof(char)); 
    546               strcpy(opt[18], RRD_PARAM_AS_17); 
    547               optind = opterr = 0; 
    548               rrd_clear_error(); 
    549               if ( rrd_create(19,opt) < 0) { 
    550                 syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
    551                 rrd_create_er_ct++; 
    552               } else { 
    553                 rrd_create_ok_ct++; 
    554               } 
    555               for ( j=0; j<19; j++) { 
    556                 free(opt[j]); 
    557                 opt[j] = NULL; 
    558               } 
    559             }else{  
    560               fclose(fp); 
    561               rrd_already_created_ct++; 
    562               snprintf(buf,  
    563                        2048,  
    564                        "%lu:%llu:%llu:%llu:%llu:%llu:%llu",   
    565                        now-300,  /* or ctime(&now) with %s */ 
    566                        shmForAgg->ASTab[index][i].flowNbIN,  /* 1 */ 
    567                        shmForAgg->ASTab[index][i].flowNbOUT, 
    568                        shmForAgg->ASTab[index][i].bytesNbIN, 
    569                        shmForAgg->ASTab[index][i].bytesNbOUT, 
    570                        shmForAgg->ASTab[index][i].pktsNbIN,  /* 5 */ 
    571                        shmForAgg->ASTab[index][i].pktsNbOUT 
    572                        ); 
    573               optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
    574               strcpy(optUpdate[0], RRD_UPDATE_0); 
    575               optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
    576               strcpy(optUpdate[1], name); 
    577               optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
    578               strcpy(optUpdate[2], buf); 
    579               optind = opterr = 0;  
    580               rrd_clear_error(); 
    581               if ( rrd_update(3, optUpdate) < 0 ) {  
    582                 syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
    583                 rrd_update_er_ct++; 
    584               } else { 
    585                 rrd_update_ok_ct++; 
    586               } 
    587               for ( j=0; j<3; j++) { 
    588                 free(optUpdate[j]); 
    589                 optUpdate[j] = NULL; 
    590               } 
    591             } 
    592             /* Reinit the shared tables */ 
    593             shmForAgg->ASTab[index][i].flowNbIN = 0; 
    594             shmForAgg->ASTab[index][i].bytesNbIN = 0; 
    595             shmForAgg->ASTab[index][i].pktsNbIN = 0; 
    596             shmForAgg->ASTab[index][i].flowNbOUT = 0; 
    597             shmForAgg->ASTab[index][i].bytesNbOUT = 0; 
    598             shmForAgg->ASTab[index][i].pktsNbOUT = 0; 
    599           } 
    600         } 
     575                /* 
     576                 * 
     577                 * AS ACCOUNTING 
     578                 * 
     579                 */ 
     580                for (i=0; i<shmForAgg->ASNb; i++) 
     581                { 
     582                    /* HERE create or update RRD FILE */ 
     583                    if (shmForAgg->ASTab[index][i].sampling != 0) 
     584                    { 
     585                        for (j=0; j<strlen(name); j++) 
     586                        { 
     587                            name[j] = '\0'; 
     588                        } 
     589                        for (j=0; j<strlen(createstr); j++) 
     590                        { 
     591                            createstr[j] = '\0'; 
     592                        } 
     593                        for (j=0; j<strlen(asStr); j++) 
     594                        { 
     595                            asStr[j] = '\0'; 
     596                        } 
     597                        for (j=0; j<strlen(buf); j++) 
     598                        { 
     599                            buf[j] = '\0'; 
     600                        } 
     601                        strcat(name, AS_RRD_LOCATION); 
     602                        sprintf(asStr, "%hu_%lu", 
     603                                shmForAgg->ASTab[index][i].as, 
     604                                shmForAgg->ASTab[index][i].sampling 
     605                               ); 
     606                        strcat(name, asStr); 
     607                        strcat(name, RRD_EXTENSION); 
     608                        if ( (fp=fopen(name,"r")) == NULL ) 
     609                        { 
     610                            opt[0]= (char *) malloc((strlen(RRD_PARAM_AS_0) + 1) * sizeof(char)); 
     611                            strcpy(opt[0], RRD_PARAM_AS_0); 
     612                            opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     613                            strcpy(opt[1], name); 
     614                            opt[2]= (char *) malloc((strlen(RRD_PARAM_AS_1) + 1) * sizeof(char)); 
     615                            strcpy(opt[2], RRD_PARAM_AS_1); 
     616                            opt[3]= (char *) malloc((strlen(RRD_PARAM_AS_2) + 1) * sizeof(char)); 
     617                            strcpy(opt[3], RRD_PARAM_AS_2); 
     618                            opt[4]= (char *) malloc((strlen(RRD_PARAM_AS_3) + 1) * sizeof(char)); 
     619                            strcpy(opt[4], RRD_PARAM_AS_3); 
     620                            opt[5]= (char *) malloc((strlen(RRD_PARAM_AS_4) + 1) * sizeof(char)); 
     621                            strcpy(opt[5], RRD_PARAM_AS_4); 
     622                            opt[6]= (char *) malloc((strlen(RRD_PARAM_AS_5) + 1) * sizeof(char)); 
     623                            strcpy(opt[6], RRD_PARAM_AS_5); 
     624                            opt[7]= (char *) malloc((strlen(RRD_PARAM_AS_6) + 1) * sizeof(char)); 
     625                            strcpy(opt[7], RRD_PARAM_AS_6); 
     626                            opt[8]= (char *) malloc((strlen(RRD_PARAM_AS_7) + 1) * sizeof(char)); 
     627                            strcpy(opt[8], RRD_PARAM_AS_7); 
     628                            opt[9]= (char *) malloc((strlen(RRD_PARAM_AS_8) + 1) * sizeof(char)); 
     629                            strcpy(opt[9], RRD_PARAM_AS_8); 
     630                            opt[10]= (char *) malloc((strlen(RRD_PARAM_AS_9) + 1) * sizeof(char)); 
     631                            strcpy(opt[10], RRD_PARAM_AS_9); 
     632                            opt[11]= (char *) malloc((strlen(RRD_PARAM_AS_10) + 1) * sizeof(char)); 
     633                            strcpy(opt[11], RRD_PARAM_AS_10); 
     634                            opt[12]= (char *) malloc((strlen(RRD_PARAM_AS_11) + 1) * sizeof(char)); 
     635                            strcpy(opt[12], RRD_PARAM_AS_11); 
     636                            opt[13]= (char *) malloc((strlen(RRD_PARAM_AS_12) + 1) * sizeof(char)); 
     637                            strcpy(opt[13], RRD_PARAM_AS_12); 
     638                            opt[14]= (char *) malloc((strlen(RRD_PARAM_AS_13) + 1) * sizeof(char)); 
     639                            strcpy(opt[14], RRD_PARAM_AS_13); 
     640                            opt[15]= (char *) malloc((strlen(RRD_PARAM_AS_14) + 1) * sizeof(char)); 
     641                            strcpy(opt[15], RRD_PARAM_AS_14); 
     642                            opt[16]= (char *) malloc((strlen(RRD_PARAM_AS_15) + 1) * sizeof(char)); 
     643                            strcpy(opt[16], RRD_PARAM_AS_15); 
     644                            opt[17]= (char *) malloc((strlen(RRD_PARAM_AS_16) + 1) * sizeof(char)); 
     645                            strcpy(opt[17], RRD_PARAM_AS_16); 
     646                            opt[18]= (char *) malloc((strlen(RRD_PARAM_AS_17) + 1) * sizeof(char)); 
     647                            strcpy(opt[18], RRD_PARAM_AS_17); 
     648                            optind = opterr = 0; 
     649                            rrd_clear_error(); 
     650                            if ( rrd_create(19,opt) < 0) 
     651                            { 
     652                                syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
     653                                rrd_create_er_ct++; 
     654                            } 
     655                            else 
     656                            { 
     657                                rrd_create_ok_ct++; 
     658                            } 
     659                            for ( j=0; j<19; j++) 
     660                            { 
     661                                free(opt[j]); 
     662                                opt[j] = NULL; 
     663                            } 
     664                        } 
     665                        else 
     666                        { 
     667                            fclose(fp); 
     668                            rrd_already_created_ct++; 
     669                            snprintf(buf, 
     670                                     2048, 
     671                                     "%lu:%llu:%llu:%llu:%llu:%llu:%llu", 
     672                                     now-300,  /* or ctime(&now) with %s */ 
     673                                     shmForAgg->ASTab[index][i].flowNbIN,  /* 1 */ 
     674                                     shmForAgg->ASTab[index][i].flowNbOUT, 
     675                                     shmForAgg->ASTab[index][i].bytesNbIN, 
     676                                     shmForAgg->ASTab[index][i].bytesNbOUT, 
     677                                     shmForAgg->ASTab[index][i].pktsNbIN,  /* 5 */ 
     678                                     shmForAgg->ASTab[index][i].pktsNbOUT 
     679                                    ); 
     680                            optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
     681                            strcpy(optUpdate[0], RRD_UPDATE_0); 
     682                            optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     683                            strcpy(optUpdate[1], name); 
     684                            optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
     685                            strcpy(optUpdate[2], buf); 
     686                            optind = opterr = 0; 
     687                            rrd_clear_error(); 
     688                            if ( rrd_update(3, optUpdate) < 0 ) 
     689                            { 
     690                                syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
     691                                rrd_update_er_ct++; 
     692                            } 
     693                            else 
     694                            { 
     695                                rrd_update_ok_ct++; 
     696                            } 
     697                            for ( j=0; j<3; j++) 
     698                            { 
     699                                free(optUpdate[j]); 
     700                                optUpdate[j] = NULL; 
     701                            } 
     702                        } 
     703                        /* Reinit the shared tables */ 
     704                        shmForAgg->ASTab[index][i].flowNbIN = 0; 
     705                        shmForAgg->ASTab[index][i].bytesNbIN = 0; 
     706                        shmForAgg->ASTab[index][i].pktsNbIN = 0; 
     707                        shmForAgg->ASTab[index][i].flowNbOUT = 0; 
     708                        shmForAgg->ASTab[index][i].bytesNbOUT = 0; 
     709                        shmForAgg->ASTab[index][i].pktsNbOUT = 0; 
     710                    } 
     711                } 
    601712#ifdef IPV6LINKAGG 
    602         /*  
    603          * 
    604          * IPv6 Links ACCOUNTING  
    605          * 
    606          */ 
    607         for (i=0; i<ROUTER_INDEX_MAX; i++){ 
    608           for (j=0; j<MAX_INDEX_BY_ROUTER; j++) { 
    609           /* HERE create or update RRD FILE for IPV6 LINKs AGGregation */ 
    610             if (shmForAgg->indexV6Tab[index][i][j].hasStats == 1) { 
    611               for (k=0; k<strlen(name); k++) {name[k] = '\0';} 
    612               for (k=0; k<strlen(createstr); k++) {createstr[k] = '\0';} 
    613               for (k=0; k<strlen(ipv6LinkStr); k++) {ipv6LinkStr[k] = '\0';} 
    614               for (k=0; k<strlen(buf); k++) {buf[k] = '\0';} 
    615               strcat(name, SNMP_INDEX_RRD_LOCATION); 
    616               sprintf(ipv6LinkStr, "%lu_%lu_%lu_%lu_%hu_%hu",  
    617                       shmForAgg->indexV6Tab[index][i][j].routerIPAddress>>24, 
    618                       shmForAgg->indexV6Tab[index][i][j].routerIPAddress<<8>>24, 
    619                       shmForAgg->indexV6Tab[index][i][j].routerIPAddress<<16>>24, 
    620                       shmForAgg->indexV6Tab[index][i][j].routerIPAddress<<24>>24, 
    621                       (unsigned short) 1, 
    622                       shmForAgg->indexV6Tab[index][i][j].indexSNMP 
    623                       ); 
    624               strcat(name, ipv6LinkStr); 
    625               strcat(name, RRD_EXTENSION); 
    626               if ( (fp=fopen(name,"r")) == NULL ){ 
    627                 opt[0]= (char *) malloc((strlen(RRD_PARAM_INDEX_0) + 1) * sizeof(char)); 
    628                 strcpy(opt[0], RRD_PARAM_INDEX_0); 
    629                 opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
    630                 strcpy(opt[1], name); 
    631                 opt[2]= (char *) malloc((strlen(RRD_PARAM_INDEX_1) + 1) * sizeof(char)); 
    632                 strcpy(opt[2], RRD_PARAM_INDEX_1); 
    633                 opt[3]= (char *) malloc((strlen(RRD_PARAM_INDEX_2) + 1) * sizeof(char)); 
    634                 strcpy(opt[3], RRD_PARAM_INDEX_2); 
    635                 opt[4]= (char *) malloc((strlen(RRD_PARAM_INDEX_3) + 1) * sizeof(char)); 
    636                 strcpy(opt[4], RRD_PARAM_INDEX_3); 
    637                 opt[5]= (char *) malloc((strlen(RRD_PARAM_INDEX_4) + 1) * sizeof(char)); 
    638                 strcpy(opt[5], RRD_PARAM_INDEX_4); 
    639                 opt[6]= (char *) malloc((strlen(RRD_PARAM_INDEX_5) + 1) * sizeof(char)); 
    640                 strcpy(opt[6], RRD_PARAM_INDEX_5); 
    641                 opt[7]= (char *) malloc((strlen(RRD_PARAM_INDEX_6) + 1) * sizeof(char)); 
    642                 strcpy(opt[7], RRD_PARAM_INDEX_6); 
    643                 opt[8]= (char *) malloc((strlen(RRD_PARAM_INDEX_7) + 1) * sizeof(char)); 
    644                 strcpy(opt[8], RRD_PARAM_INDEX_7); 
    645                 opt[9]= (char *) malloc((strlen(RRD_PARAM_INDEX_8) + 1) * sizeof(char)); 
    646                 strcpy(opt[9], RRD_PARAM_INDEX_8); 
    647                 opt[10]= (char *) malloc((strlen(RRD_PARAM_INDEX_9) + 1) * sizeof(char)); 
    648                 strcpy(opt[10], RRD_PARAM_INDEX_9); 
    649                 opt[11]= (char *) malloc((strlen(RRD_PARAM_INDEX_10) + 1) * sizeof(char)); 
    650                 strcpy(opt[11], RRD_PARAM_INDEX_10); 
    651                 opt[12]= (char *) malloc((strlen(RRD_PARAM_INDEX_11) + 1) * sizeof(char)); 
    652                 strcpy(opt[12], RRD_PARAM_INDEX_11); 
    653                 opt[13]= (char *) malloc((strlen(RRD_PARAM_INDEX_12) + 1) * sizeof(char)); 
    654                 strcpy(opt[13], RRD_PARAM_INDEX_12); 
    655                 opt[14]= (char *) malloc((strlen(RRD_PARAM_INDEX_13) + 1) * sizeof(char)); 
    656                 strcpy(opt[14], RRD_PARAM_INDEX_13); 
    657                 opt[15]= (char *) malloc((strlen(RRD_PARAM_INDEX_14) + 1) * sizeof(char)); 
    658                 strcpy(opt[15], RRD_PARAM_INDEX_14); 
    659                 opt[16]= (char *) malloc((strlen(RRD_PARAM_INDEX_15) + 1) * sizeof(char)); 
    660                 strcpy(opt[16], RRD_PARAM_INDEX_15); 
    661                 opt[17]= (char *) malloc((strlen(RRD_PARAM_INDEX_16) + 1) * sizeof(char)); 
    662                 strcpy(opt[17], RRD_PARAM_INDEX_16); 
    663                 opt[18]= (char *) malloc((strlen(RRD_PARAM_INDEX_17) + 1) * sizeof(char)); 
    664                 strcpy(opt[18], RRD_PARAM_INDEX_17); 
    665                 optind = opterr = 0; 
    666                 rrd_clear_error(); 
    667                 if ( rrd_create(19,opt) < 0) { 
    668                   syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
    669                   rrd_create_er_ct++; 
    670                 } else { 
    671                   rrd_create_ok_ct++; 
    672                 } 
    673                 for ( k=0; k<19; k++) { 
    674                   free(opt[k]); 
    675                   opt[k] = NULL; 
    676                 } 
    677               }else{  
    678                 fclose(fp); 
    679                 rrd_already_created_ct++; 
    680                 snprintf(buf,  
    681                          2048,  
    682                          "%lu:%llu:%llu:%llu:%llu:%llu:%llu",   
    683                          now-300,  /* or ctime(&now) with %s */ 
    684                          shmForAgg->indexV6Tab[index][i][j].flowNbIN,  /* 1 */ 
    685                          shmForAgg->indexV6Tab[index][i][j].flowNbOUT, 
    686                          shmForAgg->indexV6Tab[index][i][j].bytesNbIN, 
    687                          shmForAgg->indexV6Tab[index][i][j].bytesNbOUT, 
    688                          shmForAgg->indexV6Tab[index][i][j].pktsNbIN,  /* 5 */ 
    689                          shmForAgg->indexV6Tab[index][i][j].pktsNbOUT 
    690                          ); 
    691                 optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
    692                 strcpy(optUpdate[0], RRD_UPDATE_0); 
    693                 optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
    694                 strcpy(optUpdate[1], name); 
    695                 optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
    696                 strcpy(optUpdate[2], buf); 
    697                 optind = opterr = 0;  
    698                 rrd_clear_error(); 
    699                 if ( rrd_update(3, optUpdate) < 0 ) {  
    700                   syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
    701                   rrd_update_er_ct++; 
    702                 } else { 
    703                   rrd_update_ok_ct++; 
    704                 } 
    705                 for ( k=0; k<3; k++) { 
    706                   free(optUpdate[k]); 
    707                   optUpdate[k] = NULL; 
    708                 } 
    709               } 
    710               shmForAgg->indexV6Tab[index][i][j].bytesNbIN = 0; 
    711               shmForAgg->indexV6Tab[index][i][j].pktsNbIN = 0; 
    712               shmForAgg->indexV6Tab[index][i][j].flowNbIN = 0; 
    713               shmForAgg->indexV6Tab[index][i][j].bytesNbOUT = 0; 
    714               shmForAgg->indexV6Tab[index][i][j].pktsNbOUT = 0; 
    715               shmForAgg->indexV6Tab[index][i][j].flowNbOUT = 0; 
    716             } 
    717           } 
    718         } 
     713                /* 
     714                 * 
     715                 * IPv6 Links ACCOUNTING 
     716                 * 
     717                 */ 
     718                for (i=0; i<ROUTER_INDEX_MAX; i++) 
     719                { 
     720                    for (j=0; j<MAX_INDEX_BY_ROUTER; j++) 
     721                    { 
     722                        /* HERE create or update RRD FILE for IPV6 LINKs AGGregation */ 
     723                        if (shmForAgg->indexV6Tab[index][i][j].hasStats == 1) 
     724                        { 
     725                            for (k=0; k<strlen(name); k++) 
     726                            { 
     727                                name[k] = '\0'; 
     728                            } 
     729                            for (k=0; k<strlen(createstr); k++) 
     730                            { 
     731                                createstr[k] = '\0'; 
     732                            } 
     733                            for (k=0; k<strlen(ipv6LinkStr); k++) 
     734                            { 
     735                                ipv6LinkStr[k] = '\0'; 
     736                            } 
     737                            for (k=0; k<strlen(buf); k++) 
     738                            { 
     739                                buf[k] = '\0'; 
     740                            } 
     741                            strcat(name, SNMP_INDEX_RRD_LOCATION); 
     742                            sprintf(ipv6LinkStr, "%lu_%lu_%lu_%lu_%hu_%hu", 
     743                                    shmForAgg->indexV6Tab[index][i][j].routerIPAddress>>24, 
     744                                    shmForAgg->indexV6Tab[index][i][j].routerIPAddress<<8>>24, 
     745                                    shmForAgg->indexV6Tab[index][i][j].routerIPAddress<<16>>24, 
     746                                    shmForAgg->indexV6Tab[index][i][j].routerIPAddress<<24>>24, 
     747                                    (unsigned short) 1, 
     748                                    shmForAgg->indexV6Tab[index][i][j].indexSNMP 
     749                                   ); 
     750                            strcat(name, ipv6LinkStr); 
     751                            strcat(name, RRD_EXTENSION); 
     752                            if ( (fp=fopen(name,"r")) == NULL ) 
     753                            { 
     754                                opt[0]= (char *) malloc((strlen(RRD_PARAM_INDEX_0) + 1) * sizeof(char)); 
     755                                strcpy(opt[0], RRD_PARAM_INDEX_0); 
     756                                opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     757                                strcpy(opt[1], name); 
     758                                opt[2]= (char *) malloc((strlen(RRD_PARAM_INDEX_1) + 1) * sizeof(char)); 
     759                                strcpy(opt[2], RRD_PARAM_INDEX_1); 
     760                                opt[3]= (char *) malloc((strlen(RRD_PARAM_INDEX_2) + 1) * sizeof(char)); 
     761                                strcpy(opt[3], RRD_PARAM_INDEX_2); 
     762                                opt[4]= (char *) malloc((strlen(RRD_PARAM_INDEX_3) + 1) * sizeof(char)); 
     763                                strcpy(opt[4], RRD_PARAM_INDEX_3); 
     764                                opt[5]= (char *) malloc((strlen(RRD_PARAM_INDEX_4) + 1) * sizeof(char)); 
     765                                strcpy(opt[5], RRD_PARAM_INDEX_4); 
     766                                opt[6]= (char *) malloc((strlen(RRD_PARAM_INDEX_5) + 1) * sizeof(char)); 
     767                                strcpy(opt[6], RRD_PARAM_INDEX_5); 
     768                                opt[7]= (char *) malloc((strlen(RRD_PARAM_INDEX_6) + 1) * sizeof(char)); 
     769                                strcpy(opt[7], RRD_PARAM_INDEX_6); 
     770                                opt[8]= (char *) malloc((strlen(RRD_PARAM_INDEX_7) + 1) * sizeof(char)); 
     771                                strcpy(opt[8], RRD_PARAM_INDEX_7); 
     772                                opt[9]= (char *) malloc((strlen(RRD_PARAM_INDEX_8) + 1) * sizeof(char)); 
     773                                strcpy(opt[9], RRD_PARAM_INDEX_8); 
     774                                opt[10]= (char *) malloc((strlen(RRD_PARAM_INDEX_9) + 1) * sizeof(char)); 
     775                                strcpy(opt[10], RRD_PARAM_INDEX_9); 
     776                                opt[11]= (char *) malloc((strlen(RRD_PARAM_INDEX_10) + 1) * sizeof(char)); 
     777                                strcpy(opt[11], RRD_PARAM_INDEX_10); 
     778                                opt[12]= (char *) malloc((strlen(RRD_PARAM_INDEX_11) + 1) * sizeof(char)); 
     779                                strcpy(opt[12], RRD_PARAM_INDEX_11); 
     780                                opt[13]= (char *) malloc((strlen(RRD_PARAM_INDEX_12) + 1) * sizeof(char)); 
     781                                strcpy(opt[13], RRD_PARAM_INDEX_12); 
     782                                opt[14]= (char *) malloc((strlen(RRD_PARAM_INDEX_13) + 1) * sizeof(char)); 
     783                                strcpy(opt[14], RRD_PARAM_INDEX_13); 
     784                                opt[15]= (char *) malloc((strlen(RRD_PARAM_INDEX_14) + 1) * sizeof(char)); 
     785                                strcpy(opt[15], RRD_PARAM_INDEX_14); 
     786                                opt[16]= (char *) malloc((strlen(RRD_PARAM_INDEX_15) + 1) * sizeof(char)); 
     787                                strcpy(opt[16], RRD_PARAM_INDEX_15); 
     788                                opt[17]= (char *) malloc((strlen(RRD_PARAM_INDEX_16) + 1) * sizeof(char)); 
     789                                strcpy(opt[17], RRD_PARAM_INDEX_16); 
     790                                opt[18]= (char *) malloc((strlen(RRD_PARAM_INDEX_17) + 1) * sizeof(char)); 
     791                                strcpy(opt[18], RRD_PARAM_INDEX_17); 
     792                                optind = opterr = 0; 
     793                                rrd_clear_error(); 
     794                                if ( rrd_create(19,opt) < 0) 
     795                                { 
     796                                    syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
     797                                    rrd_create_er_ct++; 
     798                                } 
     799                                else 
     800                                { 
     801                                    rrd_create_ok_ct++; 
     802                                } 
     803                                for ( k=0; k<19; k++) 
     804                                { 
     805                                    free(opt[k]); 
     806                                    opt[k] = NULL; 
     807                                } 
     808                            } 
     809                            else 
     810                            { 
     811                                fclose(fp); 
     812                                rrd_already_created_ct++; 
     813                                snprintf(buf, 
     814                                         2048, 
     815                                         "%lu:%llu:%llu:%llu:%llu:%llu:%llu", 
     816                                         now-300,  /* or ctime(&now) with %s */ 
     817                                         shmForAgg->indexV6Tab[index][i][j].flowNbIN,  /* 1 */ 
     818                                         shmForAgg->indexV6Tab[index][i][j].flowNbOUT, 
     819                                         shmForAgg->indexV6Tab[index][i][j].bytesNbIN, 
     820                                         shmForAgg->indexV6Tab[index][i][j].bytesNbOUT, 
     821                                         shmForAgg->indexV6Tab[index][i][j].pktsNbIN,  /* 5 */ 
     822                                         shmForAgg->indexV6Tab[index][i][j].pktsNbOUT 
     823                                        ); 
     824                                optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
     825                                strcpy(optUpdate[0], RRD_UPDATE_0); 
     826                                optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     827                                strcpy(optUpdate[1], name); 
     828                                optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
     829                                strcpy(optUpdate[2], buf); 
     830                                optind = opterr = 0; 
     831                                rrd_clear_error(); 
     832                                if ( rrd_update(3, optUpdate) < 0 ) 
     833                                { 
     834                                    syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
     835                                    rrd_update_er_ct++; 
     836                                } 
     837                                else 
     838                                { 
     839                                    rrd_update_ok_ct++; 
     840                                } 
     841                                for ( k=0; k<3; k++) 
     842                                { 
     843                                    free(optUpdate[k]); 
     844                                    optUpdate[k] = NULL; 
     845                                } 
     846                            } 
     847                            shmForAgg->indexV6Tab[index][i][j].bytesNbIN = 0; 
     848                            shmForAgg->indexV6Tab[index][i][j].pktsNbIN = 0; 
     849                            shmForAgg->indexV6Tab[index][i][j].flowNbIN = 0; 
     850                            shmForAgg->indexV6Tab[index][i][j].bytesNbOUT = 0; 
     851                            shmForAgg->indexV6Tab[index][i][j].pktsNbOUT = 0; 
     852                            shmForAgg->indexV6Tab[index][i][j].flowNbOUT = 0; 
     853                        } 
     854                    } 
     855                } 
    719856#endif 
    720857#endif /* AS */ 
    721         if (rrdMibsUpdate(index) != 1) {syslog(LOG_ERR, "ERROR in RRD MIBs update file\n");} 
    722         now2 = time((time_t *)NULL); 
     858                if (rrdMibsUpdate(index) != 1) 
     859                { 
     860                    syslog(LOG_ERR, "ERROR in RRD MIBs update file\n"); 
     861                } 
     862                if (rrdL7IPv4MibsUpdate(index) != 1) 
     863                { 
     864                    syslog(LOG_ERR, "ERROR in RRD MIBs update file\n"); 
     865                } 
     866                now2 = time((time_t *)NULL); 
    723867#ifdef DEBUGAGG 
    724         fprintf(stderr, "IPv4 subnet managment (rrd update) : \n %d sec, %d files updated, %d errors, total %d\n %d rrd file already created, %d errors in creation, %d new rrd file creations", 
    725                 (int)now2-now, 
    726                 rrd_update_ok_ct, 
    727                 rrd_update_er_ct, 
    728                 rrd_update_ok_ct+rrd_update_er_ct, 
    729                 rrd_already_created_ct, 
    730                 rrd_create_er_ct, 
    731                 rrd_create_ok_ct); 
     868                fprintf(stderr, "IPv4 subnet managment (rrd update) : \n %d sec, %d files updated, %d errors, total %d\n %d rrd file already created, %d errors in creation, %d new rrd file creations", 
     869                        (int)now2-now, 
     870                        rrd_update_ok_ct, 
     871                        rrd_update_er_ct, 
     872                        rrd_update_ok_ct+rrd_update_er_ct, 
     873                        rrd_already_created_ct, 
     874                        rrd_create_er_ct, 
     875                        rrd_create_ok_ct); 
    732876#endif 
    733         rrd_update_ok_ct = 0; 
    734         rrd_update_er_ct = 0; 
    735         rrd_already_created_ct = 0; 
    736         rrd_create_er_ct = 0; 
    737         rrd_create_ok_ct = 0; 
    738         rrd_clear_error(); 
    739       } else { 
    740         isFirstUpdate = 0; 
    741         /* RRD Update only for the MIB counters, else we clear all counters in shared memory (after) */ 
    742         if (rrdMibsUpdate(index) != 1) {syslog(LOG_ERR, "ERROR in RRD MIBs update file\n");} 
    743         /* CLEAR */ 
    744         for (i=0; i<shmForAgg->v4PrefixNb; i++){ 
    745           shmForAgg->prefixV4Tab[index][i].flowNbIN = 0; 
    746           shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0; 
    747           shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0; 
    748           shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0; 
    749           shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0; 
    750           shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0; 
    751           shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0; 
    752           shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0; 
    753           shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0; 
    754           shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0; 
    755           shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0; 
    756           shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0; 
    757           shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0; 
    758           shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0;  
    759         } 
    760         for (i=0; i<shmForAgg->v4SubnetNb; i++){         
    761           shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0; 
    762           shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0; 
    763           shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0; 
    764           shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0; 
    765           shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0; 
    766           shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0; 
    767           shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0; 
    768           shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0; 
    769           shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0; 
    770           shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0; 
    771           shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0; 
    772           shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0; 
    773           shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0; 
    774           shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0;  
    775         } 
     877                rrd_update_ok_ct = 0; 
     878                rrd_update_er_ct = 0; 
     879                rrd_already_created_ct = 0; 
     880                rrd_create_er_ct = 0; 
     881                rrd_create_ok_ct = 0; 
     882                rrd_clear_error(); 
     883            } 
     884            else 
     885            { 
     886                isFirstUpdate = 0; 
     887                /* RRD Update only for the MIB counters, else we clear all counters in shared memory (after) */ 
     888                if (rrdMibsUpdate(index) != 1) 
     889                { 
     890                    syslog(LOG_ERR, "ERROR in RRD MIBs update file\n"); 
     891                } 
     892                if (rrdL7IPv4MibsUpdate(index) != 1) 
     893                { 
     894                    syslog(LOG_ERR, "ERROR in RRD MIBs update file\n"); 
     895                } 
     896                /* CLEAR */ 
     897                for (i=0; i<shmForAgg->v4PrefixNb; i++) 
     898                { 
     899                    shmForAgg->prefixV4Tab[index][i].flowNbIN = 0; 
     900                    shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0; 
     901                    shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0; 
     902                    shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0; 
     903                    shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0; 
     904                    shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0; 
     905                    shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0; 
     906                    shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0; 
     907                    shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0; 
     908                    shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0; 
     909                    shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0; 
     910                    shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0; 
     911                    shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0; 
     912                    shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0; 
     913                } 
     914                for (i=0; i<shmForAgg->v4SubnetNb; i++) 
     915                { 
     916                    shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0; 
     917                    shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0; 
     918                    shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0; 
     919                    shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0; 
     920                    shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0; 
     921                    shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0; 
     922                    shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0; 
     923                    shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0; 
     924                    shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0; 
     925                    shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0; 
     926                    shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0; 
     927                    shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0; 
     928                    shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0; 
     929                    shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0; 
     930                } 
    776931#ifdef MATRIX 
    777         for (i=0; i<ROUTER_INDEX_MAX; i++){ 
    778           for (j=0; j<ROUTER_INDEX_MAX; j++) { 
    779             shmForAgg->matrixPOP[index][i][j].bytesNb = 0; 
    780             shmForAgg->matrixPOP[index][i][j].pktsNb = 0; 
    781             shmForAgg->matrixPOP[index][i][j].flowNb = 0; 
    782           } 
    783         } 
     932                for (i=0; i<ROUTER_INDEX_MAX; i++) 
     933                { 
     934                    for (j=0; j<ROUTER_INDEX_MAX; j++) 
     935                    { 
     936                        shmForAgg->matrixPOP[index][i][j].bytesNb = 0; 
     937                        shmForAgg->matrixPOP[index][i][j].pktsNb = 0; 
     938                        shmForAgg->matrixPOP[index][i][j].flowNb = 0; 
     939                    } 
     940                } 
    784941#endif 
    785942#ifdef ASACC 
    786         for (i=0; i<shmForAgg->ASNb; i++){ 
    787           shmForAgg->ASTab[index][i].flowNbIN = 0; 
    788           shmForAgg->ASTab[index][i].bytesNbIN = 0; 
    789           shmForAgg->ASTab[index][i].pktsNbIN = 0; 
    790           shmForAgg->ASTab[index][i].flowNbOUT = 0; 
    791           shmForAgg->ASTab[index][i].bytesNbOUT = 0; 
    792           shmForAgg->ASTab[index][i].pktsNbOUT = 0; 
    793         } 
     943                for (i=0; i<shmForAgg->ASNb; i++) 
     944                { 
     945                    shmForAgg->ASTab[index][i].flowNbIN = 0; 
     946                    shmForAgg->ASTab[index][i].bytesNbIN = 0; 
     947                    shmForAgg->ASTab[index][i].pktsNbIN = 0; 
     948                    shmForAgg->ASTab[index][i].flowNbOUT = 0; 
     949                    shmForAgg->ASTab[index][i].bytesNbOUT = 0; 
     950                    shmForAgg->ASTab[index][i].pktsNbOUT = 0; 
     951                } 
    794952#endif 
    795953#ifdef IPV6LINKAGG 
    796         for (i=0; i<ROUTER_INDEX_MAX; i++){ 
    797           for (j=0; j<MAX_INDEX_BY_ROUTER; j++) { 
    798             shmForAgg->indexV6Tab[index][i][j].bytesNbIN = 0; 
    799             shmForAgg->indexV6Tab[index][i][j].pktsNbIN = 0; 
    800             shmForAgg->indexV6Tab[index][i][j].flowNbIN = 0; 
    801             shmForAgg->indexV6Tab[index][i][j].bytesNbOUT = 0; 
    802             shmForAgg->indexV6Tab[index][i][j].pktsNbOUT = 0; 
    803             shmForAgg->indexV6Tab[index][i][j].flowNbOUT = 0; 
    804           } 
    805         } 
     954                for (i=0; i<ROUTER_INDEX_MAX; i++) 
     955                { 
     956                    for (j=0; j<MAX_INDEX_BY_ROUTER; j++) 
     957                    { 
     958                        shmForAgg->indexV6Tab[index][i][j].bytesNbIN = 0; 
     959                        shmForAgg->indexV6Tab[index][i][j].pktsNbIN = 0; 
     960                        shmForAgg->indexV6Tab[index][i][j].flowNbIN = 0; 
     961                        shmForAgg->indexV6Tab[index][i][j].bytesNbOUT = 0; 
     962                        shmForAgg->indexV6Tab[index][i][j].pktsNbOUT = 0; 
     963                        shmForAgg->indexV6Tab[index][i][j].flowNbOUT = 0; 
     964                    } 
     965                } 
    806966#endif 
    807         /* reinit */ 
    808       } /* end is first update */  
    809     } /* end read ok */ 
    810     sleep(10); 
    811   } while (1); 
    812   exit(0); 
     967                /* reinit */ 
     968            } /* end is first update */ 
     969        } /* end read ok */ 
     970        sleep(10); 
     971    } 
     972    while (1); 
     973    exit(0); 
    813974} 
    814975 
     
    819980short rrdMibsUpdate(int index) 
    820981{ 
    821   int i, j, k = 0; 
    822   int rrd_update_er_ct = 0; 
    823   int rrd_update_ok_ct = 0; 
    824   int rrd_already_created_ct = 0; 
    825   int rrd_create_er_ct = 0; 
    826   int rrd_create_ok_ct = 0; 
    827   static char buf[2048]; 
    828   static char name[2048]; 
    829   static char createstr[2048]; 
    830   char *opt[27]; 
    831   char *optUpdate[3]; 
    832   FILE *fp; 
    833   static time_t now, now2; 
    834  
    835   now = time((time_t *)NULL); 
    836   for (k=0; k<strlen(name); k++) {name[k] = '\0';} 
    837   for (k=0; k<strlen(buf); k++) {buf[k] = '\0';} 
    838   strcat(name, MIB_RRD_LOCATION); 
    839   strcat(name, GLOBAL_MIB_RRD_FILE); 
    840   if ( (fp=fopen(name,"r")) == NULL ){ 
    841     opt[0]= (char *) malloc((strlen(RRD_PARAM_MIB_0) + 1) * sizeof(char)); 
    842     strcpy(opt[0], RRD_PARAM_MIB_0); 
    843     opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
    844     strcpy(opt[1], name); 
    845     opt[2]= (char *) malloc((strlen(RRD_PARAM_MIB_1) + 1) * sizeof(char)); 
    846     strcpy(opt[2], RRD_PARAM_MIB_1); 
    847     opt[3]= (char *) malloc((strlen(RRD_PARAM_MIB_2) + 1) * sizeof(char)); 
    848     strcpy(opt[3], RRD_PARAM_MIB_2); 
    849     opt[4]= (char *) malloc((strlen(RRD_PARAM_MIB_3) + 1) * sizeof(char)); 
    850     strcpy(opt[4], RRD_PARAM_MIB_3); 
    851     opt[5]= (char *) malloc((strlen(RRD_PARAM_MIB_4) + 1) * sizeof(char)); 
    852     strcpy(opt[5], RRD_PARAM_MIB_4); 
    853     opt[6]= (char *) malloc((strlen(RRD_PARAM_MIB_5) + 1) * sizeof(char)); 
    854     strcpy(opt[6], RRD_PARAM_MIB_5); 
    855     opt[7]= (char *) malloc((strlen(RRD_PARAM_MIB_6) + 1) * sizeof(char)); 
    856     strcpy(opt[7], RRD_PARAM_MIB_6); 
    857     opt[8]= (char *) malloc((strlen(RRD_PARAM_MIB_7) + 1) * sizeof(char)); 
    858     strcpy(opt[8], RRD_PARAM_MIB_7); 
    859     opt[9]= (char *) malloc((strlen(RRD_PARAM_MIB_8) + 1) * sizeof(char)); 
    860     strcpy(opt[9], RRD_PARAM_MIB_8); 
    861     opt[10]= (char *) malloc((strlen(RRD_PARAM_MIB_9) + 1) * sizeof(char)); 
    862     strcpy(opt[10], RRD_PARAM_MIB_9); 
    863     opt[11]= (char *) malloc((strlen(RRD_PARAM_MIB_10) + 1) * sizeof(char)); 
    864     strcpy(opt[11], RRD_PARAM_MIB_10); 
    865     opt[12]= (char *) malloc((strlen(RRD_PARAM_MIB_11) + 1) * sizeof(char)); 
    866     strcpy(opt[12], RRD_PARAM_MIB_11); 
    867     opt[13]= (char *) malloc((strlen(RRD_PARAM_MIB_12) + 1) * sizeof(char)); 
    868     strcpy(opt[13], RRD_PARAM_MIB_12); 
    869     opt[14]= (char *) malloc((strlen(RRD_PARAM_MIB_13) + 1) * sizeof(char)); 
    870     strcpy(opt[14], RRD_PARAM_MIB_13); 
    871     opt[15]= (char *) malloc((strlen(RRD_PARAM_MIB_14) + 1) * sizeof(char)); 
    872     strcpy(opt[15], RRD_PARAM_MIB_14); 
    873     opt[16]= (char *) malloc((strlen(RRD_PARAM_MIB_15) + 1) * sizeof(char)); 
    874     strcpy(opt[16], RRD_PARAM_MIB_15); 
    875     opt[17]= (char *) malloc((strlen(RRD_PARAM_MIB_16) + 1) * sizeof(char)); 
    876     strcpy(opt[17], RRD_PARAM_MIB_16); 
    877     opt[18]= (char *) malloc((strlen(RRD_PARAM_MIB_17) + 1) * sizeof(char)); 
    878     strcpy(opt[18], RRD_PARAM_MIB_17); 
    879     opt[19]= (char *) malloc((strlen(RRD_PARAM_MIB_18) + 1) * sizeof(char)); 
    880     strcpy(opt[19], RRD_PARAM_MIB_18); 
    881     opt[20]= (char *) malloc((strlen(RRD_PARAM_MIB_19) + 1) * sizeof(char)); 
    882     strcpy(opt[20], RRD_PARAM_MIB_19); 
    883     opt[21]= (char *) malloc((strlen(RRD_PARAM_MIB_20) + 1) * sizeof(char)); 
    884     strcpy(opt[21], RRD_PARAM_MIB_20); 
    885     opt[22]= (char *) malloc((strlen(RRD_PARAM_MIB_21) + 1) * sizeof(char)); 
    886     strcpy(opt[22], RRD_PARAM_MIB_21); 
    887     opt[23]= (char *) malloc((strlen(RRD_PARAM_MIB_22) + 1) * sizeof(char)); 
    888     strcpy(opt[23], RRD_PARAM_MIB_22); 
    889     optind = opterr = 0; 
    890     rrd_clear_error(); 
    891     if ( rrd_create(24,opt) < 0) { 
    892       syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
    893       rrd_create_er_ct++; 
    894     } else { 
    895       rrd_create_ok_ct++; 
     982    int i, j, k = 0; 
     983    int rrd_update_er_ct = 0; 
     984    int rrd_update_ok_ct = 0; 
     985    int rrd_already_created_ct = 0; 
     986    int rrd_create_er_ct = 0; 
     987    int rrd_create_ok_ct = 0; 
     988    static char buf[2048]; 
     989    static char name[2048]; 
     990    static char createstr[2048]; 
     991    char *opt[27]; 
     992    char *optUpdate[3]; 
     993    FILE *fp; 
     994    static time_t now, now2; 
     995 
     996    now = time((time_t *)NULL); 
     997    for (k=0; k<strlen(name); k++) 
     998    { 
     999        name[k] = '\0'; 
    8961000    } 
    897     for ( k=0; k<24; k++) { 
    898       free(opt[k]); 
    899       opt[k] = NULL; 
     1001    for (k=0; k<strlen(buf); k++) 
     1002    { 
     1003        buf[k] = '\0'; 
    9001004    } 
    901   }else{  
    902     fclose(fp); 
    903     rrd_already_created_ct++; 
    904     snprintf(buf,  
    905              2048,  
    906              "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",   
    907              now-300,  /* or ctime(&now) with %s */ 
    908              shmForAgg->myMIB[index].ipPacketNb, 
    909              shmForAgg->myMIB[index].udpPacketNb, 
    910              shmForAgg->myMIB[index].v9PacketNb, 
    911              shmForAgg->myMIB[index].v9UnSeqNb, 
    912              shmForAgg->myMIB[index].flowSetNb, 
    913              shmForAgg->myMIB[index].dataFlowSetNb, 
    914              shmForAgg->myMIB[index].defFlowSetNb, 
    915              shmForAgg->myMIB[index].optDataFlowSetNb, 
    916              shmForAgg->myMIB[index].optDefFlowSetNb, 
    917              shmForAgg->myMIB[index].flowNb, 
    918              shmForAgg->myMIB[index].realFlowNb 
    919              ); 
    920     fprintf(stderr,"\n%s\n",buf); 
    921     optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
    922     strcpy(optUpdate[0], RRD_UPDATE_0); 
    923     optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
    924     strcpy(optUpdate[1], name); 
    925     optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
    926     strcpy(optUpdate[2], buf); 
    927     optind = opterr = 0;  
    928     rrd_clear_error(); 
    929     if ( rrd_update(3, optUpdate) < 0 ) {  
    930       syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
    931       rrd_update_er_ct++; 
    932     } else { 
    933       rrd_update_ok_ct++; 
     1005    strcat(name, MIB_RRD_LOCATION); 
     1006    strcat(name, GLOBAL_MIB_RRD_FILE); 
     1007    if ( (fp=fopen(name,"r")) == NULL ) 
     1008    { 
     1009        opt[0]= (char *) malloc((strlen(RRD_PARAM_MIB_0) + 1) * sizeof(char)); 
     1010        strcpy(opt[0], RRD_PARAM_MIB_0); 
     1011        opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     1012        strcpy(opt[1], name); 
     1013        opt[2]= (char *) malloc((strlen(RRD_PARAM_MIB_1) + 1) * sizeof(char)); 
     1014        strcpy(opt[2], RRD_PARAM_MIB_1); 
     1015        opt[3]= (char *) malloc((strlen(RRD_PARAM_MIB_2) + 1) * sizeof(char)); 
     1016        strcpy(opt[3], RRD_PARAM_MIB_2); 
     1017        opt[4]= (char *) malloc((strlen(RRD_PARAM_MIB_3) + 1) * sizeof(char)); 
     1018        strcpy(opt[4], RRD_PARAM_MIB_3); 
     1019        opt[5]= (char *) malloc((strlen(RRD_PARAM_MIB_4) + 1) * sizeof(char)); 
     1020        strcpy(opt[5], RRD_PARAM_MIB_4); 
     1021        opt[6]= (char *) malloc((strlen(RRD_PARAM_MIB_5) + 1) * sizeof(char)); 
     1022        strcpy(opt[6], RRD_PARAM_MIB_5); 
     1023        opt[7]= (char *) malloc((strlen(RRD_PARAM_MIB_6) + 1) * sizeof(char)); 
     1024        strcpy(opt[7], RRD_PARAM_MIB_6); 
     1025        opt[8]= (char *) malloc((strlen(RRD_PARAM_MIB_7) + 1) * sizeof(char)); 
     1026        strcpy(opt[8], RRD_PARAM_MIB_7); 
     1027        opt[9]= (char *) malloc((strlen(RRD_PARAM_MIB_8) + 1) * sizeof(char)); 
     1028        strcpy(opt[9], RRD_PARAM_MIB_8); 
     1029        opt[10]= (char *) malloc((strlen(RRD_PARAM_MIB_9) + 1) * sizeof(char)); 
     1030        strcpy(opt[10], RRD_PARAM_MIB_9); 
     1031        opt[11]= (char *) malloc((strlen(RRD_PARAM_MIB_10) + 1) * sizeof(char)); 
     1032        strcpy(opt[11], RRD_PARAM_MIB_10); 
     1033        opt[12]= (char *) malloc((strlen(RRD_PARAM_MIB_11) + 1) * sizeof(char)); 
     1034        strcpy(opt[12], RRD_PARAM_MIB_11); 
     1035        opt[13]= (char *) malloc((strlen(RRD_PARAM_MIB_12) + 1) * sizeof(char)); 
     1036        strcpy(opt[13], RRD_PARAM_MIB_12); 
     1037        opt[14]= (char *) malloc((strlen(RRD_PARAM_MIB_13) + 1) * sizeof(char)); 
     1038        strcpy(opt[14], RRD_PARAM_MIB_13); 
     1039        opt[15]= (char *) malloc((strlen(RRD_PARAM_MIB_14) + 1) * sizeof(char)); 
     1040        strcpy(opt[15], RRD_PARAM_MIB_14); 
     1041        opt[16]= (char *) malloc((strlen(RRD_PARAM_MIB_15) + 1) * sizeof(char)); 
     1042        strcpy(opt[16], RRD_PARAM_MIB_15); 
     1043        opt[17]= (char *) malloc((strlen(RRD_PARAM_MIB_16) + 1) * sizeof(char)); 
     1044        strcpy(opt[17], RRD_PARAM_MIB_16); 
     1045        opt[18]= (char *) malloc((strlen(RRD_PARAM_MIB_17) + 1) * sizeof(char)); 
     1046        strcpy(opt[18], RRD_PARAM_MIB_17); 
     1047        opt[19]= (char *) malloc((strlen(RRD_PARAM_MIB_18) + 1) * sizeof(char)); 
     1048        strcpy(opt[19], RRD_PARAM_MIB_18); 
     1049        opt[20]= (char *) malloc((strlen(RRD_PARAM_MIB_19) + 1) * sizeof(char)); 
     1050        strcpy(opt[20], RRD_PARAM_MIB_19); 
     1051        opt[21]= (char *) malloc((strlen(RRD_PARAM_MIB_20) + 1) * sizeof(char)); 
     1052        strcpy(opt[21], RRD_PARAM_MIB_20); 
     1053        opt[22]= (char *) malloc((strlen(RRD_PARAM_MIB_21) + 1) * sizeof(char)); 
     1054        strcpy(opt[22], RRD_PARAM_MIB_21); 
     1055        opt[23]= (char *) malloc((strlen(RRD_PARAM_MIB_22) + 1) * sizeof(char)); 
     1056        strcpy(opt[23], RRD_PARAM_MIB_22); 
     1057        optind = opterr = 0; 
     1058        rrd_clear_error(); 
     1059        if ( rrd_create(24,opt) < 0) 
     1060        { 
     1061            syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
     1062            rrd_create_er_ct++; 
     1063        } 
     1064        else 
     1065        { 
     1066            rrd_create_ok_ct++; 
     1067        } 
     1068        for ( k=0; k<24; k++) 
     1069        { 
     1070            free(opt[k]); 
     1071            opt[k] = NULL; 
     1072        } 
    9341073    } 
    935     for ( k=0; k<3; k++) { 
    936       free(optUpdate[k]); 
    937       optUpdate[k] = NULL; 
     1074    else 
     1075    { 
     1076        fclose(fp); 
     1077        rrd_already_created_ct++; 
     1078        snprintf(buf, 
     1079                 2048, 
     1080                 "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu", 
     1081                 now-300,  /* or ctime(&now) with %s */ 
     1082                 shmForAgg->myMIB[index].ipPacketNb, 
     1083                 shmForAgg->myMIB[index].udpPacketNb, 
     1084                 shmForAgg->myMIB[index].v9PacketNb, 
     1085                 shmForAgg->myMIB[index].v9UnSeqNb, 
     1086                 shmForAgg->myMIB[index].flowSetNb, 
     1087                 shmForAgg->myMIB[index].dataFlowSetNb, 
     1088                 shmForAgg->myMIB[index].defFlowSetNb, 
     1089                 shmForAgg->myMIB[index].optDataFlowSetNb, 
     1090                 shmForAgg->myMIB[index].optDefFlowSetNb, 
     1091                 shmForAgg->myMIB[index].flowNb, 
     1092                 shmForAgg->myMIB[index].realFlowNb 
     1093                ); 
     1094        fprintf(stderr,"\n%s\n",buf); 
     1095        optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
     1096        strcpy(optUpdate[0], RRD_UPDATE_0); 
     1097        optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     1098        strcpy(optUpdate[1], name); 
     1099        optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
     1100        strcpy(optUpdate[2], buf); 
     1101        optind = opterr = 0; 
     1102        rrd_clear_error(); 
     1103        if ( rrd_update(3, optUpdate) < 0 ) 
     1104        { 
     1105            syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
     1106            rrd_update_er_ct++; 
     1107        } 
     1108        else 
     1109        { 
     1110            rrd_update_ok_ct++; 
     1111        } 
     1112        for ( k=0; k<3; k++) 
     1113        { 
     1114            free(optUpdate[k]); 
     1115            optUpdate[k] = NULL; 
     1116        } 
    9381117    } 
    939   } 
    940   shmForAgg->myMIB[index].ipPacketNb = 0; 
    941   shmForAgg->myMIB[index].udpPacketNb = 0; 
    942   shmForAgg->myMIB[index].v9PacketNb = 0; 
    943   shmForAgg->myMIB[index].v9UnSeqNb = 0; 
    944   shmForAgg->myMIB[index].flowSetNb = 0; 
    945   shmForAgg->myMIB[index].dataFlowSetNb = 0; 
    946   shmForAgg->myMIB[index].defFlowSetNb = 0; 
    947   shmForAgg->myMIB[index].optDataFlowSetNb = 0; 
    948   shmForAgg->myMIB[index].optDefFlowSetNb = 0; 
    949   shmForAgg->myMIB[index].flowNb = 0; 
    950   shmForAgg->myMIB[index].realFlowNb = 0; 
    951   return 1; 
     1118    shmForAgg->myMIB[index].ipPacketNb = 0; 
     1119    shmForAgg->myMIB[index].udpPacketNb = 0; 
     1120    shmForAgg->myMIB[index].v9PacketNb = 0; 
     1121    shmForAgg->myMIB[index].v9UnSeqNb = 0; 
     1122    shmForAgg->myMIB[index].flowSetNb = 0; 
     1123    shmForAgg->myMIB[index].dataFlowSetNb = 0; 
     1124    shmForAgg->myMIB[index].defFlowSetNb = 0; 
     1125    shmForAgg->myMIB[index].optDataFlowSetNb = 0; 
     1126    shmForAgg->myMIB[index].optDefFlowSetNb = 0; 
     1127    shmForAgg->myMIB[index].flowNb = 0; 
     1128    shmForAgg->myMIB[index].realFlowNb = 0; 
     1129    return 1; 
    9521130} 
     1131 
     1132/* 
     1133 * rrdL7IPv4MibsUpdate 
     1134 */ 
     1135short rrdL7IPv4MibsUpdate(int index) 
     1136{ 
     1137    int i, j, k = 0; 
     1138    int rrd_update_er_ct = 0; 
     1139    int rrd_update_ok_ct = 0; 
     1140    int rrd_already_created_ct = 0; 
     1141    int rrd_create_er_ct = 0; 
     1142    int rrd_create_ok_ct = 0; 
     1143    static char buf[2048]; 
     1144    static char name[2048]; 
     1145    static char createstr[2048]; 
     1146    char *opt[27]; 
     1147    char *optUpdate[3]; 
     1148    FILE *fp; 
     1149    static time_t now, now2; 
     1150 
     1151    now = time((time_t *)NULL); 
     1152    for (k=0; k<strlen(name); k++) 
     1153    { 
     1154        name[k] = '\0'; 
     1155    } 
     1156    for (k=0; k<strlen(buf); k++) 
     1157    { 
     1158        buf[k] = '\0'; 
     1159    } 
     1160    strcat(name, MIB_RRD_LOCATION); 
     1161    strcat(name, L7_IPV4_MIB_RRD_FILE); 
     1162    if ( (fp=fopen(name,"r")) == NULL ) 
     1163    { 
     1164        opt[0]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_0) + 1) * sizeof(char)); 
     1165        strcpy(opt[0], RRD_PARAM_MIB_IPV4_AP_0); 
     1166        opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     1167        strcpy(opt[1], name); 
     1168        opt[2]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_1) + 1) * sizeof(char)); 
     1169        strcpy(opt[2], RRD_PARAM_MIB_IPV4_AP_1); 
     1170        opt[3]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_2) + 1) * sizeof(char)); 
     1171        strcpy(opt[3], RRD_PARAM_MIB_IPV4_AP_2); 
     1172        opt[4]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_3) + 1) * sizeof(char)); 
     1173        strcpy(opt[4], RRD_PARAM_MIB_IPV4_AP_3); 
     1174        opt[5]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_4) + 1) * sizeof(char)); 
     1175        strcpy(opt[5], RRD_PARAM_MIB_IPV4_AP_4); 
     1176        opt[6]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_5) + 1) * sizeof(char)); 
     1177        strcpy(opt[6], RRD_PARAM_MIB_IPV4_AP_5); 
     1178        opt[7]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_6) + 1) * sizeof(char)); 
     1179        strcpy(opt[7], RRD_PARAM_MIB_IPV4_AP_6); 
     1180        opt[8]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_7) + 1) * sizeof(char)); 
     1181        strcpy(opt[8], RRD_PARAM_MIB_IPV4_AP_7); 
     1182        opt[9]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_8) + 1) * sizeof(char)); 
     1183        strcpy(opt[9], RRD_PARAM_MIB_IPV4_AP_8); 
     1184        opt[10]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_9) + 1) * sizeof(char)); 
     1185        strcpy(opt[10], RRD_PARAM_MIB_IPV4_AP_9); 
     1186        opt[11]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_10) + 1) * sizeof(char)); 
     1187        strcpy(opt[11], RRD_PARAM_MIB_IPV4_AP_10); 
     1188        opt[12]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_11) + 1) * sizeof(char)); 
     1189        strcpy(opt[12], RRD_PARAM_MIB_IPV4_AP_11); 
     1190        opt[13]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_12) + 1) * sizeof(char)); 
     1191        strcpy(opt[13], RRD_PARAM_MIB_IPV4_AP_12); 
     1192        opt[14]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_13) + 1) * sizeof(char)); 
     1193        strcpy(opt[14], RRD_PARAM_MIB_IPV4_AP_13); 
     1194        opt[15]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_14) + 1) * sizeof(char)); 
     1195        strcpy(opt[15], RRD_PARAM_MIB_IPV4_AP_14); 
     1196        opt[16]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_15) + 1) * sizeof(char)); 
     1197        strcpy(opt[16], RRD_PARAM_MIB_IPV4_AP_15); 
     1198        opt[17]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_16) + 1) * sizeof(char)); 
     1199        strcpy(opt[17], RRD_PARAM_MIB_IPV4_AP_16); 
     1200        opt[18]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_17) + 1) * sizeof(char)); 
     1201        strcpy(opt[18], RRD_PARAM_MIB_IPV4_AP_17); 
     1202        opt[19]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_18) + 1) * sizeof(char)); 
     1203        strcpy(opt[19], RRD_PARAM_MIB_IPV4_AP_18); 
     1204        opt[20]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_19) + 1) * sizeof(char)); 
     1205        strcpy(opt[20], RRD_PARAM_MIB_IPV4_AP_19); 
     1206        opt[21]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_20) + 1) * sizeof(char)); 
     1207        strcpy(opt[21], RRD_PARAM_MIB_IPV4_AP_20); 
     1208        opt[22]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_21) + 1) * sizeof(char)); 
     1209        strcpy(opt[22], RRD_PARAM_MIB_IPV4_AP_21); 
     1210        opt[23]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_22) + 1) * sizeof(char)); 
     1211        strcpy(opt[23], RRD_PARAM_MIB_IPV4_AP_22); 
     1212        opt[24]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_23) + 1) * sizeof(char)); 
     1213        strcpy(opt[24], RRD_PARAM_MIB_IPV4_AP_23); 
     1214        optind = opterr = 0; 
     1215        rrd_clear_error(); 
     1216        if ( rrd_create(25,opt) < 0) 
     1217        { 
     1218            syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); 
     1219            rrd_create_er_ct++; 
     1220        } 
     1221        else 
     1222        { 
     1223            rrd_create_ok_ct++; 
     1224        } 
     1225        for ( k=0; k<25; k++) 
     1226        { 
     1227            free(opt[k]); 
     1228            opt[k] = NULL; 
     1229        } 
     1230    } 
     1231    else 
     1232    { 
     1233        fclose(fp); 
     1234        rrd_already_created_ct++; 
     1235        snprintf(buf, 
     1236                 2048, 
     1237                 "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu", 
     1238                 now-300,  /* or ctime(&now) with %s */ 
     1239                 shmForAgg->myMIB[index].ipv4WebBytesNb, 
     1240                 shmForAgg->myMIB[index].ipv4WebPcktsNb, 
     1241                 shmForAgg->myMIB[index].ipv4WebFlowNb, 
     1242                 shmForAgg->myMIB[index].ipv4MailBytesNb, 
     1243                 shmForAgg->myMIB[index].ipv4MailPcktsNb, 
     1244                 shmForAgg->myMIB[index].ipv4MailFlowNb, 
     1245                 shmForAgg->myMIB[index].ipv4DNSBytesNb, 
     1246                 shmForAgg->myMIB[index].ipv4DNSPcktsNb, 
     1247                 shmForAgg->myMIB[index].ipv4DNSFlowNb, 
     1248                 shmForAgg->myMIB[index].ipv4OthersApBytesNb, 
     1249                 shmForAgg->myMIB[index].ipv4OthersApPcktsNb, 
     1250                 shmForAgg->myMIB[index].ipv4OthersApFlowNb 
     1251                ); 
     1252        fprintf(stderr,"\n%s\n",buf); 
     1253        optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); 
     1254        strcpy(optUpdate[0], RRD_UPDATE_0); 
     1255        optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); 
     1256        strcpy(optUpdate[1], name); 
     1257        optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); 
     1258        strcpy(optUpdate[2], buf); 
     1259        optind = opterr = 0; 
     1260        rrd_clear_error(); 
     1261        if ( rrd_update(3, optUpdate) < 0 ) 
     1262        { 
     1263            syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); 
     1264            rrd_update_er_ct++; 
     1265        } 
     1266        else 
     1267        { 
     1268            rrd_update_ok_ct++; 
     1269        } 
     1270        for ( k=0; k<3; k++) 
     1271        { 
     1272            free(optUpdate[k]); 
     1273            optUpdate[k] = NULL; 
     1274        } 
     1275    } 
     1276    shmForAgg->myMIB[index].ipv4WebBytesNb = 0; 
     1277    shmForAgg->myMIB[index].ipv4WebPcktsNb = 0; 
     1278    shmForAgg->myMIB[index].ipv4WebFlowNb = 0; 
     1279    shmForAgg->myMIB[index].ipv4MailBytesNb = 0; 
     1280    shmForAgg->myMIB[index].ipv4MailPcktsNb = 0; 
     1281    shmForAgg->myMIB[index].ipv4MailFlowNb = 0; 
     1282    shmForAgg->myMIB[index].ipv4DNSBytesNb = 0; 
     1283    shmForAgg->myMIB[index].ipv4DNSPcktsNb = 0; 
     1284    shmForAgg->myMIB[index].ipv4DNSFlowNb = 0; 
     1285    shmForAgg->myMIB[index].ipv4OthersApBytesNb = 0; 
     1286    shmForAgg->myMIB[index].ipv4OthersApPcktsNb = 0; 
     1287    shmForAgg->myMIB[index].ipv4OthersApFlowNb = 0; 
     1288    return 1; 
     1289}