Changeset 13 for trunk/src/rules_mgmt.c

Show
Ignore:
Timestamp:
02/14/06 17:58:08 (17 years ago)
Author:
andreu
Message:

prefix bug fixed in rules_mgmt.c

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/rules_mgmt.c

    r10 r13  
    3535    fprintf(stderr, "  operator: %hu\n", rdPtr->operator); 
    3636    if (rdPtr->value!=NULL) { 
     37      fprintf(stderr, "  mask: %hu\n", rdPtr->value->mask); 
    3738      switch (rdPtr->value->valueLength){ 
    3839      case 1: 
     
    292293    if ( strspn(line, "#") == 0 ) { 
    293294      strcpy(lineCopy, line); 
    294       fprintf(stderr,"ligne en cours : %d\n", cptLine); 
    295295      if (strncmp("N", lineCopy, 1) == 0){ 
    296296        if (sscanf(line, "%1s %s\n", 
     
    353353      } 
    354354      cptLine++; 
    355       fprintf(stderr,"ligne : %d\n", cptLine); 
    356355    } 
    357356  } 
     
    498497  unsigned short v0, v1, v2, v3; 
    499498  unsigned char buffer4[4]; 
    500 /*   static unsigned short mask; */ 
     499  static char *token; 
     500  static char mask[4]; 
     501  int lg = 0; 
     502  int lgMask = 0; 
     503  static char value[16]; 
    501504  tmp = (ValuesPtr) malloc(sizeof(struct Values)); 
    502505  if (tmp==NULL) { 
     
    504507    exit(1); 
    505508  } else { 
    506     if (sscanf(val, "%hu.%hu.%hu.%hu", &v0, &v1, &v2, &v3) == 0) { 
    507       syslog(LOG_ERR, "Errors in Tests definition : wrong IPv4 value"); 
    508       exit(1); 
    509     } 
    510     buffer4[3] = (unsigned char)v0; 
    511     buffer4[2] = (unsigned char)v1; 
    512     buffer4[1] = (unsigned char)v2; 
    513     buffer4[0] = (unsigned char)v3;      
    514     tmp->valueLength = 4; 
    515     tmp->stor.lvalue = *((unsigned long*)(&buffer4)); 
    516     tmp->mask = 32; 
    517     tmp->next = vPtr; 
     509    if ( (token=memccpy(value, val, '/', strlen(val)))==NULL) { 
     510      /* address case */ 
     511      if (sscanf(value, "%hu.%hu.%hu.%hu", &v0, &v1, &v2, &v3) == 0) { 
     512        syslog(LOG_ERR, "Errors in Tests definition : wrong IPv4 value"); 
     513        exit(1); 
     514      } 
     515      buffer4[3] = (unsigned char)v0; 
     516      buffer4[2] = (unsigned char)v1; 
     517      buffer4[1] = (unsigned char)v2; 
     518      buffer4[0] = (unsigned char)v3;    
     519      tmp->valueLength = 4; 
     520      tmp->mask = 32; 
     521      tmp->stor.lvalue = *((unsigned long*)(&buffer4)); 
     522      tmp->mask = 32; 
     523      tmp->next = vPtr; 
     524    } else { 
     525      lg = strlen(value); 
     526      lgMask = strlen(token); 
     527      value[lg-1-lgMask] = '\0'; 
     528      strcpy( mask, strchr(val,'/')+1); 
     529      if (sscanf(value, "%hu.%hu.%hu.%hu", &v0, &v1, &v2, &v3) == 0) { 
     530        syslog(LOG_ERR, "Errors in Tests definition : wrong IPv4 value"); 
     531        exit(1); 
     532      } 
     533      buffer4[3] = (unsigned char)v0; 
     534      buffer4[2] = (unsigned char)v1; 
     535      buffer4[1] = (unsigned char)v2; 
     536      buffer4[0] = (unsigned char)v3;    
     537      tmp->valueLength = 4; 
     538      tmp->mask = atoi(mask); 
     539      tmp->stor.lvalue = *((unsigned long*)(&buffer4)); 
     540      tmp->next = vPtr;       
     541    } 
    518542  } 
    519543  return tmp; 
     
    539563    if ( (token=memccpy(value, val, '/', strlen(val)))==NULL) { 
    540564      /* address case */ 
    541       fprintf(stderr,"address case\n"); 
    542565      result = inet_pton(AF_INET6, val, netw_form); 
    543566      switch(result) { 
     
    560583      tmp->next = vPtr; 
    561584    } else { 
    562       fprintf(stderr,"prefix case\n"); 
    563585      lg = strlen(value); 
    564586      lgMask = strlen(token); 
    565587      value[lg-1-lgMask] = '\0'; 
    566588      strcpy( mask, strchr(val,'/')+1); 
    567       fprintf(stderr,"apres strcpy: %s et %d\n", value, atoi(mask)); 
    568589      result = inet_pton(AF_INET6, value, netw_form); 
    569590      switch(result) { 
     
    579600      memcpy(&v6addr, netw_form, sizeof(netw_form)); 
    580601      tmp->valueLength = 16; 
    581       fprintf(stderr,"ici\n"); 
    582602      tmp->mask = atoi(mask); 
    583       fprintf(stderr,"la %hu\n",  tmp->mask); 
    584603      tmp->stor.tabAdd6[0] = v6addr.s6_addr32[0]; 
    585604      tmp->stor.tabAdd6[1] = v6addr.s6_addr32[1]; 
     
    587606      tmp->stor.tabAdd6[3] = v6addr.s6_addr32[3]; 
    588607      tmp->next = vPtr; 
    589       fprintf(stderr,"plus la\n"); 
    590608    } 
    591609  }