Various ra related printing bug patches

Peter Van Epp vanepp at sfu.ca
Mon Feb 27 00:18:02 EST 2006


	Below is a pair of patches which improve ra print formatting (with the
caveot that they may break other things :-)) for the brave or foolish to try
(especially anyone with MPLS). They are against argus-clients-2.0.6.fixes.1
and fix the following bugs:

1) printing all the labels causes a seg fault (buffer too small)

2) src/dst jitter were the same (flags didn't get reversed for dst)

3) user data labels weren't printed if no data (even if selected)

4) many items (I have a list if there is interest) printed a leading separator
   when they were the only thing in the RA_FIELD_SPECIFIER line in an ra.conf
file that looks like this:

RA_FIELD_DELIMITER=','
RA_PRINT_HOSTNAMES=protocol
RA_FIELD_SPECIFIER=time trans dur avgdur snet saddr dnet daddr proto sport dport
 stos dtos sttl dttl bytes pkts load loss rate srcid ind mac dir jitter status u
ser win seq mpls vlan ipid
RA_USEC_PRECISION=6
RA_PRINT_LABELS=0

	which incidentally prints all implemented fields and the labels (which
you don't seem to be able to select from the command line only the conf file).

5) many of the dual printing options (time, bytes etc.) didn't deal with a 
   different RA_FIELD_DELIMITER in between the first and second entry (using
   the default blank always).

	There are a few more that should be done (but aren't yet :-)) too:
man jitter comes out -0.00, several of the source/dest options could have a
"both" mode (such as time = starttime + endtime) so you can select both or 
either src or dst field which you can't now. However this patch (assuming it 
doesn't break a bunch of corner cases that I didn't see) fixes everything that
seems to be broken and the rest would be nice enhancments for later. 
	There is also some ra man page changes that are needed but not yet 
done.
	Send mail if I've broken something :-). 

Peter Van Epp / Operations and Technical Support 
Simon Fraser University, Burnaby, B.C. Canada

---- cut here ---
*** common/argus_client.c.orig	Mon Feb 13 20:32:51 2006
--- common/argus_client.c	Sun Feb 26 20:48:51 2006
***************
*** 69,74 ****
--- 69,78 ----
           RaPrintDate = 0;
           for (x = 0; x < MAX_PRINT_ALG_TYPES; x++) {
              if (!strncmp (RaPrintKeyWords[x], soption, strlen(RaPrintKeyWords[x]))) {
+ 	       if (x == 0) {
+ 		  RaPrintStartTime = 1;
+ 		  RaPrintLastTime = 1;
+ 	       }
                 if (x < 3) RaPrintDate++;
                 switch (RaOptionOperation) {
                    case RA_ADD_OPTION:
***************
*** 3090,3096 ****
     }
  
     if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0')) {
!       char tmpbuf[128], *ptr = tmpbuf, *str = RaLabel, lastchr = ' ';
  
        bzero (tmpbuf, sizeof(tmpbuf));
        lastchr = RaFieldDelimiter;
--- 3094,3100 ----
     }
  
     if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0')) {
!       char tmpbuf[1024], *ptr = tmpbuf, *str = RaLabel, lastchr = ' ';
  
        bzero (tmpbuf, sizeof(tmpbuf));
        lastchr = RaFieldDelimiter;
***************
*** 3120,3127 ****
  {
     if (lflag)
        ArgusPrintLastDateLabel (buf);
!    else
        ArgusPrintStartDateLabel (buf);
  }
  
  
--- 3124,3133 ----
  {
     if (lflag)
        ArgusPrintLastDateLabel (buf);
!    else {
        ArgusPrintStartDateLabel (buf);
+       ArgusPrintLastDateLabel (buf);
+    }
  }
  
  
***************
*** 3448,3454 ****
           if (len & 0x01)
              sprintf(&buf[strlen(buf)], " ");
        }
!    }
  }
  
  void
--- 3454,3461 ----
           if (len & 0x01)
              sprintf(&buf[strlen(buf)], " ");
        }
!    } else 
!       sprintf (&buf[strlen(buf)], " srcUdata%cdstUdata ", RaFieldDelimiter);
  }
  
  void
---- cut here --- 
*** common/argus_util.c.orig	Sat Dec  6 09:43:56 2003
--- common/argus_util.c	Sun Feb 26 20:14:06 2006
***************
*** 909,915 ****
  void
  ArgusPrintStartDate (char *date, struct ArgusRecord *ptr)
  {
-    char delim = ' ';
     struct timeval *tvp = NULL;
  
     if (ptr->ahdr.type & ARGUS_MAR)
--- 909,914 ----
***************
*** 917,932 ****
     else
        tvp = &ptr->argus_far.time.start;
  
!    if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
!       delim = RaFieldDelimiter;
! 
!    sprintf (&date[strlen(date)], "%s%c", print_time(tvp), delim);
  }
  
  void
  ArgusPrintLastDate (char *date, struct ArgusRecord *ptr)
  {
-    char delim = ' ';
     struct timeval *tvp = NULL;
  
     if (ptr->ahdr.type & ARGUS_MAR)
--- 916,927 ----
     else
        tvp = &ptr->argus_far.time.start;
  
!    sprintf (&date[strlen(date)], "%s", print_time(tvp));
  }
  
  void
  ArgusPrintLastDate (char *date, struct ArgusRecord *ptr)
  {
     struct timeval *tvp = NULL;
  
     if (ptr->ahdr.type & ARGUS_MAR)
***************
*** 934,943 ****
     else 
        tvp = &ptr->argus_far.time.last;
        
!    if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
!       delim = RaFieldDelimiter;
! 
!    sprintf (&date[strlen(date)], "%s%c", print_time(tvp), delim);
  }
  
  void
