Changeset 23 for trunk/src/renetcol.c

Show
Ignore:
Timestamp:
02/05/07 17:50:16 (16 years ago)
Author:
andreu
Message:

optimization : new param : myPtrs in checkdataflowset function

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/renetcol.c

    r22 r23  
    2626#include "renetcol.h" 
    2727 
    28 /* #ifdef CRIHAN */ 
    29 struct IPFLowCache tabIP[MAX_IP_FLOW], *tabIPPtr = tabIP; 
    30 struct MPLSFlowCache tabMPLS[MAX_MPLS_FLOW], *tabMPLSPtr = tabMPLS; 
    31 unsigned long ipNb = 0; /* counter of IP flows number */ 
    32 unsigned long mplsNb = 0; /* counter of MPLS flow number */ 
    33 unsigned long *ipNbPtr = &ipNb; 
    34 unsigned long *mplsNbPtr = &mplsNb; 
    35 unsigned short currentIPOutputFile = 0; /* index on the current IP file */ 
    36 unsigned short currentMPLSOutputFile = 0; /* index on the current MPLS file */ 
     28struct MyPtrs myPtrs; /* defined in dataflowset.h */ 
     29 
     30struct IPFLowCache tabIP[MAX_IP_FLOW]; 
     31struct MPLSFlowCache tabMPLS[MAX_MPLS_FLOW]; 
     32unsigned long ipNb = 0;                     /* counter of IP flows number */ 
     33unsigned long mplsNb = 0;                   /* counter of MPLS flow number */ 
     34 
     35unsigned short currentIPOutputFile = 0;    /* index on the current IP file */ 
     36unsigned short currentMPLSOutputFile = 0;  /* index on the current MPLS file */ 
    3737char outputName[256]; 
    38 char cof_str[20]; /* current ouput file name */ 
    39 FILE *fIP; /* pointer on the IP output file */ 
    40 FILE *fMPLS; /* pointer on the MPLS output file */ 
    41 /* #endif */ 
    42  
    43 char *rulesFileName; /* file name of the rules (like acl) */ 
    44 char *configFileName;  /* file name where routers list is */ 
    45 char *prefixV4FileName;  /* IPv4 prefix list */ 
     38char cof_str[20];                          /* current ouput file name */ 
     39FILE *fIP;                                 /* pointer on the IP output file */ 
     40FILE *fMPLS;                              /* pointer on the MPLS output file */ 
     41 
     42char *rulesFileName;                    /* file name of the rules (like acl) */ 
     43char *configFileName;                   /* file name where routers list is */ 
     44char *prefixV4FileName;                 /* IPv4 prefix list */ 
    4645 
    4746struct sigaction myAction; /* handler for renetcolSender communication */ 
     
    5049/* struct sigaction myAction;  for timer not used in this version */ 
    5150 
    52 unsigned short currentIntervalle = 0; /* based on 5 min intervalles */  
    53  
    54 unsigned short offsetV9 = 0; /* index in a neflow v9 packet */ 
    55 unsigned short *offsetV9Ptr = &offsetV9; 
     51unsigned short currentIntervalle = 0;        /* based on 5 min intervalles */  
     52 
     53unsigned short offsetV9 = 0;                 /* index in a neflow v9 packet */ 
    5654 
    5755unsigned char buffer1; 
     
    6159 
    6260short currentFlowsetNumber; 
    63 short *currentFlowsetNumberPtr = &currentFlowsetNumber; 
    6461short currentFlowsetId; 
    65 short *currentFlowsetIdPtr = &currentFlowsetId; 
    6662TplFlowSetPtr curTplFlSetPtr; /* current template flowset pointer */ 
    6763TplOptionPtr curTplOptionPtr; 
    68 RouterPtr routersListPtr; 
    69 RouterPtr currentRouterPtr; 
    70 DatagramPtr pcktPtr; 
     64RouterPtr routersListPtr;  
     65 
    7166unsigned long sortedRouterList[ROUTER_INDEX_MAX]; 
    7267unsigned long indexedRouterList[ROUTER_INDEX_MAX]; 
    73 int routerNb = 0; /* routers number */ 
    74 unsigned short v4PrefixNb = 0; /* IPv4 prefix number */ 
    75 struct PrefixV4 prefixV4Tab[MAX_IPV4_PREFIX]; /* IPv4 prefix structure */ 
    76 RulesPtr rulesListPtr; /* Rules list */ 
    77 NetFlowV9HeaderPtr currentHeaderV9Ptr; 
     68int routerNb = 0;                                  /* routers number */ 
     69unsigned short v4PrefixNb = 0;                     /* IPv4 prefix number */ 
     70struct PrefixV4 prefixV4Tab[2][MAX_IPV4_PREFIX];      /* IPv4 prefix structure */ 
     71unsigned short indexForShmTable = 0; 
     72 
    7873key_t myKey = 0; /* FIXME to delete in futur */ 
    7974int myQueue = 0; /* FIXME to delete in futur */ 
     
    8176/* Next structure used as cache in rules reading */ 
    8277RuleDefPtr rulesAddress[FIELD_TYPE_NUMBER+1][MAX_RULES_PER_FIELD];  
    83 RuleDefPtr *rulesAddressPtr; 
    8478 
    8579int reInitConf = 0; 
    86  
    87 static unsigned long datagramNumber; 
    8880 
    8981static time_t lastRock; 
    9082static struct tm *tmPtr; 
    9183 
    92 static unsigned long myHost; /* FIXME to erase */ 
    9384extern int errno; 
    9485static int inputSock; 
     
    10091/* static unsigned short flowNumber; */ 
    10192static unsigned short receptPort = RECEPTION_PORT; 
    102 static unsigned char *ptr_buffer; 
     93/* static unsigned char *ptr_buffer; */ 
    10394static char *receptAddress = RECEPTION_ADDRESS; 
    10495static struct sockaddr_in name; 
     
    139130 
    140131  initCache(); 
    141   fprintf(stderr, "reading the routers list\n"); 
     132  fprintf(stderr, "renetcol: reading the routers list...\n"); 
    142133  routerNb = getRegisteredRouters(configFileName, &sortedRouterList[0],  
    143134                                  &indexedRouterList[0]); 
    144   fprintf(stderr, "reading the IPv4 prefix\n"); 
     135  fprintf(stderr, "renetcol: OK\n"); 
     136  fprintf(stderr, "renetcol: reading the IPv4 prefix...\n"); 
    145137  if ( (v4PrefixNb = getPrefixV4(prefixV4FileName, &prefixV4Tab[0])) < 1){ 
    146     fprintf(stderr, "Error during prefix v4 reading\n"); 
     138    fprintf(stderr, "renetcol:  Error \n"); 
    147139    exit(1); 
    148   } 
    149   rulesListPtr = NULL; 
    150   fprintf(stderr, "reading the rules\n"); 
    151   rulesListPtr = getLightRules(rulesListPtr, rulesFileName); 
    152   tmp = rulesListPtr; 
     140  } else { 
     141    fprintf(stderr, "renetcol:  OK \n"); 
     142  } 
     143  myPtrs.rulesListPtr = NULL; 
     144  fprintf(stderr, "renetcol: reading the rules...\n"); 
     145  myPtrs.rulesListPtr = getLightRules(myPtrs.rulesListPtr, rulesFileName); 
     146  fprintf(stderr, "renetcol : OK \n"); 
     147  tmp = myPtrs.rulesListPtr; 
    153148  for ( ; tmp->next; tmp=tmp->next) { 
    154149    if (tmp->type != 2) { 
    155       rulesListPtr = delRule(tmp, rulesListPtr); 
     150      myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr); 
    156151    } 
    157152  } 
     
    159154/*   exit(1); */ 
    160155 
    161   fprintf(stderr, "I become a deamon, next messages via syslogd.\n"); 
     156  fprintf(stderr, "renetcol: I become a deamon, next messages via syslogd. By.\n"); 
    162157  if (fork () != 0) 
    163158    exit (0); 
     
    174169 
    175170  /* Pointer on rules Table */ 
    176   setCache(rulesListPtr); 
    177   rulesAddressPtr = (RuleDefPtr *)rulesAddress; 
     171  setCache(myPtrs.rulesListPtr); 
     172  myPtrs.rulesAddressPtr = (RuleDefPtr *)rulesAddress; 
    178173 
    179174  /* init IPC messages queue */ 
     
    183178 
    184179  /* INIT THE CURRENTS VARIABLES*/ 
    185   currentRouterPtr = routersListPtr; 
    186   currentHeaderV9Ptr = (NetFlowV9HeaderPtr) 
     180  myPtrs.currentRouterPtr = routersListPtr; 
     181  myPtrs.currentHeaderV9Ptr = (NetFlowV9HeaderPtr) 
    187182    malloc(sizeof(struct NetFlowV9Header)); 
    188   pcktPtr = (DatagramPtr) malloc(sizeof(struct Datagram)); 
    189   if (pcktPtr==NULL) { 
     183  myPtrs.offsetV9Ptr = &offsetV9; 
     184  myPtrs.currentFlowsetIdPtr = &currentFlowsetId; 
     185  myPtrs.pcktPtr = (DatagramPtr) malloc(sizeof(struct Datagram)); 
     186  myPtrs.currentFlowsetNumberPtr = &currentFlowsetNumber; 
     187  myPtrs.ipNbPtr =  &ipNb; 
     188  myPtrs.mplsNbPtr =  &mplsNb; 
     189   
     190  if (myPtrs.pcktPtr==NULL) { 
    190191    fprintf(stderr, "ERROR in struct Datagram allocation\n"); 
    191192    exit(1); 
    192193  } else { 
    193     pcktPtr->ipH = (IpHeaderPtr) malloc(sizeof(struct IpHeader)); 
    194     pcktPtr->udp_header = (UdpHeaderPtr) malloc(sizeof(struct UdpHeader)); 
    195   } 
    196  
    197   if (! (ptr_buffer = malloc(sockBufSize)))   
     194    myPtrs.pcktPtr->ipH = (IpHeaderPtr) malloc(sizeof(struct IpHeader)); 
     195    myPtrs.pcktPtr->udp_header = (UdpHeaderPtr) malloc(sizeof(struct UdpHeader)); 
     196  } 
     197 
     198  if (! (myPtrs.ptr_buffer = malloc(sockBufSize)))   
    198199    { 
    199200      printf("ERROR during socket buffer allocation\n"); 
     
    204205  initStream(); 
    205206 
    206   datagramNumber =0; /* FIXME : ???? */ 
    207  
    208207  socketLoop(); /* all work on datagram is made here */ 
     208 
    209209  closelog(); 
     210 
    210211  fprintf(stderr, "END\n"); 
     212 
    211213  return (0); 
    212214} 
    213215 
    214216/* 
    215  * 
    216  */ 
    217 void sendMyPid(int queueID) 
     217 * send his PID to another program via IPC message queue 
     218 * 
     219 * @param queueID the IPC queue ident 
     220 * 
     221 */ 
     222void  
     223sendMyPid(int queueID) 
    218224{ 
    219225  msgType myMsg; 
     
    235241 
    236242/* 
     243 * Send the "read rules list" message to another program 
     244 * 
     245 * @param queueID the IPC queue ident 
    237246 * 
    238247 */ 
     
    252261 
    253262/* 
    254  * 
    255  */ 
    256 void sigusr1Mgmt(int num) 
     263 *  
     264 */ 
     265void  
     266sigusr1Mgmt(int num) 
    257267{ 
    258268  sigusr1Up = 1; 
     
    260270 
    261271/* 
    262  * 
     272 * init the rule structure 
    263273 */ 
    264274void  
     
    267277  RulesPtr tmp = NULL; 
    268278  initCache(); 
    269   tmp = rulesListPtr; 
     279  tmp = myPtrs.rulesListPtr; 
    270280  for ( ; tmp; tmp=tmp->next) { 
    271     rulesListPtr = delRule(tmp, rulesListPtr); 
    272   } 
    273   rulesListPtr = NULL; 
    274   rulesListPtr = getLightRules(rulesListPtr, rulesFileName); 
    275   tmp = rulesListPtr; 
     281    myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr); 
     282  } 
     283  myPtrs.rulesListPtr = NULL; 
     284  myPtrs.rulesListPtr = getLightRules(myPtrs.rulesListPtr, rulesFileName); 
     285  tmp = myPtrs.rulesListPtr; 
    276286  for ( ; tmp; tmp=tmp->next) { 
    277287    if (tmp->type != 2) { 
    278       rulesListPtr = delRule(tmp, rulesListPtr); 
     288      myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr); 
    279289    } 
    280290  } 
    281291  tmp = NULL; 
    282292  initCache(); 
    283   setCache(rulesListPtr); 
     293  setCache(myPtrs.rulesListPtr); 
    284294  sendReadRulesSignal(myQueue); 
    285295} 
    286296 
    287297/* 
    288  * 
     298 * init cache table 
    289299 */ 
    290300void 
     
    339349  buffer4[2] = (unsigned char)n1; 
    340350  buffer4[3] = (unsigned char)n0; 
    341   myHost = *((unsigned long*)&buffer4[0]); 
    342351} 
    343352 
     
    353362  time_t now = time((time_t *)NULL); 
    354363  int iIP, iMPLS, i; 
     364  int loopNb = 0; 
    355365  time_t lastIPOutput, lastMPLSOutput; 
    356366  time_t receptionTime; 
     
    371381    }  
    372382    socketReading(); 
    373     getIpHeader(pcktPtr, ptr_buffer); 
    374     regRouter = checkIpHeader(pcktPtr, &sortedRouterList[0], routerNb); 
    375     getUdpHeader(pcktPtr, ptr_buffer); 
    376     checkUdpHeader(pcktPtr, regRouter, receptPort); 
     383    getIpHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer); 
     384    regRouter = checkIpHeader(myPtrs.pcktPtr, &sortedRouterList[0], routerNb); 
     385    getUdpHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer); 
     386    if ( checkUdpHeader(myPtrs.pcktPtr, regRouter, receptPort) == 1 ){ 
     387      continue; 
     388    } 
    377389     
    378390    switch( version =  
    379             getNetFlowHeader(pcktPtr, ptr_buffer,  
    380                              currentHeaderV9Ptr, offsetV9Ptr)){ 
     391            getNetFlowHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer,  
     392                             myPtrs.currentHeaderV9Ptr, myPtrs.offsetV9Ptr)){ 
    381393    case 9: 
    382       if ((currentRouterPtr=notExistRouter(routersListPtr,  
    383                                            pcktPtr->ipH->srcAdd))==NULL) { 
     394      if ((myPtrs.currentRouterPtr=notExistRouter(routersListPtr,  
     395                                                  myPtrs.pcktPtr->ipH->srcAdd))==NULL) { 
    384396        routersListPtr = addRouter(routersListPtr,  
    385                                    pcktPtr->ipH->srcAdd,  
     397                                   myPtrs.pcktPtr->ipH->srcAdd,  
    386398                                   (unsigned long) 0); 
    387         currentRouterPtr = routersListPtr; 
     399        myPtrs.currentRouterPtr = routersListPtr; 
    388400      } 
    389401      currentFlowsetNumber = 0; 
    390402      shift = 0; 
    391       while ((currentFlowsetNumber < currentHeaderV9Ptr->count)) { 
     403      while ((currentFlowsetNumber < myPtrs.currentHeaderV9Ptr->count)) { 
    392404        curTplFlSetPtr = NULL; 
    393405        currentFlowsetId=getFlowsetId(currentFlowsetNumber,  
    394                                       offsetV9Ptr, ptr_buffer); 
     406                                      myPtrs.offsetV9Ptr, myPtrs.ptr_buffer); 
    395407        if ( currentFlowsetId == 0 ) { 
    396           shift = checkTemplateFlowSet(currentRouterPtr, offsetV9Ptr,  
    397                                        ptr_buffer, currentHeaderV9Ptr, 
     408          shift = checkTemplateFlowSet(myPtrs.currentRouterPtr, myPtrs.offsetV9Ptr,  
     409                                       myPtrs.ptr_buffer, myPtrs.currentHeaderV9Ptr, 
    398410                                       curTplFlSetPtr, 
    399                                        currentFlowsetNumberPtr, 
     411                                       myPtrs.currentFlowsetNumberPtr, 
    400412                                       myQueue); 
    401           /* FIXME : TplFlSet Def in a file before next release */ 
    402           /* showAllTplFlSet(); */ 
    403413        } else if (currentFlowsetId == 1) { 
    404           shift = checkTemplateOption(currentRouterPtr, offsetV9Ptr,  
    405                                       ptr_buffer, currentHeaderV9Ptr, 
     414          shift = checkTemplateOption(myPtrs.currentRouterPtr, myPtrs.offsetV9Ptr,  
     415                                      myPtrs.ptr_buffer, myPtrs.currentHeaderV9Ptr, 
    406416                                      curTplOptionPtr, 
    407                                       currentFlowsetNumberPtr); 
     417                                      myPtrs.currentFlowsetNumberPtr); 
    408418        } else { 
    409           shift = checkDataFlowSet(shift, currentRouterPtr, 
    410                                    currentHeaderV9Ptr, offsetV9Ptr, 
    411                                    ptr_buffer, currentFlowsetNumberPtr, 
    412                                    currentFlowsetIdPtr, pcktPtr, 
    413                                    rulesAddressPtr, rulesListPtr, 
    414                                    myQueue, prefixV4Tab, 
    415                                    (size_t) v4PrefixNb, 
    416                                    tabIPPtr,  
    417                                    tabMPLSPtr,  
    418                                    ipNbPtr, mplsNbPtr); 
     419          shift = checkDataFlowSet(shift, 
     420                                   &myPtrs, 
     421                                   myQueue,  
     422                                   prefixV4Tab, 
     423                                   (size_t) v4PrefixNb 
     424                                   ); 
    419425        } 
    420       } 
     426      } /* end while flowset exist */ 
    421427      break; 
    422428    default: 
    423       /* FIXME : Uncomment before next release */ 
    424 /*        syslog(LOG_INFO,  */ 
    425 /*           "NetFlow exp. version unknown: %hu, from router: %lu.%lu.%lu.%lu", */ 
    426 /*           (unsigned short) version, */ 
    427 /*           (pcktPtr->ipH->srcAdd>>24), */ 
    428 /*           (pcktPtr->ipH->srcAdd<<8>>24), */ 
    429 /*           (pcktPtr->ipH->srcAdd<<16>>24), */ 
    430 /*           (pcktPtr->ipH->srcAdd<<24>>24));  */ 
     429      syslog(LOG_INFO,  
     430             "NetFlow exp. version unknown: %hu, from router: %lu.%lu.%lu.%lu", 
     431             (unsigned short) version, 
     432             (myPtrs.pcktPtr->ipH->srcAdd>>24), 
     433             (myPtrs.pcktPtr->ipH->srcAdd<<8>>24), 
     434             (myPtrs.pcktPtr->ipH->srcAdd<<16>>24), 
     435             (myPtrs.pcktPtr->ipH->srcAdd<<24>>24));  
    431436      break; 
    432437    } 
    433 /*     for (i=0; i<v4PrefixNb; i++){ */ 
    434 /*       fprintf(stderr, "%lu %llu flows\n", */ 
    435 /*            prefixV4Tab[i].beginning, */ 
    436 /*            prefixV4Tab[i].flowNb); */ 
    437 /*     } */ 
     438    if (loopNb  > 100 ){ 
     439      /* FIXME perhaps call this function via the compilation options */ 
     440      writeAllTplFlSet(); 
     441      for (i=0; i<v4PrefixNb; i++){ 
     442        fprintf(stderr, "%lu \n %llu flows,\t %llu bytes,\t %llu pkts\n Pkts (udp tcp icmp others): %llu \t %llu \t %llu \t %llu\n Bytes (udp tcp icmp others): %llu \t %llu \t %llu \t %llu\n Flows (udp tcp icmp others): %llu \t %llu \t %llu \t %llu\n \n %llu flows,\t %llu bytes,\t %llu pkts\n Pkts (udp tcp icmp others): %llu \t %llu \t %llu \t %llu\n Bytes (udp tcp icmp others): %llu \t %llu \t %llu \t %llu\n Flows (udp tcp icmp others): %llu \t %llu \t %llu \t %llu\n \n", 
     443                prefixV4Tab[i].beginning, 
     444                prefixV4Tab[i].flowNbIN, 
     445                prefixV4Tab[i].bytesNbIN, 
     446                prefixV4Tab[i].pktsNbIN, 
     447                prefixV4Tab[i].udpPktsNbIN, 
     448                prefixV4Tab[i].tcpPktsNbIN, 
     449                prefixV4Tab[i].icmpPktsNbIN, 
     450                prefixV4Tab[i].othersPktsNbIN, 
     451                prefixV4Tab[i].udpBytesNbIN, 
     452                prefixV4Tab[i].tcpBytesNbIN, 
     453                prefixV4Tab[i].icmpBytesNbIN, 
     454                prefixV4Tab[i].othersBytesNbIN, 
     455                prefixV4Tab[i].udpFlowNbIN, 
     456                prefixV4Tab[i].tcpFlowNbIN, 
     457                prefixV4Tab[i].icmpFlowNbIN, 
     458                prefixV4Tab[i].othersFlowNbIN, 
     459                prefixV4Tab[i].flowNbOUT, 
     460                prefixV4Tab[i].bytesNbOUT, 
     461                prefixV4Tab[i].pktsNbOUT, 
     462                prefixV4Tab[i].udpPktsNbOUT, 
     463                prefixV4Tab[i].tcpPktsNbOUT, 
     464                prefixV4Tab[i].icmpPktsNbOUT, 
     465                prefixV4Tab[i].othersPktsNbOUT, 
     466                prefixV4Tab[i].udpBytesNbOUT, 
     467                prefixV4Tab[i].tcpBytesNbOUT, 
     468                prefixV4Tab[i].icmpBytesNbOUT, 
     469                prefixV4Tab[i].othersBytesNbOUT, 
     470                prefixV4Tab[i].udpFlowNbOUT, 
     471                prefixV4Tab[i].tcpFlowNbOUT, 
     472                prefixV4Tab[i].icmpFlowNbOUT, 
     473                prefixV4Tab[i].othersFlowNbOUT 
     474                ); 
     475      } 
     476      loopNb = 0; 
     477    } 
     478    loopNb++; 
    438479 
    439480#ifdef CRIHAN 
     
    558599    } 
    559600  /* Here socket DGRAM creation, only to not have a unreachable service */ 
     601  /* message in return */ 
    560602  inputSock2 = socket(AF_INET, SOCK_DGRAM, 0);  
    561603  if (inputSock2 < 0) 
     
    597639 
    598640  sockNameFromlg = sizeof(fromName); 
    599   rcv = recvfrom(inputSock, ptr_buffer, sockBufSize, 0, 
     641  rcv = recvfrom(inputSock, myPtrs.ptr_buffer, sockBufSize, 0, 
    600642                 (struct sockaddr *)(&fromName), 
    601643                 (socklen_t *)&sockNameFromlg);    
     
    613655  
    614656/*  
    615  * check up flow datagramme  
     657 * check up flow datagramme   
    616658 */ 
    617659short  
    618660checkFlow(short flowNumber) 
    619661{ 
    620   return(0); 
     662  return(0); /* FIXME : why this function ??? */ 
    621663} 
    622664 
     
    624666 * showAllTplFlSet 
    625667 * 
     668 * to use only in debug mode 
    626669 */ 
    627670void  
     
    643686              tmpFS->templateFlowSetId, 
    644687              tmpFS->sourceId); 
    645       printFieldSet(tmpFS->fieldSet); 
     688      printFieldSet(stderr, tmpFS->fieldSet); 
    646689      fprintf(stderr,"\n"); 
    647690    } 
     
    651694                tmpOP->templateOptionId, 
    652695                tmpOP->sourceId); 
    653         printFieldSet(tmpOP->fieldSet); 
     696        printFieldSet(stderr, tmpOP->fieldSet); 
    654697        fprintf(stderr,"\n"); 
    655698      } 
     
    658701  } 
    659702} 
     703 
     704 
     705/*  
     706 * writeAllTplFlSet 
     707 * 
     708 */ 
     709void  
     710writeAllTplFlSet() 
     711{ 
     712 
     713  RouterPtr tmp = routersListPtr; 
     714  TplFlowSetPtr tmpFS; 
     715  TplOptionPtr tmpOP; 
     716  FILE *TPLFILE; 
     717  if (!(TPLFILE = fopen("/tmp/TemplateDef.txt", "w"))) { 
     718    syslog (LOG_ERR, "error during %s opening", "/tmp/TemplateDef.txt"); 
     719  } 
     720  fprintf(TPLFILE,"\n*********************************************\n* All template definitions: (field, size) : *\n*********************************************\n"); 
     721  for (; tmp; tmp=tmp->next) { 
     722    fprintf(TPLFILE,"----------------------\nrouter %lu.%lu.%lu.%lu : \n----------------------\n", 
     723            (tmp->IpAddress>>24), 
     724            (tmp->IpAddress<<8>>24), 
     725            (tmp->IpAddress<<16>>24), 
     726            (tmp->IpAddress<<24>>24)); 
     727    tmpFS =  tmp->tplList; 
     728    for (; tmpFS; tmpFS=tmpFS->next) { 
     729      fprintf(TPLFILE,"TId %hu (sourceId: %lu):\n",  
     730              tmpFS->templateFlowSetId, 
     731              tmpFS->sourceId); 
     732      printFieldSet(TPLFILE, tmpFS->fieldSet); 
     733      fprintf(TPLFILE,"\n"); 
     734    } 
     735    if ((tmpOP = tmp->tplOptList) != NULL){ 
     736      for (; tmpOP; tmpOP=tmpOP->next) { 
     737        fprintf(TPLFILE,"OpTId %hu (sourceId: %lu) >\n",  
     738                tmpOP->templateOptionId, 
     739                tmpOP->sourceId); 
     740        printFieldSet(TPLFILE, tmpOP->fieldSet); 
     741        fprintf(TPLFILE,"\n"); 
     742      } 
     743      fprintf(TPLFILE,"\n"); 
     744    } 
     745  } 
     746  fclose(TPLFILE); 
     747}