source: genesis/tools/nodechk/nodechk.c@ 3278

Last change on this file since 3278 was 3278, checked in by rudolf, 20 years ago
  • Property svn:executable set to *
File size: 32.9 KB
Line 
1// (c) Copyright 2004 Stichting Wireless Leiden, all
2// rights reserved. More information can be found on
3// http://wwww.wirelessleiden.nl and the license is at:
4// http://wleiden.webweaving.org:8080/svn/node-config/LICENSE
5//
6// Nodechck - Programma om wleiden.conf files te lezen
7// en te vergelijken met actuele informatie uit de nodes
8//
9// Rev.0.4 22/11/2004 RO
10// compatibility:
11// io.h verwijderd
12// memicmp() voor unix toegevoegd
13// getest op unix
14//
15// Rev.0.3 22/11/2004 RO
16// niet-ANSI functies eruit gegooid, voorbereid met #ifdef voor linux padnamen (niet getest)
17// input ./nnames: tekstfile, lijst van nodenamen
18// input ./confs: tekstfile, actuele output van nodes, gegenereerd door extern script
19// input ./location: tekstfile: pad naar nodemappen in bv. svn
20// code en structures toegevoegd om node output in te lezen
21// in configip1 kolommen toegevoegd met actuele node-info. o.a. macadres
22// ip-adres in interfaceconfig van wleiden.conf is bepalend voor koppeling met actuele data
23//
24// Rev.0.2 14/11/2004 RO
25// $master_ip bij interface ingevuld
26// komma's vervangen door ; in plaats van weglaten
27// structures IPADDRESS en IPRANGE toegevoegd voor eenvoudiger vergelijken
28// rekening houden met ontbrekende sprintf bij sommige $config-regels
29// uitvoer naar configs1.csv, configs2.csv(gesorteerd op ip)
30// configip1.csv(ipstart en ipend toegevoegd,overbodige kolommen verwijderd, comment in .csv toegevoegd
31//
32// Rev.0.1 12/11/2004 RO
33// dimensies van desc, point_to_point, ospfneighbors verhoogd
34// gegevens van hoofd interface in aliassen overgenomen
35// komma's uit velden geskipt ivm csv-lijst (3e regel node-som heeft ',' in desc-veld)
36//
37// Rev.0.0 10/11/2004 initial revision Rudolf Oosterhuis
38
39#include <stdio.h>
40#include <time.h>
41#include <string.h>
42#include <ctype.h>
43#include <stdlib.h>
44
45#define BOOL unsigned int
46#define FALSE (0==1)
47#define TRUE (0==0)
48
49typedef struct
50{
51 unsigned char ip0;
52 unsigned char ip1;
53 unsigned char ip2;
54 unsigned char ip3;
55} IPADDRESS;
56
57typedef struct
58{
59 IPADDRESS ip;
60 unsigned char mask;
61} IPRANGE;
62
63typedef struct
64{
65 char volgnr[4];
66 char name[20];
67 char present[2];
68} CNODEOUTPUT;
69
70typedef struct
71{
72 char volgnr[4];
73 char nodenr[4];
74 char configname[10];
75 char ether[20];
76 char status[20];
77 char ssid[40];
78 char stationname[40];
79 char channel[4];
80} CARDOUTPUT;
81
82typedef struct
83{
84 char cardnr[4];
85 char ip[18];
86 char netmask[12];
87 char broadcast[18];
88} IFOUTPUT;
89
90typedef struct
91{
92 char volgnr[4];
93 char name[20];
94 char location[100];
95 char master_ip[20];
96 char gw_open[10];
97 char nodetype[10];
98 char nodename[30];
99 char status[10];
100 char OS[20];
101 char labelpos[30];
102 char X[10];
103 char Y[10];
104 char N[10];
105 char E[10];
106 char ESSID[34];
107} CNODE;
108
109typedef struct
110{
111 char volgnr[4];
112 char nodenr[4];
113 char configname[10];
114 char sprintfname[10];
115 char type[10];
116 char ip[20];
117 char desc[46];
118 char sdesc[20];
119 char speed[20];
120
121 char pointtopoint[35];
122
123 char ospfbroadcast[6];
124 char ospfneighbors[35];
125
126 char mode[10];
127 char essid[34];
128 char channel[3];
129
130 char polar[6];
131 char antenna[10];
132 char gain[10];
133 char direction[6];
134 char beamwidth[6];
135 char cable[3];
136 char heigth[4];
137
138 char dhcp[8];
139 IPRANGE ipr;
140 IPADDRESS ipstart;
141 IPADDRESS ipend;
142 IPADDRESS ptp1;
143 IPADDRESS ptp2;
144 IPADDRESS on1;
145 IPADDRESS on2;
146} CARD;
147
148
149void LeesNode(void);
150void LeesNodeOutput(void);
151void BehandelRegel(void);
152void BehandelOutputRegel(void);
153void FormatRegel(void);
154void MaakCSV(int code);
155void MaakCSV2(int code);
156void MaakIpOverzicht(void);
157void AddKomma(void);
158void AddTekst(void);
159void VulIpAdressen(void);
160void SwapCards(int i);
161int CompareIp(IPADDRESS *ad1,IPADDRESS *ad2);
162
163char nnamesbuf[2000];
164char location[64];
165char fn[64];
166char buf[50];
167#define BUFLEN 1000
168char Tekstbuf[BUFLEN];
169char Regelbuf[BUFLEN];
170char Formatbuf[BUFLEN];
171FILE *hConf;
172size_t numread,toread;
173CNODEOUTPUT CNodeOutput[100];
174CNODE CNode[100];
175IFOUTPUT IfOutput[600];
176CARDOUTPUT CardOutput[400];
177CARD Card[600];
178int NodeTeller;
179int CardTeller;
180int NodeOutputTeller;
181int CardOutputTeller;
182int IfOutputTeller;
183BOOL bNodeBezig;
184BOOL bCardBezig;
185
186#ifndef WIN32
187int memicmp(char *a,char *b,size_t c);
188int memicmp(char *a,char *b,size_t c)
189{
190 int i;
191 char ba[200],bb[200];
192 memcpy(ba,a,c);
193 memcpy(bb,b,c);
194 for (i=0;i<c;i++)
195 {
196 ba[i]=toupper(ba[i]);
197 bb[i]=toupper(bb[i]);
198 }
199 return memcmp(ba,bb,c);
200}
201
202#endif
203
204main()
205{
206 FILE *hFile;
207 NodeTeller=0;
208 CardTeller=0;
209
210 if (hFile=fopen("location","r"))
211 {
212 fread(location,sizeof(char),64,hFile);
213 fclose(hFile);
214 {
215 char *pos=&location[strlen(location)-1];
216 while (*pos=='\n'||*pos=='\r'||*pos=='\t'||*pos==' ')
217 {
218 *pos='\0';
219 pos--;
220 }
221 }
222 if (hFile=fopen("nnames","r"))
223 {
224 char *pos;
225 numread=fread(nnamesbuf,sizeof(char),2000,hFile);
226 fclose(hFile);
227 pos=strtok(nnamesbuf,"\n\r");
228 while(pos)
229 {
230 memset((char*)&(CNode[NodeTeller]),'\0',sizeof(CNode[NodeTeller]));
231 strcpy(CNode[NodeTeller++].name,pos);
232 pos=strtok(NULL,"\n\r");
233 }
234 NodeTeller=0;
235 while (*(CNode[NodeTeller].name))
236 {
237#ifdef WIN32
238 sprintf(fn,"%s%s\\wleiden.conf",location,CNode[NodeTeller].name);
239#else
240 sprintf(fn,"%s%s/wleiden.conf",location,CNode[NodeTeller].name);
241#endif
242 printf(fn);
243 printf("\n");
244
245 if (hConf=fopen(fn,"r"))
246 {
247 LeesNode();
248 fclose(hConf);
249 }
250 NodeTeller++;
251 }
252 }
253 }
254 sprintf(buf,"\naantal nodes: %i\n\r",NodeTeller);
255 printf(buf);
256 MaakCSV(1);
257
258 if (hConf=fopen("confs","r"))
259 {
260 LeesNodeOutput();
261 fclose(hConf);
262 }
263 MaakIpOverzicht();
264
265 return 0;
266}
267
268void LeesNodeOutput(void)
269{
270 char *pos;
271 int regels=0;
272 int rest;
273 memset((char*)&(CNodeOutput),'\0',sizeof(CNodeOutput));
274 NodeOutputTeller=-1;
275 CardOutputTeller=-1;
276 IfOutputTeller=-1;
277
278 toread=BUFLEN;
279 numread=fread(Tekstbuf,sizeof(char),toread,hConf);
280
281 pos=strtok(Tekstbuf,"\n\r" );
282 while (pos)
283 {
284 unsigned j;
285 strcpy(Regelbuf,Tekstbuf);
286 rest=strlen(Regelbuf);
287 for (j=0;j<numread-rest-1;j++)
288 {
289 Tekstbuf[j]=Tekstbuf[j+rest+1]; //tekst naar links schuiven
290 }
291 if (numread==BUFLEN)
292 {
293 numread-=(rest+1);
294 numread+=fread(Tekstbuf+numread,sizeof(char),rest+1,hConf);
295 if (numread<BUFLEN) Tekstbuf[numread]='\0';
296 }
297 else
298 {
299 numread-=(rest+1);
300 Tekstbuf[numread]='\0';
301 }
302
303 BehandelOutputRegel();
304 strcat(Regelbuf,"\n");
305 printf("%s",Regelbuf);
306 regels++;
307 pos=strtok(Tekstbuf,"\n\r" );
308 }
309 sprintf(buf,"\naantal regels: %i\n\r",regels);
310 printf(buf);
311}
312
313void BehandelOutputRegel(void)
314{
315 char *pos=Regelbuf;
316 CNODEOUTPUT *pCNO;
317 CARDOUTPUT *pCDO;
318 IFOUTPUT *pIO;
319 while (*pos=='\n'||*pos=='\r') pos++;
320 if (!memicmp(pos,"CONFIG FOR ",11))
321 {
322 pCNO=&CNodeOutput[++NodeOutputTeller];
323 strncpy(pCNO->name,pos+11,sizeof(pCNO->name));
324 sprintf(pCNO->volgnr,"%3d",NodeOutputTeller);
325 strcpy(pCNO->present,"0");
326 }
327 else if (*pos!=' '&&*pos!='\t')
328 {
329 //interface naam
330 unsigned int len;
331 char *pos1=pos;
332 pCDO=&CardOutput[++CardOutputTeller];
333 pCNO=&CNodeOutput[NodeOutputTeller];
334 strcpy(pCNO->present,"1");
335 while(*pos1++!=':');
336 len=pos1-pos-1;
337 if (len>9) len=9;
338 memcpy(pCDO->configname,pos,len);
339 pCDO->configname[len]='\0';
340 sprintf(pCDO->volgnr,"%3d",CardOutputTeller);
341 sprintf(pCDO->nodenr,"%3d",NodeOutputTeller);
342 }
343 else
344 {
345 pCDO=&CardOutput[CardOutputTeller];
346 while (*pos==' '||*pos=='\t'||*pos=='\n'||*pos=='\r') pos++;//skip leading spaces
347 if (!memicmp(pos,"inet ",5))
348 {
349 unsigned int len;
350 char *pos1=pos+5;
351 pIO=&IfOutput[++IfOutputTeller];
352 while(*pos1++!=' ');
353 len=pos1-pos-6;
354 if (len>17) len=17;
355 memcpy(pIO->ip,pos+5,len);
356 pIO->ip[len]='\0';
357 memcpy(pIO->netmask,pos1+8,10);
358 pIO->netmask[10]='\0';
359 if (*(pos1+19)=='b') //broadcast
360 {
361 strcpy(pIO->broadcast,pos1+29);
362 }
363 sprintf(pIO->cardnr,"%3d",CardOutputTeller);
364 }
365 else if (!memicmp(pos,"ether ",6)) strcpy(pCDO->ether,pos+6);
366 else if (!memicmp(pos,"status: ",8)) strcpy(pCDO->status,pos+8);
367 else if (!memicmp(pos,"ssid ",5))
368 {
369 unsigned int len;
370 char *pos1=pos+5;
371 while(*pos1++!=' ');
372 len=pos1-pos-6;
373 if (len>38) len=38;
374 memcpy(pCDO->ssid,pos+5,len);
375 pCDO->ssid[len]='\0';
376 }
377 else if (!memicmp(pos,"channel ",8))
378 {
379 unsigned int len;
380 char *pos1=pos+8;
381 while(*pos1++!=' ');
382 len=pos1-pos-9;
383 if (len>3) len=3;
384 memcpy(pCDO->channel,pos+8,len);
385 pCDO->channel[len]='\0';
386 }
387 else if (!memicmp(pos,"stationname ",12)) strcpy(pCDO->stationname,pos+12);
388 }
389}
390
391void LeesNode(void)
392{
393 char *pos;
394 int regels=0;
395 int rest;
396 bCardBezig=FALSE;
397
398 toread=BUFLEN;
399 numread=fread(Tekstbuf,sizeof(char),toread,hConf);
400
401 pos=strtok(Tekstbuf,"\n\r" );
402 while (pos)
403 {
404 unsigned j;
405 strcpy(Regelbuf,Tekstbuf);
406 rest=strlen(Regelbuf);
407 for (j=0;j<numread-rest-1;j++)
408 {
409 Tekstbuf[j]=Tekstbuf[j+rest+1]; //tekst naar links schuiven
410 }
411 if (numread==BUFLEN)
412 {
413 numread-=(rest+1);
414 numread+=fread(Tekstbuf+numread,sizeof(char),rest+1,hConf);
415 if (numread<BUFLEN) Tekstbuf[numread]='\0';
416 }
417 else
418 {
419 numread-=(rest+1);
420 Tekstbuf[numread]='\0';
421 }
422
423 BehandelRegel();
424 strcat(Formatbuf,"\n");
425 printf(Formatbuf);
426 regels++;
427 pos=strtok(Tekstbuf,"\n\r" );
428 }
429 sprintf(buf,"\naantal regels: %i\n\r",regels);
430 printf(buf);
431}
432
433void FormatRegel(void)
434{
435 char *pos=Regelbuf;
436 char *pose=Formatbuf;
437 BOOL bDescFlag;
438 BOOL bDubbelIpFlag;
439 {
440 //vervang # door \0
441 char *posd=pos;
442 while (*posd!='#'&&*posd!='\0') posd++;
443 *posd='\0';
444 }
445 {
446 //vervang /" door /'
447 char *posd=pos;
448 while (*posd!='\0')
449 {
450 if (*posd=='\"') *posd='\'';
451 posd++;
452 }
453 }
454 while (pos[strlen(pos)-1]==' ') //skip trailing spaces
455 {
456 pos[strlen(pos)-1]='\0';
457 }
458 if (pos[strlen(pos)-1]==';') //skip trailing ;
459 {
460 pos[strlen(pos)-1]='\0';
461 }
462 if (pos[strlen(pos)-1]=='\'') //skip trailing '
463 {
464 pos[strlen(pos)-1]='\0';
465 }
466 while (pos[strlen(pos)-1]==' ') //skip trailing spaces
467 {
468 pos[strlen(pos)-1]='\0';
469 }
470 while (*pos==' '||*pos=='\t'||*pos=='\n'||*pos=='\r') pos++;//skip leading spaces
471
472 bDescFlag=(!memicmp(pos,"DESC",4)); //bij DESC spaties laten
473 bDubbelIpFlag=(!memicmp(pos,"POINT_TO_POINT=",15)||!memicmp(pos,"OSPF_NEIGHBORS=",15)); //spaties vervangen door ;
474 for (;*pos!='\0';pos++)
475 {
476 if (bDubbelIpFlag&&(*pos==' '||*pos=='\t'))
477 {
478 while (*pos==' '||*pos=='\t') pos++;//skip overige spaces
479 *(--pos)=';';
480 }
481 while (!bDescFlag&&(*pos==' '||*pos=='\t')) pos++;//skip spaces
482 if (*pos=='\'') //neem tekst tussen quotes letterlijk over
483 { //tot volgende quote of eind
484 *pose++=*pos++;
485 while (*pos!='\''&&*pos!='\0')
486 {
487 if (*pos==',') *pos=';'; //geen komma's ivm csv-list
488 *pose++=*pos++;
489 }
490 }
491 if (*pos==',') *pos=';'; //geen komma's ivm csv-list
492 *pose++=*pos;
493 }
494 *pose='\0';
495 strcpy(Regelbuf,Formatbuf);
496}
497
498void BehandelRegel(void)
499{
500 char *pos=Regelbuf;
501 CNODE *pCN=&CNode[NodeTeller];
502 CARD *pCd=&Card[CardTeller];
503 FormatRegel();
504
505 if (!bCardBezig)
506 {
507 if (!memicmp(pos,"$location='",11)) strncpy(pCN->location,pos+11,sizeof(pCN->location));
508 else if (!memicmp(pos,"$master_ip='",12))
509 {
510 sprintf(pCN->volgnr,"%3d",NodeTeller); //hier want t hoeft maar 1 keer
511 strncpy(pCN->master_ip,pos+12,sizeof(pCN->master_ip));
512 }
513 else if (!memicmp(pos,"$gw_open='",10)) strncpy(pCN->gw_open,pos+10,sizeof(pCN->gw_open));
514 else if (!memicmp(pos,"$nodetype='",11)) strncpy(pCN->nodetype,pos+11,sizeof(pCN->nodetype));
515 else if (!memicmp(pos,"$nodename='",11)) strncpy(pCN->nodename,pos+11,sizeof(pCN->nodename));
516 else if (!memicmp(pos,"$status='",9)) strncpy(pCN->status,pos+9,sizeof(pCN->status));
517 else if (!memicmp(pos,"$OS='",5)) strncpy(pCN->OS,pos+5,sizeof(pCN->OS));
518 else if (!memicmp(pos,"$labelpos='",11)) strncpy(pCN->labelpos,pos+11,sizeof(pCN->labelpos));
519 else if (!memicmp(pos,"$X='",4)) strncpy(pCN->X,pos+4,sizeof(pCN->X));
520 else if (!memicmp(pos,"$Y='",4)) strncpy(pCN->Y,pos+4,sizeof(pCN->Y));
521 else if (!memicmp(pos,"$N='",4)) strncpy(pCN->N,pos+4,sizeof(pCN->N));
522 else if (!memicmp(pos,"$E='",4)) strncpy(pCN->E,pos+4,sizeof(pCN->E));
523 else if (!memicmp(pos,"$ESSID='",8)) strncpy(pCN->ESSID,pos+8,sizeof(pCN->ESSID));
524
525 else if (!memicmp(pos,"$config{'",9))
526 {
527 unsigned int len;
528 char *pos1=pos+9;
529 while(*pos1++!='\'');
530 len=pos1-pos-10;
531 if (len>9) len=9;
532 memcpy(pCd->configname,pos+9,len);
533 pCd->configname[len]='\0';
534 sprintf(pCd->volgnr,"%3d",CardTeller); //hier want t hoeft maar 1 keer
535 sprintf(pCd->nodenr,"%3d",NodeTeller); //hier want t hoeft maar 1 keer
536 //opvang voor ontbreken van 'sprintf' bij sommige configs
537 if (*(pos+12+len)=='<')
538 {
539 strncpy(pCd->sprintfname,pos+len+14,sizeof(pCd->sprintfname));
540 }
541 else strncpy(pCd->sprintfname,pos+len+21,sizeof(pCd->sprintfname));
542 bCardBezig=TRUE;
543 if (*(pCd->configname+strlen(pCd->configname)-2)==':')
544 { //alias, dan hoofdgegevens overnemen, ga ervan uit dat hoofd-interface altijd direct aan aliassen voorafgaat
545 int j=0;
546 while (*((pCd-j)->configname+strlen((pCd-j)->configname)-2)==':'&&(j<=CardTeller)) j++;
547 if (j<=CardTeller)
548 {
549 strncpy(pCd->mode,(pCd-j)->mode,sizeof(pCd->mode));
550 strncpy(pCd->essid,(pCd-j)->essid,sizeof(pCd->essid));
551 strncpy(pCd->channel,(pCd-j)->channel,sizeof(pCd->channel));
552 strncpy(pCd->polar,(pCd-j)->polar,sizeof(pCd->polar));
553 strncpy(pCd->antenna,(pCd-j)->antenna,sizeof(pCd->antenna));
554 strncpy(pCd->gain,(pCd-j)->gain,sizeof(pCd->gain));
555 strncpy(pCd->direction,(pCd-j)->direction,sizeof(pCd->direction));
556 strncpy(pCd->beamwidth,(pCd-j)->beamwidth,sizeof(pCd->beamwidth));
557 strncpy(pCd->cable,(pCd-j)->cable,sizeof(pCd->cable));
558 strncpy(pCd->heigth,(pCd-j)->heigth,sizeof(pCd->heigth));
559 }
560 }
561 }
562 }
563 else /*if (bCardBezig)*/
564 {
565 if (!memicmp(pos,pCd->sprintfname,strlen(pCd->sprintfname)))
566 {
567 VulIpAdressen();
568 CardTeller++;
569 bCardBezig=FALSE;
570 }
571 else if (!memicmp(pos,"TYPE=",5)) strncpy(pCd->type,pos+5,sizeof(pCd->type));
572 else if (!memicmp(pos,"IP=",3))
573 {
574 if (!memicmp(pos+3,"$master_ip",10))
575 {
576 strcpy(pCd->ip,pCN->master_ip);
577 strcat(pCd->ip,pos+13);
578 }
579 else strncpy(pCd->ip,pos+3,sizeof(pCd->ip));
580 }
581 else if (!memcmp(pos,"DESC=",5)) strncpy(pCd->desc,pos+5,sizeof(pCd->desc));
582 else if (!memicmp(pos,"SDESC=",6)) strncpy(pCd->sdesc,pos+6,sizeof(pCd->sdesc));
583 else if (!memicmp(pos,"SPEED=",6)) strncpy(pCd->speed,pos+6,sizeof(pCd->speed));
584 else if (!memicmp(pos,"POINT_TO_POINT=",15)) strncpy(pCd->pointtopoint,pos+15,sizeof(pCd->pointtopoint));
585 else if (!memicmp(pos,"OSPF_BROADCAST=",15)) strncpy(pCd->ospfbroadcast,pos+15,sizeof(pCd->ospfbroadcast));
586 else if (!memicmp(pos,"OSPF_NEIGHBORS=",15)) strncpy(pCd->ospfneighbors,pos+15,sizeof(pCd->ospfneighbors));
587 else if (!memicmp(pos,"DHCP=",5)) strncpy(pCd->dhcp,pos+5,sizeof(pCd->dhcp));
588 else if (!memicmp(pos,"MODE=",5)) strncpy(pCd->mode,pos+5,sizeof(pCd->mode));
589 else if (!memicmp(pos,"ESSID=",6)) strncpy(pCd->essid,pos+6,sizeof(pCd->essid));
590 else if (!memicmp(pos,"CHANNEL=",8)) strncpy(pCd->channel,pos+8,sizeof(pCd->channel));
591 else if (!memicmp(pos,"POLAR=",6)) strncpy(pCd->polar,pos+6,sizeof(pCd->polar));
592 else if (!memicmp(pos,"ANTENNA=",8)) strncpy(pCd->antenna,pos+8,sizeof(pCd->antenna));
593 else if (!memicmp(pos,"GAIN=",5)) strncpy(pCd->gain,pos+5,sizeof(pCd->gain));
594 else if (!memicmp(pos,"DIRECTION=",10)) strncpy(pCd->direction,pos+10,sizeof(pCd->direction));
595 else if (!memicmp(pos,"BEAMWIDTH=",10)) strncpy(pCd->beamwidth,pos+10,sizeof(pCd->beamwidth));
596 else if (!memicmp(pos,"CABLE=",6)) strncpy(pCd->cable,pos+6,sizeof(pCd->cable));
597 else if (!memicmp(pos,"HEIGTH=",7)) strncpy(pCd->heigth,pos+7,sizeof(pCd->heigth));
598 }
599}
600
601void VulIpAdressen(void)
602{
603 CARD *pCd=&Card[CardTeller];
604 char buf[36];
605 char *t;
606 strcpy(buf,pCd->ip);//111.111.111.111/30
607 t=strtok(buf,".");
608 if (t)
609 {
610 pCd->ipr.ip.ip0=(unsigned char)atoi(t);
611 t=strtok(NULL,".");
612 if (t)
613 {
614 pCd->ipr.ip.ip1=(unsigned char)atoi(t);
615 t=strtok(NULL,".");
616 if (t)
617 {
618 pCd->ipr.ip.ip2=(unsigned char)atoi(t);
619 t=strtok(NULL,"/");// let op /
620 if (t)
621 {
622 pCd->ipr.ip.ip3=(unsigned char)atoi(t);
623 t=strtok(NULL,".");
624 if (t) pCd->ipr.mask=(unsigned char)atoi(t);
625 }
626 }
627 }
628 }
629 strcpy(buf,pCd->pointtopoint);//111.111.111.111;111.111.111.111
630 t=strtok(buf,".");
631 if (t)
632 {
633 pCd->ptp1.ip0=(unsigned char)atoi(t);
634 t=strtok(NULL,".");
635 if (t)
636 {
637 pCd->ptp1.ip1=(unsigned char)atoi(t);
638 t=strtok(NULL,".");
639 if (t)
640 {
641 pCd->ptp1.ip2=(unsigned char)atoi(t);
642 t=strtok(NULL,";");// let op ;
643 if (t)
644 {
645 pCd->ptp1.ip3=(unsigned char)atoi(t);
646 t=strtok(NULL,".");
647 if (t)
648 {
649 pCd->ptp2.ip0=(unsigned char)atoi(t);
650 t=strtok(NULL,".");
651 if (t)
652 {
653 pCd->ptp2.ip1=(unsigned char)atoi(t);
654 t=strtok(NULL,".");
655 if (t)
656 {
657 pCd->ptp2.ip2=(unsigned char)atoi(t);
658 t=strtok(NULL,";");
659 if (t) pCd->ptp2.ip3=(unsigned char)atoi(t);
660 }
661 }
662 }
663 }
664 }
665 }
666 }
667 strcpy(buf,pCd->ospfneighbors);//111.111.111.111;111.111.111.111
668 t=strtok(buf,".");
669 if (t)
670 {
671 pCd->on1.ip0=(unsigned char)atoi(t);
672 t=strtok(NULL,".");
673 if (t)
674 {
675 pCd->on1.ip1=(unsigned char)atoi(t);
676 t=strtok(NULL,".");
677 if (t)
678 {
679 pCd->on1.ip2=(unsigned char)atoi(t);
680 t=strtok(NULL,";");// let op ;
681 if (t)
682 {
683 pCd->on1.ip3=(unsigned char)atoi(t);
684 t=strtok(NULL,".");
685 if (t)
686 {
687 pCd->on2.ip0=(unsigned char)atoi(t);
688 t=strtok(NULL,".");
689 if (t)
690 {
691 pCd->on2.ip1=(unsigned char)atoi(t);
692 t=strtok(NULL,".");
693 if (t)
694 {
695 pCd->on2.ip2=(unsigned char)atoi(t);
696 t=strtok(NULL,";");
697 if (t) pCd->on2.ip3=(unsigned char)atoi(t);
698 }
699 }
700 }
701 }
702 }
703 }
704 }
705 {
706 IPADDRESS ips=pCd->ipr.ip;
707 int mask3=pCd->ipr.mask;
708 if (mask3<24)//komt nu niet voor, maar vang af met 0,0,0,0
709 {
710 ips.ip0=ips.ip1=ips.ip2=ips.ip3=0;
711 pCd->ipstart=pCd->ipend=ips;
712 }
713 else
714 {
715 int mask3p,mask3pxor;
716 mask3-=24;
717 mask3p=255;
718 mask3p>>=mask3; //shift right
719 mask3pxor=255^mask3p;
720 ips.ip3=ips.ip3&mask3pxor;
721 pCd->ipstart=ips;
722 ips.ip3=ips.ip3|mask3p;
723 pCd->ipend=ips;
724 }
725 }
726}
727
728void MaakIpOverzicht(void)
729{
730 //bubble sort card records op oplopend ip
731 CARD *pCd1,*pCd2;
732 IPADDRESS *pAd1, *pAd2;
733 int i,j;
734 BOOL swapped;
735 do
736 {
737 swapped=FALSE;
738 for (i=0,j=1;i<CardTeller-1;i++,j++)
739 {
740 BOOL swappen=FALSE;
741 pCd1=&Card[i];pCd2=&Card[j];
742 pAd1=&(pCd1->ipr.ip);pAd2=&(pCd2->ipr.ip);
743 if (pAd1->ip0>pAd2->ip0) swappen=TRUE;
744 else if (pAd1->ip0<pAd2->ip0) continue;
745 else if (pAd1->ip1>pAd2->ip1) swappen=TRUE;
746 else if (pAd1->ip1<pAd2->ip1) continue;
747 else if (pAd1->ip2>pAd2->ip2) swappen=TRUE;
748 else if (pAd1->ip2<pAd2->ip2) continue;
749 else if (pAd1->ip3>pAd2->ip3) swappen=TRUE;
750 else if (pAd1->ip3<pAd2->ip3) continue;
751 else if (pCd1->ipr.mask<pCd2->ipr.mask) swappen=TRUE;
752 if (swappen)
753 {
754 SwapCards(i);
755 swapped=TRUE;
756 }
757 }
758 }
759 while (swapped);
760 MaakCSV(2);
761 MaakCSV2(1);
762}
763
764void SwapCards(int i)
765{
766 CARD tempCd=Card[i+1];
767 Card[i+1]=Card[i];
768 Card[i]=tempCd;
769}
770
771void MaakCSV2(int code)
772{
773 int i;
774 CNODE *pCN;
775 CARD *pCd;
776 if (code==1) hConf=fopen("configip1.csv","w");
777 if (code==2) hConf=fopen("configip2.csv","w");
778 if (hConf)
779 {
780 strcpy(buf,"status");AddTekst();AddKomma();
781 strcpy(buf,"nodename");AddTekst();AddKomma();
782 strcpy(buf,"configname");AddTekst();AddKomma();
783 strcpy(buf,"essid");AddTekst();AddKomma();
784 strcpy(buf,"sdesc");AddTekst();AddKomma();
785 strcpy(buf,"master_ip");AddTekst();AddKomma();
786 strcpy(buf,"IP-range");AddTekst();AddKomma();
787 strcpy(buf,"IP-start");AddTekst();AddKomma();
788 strcpy(buf,"IP-end");AddTekst();AddKomma();
789 strcpy(buf,"point_to_point");AddTekst();AddKomma();
790 strcpy(buf,"ospf_neighbors");AddTekst();AddKomma();
791 strcpy(buf,"mode");AddTekst();AddKomma();
792 strcpy(buf,"channel");AddTekst();AddKomma();
793 strcpy(buf,"Current data from nodes");AddTekst();AddKomma();
794 fwrite( "\n", sizeof( char ), 1, hConf );
795
796 for (i=0;i<CardTeller;i++)
797 {
798 pCd=&Card[i];
799 pCN=&CNode[atoi(pCd->nodenr)];
800 if (i>0)
801 { //extra lege regel
802 if (CompareIp(&(pCd->ipstart),&((pCd-1)->ipstart))||CompareIp(&(pCd->ipend),&((pCd-1)->ipend)))
803 fwrite( "\n", sizeof( char ), 1, hConf );
804 }
805 fwrite( pCN->status, sizeof( char ), strlen(pCN->status), hConf );AddKomma();
806 fwrite( pCN->nodename, sizeof( char ), strlen(pCN->nodename), hConf );AddKomma();
807 fwrite( pCd->configname, sizeof( char ), strlen(pCd->configname), hConf );AddKomma();
808 fwrite( pCd->essid, sizeof( char ), strlen(pCd->essid), hConf );AddKomma();
809 fwrite( pCd->sdesc, sizeof( char ), strlen(pCd->sdesc), hConf );AddKomma();
810 fwrite( pCN->master_ip, sizeof( char ), strlen(pCN->master_ip), hConf );AddKomma();
811 fwrite( pCd->ip, sizeof( char ), strlen(pCd->ip), hConf );AddKomma();
812 {
813 char buf[20];
814 sprintf(buf,"%i.%i.%i.%i",pCd->ipstart.ip0,pCd->ipstart.ip1,pCd->ipstart.ip2,pCd->ipstart.ip3);
815 fwrite( buf, sizeof( char ),strlen(buf), hConf );AddKomma();
816 sprintf(buf,"%i.%i.%i.%i",pCd->ipend.ip0,pCd->ipend.ip1,pCd->ipend.ip2,pCd->ipend.ip3);
817 fwrite( buf, sizeof( char ),strlen(buf), hConf );AddKomma();
818 }
819 fwrite( pCd->pointtopoint, sizeof( char ), strlen(pCd->pointtopoint), hConf );AddKomma();
820 fwrite( pCd->ospfneighbors, sizeof( char ), strlen(pCd->ospfneighbors), hConf );AddKomma();
821 fwrite( pCd->mode, sizeof( char ), strlen(pCd->mode), hConf );AddKomma();
822 fwrite( pCd->channel, sizeof( char ), strlen(pCd->channel), hConf );AddKomma();
823 {
824 int j;
825 IFOUTPUT *pIO;
826 for (j=0;j<IfOutputTeller;j++)
827 {
828 pIO=&IfOutput[j];
829 if (!memcmp(pIO->ip,pCd->ip,strlen(pIO->ip))) break;
830 }
831 if (j<IfOutputTeller)
832 {
833 CARDOUTPUT *pCDO=&CardOutput[atoi(pIO->cardnr)];
834 fwrite( pCDO->configname, sizeof( char ), strlen(pCDO->configname), hConf );AddKomma();
835 fwrite( pCDO->ether, sizeof( char ), strlen(pCDO->ether), hConf );AddKomma();
836 fwrite( pCDO->status, sizeof( char ), strlen(pCDO->status), hConf );AddKomma();
837 fwrite( pCDO->ssid, sizeof( char ), strlen(pCDO->ssid), hConf );AddKomma();
838 fwrite( pCDO->stationname, sizeof( char ), strlen(pCDO->stationname), hConf );AddKomma();
839 fwrite( pCDO->channel, sizeof( char ), strlen(pCDO->channel), hConf );AddKomma();
840 }
841 else
842 {
843 AddKomma();
844 AddKomma();
845 AddKomma();
846 AddKomma();
847 AddKomma();
848 AddKomma();
849 }
850
851 }
852
853
854
855
856
857
858#ifdef xyz //even er uit
859 {
860 BOOL even;
861 int test=pCd->ipr.ip.ip3;
862 even=(test==((int)(test/2))*2);
863 if (!memicmp(pCd->mode,"managed",7)&&!even)
864 {
865 fwrite("oneven ip-adres en managed mode",sizeof( char ),31,hConf);
866 AddKomma();
867 }
868 if (!memicmp(pCd->mode,"master",6)&&even)
869 {
870 fwrite("even ip-adres en master mode",sizeof( char ),28,hConf);
871 AddKomma();
872 }
873 }
874
875 if (CompareIp(&pCd->ptp1,&pCd->ipstart)<0||CompareIp(&pCd->ptp1,&pCd->ipend)>0)
876 {
877 fwrite("point-to-point adres buiten range",sizeof( char ),33,hConf);
878 AddKomma();
879 }
880 if (CompareIp(&pCd->on1,&pCd->ipstart)<0||CompareIp(&pCd->on1,&pCd->ipend)>0)
881 {
882 fwrite("ospf-neighbors adres buiten range",sizeof( char ),33,hConf);
883 AddKomma();
884 }
885#endif
886 fwrite( "\n", sizeof( char ), 1, hConf );
887 }
888 fclose(hConf);
889 }
890}
891
892void MaakCSV(int code)
893{
894 int i;
895 CNODE *pCN;
896 CARD *pCd;
897 if (code==1) hConf=fopen("configs1.csv","w");
898 if (code==2) hConf=fopen("configs2.csv","w");
899 if (hConf)
900 {
901// strcpy(buf,"Volgnr");AddTekst();AddKomma();
902 strcpy(buf,"location");AddTekst();AddKomma();
903 strcpy(buf,"master_ip");AddTekst();AddKomma();
904 strcpy(buf,"gw_open");AddTekst();AddKomma();
905 strcpy(buf,"nodetype");AddTekst();AddKomma();
906 strcpy(buf,"nodename");AddTekst();AddKomma();
907 strcpy(buf,"status");AddTekst();AddKomma();
908 strcpy(buf,"OS");AddTekst();AddKomma();
909 strcpy(buf,"labelpos");AddTekst();AddKomma();
910 strcpy(buf,"X");AddTekst();AddKomma();
911 strcpy(buf,"Y");AddTekst();AddKomma();
912 strcpy(buf,"N");AddTekst();AddKomma();
913 strcpy(buf,"E");AddTekst();AddKomma();
914 strcpy(buf,"ESSID");AddTekst();AddKomma();
915// strcpy(buf,"volgnr");AddTekst();AddKomma();
916 strcpy(buf,"configname");AddTekst();AddKomma();
917 strcpy(buf,"sprintfname");AddTekst();AddKomma();
918 strcpy(buf,"type");AddTekst();AddKomma();
919 strcpy(buf,"ip");AddTekst();AddKomma();
920 strcpy(buf,"desc");AddTekst();AddKomma();
921 strcpy(buf,"sdesc");AddTekst();AddKomma();
922 strcpy(buf,"speed");AddTekst();AddKomma();
923 strcpy(buf,"point_to_point");AddTekst();AddKomma();
924 strcpy(buf,"ospf_broadcast");AddTekst();AddKomma();
925 strcpy(buf,"ospf_neighbors");AddTekst();AddKomma();
926 strcpy(buf,"dhcp");AddTekst();AddKomma();
927 strcpy(buf,"mode");AddTekst();AddKomma();
928 strcpy(buf,"essid");AddTekst();AddKomma();
929 strcpy(buf,"channel");AddTekst();AddKomma();
930 strcpy(buf,"polar");AddTekst();AddKomma();
931 strcpy(buf,"antenna");AddTekst();AddKomma();
932 strcpy(buf,"gain");AddTekst();AddKomma();
933 strcpy(buf,"direction");AddTekst();AddKomma();
934 strcpy(buf,"beamwidth");AddTekst();AddKomma();
935 strcpy(buf,"cable");AddTekst();AddKomma();
936 strcpy(buf,"heigth");AddTekst();AddKomma();
937
938 fwrite( "\n", sizeof( char ), 1, hConf );
939
940 for (i=0;i<CardTeller;i++)
941 {
942 pCd=&Card[i];
943 pCN=&CNode[atoi(pCd->nodenr)];
944// fwrite( pCN->volgnr, sizeof( char ), strlen(pCN->volgnr), hConf );AddKomma();
945 fwrite( pCN->location, sizeof( char ), strlen(pCN->location), hConf );AddKomma();
946 fwrite( pCN->master_ip, sizeof( char ), strlen(pCN->master_ip), hConf );AddKomma();
947 fwrite( pCN->gw_open, sizeof( char ), strlen(pCN->gw_open), hConf );AddKomma();
948 fwrite( pCN->nodetype, sizeof( char ), strlen(pCN->nodetype), hConf );AddKomma();
949 fwrite( pCN->nodename, sizeof( char ), strlen(pCN->nodename), hConf );AddKomma();
950 fwrite( pCN->status, sizeof( char ), strlen(pCN->status), hConf );AddKomma();
951 fwrite( pCN->OS, sizeof( char ), strlen(pCN->OS), hConf );AddKomma();
952 fwrite( pCN->labelpos, sizeof( char ), strlen(pCN->labelpos), hConf );AddKomma();
953 fwrite( pCN->X, sizeof( char ), strlen(pCN->X), hConf );AddKomma();
954 fwrite( pCN->Y, sizeof( char ), strlen(pCN->Y), hConf );AddKomma();
955 fwrite( pCN->N, sizeof( char ), strlen(pCN->N), hConf );AddKomma();
956 fwrite( pCN->E, sizeof( char ), strlen(pCN->E), hConf );AddKomma();
957 fwrite( pCN->ESSID, sizeof( char ), strlen(pCN->ESSID), hConf );AddKomma();
958// fwrite( pCd->volgnr, sizeof( char ), strlen(pCd->volgnr), hConf );AddKomma();
959 fwrite( pCd->configname, sizeof( char ), strlen(pCd->configname), hConf );AddKomma();
960 fwrite( pCd->sprintfname, sizeof( char ), strlen(pCd->sprintfname), hConf );AddKomma();
961 fwrite( pCd->type, sizeof( char ), strlen(pCd->type), hConf );AddKomma();
962 fwrite( pCd->ip, sizeof( char ), strlen(pCd->ip), hConf );AddKomma();
963 fwrite( pCd->desc, sizeof( char ), strlen(pCd->desc), hConf );AddKomma();
964 fwrite( pCd->sdesc, sizeof( char ), strlen(pCd->sdesc), hConf );AddKomma();
965 fwrite( pCd->speed, sizeof( char ), strlen(pCd->speed), hConf );AddKomma();
966 fwrite( pCd->pointtopoint, sizeof( char ), strlen(pCd->pointtopoint), hConf );AddKomma();
967 fwrite( pCd->ospfbroadcast, sizeof( char ), strlen(pCd->ospfbroadcast), hConf );AddKomma();
968 fwrite( pCd->ospfneighbors, sizeof( char ), strlen(pCd->ospfneighbors), hConf );AddKomma();
969 fwrite( pCd->dhcp, sizeof( char ), strlen(pCd->dhcp), hConf );AddKomma();
970 fwrite( pCd->mode, sizeof( char ), strlen(pCd->mode), hConf );AddKomma();
971 fwrite( pCd->essid, sizeof( char ), strlen(pCd->essid), hConf );AddKomma();
972 fwrite( pCd->channel, sizeof( char ), strlen(pCd->channel), hConf );AddKomma();
973 fwrite( pCd->polar, sizeof( char ), strlen(pCd->polar), hConf );AddKomma();
974 fwrite( pCd->antenna, sizeof( char ), strlen(pCd->antenna), hConf );AddKomma();
975 fwrite( pCd->gain, sizeof( char ), strlen(pCd->gain), hConf );AddKomma();
976 fwrite( pCd->direction, sizeof( char ), strlen(pCd->direction), hConf );AddKomma();
977 fwrite( pCd->beamwidth, sizeof( char ), strlen(pCd->beamwidth), hConf );AddKomma();
978 fwrite( pCd->cable, sizeof( char ), strlen(pCd->cable), hConf );AddKomma();
979 fwrite( pCd->heigth, sizeof( char ), strlen(pCd->heigth), hConf );AddKomma();
980 fwrite( "\n", sizeof( char ), 1, hConf );
981 }
982 fclose(hConf);
983 }
984}
985
986void AddKomma(void)
987{
988 fwrite( ",", sizeof( char ), 1, hConf );
989}
990
991void AddTekst(void)
992{
993 fwrite( buf, sizeof( char ), strlen(buf), hConf );
994}
995
996int CompareIp(IPADDRESS *ad1,IPADDRESS *ad2)
997{//ad1>ad2->1;ad1==ad2->0;ad1<ad2->-1
998 if(ad1->ip0>ad2->ip0) return 1;
999 if(ad1->ip0<ad2->ip0) return -1;
1000 if(ad1->ip1>ad2->ip1) return 1;
1001 if(ad1->ip1<ad2->ip1) return -1;
1002 if(ad1->ip2>ad2->ip2) return 1;
1003 if(ad1->ip2<ad2->ip2) return -1;
1004 if(ad1->ip3>ad2->ip3) return 1;
1005 if(ad1->ip3<ad2->ip3) return -1;
1006 return 0;
1007}
1008
Note: See TracBrowser for help on using the repository browser.