Changeset 3271 in genesis for tools/nodechk/nodechk.c
- Timestamp:
- Nov 22, 2004, 12:41:38 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/nodechk/nodechk.c
r3182 r3271 4 4 // http://wleiden.webweaving.org:8080/svn/node-config/LICENSE 5 5 // 6 // Nodechck - Programma om wleiden.conf files te lezen en te bewerken 6 // Nodechck - Programma om wleiden.conf files te lezen 7 // en te vergelijken met actuele informatie uit de nodes 8 // 9 // Rev.0.3 22/11/2004 RO 10 // niet-ANSI functies eruit gegooid, voorbereid met #ifdef voor linux padnamen (niet getest) 11 // input ./nnames: tekstfile, lijst van nodenamen 12 // input ./confs: tekstfile, actuele output van nodes, gegenereerd door extern script 13 // input ./location: tekstfile: pad naar nodemappen in bv. svn 14 // code en structures toegevoegd om node output in te lezen 15 // in configip1 kolommen toegevoegd met actuele node-info. o.a. macadres 16 // ip-adres in interfaceconfig van wleiden.conf is bepalend voor koppeling met actuele data 7 17 // 8 18 // Rev.0.2 14/11/2004 RO … … 49 59 { 50 60 char volgnr[4]; 61 char name[20]; 62 char present[2]; 63 } CNODEOUTPUT; 64 65 typedef struct 66 { 67 char volgnr[4]; 68 char nodenr[4]; 69 char configname[10]; 70 char ether[20]; 71 char status[20]; 72 char ssid[40]; 73 char stationname[40]; 74 char channel[4]; 75 } CARDOUTPUT; 76 77 typedef struct 78 { 79 char cardnr[4]; 80 char ip[18]; 81 char netmask[12]; 82 char broadcast[18]; 83 } IFOUTPUT; 84 85 typedef struct 86 { 87 char volgnr[4]; 88 char name[20]; 51 89 char location[100]; 52 90 char master_ip[20]; … … 105 143 106 144 void LeesNode(void); 145 void LeesNodeOutput(void); 107 146 void BehandelRegel(void); 147 void BehandelOutputRegel(void); 108 148 void FormatRegel(void); 109 149 void MaakCSV(int code); … … 116 156 int CompareIp(IPADDRESS *ad1,IPADDRESS *ad2); 117 157 118 char fn[50]; 158 char nnamesbuf[2000]; 159 char location[64]; 160 char fn[64]; 119 161 char buf[50]; 120 162 #define BUFLEN 1000 … … 124 166 FILE *hConf; 125 167 size_t numread,toread; 168 CNODEOUTPUT CNodeOutput[100]; 126 169 CNODE CNode[100]; 127 CARD Card[500]; 170 IFOUTPUT IfOutput[600]; 171 CARDOUTPUT CardOutput[400]; 172 CARD Card[600]; 128 173 int NodeTeller; 129 174 int CardTeller; 175 int NodeOutputTeller; 176 int CardOutputTeller; 177 int IfOutputTeller; 178 BOOL bNodeBezig; 130 179 BOOL bCardBezig; 131 180 132 181 main() 133 182 { 134 //doorzoek mappen 135 struct _finddata_t c_file; 136 long hFile; 183 FILE *hFile; 137 184 NodeTeller=0; 138 185 CardTeller=0; 139 186 140 /* Find first CNode directory in current directory */ 141 if( (hFile = _findfirst( "c:\\nodes\\CNode*.*", &c_file )) == -1L ) 142 printf( "No CNode directories in current directory!\n" ); 143 else do 144 { 145 sprintf(fn,"c:\\nodes\\%s\\wleiden.conf",c_file.name); 146 printf(fn); 147 printf("\n"); 148 149 if (hConf=fopen(fn,"r")) 150 { 151 LeesNode(); 152 fclose(hConf); 153 } 154 NodeTeller++; 155 /* Find the rest of the CNode directories */ 156 } 157 while( _findnext( hFile, &c_file ) == 0 ); 158 _findclose( hFile ); 187 if (hFile=fopen("location","r")) 188 { 189 fread(location,sizeof(char),64,hFile); 190 fclose(hFile); 191 if (hFile=fopen("nnames","r")) 192 { 193 char *pos; 194 numread=fread(nnamesbuf,sizeof(char),2000,hFile); 195 fclose(hFile); 196 pos=strtok(nnamesbuf,"\n\r"); 197 while(pos) 198 { 199 memset((char*)&(CNode[NodeTeller]),'\0',sizeof(CNode[NodeTeller])); 200 strcpy(CNode[NodeTeller++].name,pos); 201 pos=strtok(NULL,"\n\r"); 202 } 203 NodeTeller=0; 204 while (*(CNode[NodeTeller].name)) 205 { 206 #ifdef WIN32 207 sprintf(fn,"%s%s\\wleiden.conf",location,CNode[NodeTeller].name); 208 #else 209 sprintf(fn,"%s%s/wleiden.conf",location,CNode[NodeTeller].name); 210 #endif 211 printf(fn); 212 printf("\n"); 213 214 if (hConf=fopen(fn,"r")) 215 { 216 LeesNode(); 217 fclose(hConf); 218 } 219 NodeTeller++; 220 } 221 } 222 } 159 223 sprintf(buf,"\naantal nodes: %i\n\r",NodeTeller); 160 224 printf(buf); 161 225 MaakCSV(1); 226 227 if (hConf=fopen("confs","r")) 228 { 229 LeesNodeOutput(); 230 fclose(hConf); 231 } 162 232 MaakIpOverzicht(); 233 163 234 return 0; 235 } 236 237 void LeesNodeOutput(void) 238 { 239 char *pos; 240 int regels=0; 241 int rest; 242 memset((char*)&(CNodeOutput),'\0',sizeof(CNodeOutput)); 243 NodeOutputTeller=-1; 244 CardOutputTeller=-1; 245 IfOutputTeller=-1; 246 247 toread=BUFLEN; 248 numread=fread(Tekstbuf,sizeof(char),toread,hConf); 249 250 pos=strtok(Tekstbuf,"\n\r" ); 251 while (pos) 252 { 253 unsigned j; 254 strcpy(Regelbuf,Tekstbuf); 255 rest=strlen(Regelbuf); 256 for (j=0;j<numread-rest-1;j++) 257 { 258 Tekstbuf[j]=Tekstbuf[j+rest+1]; //tekst naar links schuiven 259 } 260 if (numread==BUFLEN) 261 { 262 numread-=(rest+1); 263 numread+=fread(Tekstbuf+numread,sizeof(char),rest+1,hConf); 264 if (numread<BUFLEN) Tekstbuf[numread]='\0'; 265 } 266 else 267 { 268 numread-=(rest+1); 269 Tekstbuf[numread]='\0'; 270 } 271 272 BehandelOutputRegel(); 273 strcat(Regelbuf,"\n"); 274 printf("%s",Regelbuf); 275 regels++; 276 pos=strtok(Tekstbuf,"\n\r" ); 277 } 278 sprintf(buf,"\naantal regels: %i\n\r",regels); 279 printf(buf); 280 } 281 282 void BehandelOutputRegel(void) 283 { 284 char *pos=Regelbuf; 285 CNODEOUTPUT *pCNO; 286 CARDOUTPUT *pCDO; 287 IFOUTPUT *pIO; 288 while (*pos=='\n'||*pos=='\r') pos++; 289 if (!memicmp(pos,"CONFIG FOR ",11)) 290 { 291 pCNO=&CNodeOutput[++NodeOutputTeller]; 292 strncpy(pCNO->name,pos+11,sizeof(pCNO->name)); 293 sprintf(pCNO->volgnr,"%3d",NodeOutputTeller); 294 strcpy(pCNO->present,"0"); 295 } 296 else if (*pos!=' '&&*pos!='\t') 297 { 298 //interface naam 299 unsigned int len; 300 char *pos1=pos; 301 pCDO=&CardOutput[++CardOutputTeller]; 302 pCNO=&CNodeOutput[NodeOutputTeller]; 303 strcpy(pCNO->present,"1"); 304 while(*pos1++!=':'); 305 len=pos1-pos-1; 306 if (len>9) len=9; 307 memcpy(pCDO->configname,pos,len); 308 pCDO->configname[len]='\0'; 309 sprintf(pCDO->volgnr,"%3d",CardOutputTeller); 310 sprintf(pCDO->nodenr,"%3d",NodeOutputTeller); 311 } 312 else 313 { 314 pCDO=&CardOutput[CardOutputTeller]; 315 while (*pos==' '||*pos=='\t'||*pos=='\n'||*pos=='\r') pos++;//skip leading spaces 316 if (!memicmp(pos,"inet ",5)) 317 { 318 unsigned int len; 319 char *pos1=pos+5; 320 pIO=&IfOutput[++IfOutputTeller]; 321 while(*pos1++!=' '); 322 len=pos1-pos-6; 323 if (len>17) len=17; 324 memcpy(pIO->ip,pos+5,len); 325 pIO->ip[len]='\0'; 326 memcpy(pIO->netmask,pos1+8,10); 327 pIO->netmask[10]='\0'; 328 if (*(pos1+19)=='b') //broadcast 329 { 330 strcpy(pIO->broadcast,pos1+29); 331 } 332 sprintf(pIO->cardnr,"%3d",CardOutputTeller); 333 } 334 else if (!memicmp(pos,"ether ",6)) strcpy(pCDO->ether,pos+6); 335 else if (!memicmp(pos,"status: ",8)) strcpy(pCDO->status,pos+8); 336 else if (!memicmp(pos,"ssid ",5)) 337 { 338 unsigned int len; 339 char *pos1=pos+5; 340 while(*pos1++!=' '); 341 len=pos1-pos-6; 342 if (len>38) len=38; 343 memcpy(pCDO->ssid,pos+5,len); 344 pCDO->ssid[len]='\0'; 345 } 346 else if (!memicmp(pos,"channel ",8)) 347 { 348 unsigned int len; 349 char *pos1=pos+8; 350 while(*pos1++!=' '); 351 len=pos1-pos-9; 352 if (len>3) len=3; 353 memcpy(pCDO->channel,pos+8,len); 354 pCDO->channel[len]='\0'; 355 } 356 else if (!memicmp(pos,"stationname ",12)) strcpy(pCDO->stationname,pos+12); 357 } 164 358 } 165 359 … … 174 368 numread=fread(Tekstbuf,sizeof(char),toread,hConf); 175 369 176 memset((char*)&(CNode[NodeTeller]),'\0',sizeof(CNode[NodeTeller]));177 370 pos=strtok(Tekstbuf,"\n\r" ); 178 371 while (pos) … … 550 743 CNODE *pCN; 551 744 CARD *pCd; 552 if (code==1) hConf=fopen("c :\\nodes\\configip1.csv","w");553 if (code==2) hConf=fopen("c :\\nodes\\configip2.csv","w");745 if (code==1) hConf=fopen("configip1.csv","w"); 746 if (code==2) hConf=fopen("configip2.csv","w"); 554 747 if (hConf) 555 748 { … … 567 760 strcpy(buf,"mode");AddTekst();AddKomma(); 568 761 strcpy(buf,"channel");AddTekst();AddKomma(); 569 strcpy(buf," comment");AddTekst();AddKomma();762 strcpy(buf,"Current data from nodes");AddTekst();AddKomma(); 570 763 fwrite( "\n", sizeof( char ), 1, hConf ); 571 764 … … 597 790 fwrite( pCd->mode, sizeof( char ), strlen(pCd->mode), hConf );AddKomma(); 598 791 fwrite( pCd->channel, sizeof( char ), strlen(pCd->channel), hConf );AddKomma(); 792 { 793 int j; 794 IFOUTPUT *pIO; 795 for (j=0;j<IfOutputTeller;j++) 796 { 797 pIO=&IfOutput[j]; 798 if (!memcmp(pIO->ip,pCd->ip,strlen(pIO->ip))) break; 799 } 800 if (j<IfOutputTeller) 801 { 802 CARDOUTPUT *pCDO=&CardOutput[atoi(pIO->cardnr)]; 803 fwrite( pCDO->configname, sizeof( char ), strlen(pCDO->configname), hConf );AddKomma(); 804 fwrite( pCDO->ether, sizeof( char ), strlen(pCDO->ether), hConf );AddKomma(); 805 fwrite( pCDO->status, sizeof( char ), strlen(pCDO->status), hConf );AddKomma(); 806 fwrite( pCDO->ssid, sizeof( char ), strlen(pCDO->ssid), hConf );AddKomma(); 807 fwrite( pCDO->stationname, sizeof( char ), strlen(pCDO->stationname), hConf );AddKomma(); 808 fwrite( pCDO->channel, sizeof( char ), strlen(pCDO->channel), hConf );AddKomma(); 809 } 810 else 811 { 812 AddKomma(); 813 AddKomma(); 814 AddKomma(); 815 AddKomma(); 816 AddKomma(); 817 AddKomma(); 818 } 819 820 } 821 822 823 824 825 826 827 #ifdef xyz //even er uit 599 828 { 600 829 BOOL even; … … 623 852 AddKomma(); 624 853 } 854 #endif 625 855 fwrite( "\n", sizeof( char ), 1, hConf ); 626 856 } … … 634 864 CNODE *pCN; 635 865 CARD *pCd; 636 if (code==1) hConf=fopen("c :\\nodes\\configs1.csv","w");637 if (code==2) hConf=fopen("c :\\nodes\\configs2.csv","w");866 if (code==1) hConf=fopen("configs1.csv","w"); 867 if (code==2) hConf=fopen("configs2.csv","w"); 638 868 if (hConf) 639 869 { … … 745 975 return 0; 746 976 } 977
Note:
See TracChangeset
for help on using the changeset viewer.