flow-tools (1:0.68-12) 09_ftio_amd64

Summary

 lib/ftio.c       |   13 +++++++++----
 lib/ftstat.c     |    8 +++++---
 src/flow-print.c |   28 ++++++++++++++++++++--------
 3 files changed, 34 insertions(+), 15 deletions(-)

    
download this patch

Patch contents

#! /bin/sh -e
## 09_ftio_amd64 done by Oleg Milaenko <omnix@debian.org.ua>
## DP: Fixes incorrect print of time in flow-header


if [ $# -lt 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
       -patch) patch -f --no-backup-if-mismatch -p1 < $0;;

       -unpatch) patch -f --no-backup-if-mismatch -R -p1 < $0;;

        *)
                echo >&2 \
                  "`basename $0`: script expects -patch|-unpatch as argument"
                exit 1;;
esac

exit 0

@DPATCH@
diff -Naur ft-old/lib/ftio.c flow-tools-0.68/lib/ftio.c
--- ft-old/lib/ftio.c	2003-02-24 02:51:47.000000000 +0200
+++ flow-tools-0.68/lib/ftio.c	2005-09-27 17:40:52.962355776 +0300
@@ -1605,6 +1605,7 @@
   u_int32 flags, fields;
   u_long period;
   int n, streaming2;
+  time_t t;
 
   fth = &ftio->fth;
 
@@ -1639,17 +1640,21 @@
   }
 
   if (!streaming2)