--- 929,935 ----
     else 
        tvp = &ptr->argus_far.time.last;
        
!    sprintf (&date[strlen(date)], "%s", print_time(tvp));
  }
  
  void
***************
*** 967,973 ****
           sprintf (&date[strlen(date)], " ");
  
     if (RaPrintLastTime)
!       sprintf (&date[strlen(date)], "%s%c", print_time(last), delim);
  }
  
  void ArgusPrintSrcRate (char *, struct ArgusRecord *);
--- 959,965 ----
           sprintf (&date[strlen(date)], " ");
  
     if (RaPrintLastTime)
!       sprintf (&date[strlen(date)], "%s", print_time(last));
  }
  
  void ArgusPrintSrcRate (char *, struct ArgusRecord *);
***************
*** 1003,1009 ****
        if (ArgusThisAgr && (ArgusThisAgr->type == ARGUS_AGR_DSR))
           hits = ArgusThisAgr->count;
  
!       sprintf(&buf[strlen(buf)], "%5d ", hits);
     }
  }
  
--- 995,1001 ----
        if (ArgusThisAgr && (ArgusThisAgr->type == ARGUS_AGR_DSR))
           hits = ArgusThisAgr->count;
  
!       sprintf(&buf[strlen(buf)], "%5d", hits);
     }
  }
  
***************
*** 1013,1019 ****
  ArgusPrintAvgDuration (char *date, struct ArgusRecord *ptr)
  {
     struct ArgusAGRStruct *ArgusThisAgr = NULL;
!    char *sptr, *iptr, delim = ' ';
     struct timeval *start = NULL, *last = NULL;
     struct timeval  buf,  *time = &buf;
  
--- 1005,1011 ----
  ArgusPrintAvgDuration (char *date, struct ArgusRecord *ptr)
  {
     struct ArgusAGRStruct *ArgusThisAgr = NULL;
!    char *sptr, *iptr;
     struct timeval *start = NULL, *last = NULL;
     struct timeval  buf,  *time = &buf;
  
***************
*** 1065,1081 ****
        sprintf(sptr, ".%06d", (int) time->tv_usec);
        sptr[pflag + 1] = '\0';
     }
- 
-    if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
-       sprintf(&date[strlen(date)], "%c", delim);
-    else
-       sprintf(&date[strlen(date)], "%c", ' ');
  }
  
  void
  ArgusPrintDuration (char *date, struct ArgusRecord *ptr)
  {
!    char *sptr, *iptr, delim = ' ';
     struct timeval *start = NULL, *last = NULL;
     struct timeval  buf,  *time = &buf;
  
--- 1057,1068 ----
        sprintf(sptr, ".%06d", (int) time->tv_usec);
        sptr[pflag + 1] = '\0';
     }
  }
  
  void
  ArgusPrintDuration (char *date, struct ArgusRecord *ptr)
  {
!    char *sptr, *iptr;
     struct timeval *start = NULL, *last = NULL;
     struct timeval  buf,  *time = &buf;
  
***************
*** 1115,1125 ****
        sprintf(sptr, ".%06d", (int) time->tv_usec);
        sptr[pflag + 1] = '\0';
     }
- 
-    if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
-       sprintf(&date[strlen(date)], "%c", delim);
-    else
-       sprintf(&date[strlen(date)], "%c", ' ');
  }
  
  void ArgusGetIndicatorString (struct ArgusRecord *, char *);
--- 1102,1107 ----
***************
*** 1215,1222 ****
           }
        }
  
-       *ptr = RaFieldDelimiter;
- 
     } else {
        int encdone = 0;
  
--- 1197,1202 ----
***************
*** 1386,1392 ****
     else
        sprintf (argusIDStr, "%u", argus->ahdr.argusid);
  
!    sprintf(buf, "%-15.15s ", argusIDStr);
  }
  
  void ArgusPrintBinNumber (char *, struct ArgusRecord *);
--- 1366,1372 ----
     else
        sprintf (argusIDStr, "%u", argus->ahdr.argusid);
  
!    sprintf(buf, "%-15.15s", argusIDStr);
  }
  
  void ArgusPrintBinNumber (char *, struct ArgusRecord *);
***************
*** 1404,1410 ****
  
  void
  ArgusPrintSequenceNumber (char *buf, struct ArgusRecord *argus) {
!    sprintf(buf, "%d ", argus->ahdr.seqNumber);
  }
  
  
--- 1384,1390 ----
  
  void
  ArgusPrintSequenceNumber (char *buf, struct ArgusRecord *argus) {
!    sprintf(buf, "%d", argus->ahdr.seqNumber);
  }
  
  
***************
*** 1424,1433 ****
        esrcString = etheraddr_string ((u_char *)&mac->phys_union.ether.ethersrc);
        edstString = etheraddr_string ((u_char *)&mac->phys_union.ether.etherdst);
   
!       sprintf (buf, "%17.17s %17.17s ", esrcString, edstString);
  
!    } else
!       sprintf (buf, "%17.17s %17.17s ", blankStr, blankStr);
  }
  
  void
--- 1404,1424 ----
        esrcString = etheraddr_string ((u_char *)&mac->phys_union.ether.ethersrc);
        edstString = etheraddr_string ((u_char *)&mac->phys_union.ether.etherdst);
   
