Changeset 61 for trunk/src/get_conf.c

Show
Ignore:
Timestamp:
10/26/07 10:25:49 (15 years ago)
Author:
andreu
Message:

tickets 12,19 & 20 closed

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/get_conf.c

    r60 r61  
    133133 * read IPv4 prefix file and sort the list 
    134134 */ 
    135 unsigned short getPrefixV4(char *filename, struct PrefixV4 *pV4TabPtr) 
     135unsigned short getPrefixV4(char *filename,  
     136                           struct PrefixV4 *pV4TabPtr, 
     137                           struct PrefixV4 *pV4SubTabPtr, 
     138                           unsigned short *subnetNb) 
    136139{ 
    137140  FILE *prefixFile; 
     
    144147  unsigned char buffer4[4]; 
    145148  int i = 0; 
    146   char prefixStrTab[MAX_IPV4_PREFIX][50]; 
     149  char prefixStrTab[MAX_IPV4_PREFIX+MAX_IPV4_SUBNET][50]; 
     150  struct PrefixV4 lastSuperNet; 
     151  unsigned short lastSuperNetIndex = 0; 
     152  unsigned short superNetIndex = 0; 
     153  unsigned short subNetIndex = 0; 
    147154 
    148155  if (!(prefixFile = fopen(filename, "r"))) { 
     
    150157    exit(1); 
    151158  } 
     159   
     160  *subnetNb = 0; 
     161 
     162  lastSuperNet.beginning = 0; 
     163  lastSuperNet.end = 0; 
     164  lastSuperNet.mask = 0; 
     165  lastSuperNet.sampling = 0; 
     166#ifdef IPV4AGGIDR       
     167  lastSuperNet.routerNb = 0; 
     168#endif 
     169  lastSuperNet.flowNbIN = 0; 
     170  lastSuperNet.bytesNbIN = 0; 
     171  lastSuperNet.pktsNbIN = 0; 
     172  lastSuperNet.flowNbOUT = 0; 
     173  lastSuperNet.bytesNbOUT = 0; 
     174  lastSuperNet.pktsNbOUT = 0; 
     175  lastSuperNet.firstCoSIN = 0; 
     176  lastSuperNet.secondCoSIN = 0; 
     177  lastSuperNet.thirdCoSIN = 0; 
     178  lastSuperNet.fourthCoSIN = 0; 
     179  lastSuperNet.firstCoSOUT = 0; 
     180  lastSuperNet.secondCoSOUT = 0; 
     181  lastSuperNet.thirdCoSOUT = 0; 
     182  lastSuperNet.fourthCoSOUT = 0; 
     183 
    152184  for(i=0;i<MAX_IPV4_PREFIX;i++){ 
    153185    pV4TabPtr[i].beginning = 0; 
     
    173205    pV4TabPtr[i].fourthCoSOUT = 0; 
    174206  } 
     207  for(i=0;i<MAX_IPV4_SUBNET;i++){ 
     208    pV4SubTabPtr[i].beginning = 0; 
     209    pV4SubTabPtr[i].end = 0; 
     210    pV4SubTabPtr[i].mask = 0; 
     211    pV4SubTabPtr[i].sampling = 0; 
     212#ifdef IPV4AGGIDR       
     213    pV4SubTabPtr[i].routerNb = 0; 
     214#endif 
     215    pV4SubTabPtr[i].flowNbIN = 0; 
     216    pV4SubTabPtr[i].bytesNbIN = 0; 
     217    pV4SubTabPtr[i].pktsNbIN = 0; 
     218    pV4SubTabPtr[i].flowNbOUT = 0; 
     219    pV4SubTabPtr[i].bytesNbOUT = 0; 
     220    pV4SubTabPtr[i].pktsNbOUT = 0; 
     221    pV4SubTabPtr[i].firstCoSIN = 0; 
     222    pV4SubTabPtr[i].secondCoSIN = 0; 
     223    pV4SubTabPtr[i].thirdCoSIN = 0; 
     224    pV4SubTabPtr[i].fourthCoSIN = 0; 
     225    pV4SubTabPtr[i].firstCoSOUT = 0; 
     226    pV4SubTabPtr[i].secondCoSOUT = 0; 
     227    pV4SubTabPtr[i].thirdCoSOUT = 0; 
     228    pV4SubTabPtr[i].fourthCoSOUT = 0; 
     229  } 
    175230  while (fgets(line, 50, prefixFile) != 0) 
    176231    { 
    177232      strcpy(prefixStrTab[counter], line); 
    178233      counter++; 
    179       if (counter == MAX_IPV4_PREFIX) { 
     234      if (counter == MAX_IPV4_PREFIX+MAX_IPV4_SUBNET) { 
    180235        fprintf(stderr, "bufferoverflow in getPrefixV4 function (get_conf.c)\ 
    181236change the value of MAX_IPV4_PREFIX  declaration and recompile \n"); 
     
    197252      buffer4[2] = (unsigned char)n1; 
    198253      buffer4[3] = (unsigned char)n0; 
    199       pV4TabPtr[i].beginning =  
    200         *((unsigned long*)&buffer4[0]); 
    201       pV4TabPtr[i].end =  
    202         *((unsigned long*)&buffer4[0]) +~(~0<<(32-n4)); 
    203       pV4TabPtr[i].mask = n4; 
    204       pV4TabPtr[i].sampling = 0; 
    205 #ifdef IPV4AGGIDR       
    206       pV4TabPtr[i].routerNb = n5; 
    207 #endif 
    208       pV4TabPtr[i].flowNbIN = 0; 
    209       pV4TabPtr[i].bytesNbIN = 0; 
    210       pV4TabPtr[i].pktsNbIN = 0; 
    211       pV4TabPtr[i].flowNbOUT = 0; 
    212       pV4TabPtr[i].bytesNbOUT = 0; 
    213       pV4TabPtr[i].pktsNbOUT = 0; 
    214       pV4TabPtr[i].firstCoSIN = 0; 
    215       pV4TabPtr[i].secondCoSIN = 0; 
    216       pV4TabPtr[i].thirdCoSIN = 0; 
    217       pV4TabPtr[i].fourthCoSIN = 0; 
    218       pV4TabPtr[i].firstCoSOUT = 0; 
    219       pV4TabPtr[i].secondCoSOUT = 0; 
    220       pV4TabPtr[i].thirdCoSOUT = 0; 
    221       pV4TabPtr[i].fourthCoSOUT = 0; 
     254      /* we sort supernet and subnet */ 
     255      if (lastSuperNet.beginning == 0) { 
     256        /* case of first supernet */ 
     257        lastSuperNet.beginning = *((unsigned long*)&buffer4[0]); 
     258        lastSuperNet.end = *((unsigned long*)&buffer4[0]) +~(~0<<(32-n4)); 
     259        lastSuperNet.mask = n4; 
     260        lastSuperNetIndex = i; 
     261        superNetIndex++; 
     262        pV4TabPtr[i].beginning =  
     263          *((unsigned long*)&buffer4[0]); 
     264        pV4TabPtr[i].end =  
     265          *((unsigned long*)&buffer4[0]) +~(~0<<(32-n4)); 
     266        pV4TabPtr[i].mask = n4; 
     267        pV4TabPtr[i].sampling = 0; 
     268#ifdef IPV4AGGIDR       
     269        pV4TabPtr[i].routerNb = n5; 
     270#endif 
     271        pV4TabPtr[i].flowNbIN = 0; 
     272        pV4TabPtr[i].bytesNbIN = 0; 
     273        pV4TabPtr[i].pktsNbIN = 0; 
     274        pV4TabPtr[i].flowNbOUT = 0; 
     275        pV4TabPtr[i].bytesNbOUT = 0; 
     276        pV4TabPtr[i].pktsNbOUT = 0; 
     277        pV4TabPtr[i].firstCoSIN = 0; 
     278        pV4TabPtr[i].secondCoSIN = 0; 
     279        pV4TabPtr[i].thirdCoSIN = 0; 
     280        pV4TabPtr[i].fourthCoSIN = 0; 
     281        pV4TabPtr[i].firstCoSOUT = 0; 
     282        pV4TabPtr[i].secondCoSOUT = 0; 
     283        pV4TabPtr[i].thirdCoSOUT = 0; 
     284        pV4TabPtr[i].fourthCoSOUT = 0; 
     285         
     286      } else if ( (lastSuperNet.beginning <= *((unsigned long*)&buffer4[0])) 
     287                  && (lastSuperNet.end>=*((unsigned long*)&buffer4[0]) +~(~0<<(32-n4))) ) { 
     288        /* we are in the case of subnet */ 
     289        *subnetNb += 1; 
     290        fprintf(stderr,"SUBNET %lu SUPERNET %lu %lu, subnetnb : %hu\n", 
     291                *((unsigned long*)&buffer4[0]), 
     292                pV4TabPtr[lastSuperNetIndex].beginning, 
     293                pV4TabPtr[lastSuperNetIndex].end, 
     294                *subnetNb); 
     295         
     296        pV4TabPtr[lastSuperNetIndex].hasSubnet = 1; 
     297        pV4SubTabPtr[subNetIndex].beginning =  
     298          *((unsigned long*)&buffer4[0]); 
     299        pV4SubTabPtr[subNetIndex].end =  
     300          *((unsigned long*)&buffer4[0]) +~(~0<<(32-n4)); 
     301        pV4SubTabPtr[subNetIndex].mask = n4; 
     302        pV4SubTabPtr[subNetIndex].sampling = 0; 
     303#ifdef IPV4AGGIDR       
     304        pV4SubTabPtr[subNetIndex].routerNb = n5; 
     305#endif 
     306        pV4SubTabPtr[subNetIndex].flowNbIN = 0; 
     307        pV4SubTabPtr[subNetIndex].bytesNbIN = 0; 
     308        pV4SubTabPtr[subNetIndex].pktsNbIN = 0; 
     309        pV4SubTabPtr[subNetIndex].flowNbOUT = 0; 
     310        pV4SubTabPtr[subNetIndex].bytesNbOUT = 0; 
     311        pV4SubTabPtr[subNetIndex].pktsNbOUT = 0; 
     312        pV4SubTabPtr[subNetIndex].firstCoSIN = 0; 
     313        pV4SubTabPtr[subNetIndex].secondCoSIN = 0; 
     314        pV4SubTabPtr[subNetIndex].thirdCoSIN = 0; 
     315        pV4SubTabPtr[subNetIndex].fourthCoSIN = 0; 
     316        pV4SubTabPtr[subNetIndex].firstCoSOUT = 0; 
     317        pV4SubTabPtr[subNetIndex].secondCoSOUT = 0; 
     318        pV4SubTabPtr[subNetIndex].thirdCoSOUT = 0; 
     319        pV4SubTabPtr[subNetIndex].fourthCoSOUT = 0; 
     320        subNetIndex++; 
     321      } else { 
     322        /* we are in the supernet case */ 
     323        lastSuperNet.beginning = *((unsigned long*)&buffer4[0]); 
     324        lastSuperNet.end = *((unsigned long*)&buffer4[0]) +~(~0<<(32-n4)); 
     325        lastSuperNet.mask = n4; 
     326        lastSuperNetIndex = i; 
     327        pV4TabPtr[superNetIndex].beginning =  
     328          *((unsigned long*)&buffer4[0]); 
     329        pV4TabPtr[superNetIndex].end =  
     330          *((unsigned long*)&buffer4[0]) +~(~0<<(32-n4)); 
     331        pV4TabPtr[superNetIndex].mask = n4; 
     332        pV4TabPtr[superNetIndex].sampling = 0; 
     333#ifdef IPV4AGGIDR       
     334        pV4TabPtr[superNetIndex].routerNb = n5; 
     335#endif 
     336        pV4TabPtr[superNetIndex].flowNbIN = 0; 
     337        pV4TabPtr[superNetIndex].bytesNbIN = 0; 
     338        pV4TabPtr[superNetIndex].pktsNbIN = 0; 
     339        pV4TabPtr[superNetIndex].flowNbOUT = 0; 
     340        pV4TabPtr[superNetIndex].bytesNbOUT = 0; 
     341        pV4TabPtr[superNetIndex].pktsNbOUT = 0; 
     342        pV4TabPtr[superNetIndex].firstCoSIN = 0; 
     343        pV4TabPtr[superNetIndex].secondCoSIN = 0; 
     344        pV4TabPtr[superNetIndex].thirdCoSIN = 0; 
     345        pV4TabPtr[superNetIndex].fourthCoSIN = 0; 
     346        pV4TabPtr[superNetIndex].firstCoSOUT = 0; 
     347        pV4TabPtr[superNetIndex].secondCoSOUT = 0; 
     348        pV4TabPtr[superNetIndex].thirdCoSOUT = 0; 
     349        pV4TabPtr[superNetIndex].fourthCoSOUT = 0; 
     350        superNetIndex++; 
     351      } 
    222352    } 
    223353  if( fclose(prefixFile) == 0) { 
    224     return (counter); 
     354    return (superNetIndex); 
    225355  } else { 
    226356    fprintf(stderr,"%s not closed, \n", filename); 
    227357    exit(1); 
    228     return(counter); 
     358    return(superNetIndex); 
    229359  } 
    230360}