-    if (fields & FT_FIELD_CAP_START)
+    if (fields & FT_FIELD_CAP_START) {
+      t = fth->cap_start;
       fprintf(std, "%c capture start:        %s", cc,
-        ctime((time_t*)&fth->cap_start));
+        ctime(&t));
+    }
 
   if (!streaming2) {
 
     if ((flags & FT_HEADER_FLAG_DONE) || (flags & FT_HEADER_FLAG_PRELOADED)) {
 
-      if (fields & FT_FIELD_CAP_END)
+      if (fields & FT_FIELD_CAP_END) {
+	t = fth->cap_end;
         fprintf(std, "%c capture end:          %s", cc,
-          ctime((time_t*)&fth->cap_end));
+	  ctime(&t));
+      }
 
       period = fth->cap_end - fth->cap_start;
       if ((fields & FT_FIELD_CAP_END) && (fields & FT_FIELD_CAP_START))
--- flow-tools-0.68.orig/src/flow-print.c
+++ flow-tools-0.68/src/flow-print.c
@@ -298,6 +298,7 @@
   u_long bpp;
   char fmt_buf1[64], fmt_buf2[64];
   char *rec;
+  time_t time_ftt;
 
   if (ftio_check_xfield(ftio, FT_XFIELD_DPKTS |
     FT_XFIELD_DOCTETS | FT_XFIELD_FIRST | FT_XFIELD_LAST | FT_XFIELD_INPUT |
@@ -351,14 +352,16 @@
       (u_long)*cur.dPkts, (u_long)*cur.dOctets);
 
     ftt = ftltime(*cur.sysUpTime, *cur.unix_secs, *cur.unix_nsecs, *cur.First);
-    tm = localtime((time_t*)&ftt.secs);
+    time_ftt = ftt.secs;
+    tm = localtime(&time_ftt);
 
     printf(" %-2.2d%-2.2d.%-2.2d:%-2.2d:%-2.2d.%-3.3lu  ",
       (int)tm->tm_mon+1, (int)tm->tm_mday, (int)tm->tm_hour,
       (int)tm->tm_min, (int)tm->tm_sec, (u_long)ftt.msecs);
 
     ftt = ftltime(*cur.sysUpTime, *cur.unix_secs, *cur.unix_nsecs, *cur.Last);
-    tm = localtime((time_t*)&ftt.secs);
+    time_ftt = ftt.secs;
+    tm = localtime(&time_ftt);
 
     active_secs = (*cur.Last - *cur.First) / 1000;
     active_msecs = (*cur.Last - *cur.First) % 1000;
@@ -398,6 +401,7 @@
   u_long active_secs, active_msecs;
   u_long bpp;
   char *rec;
+  time_t time_ftt;
 
   if (ftio_check_xfield(ftio, FT_XFIELD_DPKTS |
     FT_XFIELD_DOCTETS | FT_XFIELD_FIRST | FT_XFIELD_LAST | FT_XFIELD_INPUT |
@@ -465,14 +469,16 @@
       (u_long)*cur.dPkts, (u_long)*cur.dOctets);
 
     ftt = ftltime(*cur.sysUpTime, *cur.unix_secs, *cur.unix_nsecs, *cur.First);
-    tm = localtime((time_t*)&ftt.secs);
+    time_ftt = ftt.secs;
+    tm = localtime(&time_ftt);
 
     printf(" %-2.2d%-2.2d.%-2.2d:%-2.2d:%-2.2d.%-3.3lu  ",
       (int)tm->tm_mon+1, (int)tm->tm_mday, (int)tm->tm_hour, (int)tm->tm_min,
       (int)tm->tm_sec, (u_long)ftt.msecs);
 
     ftt = ftltime(*cur.sysUpTime, *cur.unix_secs, *cur.unix_nsecs, *cur.Last);
-    tm = localtime((time_t*)&ftt.secs);
+    time_ftt = ftt.secs;
+    tm = localtime(&time_ftt);
 
     active_secs = (*cur.Last - *cur.First) / 1000;
     active_msecs = (*cur.Last - *cur.First) % 1000;
@@ -675,6 +681,7 @@
   struct ftver ftv;
   char fmt_buf1[64], fmt_buf2[64];
   char *rec;
+  time_t time_ftt;
 
   if (ftio_check_xfield(ftio, FT_XFIELD_DPKTS |
     FT_XFIELD_DOCTETS | FT_XFIELD_FIRST | FT_XFIELD_LAST | FT_XFIELD_INPUT |
@@ -711,14 +718,16 @@
     cur.tcp_flags = ((u_int8*)(rec+fo.tcp_flags));
 
     ftt = ftltime(*cur.sysUpTime, *cur.unix_secs, *cur.unix_nsecs, *cur.First);
-    tm = localtime((time_t*)&ftt.secs);
+    time_ftt = ftt.secs;
+    tm = localtime(&time_ftt);
 
     printf("%-2.2d%-2.2d.%-2.2d:%-2.2d:%-2.2d.%-3.3lu ",
       (int)tm->tm_mon+1, (int)tm->tm_mday, (int)tm->tm_hour,
       (int)tm->tm_min, (int)tm->tm_sec, (u_long)ftt.msecs);
 
     ftt = ftltime(*cur.sysUpTime, *cur.unix_secs, *cur.unix_nsecs, *cur.Last);
-    tm = localtime((time_t*)&ftt.secs);
+    time_ftt = ftt.secs;
+    tm = localtime(&time_ftt);
 
     printf("%-2.2d%-2.2d.%-2.2d:%-2.2d:%-2.2d.%-3.3lu ",
       (int)tm->tm_mon+1, (int)tm->tm_mday, (int)tm->tm_hour,
@@ -2173,6 +2182,7 @@
   u_long bpp;
   char fmt_buf1[64], fmt_buf2[64], fmt_buf3[64], fmt_buf4[64], fmt_buf5[64], fmt_buf6[64];
   char *rec;
+  time_t time_ftt;
 
   if (ftio_check_xfield(ftio, FT_XFIELD_DPKTS |
     FT_XFIELD_DOCTETS | FT_XFIELD_FIRST | FT_XFIELD_LAST | FT_XFIELD_INPUT |
@@ -2239,14 +2249,16 @@
       (u_long)*cur.dPkts, (u_long)*cur.dOctets);
 
     ftt = ftltime(*cur.sysUpTime, *cur.unix_secs, *cur.unix_nsecs, *cur.First);
-    tm = localtime((time_t*)&ftt.secs);
+    time_ftt = ftt.secs;
+    tm = localtime(&time_ftt);
 
     printf(" %-4.4d-%-2.2d-%-2.2d %-2.2d:%-2.2d:%-2.2d.%-3.3lu  ",
       (int)tm->tm_year+1900, (int)tm->tm_mon+1, (int)tm->tm_mday, (int)tm->tm_hour,
       (int)tm->tm_min, (int)tm->tm_sec, (u_long)ftt.msecs);
 
     ftt = ftltime(*cur.sysUpTime, *cur.unix_secs, *cur.unix_nsecs, *cur.Last);
-    tm = localtime((time_t*)&ftt.secs);
+    time_ftt = ftt.secs;
+    tm = localtime(&time_ftt);
 
     active_secs = (*cur.Last - *cur.First) / 1000;
     active_msecs = (*cur.Last - *cur.First) % 1000;
--- flow-tools-0.68.orig/lib/ftstat.c
+++ flow-tools-0.68/lib/ftstat.c
@@ -12363,7 +12363,7 @@
 {
   int comma, sort_field;
   char *buf, fmt_buf[32];
-  time_t now;
+  time_t now, time_flow;
 
   /* shortcut */
   if (!(rpt->out->options & FT_STAT_OPT_HEADER))
@@ -12619,11 +12619,13 @@
     fprintf(fp, "# records_shown:      %s\n", fmt_buf);
   }
 
+  time_flow = rpt->time_start;
   fprintf(fp, "# first-flow:           %lu %s",
-    (unsigned long)rpt->time_start, ctime((time_t*)&rpt->time_start));
+    (unsigned long)rpt->time_start, ctime(&time_flow));
 
+  time_flow = rpt->time_end;
   fprintf(fp, "# last-flow:            %lu %s",
-    (unsigned long)rpt->time_end, ctime((time_t*)&rpt->time_end));
+    (unsigned long)rpt->time_end, ctime(&time_flow));
 
   now = time((time_t*)0L);