!       sprintf (buf, "%17.17s", esrcString);
!       if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
!          sprintf(&buf[strlen(buf)], "%c", RaFieldDelimiter);
!       else
!          sprintf(&buf[strlen(buf)], "%c", ' ');
!       sprintf (&buf[strlen(buf)], "%17.17s", edstString);
  
!    } else {
!       sprintf (buf, "%17.17s", blankStr);
!       if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
!          sprintf(&buf[strlen(buf)], "%c", RaFieldDelimiter);
!       else
!          sprintf(&buf[strlen(buf)], "%c", ' ');
!       sprintf (&buf[strlen(buf)], "%17.17s", blankStr);
!    }
  }
  
  void
***************
*** 1468,1474 ****
     }
  
     if (protoStr != NULL)
!       sprintf (buf, "%4.4s ", protoStr);
  }
  
  int ArgusPrintNet = 0;
--- 1459,1465 ----
     }
  
     if (protoStr != NULL)
!       sprintf (buf, "%4.4s", protoStr);
  }
  
  int ArgusPrintNet = 0;
***************
*** 1537,1543 ****
     struct ArgusFlow *flow;
  
     if (argus->ahdr.type & ARGUS_MAR) {
!       sprintf (&buf[strlen(buf)], "%*d ", hfield, argus->argus_mar.nextMrSequenceNum);
  
     } else {
        flow = &argus->argus_far.flow;
--- 1528,1534 ----
     struct ArgusFlow *flow;
  
     if (argus->ahdr.type & ARGUS_MAR) {
!       sprintf (&buf[strlen(buf)], "%*u ", hfield, argus->argus_mar.nextMrSequenceNum);
  
     } else {
        flow = &argus->argus_far.flow;
***************
*** 1595,1603 ****
     }
  
     if (addr != NULL) 
!       sprintf (buf, "%*.*s ", thishfield, thishfield, addrstr);
     else
!       sprintf (buf, "%*.*s ", thishfield, thishfield, "                  ");
  }
  
  
--- 1586,1595 ----
     }
  
     if (addr != NULL) 
!       sprintf (buf, "%*.*s", thishfield, thishfield, addrstr);
     else
!       sprintf (buf, "%*.*s", thishfield, thishfield, "                  ");
! 
  }
  
  
***************
*** 1631,1638 ****
           case ETHERTYPE_REVARP:
           case ETHERTYPE_ARP:
              sprintf (&buf[strlen(buf)], "%*s", pfield - 1, " ");
-             if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
-                sprintf (buf, "%c", RaFieldDelimiter);
              break;
  
           default:
--- 1623,1628 ----
***************
*** 1650,1656 ****
  ArgusPrintDstPort (char *buf, struct ArgusRecord *argus)
  {
     if (argus->ahdr.type & ARGUS_MAR) {
!       sprintf (&buf[strlen(buf)], "%-*d", pfield + 1, argus->argus_mar.flows);
  
     } else {
        struct ArgusFlow *flow = &argus->argus_far.flow;
--- 1640,1646 ----
  ArgusPrintDstPort (char *buf, struct ArgusRecord *argus)
  {
     if (argus->ahdr.type & ARGUS_MAR) {
!       sprintf (&buf[strlen(buf)], "%-*u", pfield + 1, argus->argus_mar.flows);
  
     } else {
        struct ArgusFlow *flow = &argus->argus_far.flow;
***************
*** 1673,1681 ****
              } else
                 sprintf (&buf[strlen(buf)], "%*s", pfield - 1, " ");
  
-             if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
-                sprintf (buf, "%c", RaFieldDelimiter);
- 
              break;
  
           default:
--- 1663,1668 ----
***************
*** 1699,1743 ****
                 switch (proto) {
                    case IPPROTO_TCP:
                    case IPPROTO_UDP:
!                      if (RaPrintIndex > 0)
                          if ((RaPrintAlgorithms[RaPrintIndex - 1] == ArgusPrintSrcAddr) ||
                               (RaPrintAlgorithms[RaPrintIndex - 1] == ArgusPrintDstAddr))
                             if (RaFieldDelimiter == '\0')
                                if (buf[strlen(buf) - 1] == ' ')
                                   buf[strlen(buf) - 1] = '.';
  
-                      sprintf (buf, "%-*d ", thispfield, port);
                       break;
  
                    default:
-                      if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
-                         sprintf (&buf[strlen(buf)], "%c", RaFieldDelimiter);
-                      else
-                         sprintf (buf, "%-*.*s ", thispfield, thispfield, " ");
                       break;
                 }
              } else {
                 switch (proto) {
                    case IPPROTO_TCP:
                    case IPPROTO_UDP:
!                      if (RaPrintIndex > 0)
                          if ((RaPrintAlgorithms[RaPrintIndex - 1] == ArgusPrintSrcAddr) ||
                               (RaPrintAlgorithms[RaPrintIndex - 1] == ArgusPrintDstAddr))
                             if (RaFieldDelimiter == '\0')
                                if (buf[strlen(buf) - 1] == ' ')
                                   buf[strlen(buf) - 1] = '.';
  
                       if (proto == IPPROTO_TCP)
!                         sprintf (buf, "%-*.*s ", thispfield, thispfield, tcpport_string(port));
                       else
!                         sprintf (buf, "%-*.*s ", thispfield, thispfield, udpport_string(port));
                       break;
  
                    default:
!                      if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
!                         sprintf (&buf[strlen(buf)], "%c", RaFieldDelimiter);
!                      else
!                         sprintf (buf, "%-*.*s ", thispfield, thispfield, " ");
                       break;
                 }
              }
--- 1686,1728 ----
                 switch (proto) {
                    case IPPROTO_TCP:
                    case IPPROTO_UDP:
!                      if ((RaPrintIndex > 0) && ((RaFieldDelimiter == ' ') ||
! 			 (RaFieldDelimiter == '\0'))) {
                          if ((RaPrintAlgorithms[RaPrintIndex - 1] == ArgusPrintSrcAddr) ||
                               (RaPrintAlgorithms[RaPrintIndex - 1] == ArgusPrintDstAddr))
                             if (RaFieldDelimiter == '\0')
                                if (buf[strlen(buf) - 1] == ' ')
                                   buf[strlen(buf) - 1] = '.';
+ 		     }
+ 
+                      sprintf (buf, "%-*d", thispfield, port);
  
                       break;
  
                    default:
                       break;
                 }
              } else {
                 switch (proto) {
                    case IPPROTO_TCP:
                    case IPPROTO_UDP:
!                      if ((RaPrintIndex > 0) && ((RaFieldDelimiter == ' ') ||
! 			 (RaFieldDelimiter == '\0'))) {
                          if ((RaPrintAlgorithms[RaPrintIndex - 1] == ArgusPrintSrcAddr) ||
                               (RaPrintAlgorithms[RaPrintIndex - 1] == ArgusPrintDstAddr))
                             if (RaFieldDelimiter == '\0')
                                if (buf[strlen(buf) - 1] == ' ')
                                   buf[strlen(buf) - 1] = '.';
+ 		     }
  
                       if (proto == IPPROTO_TCP)
!                         sprintf (buf, "%-*.*s", thispfield, thispfield, tcpport_string(port));
                       else
!                         sprintf (buf, "%-*.*s", thispfield, thispfield, udpport_string(port));
                       break;
  
                    default:
! 
                       break;
                 }
              }
***************
*** 1748,1769 ****
              } else {
                 switch (proto) {
                    default:
!                      sprintf (buf, "%-*.*s ", thispfield, thispfield, " ");
                       break;
  
                    case IPPROTO_TCP:
                    case IPPROTO_UDP:
!                      if (RaPrintIndex > 0)
                          if ((RaPrintAlgorithms[RaPrintIndex - 1] == ArgusPrintSrcAddr) ||
                               (RaPrintAlgorithms[RaPrintIndex - 1] == ArgusPrintDstAddr))
                             if (RaFieldDelimiter == '\0')
                                if (buf[strlen(buf) - 1] == ' ')
                                   buf[strlen(buf) - 1] = '.';
! 
                       if (argus->ahdr.status & ARGUS_MERGED)
                          sprintf (buf, "%-*.*s ", thispfield, thispfield, "*");
                       else 
!                         sprintf (buf, "%-*d ", thispfield, port);
                       break;
                 }
              }
