Changeset 3182 in genesis
- Timestamp:
- Nov 14, 2004, 9:05:48 PM (20 years ago)
- Location:
- tools/nodechk
- Files:
-
- 4 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/nodechk/nodechk.c
r3166 r3182 6 6 // Nodechck - Programma om wleiden.conf files te lezen en te bewerken 7 7 // 8 // Rev.0.1 12/11/2004 8 // Rev.0.2 14/11/2004 RO 9 // $master_ip bij interface ingevuld 10 // komma's vervangen door ; in plaats van weglaten 11 // structures IPADDRESS en IPRANGE toegevoegd voor eenvoudiger vergelijken 12 // rekening houden met ontbrekende sprintf bij sommige $config-regels 13 // uitvoer naar configs1.csv, configs2.csv(gesorteerd op ip) 14 // configip1.csv(ipstart en ipend toegevoegd,overbodige kolommen verwijderd, comment in .csv toegevoegd 15 // 16 // Rev.0.1 12/11/2004 RO 9 17 // dimensies van desc, point_to_point, ospfneighbors verhoogd 10 18 // gegevens van hoofd interface in aliassen overgenomen … … 23 31 #define FALSE (0==1) 24 32 #define TRUE (0==0) 33 34 typedef struct 35 { 36 unsigned char ip0; 37 unsigned char ip1; 38 unsigned char ip2; 39 unsigned char ip3; 40 } IPADDRESS; 41 42 typedef struct 43 { 44 IPADDRESS ip; 45 unsigned char mask; 46 } IPRANGE; 25 47 26 48 typedef struct … … 72 94 73 95 char dhcp[8]; 96 IPRANGE ipr; 97 IPADDRESS ipstart; 98 IPADDRESS ipend; 99 IPADDRESS ptp1; 100 IPADDRESS ptp2; 101 IPADDRESS on1; 102 IPADDRESS on2; 74 103 } CARD; 75 104 … … 78 107 void BehandelRegel(void); 79 108 void FormatRegel(void); 80 void MaakCSV(void); 109 void MaakCSV(int code); 110 void MaakCSV2(int code); 111 void MaakIpOverzicht(void); 81 112 void AddKomma(void); 82 113 void AddTekst(void); 114 void VulIpAdressen(void); 115 void SwapCards(int i); 116 int CompareIp(IPADDRESS *ad1,IPADDRESS *ad2); 83 117 84 118 char fn[50]; … … 125 159 sprintf(buf,"\naantal nodes: %i\n\r",NodeTeller); 126 160 printf(buf); 127 MaakCSV(); 161 MaakCSV(1); 162 MaakIpOverzicht(); 128 163 return 0; 129 164 } … … 177 212 char *pose=Formatbuf; 178 213 BOOL bDescFlag; 179 214 BOOL bDubbelIpFlag; 180 215 { 181 216 //vervang # door \0 … … 212 247 213 248 bDescFlag=(!memicmp(pos,"DESC",4)); //bij DESC spaties laten 249 bDubbelIpFlag=(!memicmp(pos,"POINT_TO_POINT=",15)||!memicmp(pos,"OSPF_NEIGHBORS=",15)); //spaties vervangen door ; 214 250 for (;*pos!='\0';pos++) 215 251 { 252 if (bDubbelIpFlag&&(*pos==' '||*pos=='\t')) 253 { 254 while (*pos==' '||*pos=='\t') pos++;//skip overige spaces 255 *(--pos)=';'; 256 } 216 257 while (!bDescFlag&&(*pos==' '||*pos=='\t')) pos++;//skip spaces 217 258 if (*pos=='\'') //neem tekst tussen quotes letterlijk over … … 220 261 while (*pos!='\''&&*pos!='\0') 221 262 { 222 if (*pos==',') pos++; //geen komma's ivm csv-list223 else*pose++=*pos++;224 } 225 } 226 if (*pos==',') pos++; //geen komma's ivm csv-list227 else*pose++=*pos;263 if (*pos==',') *pos=';'; //geen komma's ivm csv-list 264 *pose++=*pos++; 265 } 266 } 267 if (*pos==',') *pos=';'; //geen komma's ivm csv-list 268 *pose++=*pos; 228 269 } 229 270 *pose='\0'; … … 269 310 sprintf(pCd->volgnr,"%3d",CardTeller); //hier want t hoeft maar 1 keer 270 311 sprintf(pCd->nodenr,"%3d",NodeTeller); //hier want t hoeft maar 1 keer 271 strncpy(pCd->sprintfname,pos+len+21,sizeof(pCd->sprintfname)); 312 //opvang voor ontbreken van 'sprintf' bij sommige configs 313 if (*(pos+12+len)=='<') 314 { 315 strncpy(pCd->sprintfname,pos+len+14,sizeof(pCd->sprintfname)); 316 } 317 else strncpy(pCd->sprintfname,pos+len+21,sizeof(pCd->sprintfname)); 272 318 bCardBezig=TRUE; 273 319 if (*(pCd->configname+strlen(pCd->configname)-2)==':') … … 295 341 if (!memicmp(pos,pCd->sprintfname,strlen(pCd->sprintfname))) 296 342 { 343 VulIpAdressen(); 297 344 CardTeller++; 298 345 bCardBezig=FALSE; 299 346 } 300 347 else if (!memicmp(pos,"TYPE=",5)) strncpy(pCd->type,pos+5,sizeof(pCd->type)); 301 else if (!memicmp(pos,"IP=",3)) strncpy(pCd->ip,pos+3,sizeof(pCd->ip)); 348 else if (!memicmp(pos,"IP=",3)) 349 { 350 if (!memicmp(pos+3,"$master_ip",10)) 351 { 352 strcpy(pCd->ip,pCN->master_ip); 353 strcat(pCd->ip,pos+13); 354 } 355 else strncpy(pCd->ip,pos+3,sizeof(pCd->ip)); 356 } 302 357 else if (!memicmp(pos,"DESC=",5)) strncpy(pCd->desc,pos+5,sizeof(pCd->desc)); 303 358 else if (!memicmp(pos,"SDESC=",6)) strncpy(pCd->sdesc,pos+6,sizeof(pCd->sdesc)); … … 320 375 } 321 376 322 void MaakCSV(void) 377 void VulIpAdressen(void) 378 { 379 CARD *pCd=&Card[CardTeller]; 380 char buf[36]; 381 char *t; 382 strcpy(buf,pCd->ip);//111.111.111.111/30 383 t=strtok(buf,"."); 384 if (t) 385 { 386 pCd->ipr.ip.ip0=(unsigned char)atoi(t); 387 t=strtok(NULL,"."); 388 if (t) 389 { 390 pCd->ipr.ip.ip1=(unsigned char)atoi(t); 391 t=strtok(NULL,"."); 392 if (t) 393 { 394 pCd->ipr.ip.ip2=(unsigned char)atoi(t); 395 t=strtok(NULL,"/");// let op / 396 if (t) 397 { 398 pCd->ipr.ip.ip3=(unsigned char)atoi(t); 399 t=strtok(NULL,"."); 400 if (t) pCd->ipr.mask=(unsigned char)atoi(t); 401 } 402 } 403 } 404 } 405 strcpy(buf,pCd->pointtopoint);//111.111.111.111;111.111.111.111 406 t=strtok(buf,"."); 407 if (t) 408 { 409 pCd->ptp1.ip0=(unsigned char)atoi(t); 410 t=strtok(NULL,"."); 411 if (t) 412 { 413 pCd->ptp1.ip1=(unsigned char)atoi(t); 414 t=strtok(NULL,"."); 415 if (t) 416 { 417 pCd->ptp1.ip2=(unsigned char)atoi(t); 418 t=strtok(NULL,";");// let op ; 419 if (t) 420 { 421 pCd->ptp1.ip3=(unsigned char)atoi(t); 422 t=strtok(NULL,"."); 423 if (t) 424 { 425 pCd->ptp2.ip0=(unsigned char)atoi(t); 426 t=strtok(NULL,"."); 427 if (t) 428 { 429 pCd->ptp2.ip1=(unsigned char)atoi(t); 430 t=strtok(NULL,"."); 431 if (t) 432 { 433 pCd->ptp2.ip2=(unsigned char)atoi(t); 434 t=strtok(NULL,";"); 435 if (t) pCd->ptp2.ip3=(unsigned char)atoi(t); 436 } 437 } 438 } 439 } 440 } 441 } 442 } 443 strcpy(buf,pCd->ospfneighbors);//111.111.111.111;111.111.111.111 444 t=strtok(buf,"."); 445 if (t) 446 { 447 pCd->on1.ip0=(unsigned char)atoi(t); 448 t=strtok(NULL,"."); 449 if (t) 450 { 451 pCd->on1.ip1=(unsigned char)atoi(t); 452 t=strtok(NULL,"."); 453 if (t) 454 { 455 pCd->on1.ip2=(unsigned char)atoi(t); 456 t=strtok(NULL,";");// let op ; 457 if (t) 458 { 459 pCd->on1.ip3=(unsigned char)atoi(t); 460 t=strtok(NULL,"."); 461 if (t) 462 { 463 pCd->on2.ip0=(unsigned char)atoi(t); 464 t=strtok(NULL,"."); 465 if (t) 466 { 467 pCd->on2.ip1=(unsigned char)atoi(t); 468 t=strtok(NULL,"."); 469 if (t) 470 { 471 pCd->on2.ip2=(unsigned char)atoi(t); 472 t=strtok(NULL,";"); 473 if (t) pCd->on2.ip3=(unsigned char)atoi(t); 474 } 475 } 476 } 477 } 478 } 479 } 480 } 481 { 482 IPADDRESS ips=pCd->ipr.ip; 483 int mask3=pCd->ipr.mask; 484 if (mask3<24)//komt nu niet voor, maar vang af met 0,0,0,0 485 { 486 ips.ip0=ips.ip1=ips.ip2=ips.ip3=0; 487 pCd->ipstart=pCd->ipend=ips; 488 } 489 else 490 { 491 int mask3p,mask3pxor; 492 mask3-=24; 493 mask3p=255; 494 mask3p>>=mask3; //shift right 495 mask3pxor=255^mask3p; 496 ips.ip3=ips.ip3&mask3pxor; 497 pCd->ipstart=ips; 498 ips.ip3=ips.ip3|mask3p; 499 pCd->ipend=ips; 500 } 501 } 502 } 503 504 void MaakIpOverzicht(void) 505 { 506 //bubble sort card records op oplopend ip 507 CARD *pCd1,*pCd2; 508 IPADDRESS *pAd1, *pAd2; 509 int i,j; 510 BOOL swapped; 511 do 512 { 513 swapped=FALSE; 514 for (i=0,j=1;i<CardTeller-1;i++,j++) 515 { 516 BOOL swappen=FALSE; 517 pCd1=&Card[i];pCd2=&Card[j]; 518 pAd1=&(pCd1->ipr.ip);pAd2=&(pCd2->ipr.ip); 519 if (pAd1->ip0>pAd2->ip0) swappen=TRUE; 520 else if (pAd1->ip0<pAd2->ip0) continue; 521 else if (pAd1->ip1>pAd2->ip1) swappen=TRUE; 522 else if (pAd1->ip1<pAd2->ip1) continue; 523 else if (pAd1->ip2>pAd2->ip2) swappen=TRUE; 524 else if (pAd1->ip2<pAd2->ip2) continue; 525 else if (pAd1->ip3>pAd2->ip3) swappen=TRUE; 526 else if (pAd1->ip3<pAd2->ip3) continue; 527 else if (pCd1->ipr.mask<pCd2->ipr.mask) swappen=TRUE; 528 if (swappen) 529 { 530 SwapCards(i); 531 swapped=TRUE; 532 } 533 } 534 } 535 while (swapped); 536 MaakCSV(2); 537 MaakCSV2(1); 538 } 539 540 void SwapCards(int i) 541 { 542 CARD tempCd=Card[i+1]; 543 Card[i+1]=Card[i]; 544 Card[i]=tempCd; 545 } 546 547 void MaakCSV2(int code) 323 548 { 324 549 int i; 325 550 CNODE *pCN; 326 551 CARD *pCd; 327 if (hConf=fopen("c:\\nodes\\configs.csv","w")) 552 if (code==1) hConf=fopen("c:\\nodes\\configip1.csv","w"); 553 if (code==2) hConf=fopen("c:\\nodes\\configip2.csv","w"); 554 if (hConf) 555 { 556 strcpy(buf,"status");AddTekst();AddKomma(); 557 strcpy(buf,"nodename");AddTekst();AddKomma(); 558 strcpy(buf,"configname");AddTekst();AddKomma(); 559 strcpy(buf,"essid");AddTekst();AddKomma(); 560 strcpy(buf,"sdesc");AddTekst();AddKomma(); 561 strcpy(buf,"master_ip");AddTekst();AddKomma(); 562 strcpy(buf,"IP-range");AddTekst();AddKomma(); 563 strcpy(buf,"IP-start");AddTekst();AddKomma(); 564 strcpy(buf,"IP-end");AddTekst();AddKomma(); 565 strcpy(buf,"point_to_point");AddTekst();AddKomma(); 566 strcpy(buf,"ospf_neighbors");AddTekst();AddKomma(); 567 strcpy(buf,"mode");AddTekst();AddKomma(); 568 strcpy(buf,"channel");AddTekst();AddKomma(); 569 strcpy(buf,"comment");AddTekst();AddKomma(); 570 fwrite( "\n", sizeof( char ), 1, hConf ); 571 572 for (i=0;i<CardTeller;i++) 573 { 574 pCd=&Card[i]; 575 pCN=&CNode[atoi(pCd->nodenr)]; 576 if (i>0) 577 { //extra lege regel 578 if (CompareIp(&(pCd->ipstart),&((pCd-1)->ipstart))||CompareIp(&(pCd->ipend),&((pCd-1)->ipend))) 579 fwrite( "\n", sizeof( char ), 1, hConf ); 580 } 581 fwrite( pCN->status, sizeof( char ), strlen(pCN->status), hConf );AddKomma(); 582 fwrite( pCN->nodename, sizeof( char ), strlen(pCN->nodename), hConf );AddKomma(); 583 fwrite( pCd->configname, sizeof( char ), strlen(pCd->configname), hConf );AddKomma(); 584 fwrite( pCd->essid, sizeof( char ), strlen(pCd->essid), hConf );AddKomma(); 585 fwrite( pCd->sdesc, sizeof( char ), strlen(pCd->sdesc), hConf );AddKomma(); 586 fwrite( pCN->master_ip, sizeof( char ), strlen(pCN->master_ip), hConf );AddKomma(); 587 fwrite( pCd->ip, sizeof( char ), strlen(pCd->ip), hConf );AddKomma(); 588 { 589 char buf[20]; 590 sprintf(buf,"%i.%i.%i.%i",pCd->ipstart.ip0,pCd->ipstart.ip1,pCd->ipstart.ip2,pCd->ipstart.ip3); 591 fwrite( buf, sizeof( char ),strlen(buf), hConf );AddKomma(); 592 sprintf(buf,"%i.%i.%i.%i",pCd->ipend.ip0,pCd->ipend.ip1,pCd->ipend.ip2,pCd->ipend.ip3); 593 fwrite( buf, sizeof( char ),strlen(buf), hConf );AddKomma(); 594 } 595 fwrite( pCd->pointtopoint, sizeof( char ), strlen(pCd->pointtopoint), hConf );AddKomma(); 596 fwrite( pCd->ospfneighbors, sizeof( char ), strlen(pCd->ospfneighbors), hConf );AddKomma(); 597 fwrite( pCd->mode, sizeof( char ), strlen(pCd->mode), hConf );AddKomma(); 598 fwrite( pCd->channel, sizeof( char ), strlen(pCd->channel), hConf );AddKomma(); 599 { 600 BOOL even; 601 int test=pCd->ipr.ip.ip3; 602 even=(test==((int)(test/2))*2); 603 if (!memicmp(pCd->mode,"managed",7)&&!even) 604 { 605 fwrite("oneven ip-adres en managed mode",sizeof( char ),31,hConf); 606 AddKomma(); 607 } 608 if (!memicmp(pCd->mode,"master",6)&&even) 609 { 610 fwrite("even ip-adres en master mode",sizeof( char ),28,hConf); 611 AddKomma(); 612 } 613 } 614 615 if (CompareIp(&pCd->ptp1,&pCd->ipstart)<0||CompareIp(&pCd->ptp1,&pCd->ipend)>0) 616 { 617 fwrite("point-to-point adres buiten range",sizeof( char ),33,hConf); 618 AddKomma(); 619 } 620 if (CompareIp(&pCd->on1,&pCd->ipstart)<0||CompareIp(&pCd->on1,&pCd->ipend)>0) 621 { 622 fwrite("ospf-neighbors adres buiten range",sizeof( char ),33,hConf); 623 AddKomma(); 624 } 625 fwrite( "\n", sizeof( char ), 1, hConf ); 626 } 627 fclose(hConf); 628 } 629 } 630 631 void MaakCSV(int code) 632 { 633 int i; 634 CNODE *pCN; 635 CARD *pCd; 636 if (code==1) hConf=fopen("c:\\nodes\\configs1.csv","w"); 637 if (code==2) hConf=fopen("c:\\nodes\\configs2.csv","w"); 638 if (hConf) 328 639 { 329 640 // strcpy(buf,"Volgnr");AddTekst();AddKomma(); … … 417 728 } 418 729 419 420 421 730 void AddTekst(void) 422 731 { 423 732 fwrite( buf, sizeof( char ), strlen(buf), hConf ); 424 733 } 734 735 int CompareIp(IPADDRESS *ad1,IPADDRESS *ad2) 736 {//ad1>ad2->1;ad1==ad2->0;ad1<ad2->-1 737 if(ad1->ip0>ad2->ip0) return 1; 738 if(ad1->ip0<ad2->ip0) return -1; 739 if(ad1->ip1>ad2->ip1) return 1; 740 if(ad1->ip1<ad2->ip1) return -1; 741 if(ad1->ip2>ad2->ip2) return 1; 742 if(ad1->ip2<ad2->ip2) return -1; 743 if(ad1->ip3>ad2->ip3) return 1; 744 if(ad1->ip3<ad2->ip3) return -1; 745 return 0; 746 } -
tools/nodechk/readme.txt
r3167 r3182 6 6 // Nodechck - Programma om wleiden.conf files te lezen en te bewerken 7 7 // 8 // Rev.0.1 12/11/2004 8 // Rev.0.2 14/11/2004 RO 9 // $master_ip bij interface ingevuld 10 // komma's vervangen door ; in plaats van weglaten 11 // structures IPADDRESS en IPRANGE toegevoegd voor eenvoudiger vergelijken 12 // rekening houden met ontbrekende sprintf bij sommige $config-regels 13 // uitvoer naar configs1.csv, configs2.csv(gesorteerd op ip) 14 // configip1.csv(ipstart en ipend toegevoegd,overbodige kolommen verwijderd, comment in .csv toegevoegd 15 // 16 // Rev.0.1 12/11/2004 RO 9 17 // dimensies van desc, point_to_point, ospfneighbors verhoogd 10 18 // gegevens van hoofd interface in aliassen overgenomen … … 14 22 15 23 input: de map c:\nodes\CNode*.*\wleiden.conf 16 output: de file c:\nodes\configs.csv 24 output: de file c:\nodes\configs1.csv 25 de file c:\nodes\configs2.csv 26 de file c:\nodes\configip1.csv
Note:
See TracChangeset
for help on using the changeset viewer.