Changeset 60 for trunk/src/get_conf.c

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

new aggregation mode based on SNMP index and AS aggregation

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/get_conf.c

    r59 r60  
    6666 
    6767  if (!(routerFile = fopen(filename, "r"))) { 
    68     fprintf (stderr, "error during %s opening\n", filename); 
     68    fprintf (stderr, "error during file \"%s\" opening\n", filename); 
    6969    exit(1); 
    7070  } 
     
    147147 
    148148  if (!(prefixFile = fopen(filename, "r"))) { 
    149     fprintf (stderr, "error during %s opening\n", filename); 
     149    fprintf (stderr, "error during file \"%s\" opening\n", filename); 
    150150    exit(1); 
    151151  } 
     
    229229  } 
    230230} 
     231 
     232/*  
     233 *  
     234 */ 
     235int compASStr(a,b) 
     236{ 
     237  static unsigned short a0; 
     238  static unsigned short b0; 
     239  sscanf((char *)a,"%hu\n",&a0); 
     240  sscanf((char *)b,"%hu\n",&b0); 
     241  if (a0 > b0) return(1); 
     242  if (a0 < b0) return(-1); 
     243  return(0); 
     244} 
     245 
     246/*  
     247 * getAS() 
     248 * 
     249 * read AS file and sort the list 
     250 */ 
     251unsigned short getAS(char *filename, struct AS *ASTabPtr) 
     252{ 
     253  FILE *asFile; 
     254  char line[200]; 
     255  unsigned short counter = 0; 
     256  unsigned short n0; 
     257  unsigned short buffer; 
     258  int i = 0; 
     259  char ASStrTab[MAX_AS][7]; 
     260 
     261  if (!(asFile = fopen(filename, "r"))) { 
     262    fprintf (stderr, "error during file \"%s\" opening\n", filename); 
     263    exit(1); 
     264  } 
     265  for(i=0;i<MAX_AS;i++){ 
     266    ASTabPtr[i].as = 0; 
     267    ASTabPtr[i].sampling = 0; 
     268  } 
     269  while (fgets(line, 7, asFile) != 0) 
     270    { 
     271      strcpy(ASStrTab[counter], line); 
     272      counter++; 
     273      if (counter > MAX_AS) { 
     274        fprintf(stderr, "bufferoverflow in getAS function (get_conf.c)\ 
     275change the value of MAX_AS declaration and recompile, counter: %hu \n", 
     276                        counter); 
     277        exit(1); 
     278      } 
     279    } 
     280  qsort(ASStrTab, counter, 7, compASStr); 
     281  for(i=0;i<counter;i++) 
     282    { 
     283      sscanf(ASStrTab[i],"%hu\n", 
     284             &n0); 
     285      buffer = (unsigned short)n0; 
     286      ASTabPtr[i].as = *((unsigned short*)&buffer); 
     287      ASTabPtr[i].sampling = 0; 
     288    } 
     289  if( fclose(asFile) == 0) { 
     290    return (counter); 
     291  } else { 
     292    fprintf(stderr,"%s not closed, \n", filename); 
     293    exit(1); 
     294    return(counter); 
     295  } 
     296} 
     297