--- 1733,1763 ----
              } else {
                 switch (proto) {
                    default:
!                      sprintf (buf, "%-*.*s", thispfield, thispfield, " ");
!                      if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
!                         sprintf (&buf[strlen(buf)], "%c", RaFieldDelimiter);
!                      else
!                         sprintf (buf, "%-*.*s ", thispfield, thispfield, " ");
                       break;
  
                    case IPPROTO_TCP:
                    case IPPROTO_UDP:
!                      if ((RaPrintIndex > 0) && ((RaFieldDelimiter == ' ') ||
! 			 (RaFieldDelimiter == '\0'))) {
                          if ((RaPrintAlgorithms[RaPrintIndex - 1] == ArgusPrintSrcAddr) ||
                               (RaPrintAlgorithms[RaPrintIndex - 1] == ArgusPrintDstAddr))
                             if (RaFieldDelimiter == '\0')
                                if (buf[strlen(buf) - 1] == ' ')
                                   buf[strlen(buf) - 1] = '.';
! 		     }
                       if (argus->ahdr.status & ARGUS_MERGED)
                          sprintf (buf, "%-*.*s ", thispfield, thispfield, "*");
                       else 
!                         sprintf (buf, "%-*d", thispfield, port);
!                      if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
!                         sprintf (&buf[strlen(buf)], "%c", RaFieldDelimiter);
!                      else
!                         sprintf (buf, "%-*.*s ", thispfield, thispfield, " ");
                       break;
                 }
              }
***************
*** 1775,1790 ****
        default:
           thispfield -= 2;
  
!          if ((ArgusThisProto == 0) && (proto != 0)) {
!             sprintf (buf, "%-*.*s ", thispfield, thispfield, llcsap_string((unsigned char) port));
!          } else {
  
-             if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0')) {
-                sprintf (buf, "%c", RaFieldDelimiter);
-             } else {
-                sprintf (buf, "%-*.*s ", thispfield, thispfield, " ");
-             }
-          }
     }
  
  }
--- 1769,1777 ----
        default:
           thispfield -= 2;
  
!          if ((ArgusThisProto == 0) && (proto != 0)) 
!             sprintf (buf, "%-*.*s", thispfield, thispfield, llcsap_string((unsigned char) port));
  
     }
  
  }
***************
*** 1969,1975 ****
        }
     }
  
!    sprintf (buf, "%s ", dirStr);
  }
  
  void
--- 1956,1962 ----
        }
     }
  
!    sprintf (buf, "%s", dirStr);
  }
  
  void
***************
*** 1986,1992 ****
        dst_count = argus->argus_far.dst.count;
     }
  
!    sprintf (buf, "%-8u %-8u  ", src_count, dst_count);
  }
  
  void
--- 1973,1979 ----
        dst_count = argus->argus_far.dst.count;
     }
  
!    sprintf (buf, "%-8u%c%-8u", src_count,RaFieldDelimiter, dst_count);
  }
  
  void
***************
*** 2001,2007 ****
        src_count = argus->argus_far.src.count;
     }
   
!    sprintf (buf, "%-8u ", src_count);
  }
  
  void
--- 1988,1994 ----
        src_count = argus->argus_far.src.count;
     }
   
!    sprintf (buf, "%-8u", src_count);
  }
  
  void
***************
*** 2016,2022 ****
        dst_count = argus->argus_far.dst.count;
     }
   
!    sprintf (buf, "%-8u ", dst_count);
  }
  
  void
--- 2003,2009 ----
        dst_count = argus->argus_far.dst.count;
     }
   
!    sprintf (buf, "%-8u", dst_count);
  }
  
  void
***************
*** 2038,2044 ****
        }
     }
  
!    sprintf (buf, "%-12u %-12u", src_bytes, dst_bytes);
  }
  
  void
--- 2025,2031 ----
        }
     }
  
!    sprintf (buf, "%-12u%c%-12u", src_bytes, RaFieldDelimiter, dst_bytes);
  }
  
  void
***************
*** 2077,2084 ****
     sprintf (buf, "%-12u", dst_bytes);
  }
  
- 
- 
  #include <math.h>
  
  void
--- 2064,2069 ----
***************
*** 2092,2099 ****
  void
  ArgusPrintDstJitter (char *buf, struct ArgusRecord *argus)
  {
!    RaPrintSrcTime = 1;
!    RaPrintDstTime = 0;
     ArgusPrintJitter (buf, argus);
  }
  
--- 2077,2084 ----
  void
  ArgusPrintDstJitter (char *buf, struct ArgusRecord *argus)
  {
!    RaPrintSrcTime = 0;
!    RaPrintDstTime = 1;
     ArgusPrintJitter (buf, argus);
  }
  
***************
*** 2147,2157 ****
           sprintf (jitterstr, "%6d.%03d (%6s)", meanval/1000, meanval%1000, stdstr);
  */
           sprintf (jitterstr, "%6d.%03d", meanval/1000, meanval%1000);
!          sprintf (&buf[strlen(buf)], "%-12s ", jitterstr);
  
        } else {
           sprintf (jitterstr, "%6d.%03d", meanval/1000, meanval%1000);
!          sprintf (&buf[strlen(buf)], "%-12s ", jitterstr);
        }
     }
  
--- 2132,2149 ----
           sprintf (jitterstr, "%6d.%03d (%6s)", meanval/1000, meanval%1000, stdstr);
  */
           sprintf (jitterstr, "%6d.%03d", meanval/1000, meanval%1000);
!          sprintf (&buf[strlen(buf)], "%-12s", jitterstr);
  
        } else {
           sprintf (jitterstr, "%6d.%03d", meanval/1000, meanval%1000);
!          sprintf (&buf[strlen(buf)], "%-12s", jitterstr);
!       }
! 
!       if (RaPrintDstTime) {
!          if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
!             sprintf(&buf[strlen(buf)], "%c", RaFieldDelimiter);
!          else 
!             sprintf(&buf[strlen(buf)], "%c", ' ');
        }
     }
  
***************
*** 2320,2331 ****
  
     sprintf (buf, "%10s", ptr);
  
     if (dst_count > 1)
        sprintf (ptr, "%.2f", ((double)(dst_count)/seconds));
     else
        sprintf (ptr, "%.2f", 0.0);
  
