Changeset 118

Show
Ignore:
Timestamp:
10.12.2005 19:05:36 (3 years ago)
Author:
tibob
Message:
  • Added bps output (Closes #5)
  • Fixed a bug in [117] (xfree(stringTime) to early)
Location:
trunk/source
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • trunk/source/config.h.in

    r117 r118  
    2020#define DEFAULT_OPTIONS_TIMEZONE      local 
    2121#define DEFAULT_OPTIONS_TIMESTAMP     right_dump 
     22#define DEFAULT_OPTIONS_DIVIDE        1 
     23#define DEFAULT_OPTIONS_BPS           0 
    2224 
    2325/* But leave these defines untouched */ 
  • trunk/source/config.l

    r117 r118  
    8888[Rr]ight                         return RIGHT; 
    8989[Ll]eft                          return LEFT; 
     90[Oo]utput                        return OUTPUT; 
     91bps                              return BPS; 
     92[Bb]yte[s]                       return BYTES; 
     93[Dd]ivide                        return DIVIDE; 
     94by                               return BY; 
    9095 
    9196[Pp][Rr][Oo][Mm][Ii][Ss][Cc]         { yylval.longval = 1; return PROMISC; } 
  • trunk/source/config.y

    r117 r118  
    108108%token RIGHT 
    109109%token LEFT 
     110%token DIVIDE BY OUTPUT BYTES BPS 
    110111 
    111112%token<SortFunc>  SORTFUNC 
     
    126127%type<longval>   Not 
    127128%type<stringval> Device 
     129%type<longval>   Divide 
    128130 
    129131%start Input 
     
    255257          pNewLog->ReverseLookup = DEFAULT_OPTIONS_REVERSELOOKUP; 
    256258          pNewLog->Append = DEFAULT_OPTIONS_APPEND; 
    257    
     259          pNewLog->Divide = DEFAULT_OPTIONS_DIVIDE; 
     260          pNewLog->bps = DEFAULT_OPTIONS_BPS; 
     261 
    258262          checkdump = 2; 
    259263          pAllLogs = pNewLog; 
     
    266270        } 
    267271      | TimeStamp EOL 
     272      | Output EOL 
    268273      | error EOL { 
    269274          parseerror("Skipping invalid line", line); 
     
    411416      ; 
    412417 
     418Output: 
     419        OUTPUT BPS Divide { 
     420          pAllLogs->Divide = $3; 
     421          pAllLogs->bps = 1; 
     422        } 
     423      | OUTPUT BYTES Divide { 
     424          pAllLogs->Divide = $3; 
     425          pAllLogs->bps = 0; 
     426        } 
     427      ; 
     428 
     429Divide: 
     430        /* nothing */ { 
     431          $$ = 1; 
     432        } 
     433      | DIVIDE BY NUMBER { 
     434          $$ = $3; 
     435        } 
    413436%% 
    414437 
  • trunk/source/data.c

    r117 r118  
    139139    char *stringTime, *DumpTime, *ClearTime=NULL, *PrevClear=NULL, *PrevDump, *stringAction; 
    140140    char *timezonestring; 
    141  
     141    time_t now; 
     142    int DivideFactor=1, MultiplyFactor=1; 
     143 
     144    now = time(NULL); 
    142145    if (tz == local) { 
    143146      timezonestring = "local time"; 
     
    179182    } 
    180183 
    181     stringTime = timefile("%Y/%m/%d %H:%M:%S", time(NULL)); 
     184    stringTime = timefile("%Y/%m/%d %H:%M:%S", now); 
    182185 
    183186    DumpTime = timefile("%Y/%m/%d %H:%M:%S", pLog->NextDump); 
     
    191194    fprintf(logfile, "# ipfm %s %s at %s (%s)\n", 
    192195            VERSION, stringAction, stringTime, timezonestring); 
    193     fprintf(logfile, "# Listening on %s\n", device); 
     196    fprintf(logfile, "# Listening on %s, dumping in %s divided by %i\n", 
     197            device, pLog->bps?"bps":"bytes", pLog->Divide); 
    194198    fprintf(logfile, "# Dump period :  %s -- %s\n", 
    195199            PrevDump, DumpTime); 
     
    203207      xfree(PrevClear); 
    204208    } 
    205  
    206209    xfree(DumpTime); 
    207210    xfree(PrevDump); 
     
    209212 
    210213    fprintf(logfile, "# %-33s%15s%15s%15s\n", 
    211             "Host", 
    212             "In (bytes)", 
    213             "Out (bytes)", 
    214             "Total (bytes)"); 
    215      
     214            "Host", "In", "Out",  "Total"); 
     215 
     216    DivideFactor *= pLog->Divide; 
     217    if (1 == pLog->bps) { 
     218      MultiplyFactor *= 8; 
     219      if (now < pLog->NextDump) { 
     220        DivideFactor *= ( now - pLog->PrevClear); 
     221      } else { 
     222        DivideFactor *= (pLog->NextDump - pLog->PrevClear); 
     223      } 
     224    } 
     225 
    216226    while (NULL != pLog->Data) { 
    217       DataFormat(pLog, pLog->Data, DataToFile, MAX_DATA_SIZE); 
     227      DataFormat(pLog, pLog->Data, DataToFile, MAX_DATA_SIZE, 
     228                 DivideFactor, MultiplyFactor); 
    218229      fprintf(logfile, "%s", DataToFile); 
    219230      /* Do not forget to free tables */ 
     
    228239    pLog->DataSize = 0; 
    229240 
     241    stringTime = timefile("%Y/%m/%d %H:%M:%S", time(NULL)); 
    230242    fprintf(logfile, "# end of dump %s\n", stringTime); 
     243    xfree(stringTime); 
     244 
    231245    if (1 == pLog->Append) { 
    232246      fprintf(logfile, "\n"); 
     
    333347 
    334348void DataFormat(struct AllLogsType *pLog, struct ipfm_data *pData, 
    335                 char *pFormatedData, int BufLen) { 
     349                char *pFormatedData, int BufLen, 
     350                int DivideFactor, int MultiplyFactor) { 
    336351  struct in_addr addr; 
    337352  int NotLookedUp = 0; 
     
    345360    if ((NULL != he) && (strlen(he->h_name) <= 34) && 
    346361        (strlen(he->h_name) > 0)) { 
     362      /* LONGINTFORMAT should be changed to something that prints decimals... */ 
    347363      snprintf(pFormatedData, BufLen, "%-35s%15" LONGINTFORMAT "%15" LONGINTFORMAT "%15" LONGINTFORMAT "\n", 
    348364               he->h_name, 
    349                pData->in,  
    350                pData->out,  
    351                pData->in + pData->out); 
     365               pData->in * MultiplyFactor / DivideFactor, 
     366               pData->out * MultiplyFactor / DivideFactor, 
     367               (pData->in + pData->out) * MultiplyFactor / DivideFactor); 
    352368    } else { 
    353369      NotLookedUp = 1; 
     
    357373    char *res; 
    358374    res = inet_ntoa(addr); 
    359       snprintf(pFormatedData, BufLen, "%-35s%15" LONGINTFORMAT "%15" LONGINTFORMAT "%15" LONGINTFORMAT "\n", 
    360              res, 
    361              pData->in,  
    362              pData->out,  
    363              pData->in + pData->out); 
    364   } 
    365 } 
     375    snprintf(pFormatedData, BufLen, "%-35s%15" LONGINTFORMAT "%15" LONGINTFORMAT "%15" LONGINTFORMAT "\n", 
     376             res, 
     377             pData->in * MultiplyFactor / DivideFactor, 
     378             pData->out * MultiplyFactor / DivideFactor, 
     379             (pData->in + pData->out) * MultiplyFactor / DivideFactor); 
     380  } 
     381} 
  • trunk/source/data.h

    r63 r118  
    4949int DataCompareTotal(const void *ptr1, const void *ptr2); 
    5050void DataFormat(struct AllLogsType *pLog, struct ipfm_data *pData, 
    51                 char *pFormatedData, int BufLen); 
     51                char *pFormatedData, int BufLen, 
     52                int DivideFactor, int MultiplyFactor); 
    5253 
    5354#endif 
  • trunk/source/filter.c

    r63 r118  
    11/* 
    22 *  filter.c - Filtering mechanism 
    3  *   
     3 * 
    44 *  (c) 1999-2001 Robert Cheramy <tibob@via.ecp.fr> 
    55 *  (c) 1999      Andres Krapf <dae@via.ecp.fr> 
  • trunk/source/filter.h

    r117 r118  
    7070  int ReverseLookup; 
    7171  int Append; 
    72    
     72 
    7373  /* right or left Timestamp selector */ 
    7474  enum enumTimeStampType TimeStampType; 
     
    8888  unsigned long int ClearInterval; 
    8989 
     90  /* Output format */ 
     91  /* divide bytes by this number */ 
     92  int Divide; 
     93  /* 1: produce bps */ 
     94  int bps; 
     95 
    9096  struct AllLogsType *Next; 
    9197}; 
  • trunk/source/init.c

    r117 r118  
    198198  pNewLog->ReverseLookup = DEFAULT_OPTIONS_REVERSELOOKUP; 
    199199  pNewLog->Append = DEFAULT_OPTIONS_APPEND; 
     200  pNewLog->Divide = DEFAULT_OPTIONS_DIVIDE; 
     201  pNewLog->bps = DEFAULT_OPTIONS_BPS; 
    200202 
    201203  pAllLogs = pNewLog; 
  • trunk/source/ipfm.c

    r117 r118  
    122122    /* Well that's an approximation. I should perhaps use an alarm() */ 
    123123    for (pTempLog = pAllLogs; NULL != pTempLog; pTempLog = pTempLog->Next) { 
    124       DEBUG_MSG("time %d nextdump %d delta %d\n", time(NULL), pTempLog->NextDump, pTempLog->NextDump - time(NULL)); 
     124/* DEBUG_MSG("time %d nextdump %d delta %d\n", time(NULL), pTempLog->NextDump, pTempLog->NextDump - time(NULL));*/ 
    125125      if (time(NULL) > pTempLog->NextDump) { 
    126126        data_dump(pTempLog); 
  • trunk/source/pcap.c

    r111 r118  
    256256  for (;;) { 
    257257    pcap_result = pcap_next_ex(pcap_global_descriptor, &header, (const u_char **) &packet); 
    258     DEBUG_MSG("pcap_next_ex returned %i\n", pcap_result); 
     258    /*    DEBUG_MSG("pcap_next_ex returned %i\n", pcap_result); */ 
    259259    switch (pcap_result) { 
    260260      case 1: 
    261261        /* A packet was received, nothing to do! */ 
    262         DEBUG_MSG("packet time/length/size %i %i %i\n", header->ts, header->caplen, header->len); 
     262        /* DEBUG_MSG("packet time/length/size %i %i %i\n", header->ts, header->caplen, header->len); */ 
    263263        break; 
    264264      case 0: