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

Last change on this file since 3182 was 3182, checked in by rudolf, 20 years ago
  • Property svn:executable set to *
File size: 26.1 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 en te bewerken
7//
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
17// dimensies van desc, point_to_point, ospfneighbors verhoogd
18// gegevens van hoofd interface in aliassen overgenomen
19// komma's uit velden geskipt ivm csv-lijst (3e regel node-som heeft ',' in desc-veld)
20//
21// Rev.0.0 10/11/2004 initial revision Rudolf Oosterhuis
22
23#include <stdio.h>
24#include <io.h>
25#include <time.h>
26#include <string.h>
27#include <ctype.h>
28#include <stdlib.h>
29
30#define BOOL unsigned int
31#define FALSE (0==1)
32#define TRUE (0==0)
33
34typedef struct
35{
36 unsigned char ip0;
37 unsigned char ip1;
38 unsigned char ip2;
39 unsigned char ip3;
40} IPADDRESS;
41
42typedef struct
43{
44 IPADDRESS ip;
45 unsigned char mask;
46} IPRANGE;
47
48typedef struct
49{
50 char volgnr[4];
51 char location[100];
52 char master_ip[20];
53 char gw_open[10];
54 char nodetype[10];
55 char nodename[30];
56 char status[10];
57 char OS[20];
58 char labelpos[30];
59 char X[10];
60 char Y[10];
61 char N[10];
62 char E[10];
63 char ESSID[34];
64} CNODE;
65
66typedef struct
67{
68 char volgnr[4];
69 char nodenr[4];
70 char configname[10];
71 char sprintfname[10];
72 char type[10];
73 char ip[20];
74 char desc[46];
75 char sdesc[20];
76 char speed[20];
77
78 char pointtopoint[35];
79
80 char ospfbroadcast[6];
81 char ospfneighbors[35];
82
83 char mode[10];
84 char essid[34];
85 char channel[3];
86
87 char polar[6];
88 char antenna[10];
89 char gain[10];
90 char direction[6];
91 char beamwidth[6];
92 char cable[3];
93 char heigth[4];
94
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;
103} CARD;
104
105
106void LeesNode(void);
107void BehandelRegel(void);
108void FormatRegel(void);
109void MaakCSV(int code);
110void MaakCSV2(int code);
111void MaakIpOverzicht(void);
112void AddKomma(void);
113void AddTekst(void);
114void VulIpAdressen(void);
115void SwapCards(int i);
116int CompareIp(IPADDRESS *ad1,IPADDRESS *ad2);
117
118char fn[50];
119char buf[50];
120#define BUFLEN 1000
121char Tekstbuf[BUFLEN];
122char Regelbuf[BUFLEN];
123char Formatbuf[BUFLEN];
124FILE *hConf;
125size_t numread,toread;
126CNODE CNode[100];
127CARD Card[500];
128int NodeTeller;
129int CardTeller;
130BOOL bCardBezig;
131
132main()
133{
134 //doorzoek mappen
135 struct _finddata_t c_file;
136 long hFile;
137 NodeTeller=0;
138 CardTeller=0;
139
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 );
159 sprintf(buf,"\naantal nodes: %i\n\r",NodeTeller);
160 printf(buf);
161 MaakCSV(1);
162 MaakIpOverzicht();
163 return 0;
164}
165
166void LeesNode(void)
167{
168 char *pos;
169 int regels=0;
170 int rest;
171 bCardBezig=FALSE;
172
173 toread=BUFLEN;
174 numread=fread(Tekstbuf,sizeof(char),toread,hConf);
175
176 memset((char*)&(CNode[NodeTeller]),'\0',sizeof(CNode[NodeTeller]));
177 pos=strtok(Tekstbuf,"\n\r" );
178 while (pos)
179 {
180 unsigned j;
181 strcpy(Regelbuf,Tekstbuf);
182 rest=strlen(Regelbuf);
183 for (j=0;j<numread-rest-1;j++)
184 {
185 Tekstbuf[j]=Tekstbuf[j+rest+1]; //tekst naar links schuiven
186 }
187 if (numread==BUFLEN)
188 {
189 numread-=(rest+1);
190 numread+=fread(Tekstbuf+numread,sizeof(char),rest+1,hConf);
191 if (numread<BUFLEN) Tekstbuf[numread]='\0';
192 }
193 else
194 {
195 numread-=(rest+1);
196 Tekstbuf[numread]='\0';
197 }
198
199 BehandelRegel();
200 strcat(Formatbuf,"\n");
201 printf(Formatbuf);
202 regels++;
203 pos=strtok(Tekstbuf,"\n\r" );
204 }
205 sprintf(buf,"\naantal regels: %i\n\r",regels);
206 printf(buf);
207}
208
209void FormatRegel(void)
210{
211 char *pos=Regelbuf;
212 char *pose=Formatbuf;
213 BOOL bDescFlag;
214 BOOL bDubbelIpFlag;
215 {
216 //vervang # door \0
217 char *posd=pos;
218 while (*posd!='#'&&*posd!='\0') posd++;
219 *posd='\0';
220 }
221 {
222 //vervang /" door /'
223 char *posd=pos;
224 while (*posd!='\0')
225 {
226 if (*posd=='\"') *posd='\'';
227 posd++;
228 }
229 }
230 while (pos[strlen(pos)-1]==' ') //skip trailing spaces
231 {
232 pos[strlen(pos)-1]='\0';
233 }
234 if (pos[strlen(pos)-1]==';') //skip trailing ;
235 {
236 pos[strlen(pos)-1]='\0';
237 }
238 if (pos[strlen(pos)-1]=='\'') //skip trailing '
239 {
240 pos[strlen(pos)-1]='\0';
241 }
242 while (pos[strlen(pos)-1]==' ') //skip trailing spaces
243 {
244 pos[strlen(pos)-1]='\0';
245 }
246 while (*pos==' '||*pos=='\t'||*pos=='\n'||*pos=='\r') pos++;//skip leading spaces
247
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 ;
250 for (;*pos!='\0';pos++)
251 {
252 if (bDubbelIpFlag&&(*pos==' '||*pos=='\t'))
253 {
254 while (*pos==' '||*pos=='\t') pos++;//skip overige spaces
255 *(--pos)=';';
256 }
257 while (!bDescFlag&&(*pos==' '||*pos=='\t')) pos++;//skip spaces
258 if (*pos=='\'') //neem tekst tussen quotes letterlijk over
259 { //tot volgende quote of eind
260 *pose++=*pos++;
261 while (*pos!='\''&&*pos!='\0')
262 {
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;
269 }
270 *pose='\0';
271 strcpy(Regelbuf,Formatbuf);
272}
273
274void BehandelRegel(void)
275{
276 char *pos=Regelbuf;
277 CNODE *pCN=&CNode[NodeTeller];
278 CARD *pCd=&Card[CardTeller];
279 FormatRegel();
280
281 if (!bCardBezig)
282 {
283 if (!memicmp(pos,"$location='",11)) strncpy(pCN->location,pos+11,sizeof(pCN->location));
284 else if (!memicmp(pos,"$master_ip='",12))
285 {
286 sprintf(pCN->volgnr,"%3d",NodeTeller); //hier want t hoeft maar 1 keer
287 strncpy(pCN->master_ip,pos+12,sizeof(pCN->master_ip));
288 }
289 else if (!memicmp(pos,"$gw_open='",10)) strncpy(pCN->gw_open,pos+10,sizeof(pCN->gw_open));
290 else if (!memicmp(pos,"$nodetype='",11)) strncpy(pCN->nodetype,pos+11,sizeof(pCN->nodetype));
291 else if (!memicmp(pos,"$nodename='",11)) strncpy(pCN->nodename,pos+11,sizeof(pCN->nodename));
292 else if (!memicmp(pos,"$status='",9)) strncpy(pCN->status,pos+9,sizeof(pCN->status));
293 else if (!memicmp(pos,"$OS='",5)) strncpy(pCN->OS,pos+5,sizeof(pCN->OS));
294 else if (!memicmp(pos,"$labelpos='",11)) strncpy(pCN->labelpos,pos+11,sizeof(pCN->labelpos));
295 else if (!memicmp(pos,"$X='",4)) strncpy(pCN->X,pos+4,sizeof(pCN->X));
296 else if (!memicmp(pos,"$Y='",4)) strncpy(pCN->Y,pos+4,sizeof(pCN->Y));
297 else if (!memicmp(pos,"$N='",4)) strncpy(pCN->N,pos+4,sizeof(pCN->N));
298 else if (!memicmp(pos,"$E='",4)) strncpy(pCN->E,pos+4,sizeof(pCN->E));
299 else if (!memicmp(pos,"$ESSID='",8)) strncpy(pCN->ESSID,pos+8,sizeof(pCN->ESSID));
300
301 else if (!memicmp(pos,"$config{'",9))
302 {
303 unsigned int len;
304 char *pos1=pos+9;
305 while(*pos1++!='\'');
306 len=pos1-pos-10;
307 if (len>9) len=9;
308 memcpy(pCd->configname,pos+9,len);
309 pCd->configname[len]='\0';
310 sprintf(pCd->volgnr,"%3d",CardTeller); //hier want t hoeft maar 1 keer
311 sprintf(pCd->nodenr,"%3d",NodeTeller); //hier want t hoeft maar 1 keer
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));
318 bCardBezig=TRUE;
319 if (*(pCd->configname+strlen(pCd->configname)-2)==':')
320 { //alias, dan hoofdgegevens overnemen, ga ervan uit dat hoofd-interface altijd direct aan aliassen voorafgaat
321 int j=0;
322 while (*((pCd-j)->configname+strlen((pCd-j)->configname)-2)==':'&&(j<=CardTeller)) j++;
323 if (j<=CardTeller)
324 {
325 strncpy(pCd->mode,(pCd-j)->mode,sizeof(pCd->mode));
326 strncpy(pCd->essid,(pCd-j)->essid,sizeof(pCd->essid));
327 strncpy(pCd->channel,(pCd-j)->channel,sizeof(pCd->channel));
328 strncpy(pCd->polar,(pCd-j)->polar,sizeof(pCd->polar));
329 strncpy(pCd->antenna,(pCd-j)->antenna,sizeof(pCd->antenna));
330 strncpy(pCd->gain,(pCd-j)->gain,sizeof(pCd->gain));
331 strncpy(pCd->direction,(pCd-j)->direction,sizeof(pCd->direction));
332 strncpy(pCd->beamwidth,(pCd-j)->beamwidth,sizeof(pCd->beamwidth));
333 strncpy(pCd->cable,(pCd-j)->cable,sizeof(pCd->cable));
334 strncpy(pCd->heigth,(pCd-j)->heigth,sizeof(pCd->heigth));
335 }
336 }
337 }
338 }
339 else /*if (bCardBezig)*/
340 {
341 if (!memicmp(pos,pCd->sprintfname,strlen(pCd->sprintfname)))
342 {
343 VulIpAdressen();
344 CardTeller++;
345 bCardBezig=FALSE;
346 }
347 else if (!memicmp(pos,"TYPE=",5)) strncpy(pCd->type,pos+5,sizeof(pCd->type));
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 }
357 else if (!memicmp(pos,"DESC=",5)) strncpy(pCd->desc,pos+5,sizeof(pCd->desc));
358 else if (!memicmp(pos,"SDESC=",6)) strncpy(pCd->sdesc,pos+6,sizeof(pCd->sdesc));
359 else if (!memicmp(pos,"SPEED=",6)) strncpy(pCd->speed,pos+6,sizeof(pCd->speed));
360 else if (!memicmp(pos,"POINT_TO_POINT=",15)) strncpy(pCd->pointtopoint,pos+15,sizeof(pCd->pointtopoint));
361 else if (!memicmp(pos,"OSPF_BROADCAST=",15)) strncpy(pCd->ospfbroadcast,pos+15,sizeof(pCd->ospfbroadcast));
362 else if (!memicmp(pos,"OSPF_NEIGHBORS=",15)) strncpy(pCd->ospfneighbors,pos+15,sizeof(pCd->ospfneighbors));
363 else if (!memicmp(pos,"DHCP=",5)) strncpy(pCd->dhcp,pos+5,sizeof(pCd->dhcp));
364 else if (!memicmp(pos,"MODE=",5)) strncpy(pCd->mode,pos+5,sizeof(pCd->mode));
365 else if (!memicmp(pos,"ESSID=",6)) strncpy(pCd->essid,pos+6,sizeof(pCd->essid));
366 else if (!memicmp(pos,"CHANNEL=",8)) strncpy(pCd->channel,pos+8,sizeof(pCd->channel));
367 else if (!memicmp(pos,"POLAR=",6)) strncpy(pCd->polar,pos+6,sizeof(pCd->polar));
368 else if (!memicmp(pos,"ANTENNA=",8)) strncpy(pCd->antenna,pos+8,sizeof(pCd->antenna));
369 else if (!memicmp(pos,"GAIN=",5)) strncpy(pCd->gain,pos+5,sizeof(pCd->gain));
370 else if (!memicmp(pos,"DIRECTION=",10)) strncpy(pCd->direction,pos+10,sizeof(pCd->direction));
371 else if (!memicmp(pos,"BEAMWIDTH=",10)) strncpy(pCd->beamwidth,pos+10,sizeof(pCd->beamwidth));
372 else if (!memicmp(pos,"CABLE=",6)) strncpy(pCd->cable,pos+6,sizeof(pCd->cable));
373 else if (!memicmp(pos,"HEIGTH=",7)) strncpy(pCd->heigth,pos+7,sizeof(pCd->heigth));
374 }
375}
376
377void 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
504void 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
540void SwapCards(int i)
541{
542 CARD tempCd=Card[i+1];
543 Card[i+1]=Card[i];
544 Card[i]=tempCd;
545}
546
547void MaakCSV2(int code)
548{
549 int i;
550 CNODE *pCN;
551 CARD *pCd;
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
631void 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)
639 {
640// strcpy(buf,"Volgnr");AddTekst();AddKomma();
641 strcpy(buf,"location");AddTekst();AddKomma();
642 strcpy(buf,"master_ip");AddTekst();AddKomma();
643 strcpy(buf,"gw_open");AddTekst();AddKomma();
644 strcpy(buf,"nodetype");AddTekst();AddKomma();
645 strcpy(buf,"nodename");AddTekst();AddKomma();
646 strcpy(buf,"status");AddTekst();AddKomma();
647 strcpy(buf,"OS");AddTekst();AddKomma();
648 strcpy(buf,"labelpos");AddTekst();AddKomma();
649 strcpy(buf,"X");AddTekst();AddKomma();
650 strcpy(buf,"Y");AddTekst();AddKomma();
651 strcpy(buf,"N");AddTekst();AddKomma();
652 strcpy(buf,"E");AddTekst();AddKomma();
653 strcpy(buf,"ESSID");AddTekst();AddKomma();
654// strcpy(buf,"volgnr");AddTekst();AddKomma();
655 strcpy(buf,"configname");AddTekst();AddKomma();
656 strcpy(buf,"sprintfname");AddTekst();AddKomma();
657 strcpy(buf,"type");AddTekst();AddKomma();
658 strcpy(buf,"ip");AddTekst();AddKomma();
659 strcpy(buf,"desc");AddTekst();AddKomma();
660 strcpy(buf,"sdesc");AddTekst();AddKomma();
661 strcpy(buf,"speed");AddTekst();AddKomma();
662 strcpy(buf,"point_to_point");AddTekst();AddKomma();
663 strcpy(buf,"ospf_broadcast");AddTekst();AddKomma();
664 strcpy(buf,"ospf_neighbors");AddTekst();AddKomma();
665 strcpy(buf,"dhcp");AddTekst();AddKomma();
666 strcpy(buf,"mode");AddTekst();AddKomma();
667 strcpy(buf,"essid");AddTekst();AddKomma();
668 strcpy(buf,"channel");AddTekst();AddKomma();
669 strcpy(buf,"polar");AddTekst();AddKomma();
670 strcpy(buf,"antenna");AddTekst();AddKomma();
671 strcpy(buf,"gain");AddTekst();AddKomma();
672 strcpy(buf,"direction");AddTekst();AddKomma();
673 strcpy(buf,"beamwidth");AddTekst();AddKomma();
674 strcpy(buf,"cable");AddTekst();AddKomma();
675 strcpy(buf,"heigth");AddTekst();AddKomma();
676
677 fwrite( "\n", sizeof( char ), 1, hConf );
678
679 for (i=0;i<CardTeller;i++)
680 {
681 pCd=&Card[i];
682 pCN=&CNode[atoi(pCd->nodenr)];
683// fwrite( pCN->volgnr, sizeof( char ), strlen(pCN->volgnr), hConf );AddKomma();
684 fwrite( pCN->location, sizeof( char ), strlen(pCN->location), hConf );AddKomma();
685 fwrite( pCN->master_ip, sizeof( char ), strlen(pCN->master_ip), hConf );AddKomma();
686 fwrite( pCN->gw_open, sizeof( char ), strlen(pCN->gw_open), hConf );AddKomma();
687 fwrite( pCN->nodetype, sizeof( char ), strlen(pCN->nodetype), hConf );AddKomma();
688 fwrite( pCN->nodename, sizeof( char ), strlen(pCN->nodename), hConf );AddKomma();
689 fwrite( pCN->status, sizeof( char ), strlen(pCN->status), hConf );AddKomma();
690 fwrite( pCN->OS, sizeof( char ), strlen(pCN->OS), hConf );AddKomma();
691 fwrite( pCN->labelpos, sizeof( char ), strlen(pCN->labelpos), hConf );AddKomma();
692 fwrite( pCN->X, sizeof( char ), strlen(pCN->X), hConf );AddKomma();
693 fwrite( pCN->Y, sizeof( char ), strlen(pCN->Y), hConf );AddKomma();
694 fwrite( pCN->N, sizeof( char ), strlen(pCN->N), hConf );AddKomma();
695 fwrite( pCN->E, sizeof( char ), strlen(pCN->E), hConf );AddKomma();
696 fwrite( pCN->ESSID, sizeof( char ), strlen(pCN->ESSID), hConf );AddKomma();
697// fwrite( pCd->volgnr, sizeof( char ), strlen(pCd->volgnr), hConf );AddKomma();
698 fwrite( pCd->configname, sizeof( char ), strlen(pCd->configname), hConf );AddKomma();
699 fwrite( pCd->sprintfname, sizeof( char ), strlen(pCd->sprintfname), hConf );AddKomma();
700 fwrite( pCd->type, sizeof( char ), strlen(pCd->type), hConf );AddKomma();
701 fwrite( pCd->ip, sizeof( char ), strlen(pCd->ip), hConf );AddKomma();
702 fwrite( pCd->desc, sizeof( char ), strlen(pCd->desc), hConf );AddKomma();
703 fwrite( pCd->sdesc, sizeof( char ), strlen(pCd->sdesc), hConf );AddKomma();
704 fwrite( pCd->speed, sizeof( char ), strlen(pCd->speed), hConf );AddKomma();
705 fwrite( pCd->pointtopoint, sizeof( char ), strlen(pCd->pointtopoint), hConf );AddKomma();
706 fwrite( pCd->ospfbroadcast, sizeof( char ), strlen(pCd->ospfbroadcast), hConf );AddKomma();
707 fwrite( pCd->ospfneighbors, sizeof( char ), strlen(pCd->ospfneighbors), hConf );AddKomma();
708 fwrite( pCd->dhcp, sizeof( char ), strlen(pCd->dhcp), hConf );AddKomma();
709 fwrite( pCd->mode, sizeof( char ), strlen(pCd->mode), hConf );AddKomma();
710 fwrite( pCd->essid, sizeof( char ), strlen(pCd->essid), hConf );AddKomma();
711 fwrite( pCd->channel, sizeof( char ), strlen(pCd->channel), hConf );AddKomma();
712 fwrite( pCd->polar, sizeof( char ), strlen(pCd->polar), hConf );AddKomma();
713 fwrite( pCd->antenna, sizeof( char ), strlen(pCd->antenna), hConf );AddKomma();
714 fwrite( pCd->gain, sizeof( char ), strlen(pCd->gain), hConf );AddKomma();
715 fwrite( pCd->direction, sizeof( char ), strlen(pCd->direction), hConf );AddKomma();
716 fwrite( pCd->beamwidth, sizeof( char ), strlen(pCd->beamwidth), hConf );AddKomma();
717 fwrite( pCd->cable, sizeof( char ), strlen(pCd->cable), hConf );AddKomma();
718 fwrite( pCd->heigth, sizeof( char ), strlen(pCd->heigth), hConf );AddKomma();
719 fwrite( "\n", sizeof( char ), 1, hConf );
720 }
721 fclose(hConf);
722 }
723}
724
725void AddKomma(void)
726{
727 fwrite( ",", sizeof( char ), 1, hConf );
728}
729
730void AddTekst(void)
731{
732 fwrite( buf, sizeof( char ), strlen(buf), hConf );
733}
734
735int 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}
Note: See TracBrowser for help on using the repository browser.