summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/tcpdump/interface.h7
-rw-r--r--usr.sbin/tcpdump/util.c52
2 files changed, 55 insertions, 4 deletions
diff --git a/usr.sbin/tcpdump/interface.h b/usr.sbin/tcpdump/interface.h
index a354a60eaac..d8946deb1df 100644
--- a/usr.sbin/tcpdump/interface.h
+++ b/usr.sbin/tcpdump/interface.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: interface.h,v 1.22 2001/02/05 15:18:47 jason Exp $ */
+/* $OpenBSD: interface.h,v 1.23 2001/03/05 22:34:00 jakob Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -20,7 +20,7 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * @(#) $Header: /home/cvs/src/usr.sbin/tcpdump/interface.h,v 1.22 2001/02/05 15:18:47 jason Exp $ (LBL)
+ * @(#) $Header: /home/cvs/src/usr.sbin/tcpdump/interface.h,v 1.23 2001/03/05 22:34:00 jakob Exp $ (LBL)
*/
#ifndef tcpdump_interface_h
@@ -144,8 +144,11 @@ extern void ts_print(const struct timeval *);
extern int fn_print(const u_char *, const u_char *);
extern int fn_printn(const u_char *, u_int, const u_char *);
+extern void relts_print(int);
extern const char *tok2str(const struct tok *, const char *, int);
extern char *dnaddr_string(u_short);
+extern void safeputs(const char *);
+extern void safeputchar(int);
extern void wrapup(int);
diff --git a/usr.sbin/tcpdump/util.c b/usr.sbin/tcpdump/util.c
index 843897acf38..376c5bb59a4 100644
--- a/usr.sbin/tcpdump/util.c
+++ b/usr.sbin/tcpdump/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.10 2000/10/31 16:06:49 deraadt Exp $ */
+/* $OpenBSD: util.c,v 1.11 2001/03/05 22:34:01 jakob Exp $ */
/*
* Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
@@ -23,7 +23,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /home/cvs/src/usr.sbin/tcpdump/util.c,v 1.10 2000/10/31 16:06:49 deraadt Exp $ (LBL)";
+ "@(#) $Header: /home/cvs/src/usr.sbin/tcpdump/util.c,v 1.11 2001/03/05 22:34:01 jakob Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -138,6 +138,33 @@ ts_print(register const struct timeval *tvp)
}
/*
+ * Print a relative number of seconds (e.g. hold time, prune timer)
+ * in the form 5m1s. This does no truncation, so 32230861 seconds
+ * is represented as 1y1w1d1h1m1s.
+ */
+void
+relts_print(int secs)
+{
+ static char *lengths[] = {"y", "w", "d", "h", "m", "s"};
+ static int seconds[] = {31536000, 604800, 86400, 3600, 60, 1};
+ char **l = lengths;
+ int *s = seconds;
+
+ if (secs <= 0) {
+ (void)printf("0s");
+ return;
+ }
+ while (secs > 0) {
+ if (secs >= *s) {
+ (void)printf("%d%s", secs / *s, *l);
+ secs -= (secs / *s) * *s;
+ }
+ s++;
+ l++;
+ }
+}
+
+/*
* Convert a token value to a string; use "fmt" if not found.
*/
const char *
@@ -272,3 +299,24 @@ read_infile(char *fname)
return (cp);
}
+
+void
+safeputs(const char *s)
+{
+ while (*s) {
+ safeputchar(*s);
+ s++;
+ }
+}
+
+void
+safeputchar(int c)
+{
+ unsigned char ch;
+
+ ch = (unsigned char)(c & 0xff);
+ if (c < 0x80 && isprint(c))
+ printf("%c", c & 0xff);
+ else
+ printf("\\%03o", c & 0xff);
+}