!    sprintf (&buf[strlen(buf)], "%10s  ", ptr);
  }
  
  /*
--- 2312,2328 ----
  
     sprintf (buf, "%10s", ptr);
  
+    if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
+       sprintf(&buf[strlen(buf)], "%c", RaFieldDelimiter);
+    else
+       sprintf(&buf[strlen(buf)], "%c", ' ');
+ 
     if (dst_count > 1)
        sprintf (ptr, "%.2f", ((double)(dst_count)/seconds));
     else
        sprintf (ptr, "%.2f", 0.0);
  
!    sprintf (&buf[strlen(buf)], "%10s", ptr);
  }
  
  /*
***************
*** 2443,2453 ****
        if (seconds) {
           sprintf (ptr, "%.4f", ((double)srcLossPkts));
           sprintf (buf, "%10s", ptr);
           sprintf (ptr, "%.4f", ((double)dstLossPkts));
!          sprintf (&buf[strlen(buf)], "%10s  ", ptr);
        } else {
           sprintf (ptr, "%.4f", 0.0);
           sprintf (buf, "%10s", ptr);
           sprintf (ptr, "%.4f", 0.0);
           sprintf (&buf[strlen(buf)], "%10s  ", ptr);
        }
--- 2440,2458 ----
        if (seconds) {
           sprintf (ptr, "%.4f", ((double)srcLossPkts));
           sprintf (buf, "%10s", ptr);
+          if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
+             sprintf(&buf[strlen(buf)], "%c", RaFieldDelimiter);
+          else
+             sprintf(&buf[strlen(buf)], "%c", ' ');
           sprintf (ptr, "%.4f", ((double)dstLossPkts));
!          sprintf (&buf[strlen(buf)], "%10s", ptr);
        } else {
           sprintf (ptr, "%.4f", 0.0);
           sprintf (buf, "%10s", ptr);
+          if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
+             sprintf(&buf[strlen(buf)], "%c", RaFieldDelimiter);
+          else
+             sprintf(&buf[strlen(buf)], "%c", ' ');
           sprintf (ptr, "%.4f", 0.0);
           sprintf (&buf[strlen(buf)], "%10s  ", ptr);
        }
***************
*** 2492,2501 ****
  
     if (seconds) {
        sprintf (ptr, "%.2f", ((double)(src_bytes * 8.0))/seconds);
!       sprintf (&buf[strlen(buf)], "%11s ", ptr);
     } else {
        sprintf (ptr, "%.2f", 0.0);
!       sprintf (&buf[strlen(buf)], "%11s ", ptr);
     }
  }
  
--- 2497,2506 ----
  
     if (seconds) {
        sprintf (ptr, "%.2f", ((double)(src_bytes * 8.0))/seconds);
!       sprintf (&buf[strlen(buf)], "%11s", ptr);
     } else {
        sprintf (ptr, "%.2f", 0.0);
!       sprintf (&buf[strlen(buf)], "%11s", ptr);
     }
  }
  
***************
*** 2538,2547 ****
  
     if (seconds) {
        sprintf (ptr, "%.2f", ((double)(dst_bytes * 8.0))/seconds);
!       sprintf (&buf[strlen(buf)], "%13s  ", ptr);
     } else {
        sprintf (ptr, "%.2f", 0.0);
!       sprintf (&buf[strlen(buf)], "%13s  ", ptr);
     }
  }
  
--- 2543,2552 ----
  
     if (seconds) {
        sprintf (ptr, "%.2f", ((double)(dst_bytes * 8.0))/seconds);
!       sprintf (&buf[strlen(buf)], "%13s", ptr);
     } else {
        sprintf (ptr, "%.2f", 0.0);
!       sprintf (&buf[strlen(buf)], "%13s", ptr);
     }
  }
  
***************
*** 2551,2557 ****
     int src_count = 0, dst_count = 0, src_bytes = 0, dst_bytes = 0;
     struct timeval *start = NULL, *last = NULL;
     struct timeval  timebuf,  *time = &timebuf;
!    char tmpbuf[128], *ptr = tmpbuf;
     double seconds;
  
     start = &argus->argus_far.time.start;
--- 2556,2562 ----
     int src_count = 0, dst_count = 0, src_bytes = 0, dst_bytes = 0;
     struct timeval *start = NULL, *last = NULL;
     struct timeval  timebuf,  *time = &timebuf;
!    char tmpbuf[128], *ptr = tmpbuf, delim = ' ';
     double seconds;
  
     start = &argus->argus_far.time.start;
***************
*** 2583,2599 ****
        src_bytes = argus->argus_far.src.bytes;
        dst_bytes = argus->argus_far.dst.bytes;
     }
  
     if (seconds) {
        sprintf (ptr, "%.2f", ((double)(src_bytes * 8.0))/seconds);
!       sprintf (buf, "%13s", ptr);
        sprintf (ptr, "%.2f", ((double)(dst_bytes * 8.0))/seconds);
!       sprintf (&buf[strlen(buf)], "%13s  ", ptr);
     } else {
        sprintf (ptr, "%.2f", 0.0);
!       sprintf (buf, "%13s", ptr);
        sprintf (ptr, "%.2f", 0.0);
!       sprintf (&buf[strlen(buf)], "%13s  ", ptr);
     }
  }
  
--- 2588,2607 ----
        src_bytes = argus->argus_far.src.bytes;
        dst_bytes = argus->argus_far.dst.bytes;
     }
+ 	
+    if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
+       delim = RaFieldDelimiter;
  
     if (seconds) {
        sprintf (ptr, "%.2f", ((double)(src_bytes * 8.0))/seconds);
!       sprintf (buf, "%13s%c", ptr, delim);
        sprintf (ptr, "%.2f", ((double)(dst_bytes * 8.0))/seconds);
!       sprintf (&buf[strlen(buf)], "%13s", ptr);
     } else {
        sprintf (ptr, "%.2f", 0.0);
!       sprintf (buf, "%13s%c", ptr, delim);
        sprintf (ptr, "%.2f", 0.0);
!       sprintf (&buf[strlen(buf)], "%13s", ptr);
     }
  }
  
***************
*** 2608,2616 ****
              sdis = i - argus->argus_far.attr_ip.sttl;
           }
        }
!       sprintf (&buf[strlen(buf)], "  %3d  ", sdis);
     } else
!       sprintf (&buf[strlen(buf)], "  %3d  ", argus->argus_far.attr_ip.sttl);
  }
  
  void
--- 2616,2624 ----
              sdis = i - argus->argus_far.attr_ip.sttl;
           }
        }
!       sprintf (&buf[strlen(buf)], "  %3d", sdis);
     } else
!       sprintf (&buf[strlen(buf)], "  %3d", argus->argus_far.attr_ip.sttl);
  }
  
  void
***************
*** 2624,2633 ****
              ddis = i - argus->argus_far.attr_ip.dttl;
           }
        }
!       sprintf (&buf[strlen(buf)], "  %3d  ", ddis);
   
     } else
!       sprintf (&buf[strlen(buf)], "  %3d  ", argus->argus_far.attr_ip.dttl);
  }
  
  void
--- 2632,2641 ----
              ddis = i - argus->argus_far.attr_ip.dttl;
           }
        }
!       sprintf (&buf[strlen(buf)], "  %3d", ddis);
   
     } else
!       sprintf (&buf[strlen(buf)], "  %3d", argus->argus_far.attr_ip.dttl);
  }
  
  void
***************
*** 2637,2651 ****
        struct ArgusVlanStruct *vlan = (struct ArgusVlanStruct *) ArgusThisFarHdrs[ARGUS_VLAN_DSR_INDEX];
   
        if (vlan->status & ARGUS_SRC_VLAN)
!          sprintf (&buf[strlen(buf)], "0x%04x ", vlan->sid);
        else
!          sprintf(&buf[strlen(buf)], "       ");
        if (vlan->status & ARGUS_DST_VLAN)
!          sprintf (&buf[strlen(buf)], "0x%04x ", vlan->did);
        else
!          sprintf(&buf[strlen(buf)], "       ");
     } else
!       sprintf (&buf[strlen(buf)], "              ");
  }
  
  void
--- 2645,2666 ----
        struct ArgusVlanStruct *vlan = (struct ArgusVlanStruct *) ArgusThisFarHdrs[ARGUS_VLAN_DSR_INDEX];
   
        if (vlan->status & ARGUS_SRC_VLAN)
!          sprintf (&buf[strlen(buf)], "0x%04x%c", vlan->sid, RaFieldDelimiter);
        else
! 	 if (RaFieldDelimiter == ' ') 
!             sprintf(&buf[strlen(buf)], "       ");
! 	 else 
!             sprintf(&buf[strlen(buf)], "%c", RaFieldDelimiter);
        if (vlan->status & ARGUS_DST_VLAN)
!          sprintf (&buf[strlen(buf)], "0x%04x", vlan->did);
        else
! 	 if (RaFieldDelimiter == ' ')
!             sprintf(&buf[strlen(buf)], "      ");
     } else
!       if (RaFieldDelimiter == ' ') 
!          sprintf (&buf[strlen(buf)], "             ");
!       else 
! 	 sprintf(&buf[strlen(buf)], "%c", RaFieldDelimiter);
  }
  
  void
***************
*** 2655,2682 ****
        struct ArgusMplsStruct *mpls = (struct ArgusMplsStruct *) ArgusThisFarHdrs[ARGUS_MPLS_DSR_INDEX];
   
        if (mpls->status & ARGUS_SRC_MPLS)
!          sprintf (&buf[strlen(buf)], " %5x ", mpls->slabel);
        else
!          sprintf(&buf[strlen(buf)], "       ");
  
        if (mpls->status & ARGUS_DST_MPLS)
!          sprintf (&buf[strlen(buf)], " %5x ", mpls->dlabel);
        else
!          sprintf(&buf[strlen(buf)], "       ");
     } else 
!       sprintf (&buf[strlen(buf)], "              ");
  }
  
  void
  ArgusPrintSrcTOS (char *buf, struct ArgusRecord *argus)
  {
!    sprintf (&buf[strlen(buf)], "  %3d  ", argus->argus_far.attr_ip.stos);
  }
  
  void
  ArgusPrintDstTOS (char *buf, struct ArgusRecord *argus)
  {
!    sprintf (&buf[strlen(buf)], "  %3d  ", argus->argus_far.attr_ip.dtos);
  }
  
  
--- 2670,2701 ----
        struct ArgusMplsStruct *mpls = (struct ArgusMplsStruct *) ArgusThisFarHdrs[ARGUS_MPLS_DSR_INDEX];
   
        if (mpls->status & ARGUS_SRC_MPLS)
!          sprintf (&buf[strlen(buf)], "%5x%c", mpls->slabel, RaFieldDelimiter);
        else
!          sprintf(&buf[strlen(buf)], "     %c", RaFieldDelimiter);
  
        if (mpls->status & ARGUS_DST_MPLS)
!          sprintf (&buf[strlen(buf)], "%5x", mpls->dlabel);
        else
! 	 if (RaFieldDelimiter == ' ')
!             sprintf(&buf[strlen(buf)], "     ");
     } else 
! 	 if (RaFieldDelimiter == ' ')
!             sprintf(&buf[strlen(buf)], "     ");
! 	 else 
!             sprintf (&buf[strlen(buf)], "%c", RaFieldDelimiter);
  }
  
  void
  ArgusPrintSrcTOS (char *buf, struct ArgusRecord *argus)
  {
!    sprintf (&buf[strlen(buf)], "  %3d ", argus->argus_far.attr_ip.stos);
  }
  
  void
  ArgusPrintDstTOS (char *buf, struct ArgusRecord *argus)
  {
!    sprintf (&buf[strlen(buf)], "  %3d" , argus->argus_far.attr_ip.dtos);
  }
  
  
***************
*** 2694,2708 ****
           if (tcp != NULL) {
              srcwin = tcp->src.win;
              dstwin = tcp->dst.win;
!             sprintf (&buf[strlen(buf)], "%-5d  %-5d  ", srcwin, dstwin);
           } else {
!             sprintf (&buf[strlen(buf)], "%14s", " ");
           }
           break;
        }
  
        default:
!          sprintf (&buf[strlen(buf)], "%14s", " ");
     }
  }
  
--- 2713,2727 ----
           if (tcp != NULL) {
              srcwin = tcp->src.win;
              dstwin = tcp->dst.win;
!             sprintf (&buf[strlen(buf)], "%-5d%c%-5d", srcwin, RaFieldDelimiter, dstwin);
           } else {
!             sprintf (&buf[strlen(buf)], "%5s%c%5s", " ", RaFieldDelimiter, " ");
           }
           break;
        }
  
        default:
!          sprintf (&buf[strlen(buf)], "%5s%c%5s", " ", RaFieldDelimiter, " ");
     }
  }
  
***************
*** 2850,2858 ****
     bzero (tmpbuf, MAXSTRLEN);
  
     for (RaPrintIndex = 0; RaPrintIndex < MAX_PRINT_ALG_TYPES; RaPrintIndex++) {
!       if (RaPrintAlgorithms[RaPrintIndex] != NULL)
           RaPrintAlgorithms[RaPrintIndex](&argus_strbuf[strlen(argus_strbuf)], argus);
!       else
           break;
     }
  
--- 2869,2881 ----
     bzero (tmpbuf, MAXSTRLEN);
  
     for (RaPrintIndex = 0; RaPrintIndex < MAX_PRINT_ALG_TYPES; RaPrintIndex++) {
!       if (RaPrintAlgorithms[RaPrintIndex] != NULL) {
           RaPrintAlgorithms[RaPrintIndex](&argus_strbuf[strlen(argus_strbuf)], argus);
!          if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
!             sprintf(&argus_strbuf[strlen(argus_strbuf)], "%c", RaFieldDelimiter);
!          else
!             sprintf(&argus_strbuf[strlen(argus_strbuf)], "%c", ' ');
!       } else
           break;
     }
  
***************
*** 2882,2894 ****
        }
  
        while (*str) {
!          if (*str == ' ') {
!             if (lastchr != RaFieldDelimiter)
!                *ptr++ = RaFieldDelimiter;
              while (isspace((int)*str)) str++;
-          }
-          lastchr = *str;
- 
           *ptr++ = *str++;
        }
  
--- 2905,2912 ----
        }
  
        while (*str) {
!          if (*str == ' ') 
              while (isspace((int)*str)) str++;
           *ptr++ = *str++;
        }
  
***************
*** 3227,3233 ****
     if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
        delim = RaFieldDelimiter;
  
!    if ((ArgusSrcUserDataLen > 0) || (ArgusDstUserDataLen)) {
        if (ArgusSrcUserDataLen > 0) {
           switch (eflag) {
              case ARGUS_ENCODE_ASCII:
--- 3245,3251 ----
     if ((RaFieldDelimiter != ' ') && (RaFieldDelimiter != '\0'))
        delim = RaFieldDelimiter;
  
!    if ((ArgusSrcUserDataLen > 0) || (ArgusDstUserDataLen > 0)) {
        if (ArgusSrcUserDataLen > 0) {
           switch (eflag) {
              case ARGUS_ENCODE_ASCII:
***************
*** 3253,3274 ****
              bzero (strbuf, sizeof(strbuf));
              bzero (conbuf, sizeof(conbuf));
              if ((len = ArgusEncode (&user->data, NULL, len, str, sizeof(strbuf))) > 0)
!                sprintf (con, "%cs[%d]=%s", delim, len, str);
              else
                 sprintf (con, " ");
  
              if (delim == ' ')
!                sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-*s ", exlen, con);
              else
!                sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-s ", con);
  
-          } else {
-             if (delim != ' ')
-                sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%c", delim);
-             else
-                sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-*s ", exlen, " ");
           }
        }
  
        if (ArgusDstUserDataLen > 0) {
           switch (eflag) {
--- 3271,3291 ----
              bzero (strbuf, sizeof(strbuf));
              bzero (conbuf, sizeof(conbuf));
              if ((len = ArgusEncode (&user->data, NULL, len, str, sizeof(strbuf))) > 0)
!                sprintf (con, "s[%d]=%s", len, str);
              else
                 sprintf (con, " ");
  
              if (delim == ' ')
!                sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-*s", exlen, con);
              else
!                sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-s", con);
  
           }
        }
+       if (delim != ' ')
+          sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%c", delim);
+       else
+          sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-*s ", exlen, " ");
  
        if (ArgusDstUserDataLen > 0) {
           switch (eflag) {
***************
*** 3296,3318 ****
              bzero (strbuf, sizeof(strbuf));
              bzero (conbuf, sizeof(conbuf));
              if ((len = ArgusEncode (&user->data, NULL, len, str, sizeof(strbuf))) > 0)
!                sprintf (con, "%cd[%d]=%s", delim, len, str);
              else
                 sprintf (con, " ");
  
              if (delim == ' ')
                 sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-*s ", exlen, con);
              else
!                sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-s ", con);
  
!          } else
!             if (delim != ' ')
!                sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%c", delim);
!             else
!                sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-*s ", exlen, " ");
        }
  
!       sprintf (&RaUserDataStr[strlen(RaUserDataStr)], " ");
     }
  }
  
--- 3313,3339 ----
              bzero (strbuf, sizeof(strbuf));
              bzero (conbuf, sizeof(conbuf));
              if ((len = ArgusEncode (&user->data, NULL, len, str, sizeof(strbuf))) > 0)
!                sprintf (con, "d[%d]=%s", len, str);
              else
                 sprintf (con, " ");
  
              if (delim == ' ')
                 sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-*s ", exlen, con);
              else
!                sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-s", con);
  
!          }
        }
+       if (delim != ' ')
+          sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%c", delim);
+       else
+          sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-*s ", exlen, " ");
  
!    } else {
!       if (delim != ' ')
!          sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%c", delim);
!       else
!          sprintf (&RaUserDataStr[strlen(RaUserDataStr)], "%-*s %-*s ", exlen, " ", exlen, " ");
     }
  }
  



More information about the argus mailing list