]> The Tcpdump Group git mirrors - tcpdump/commitdiff
avoid possible infinite loop in relts_print().
authoritojun <itojun>
Sat, 3 Jun 2000 16:40:35 +0000 (16:40 +0000)
committeritojun <itojun>
Sat, 3 Jun 2000 16:40:35 +0000 (16:40 +0000)
move safeputchar() and safeputs() into util.c for better code sharing.
some style.

interface.h
print-icmp6.c
print-telnet.c
util.c

index a45186d04f7cf7e3364a86b4d5b30892f965a5f8..a0313d7fcbff138279f811c27d9045945491671a 100644 (file)
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.126 2000-06-01 01:14:43 assar Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.127 2000-06-03 16:40:35 itojun Exp $ (LBL)
  */
 
 #ifndef tcpdump_interface_h
@@ -209,6 +209,9 @@ extern void warning(const char *, ...) __attribute__ ((format (printf, 1, 2)));
 extern char *read_infile(char *);
 extern char *copy_argv(char **);
 
+extern void safeputchar(int);
+extern void safeputs(const char *);
+
 extern char *isonsap_string(const u_char *);
 extern char *llcsap_string(u_char);
 extern char *protoid_string(const u_char *);
index 0222fd59b58d33c640934c9bc1e051fc85caf7d6..972e8e728bb10b7614ad76c59338d841dd2a74c8 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.15 2000-05-28 04:23:14 itojun Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.16 2000-06-03 16:40:35 itojun Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -578,10 +578,6 @@ mld6_print(register const u_char *bp)
 #endif
 
 #ifdef HAVE_STRUCT_ICMP6_NODEINFO
-#define safeputc(c) \
-    printf((((unsigned char)c) < 0x80 && isprint((c)) ? "%c" : "\\%03o"), \
-       ((unsigned char)c) & 0xff)
-
 static void
 dnsname_print(const u_char *cp, const u_char *ep)
 {
@@ -597,7 +593,7 @@ dnsname_print(const u_char *cp, const u_char *ep)
                                break;
                        }
                        while (i-- && cp < ep) {
-                               safeputc(*cp);
+                               safeputchar(*cp);
                                cp++;
                        }
                        if (cp + 1 < ep && *cp)
@@ -717,7 +713,7 @@ icmp6_nodeinfo_print(int icmp6len, const u_char *bp, const u_char *ep)
                                cp++;
                                printf(", \"");
                                while (cp < ep) {
-                                       safeputc(*cp);
+                                       safeputchar(*cp);
                                        cp++;
                                }
                                printf("\"");
@@ -800,7 +796,7 @@ icmp6_nodeinfo_print(int icmp6len, const u_char *bp, const u_char *ep)
                                cp++;
                                printf(", \"");
                                while (cp < ep) {
-                                       safeputc(*cp);
+                                       safeputchar(*cp);
                                        cp++;
                                }
                                printf("\"");
@@ -842,7 +838,6 @@ icmp6_nodeinfo_print(int icmp6len, const u_char *bp, const u_char *ep)
 trunc:
        fputs("[|icmp6]", stdout);
 }
-#undef safeputc
 #endif
 
 #endif /* INET6 */
index ab8351f28f00ab2decf54cf55c53f86a971f4288..e0db8ee9ea8ae0d7f4ed1252a9994273dba31723 100644 (file)
@@ -51,7 +51,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.7 2000-05-28 04:23:14 itojun Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.8 2000-06-03 16:40:35 itojun Exp $";
 #endif
 
 #include <sys/param.h>
@@ -83,22 +83,6 @@ static const char rcsid[] =
 # define TELCMD_FIRST SE
 #endif
 
-static void safeputs __P((const char *));
-
-#define safeputc(c) \
-    printf((((unsigned char)c) < 0x80 && isprint((c)) ? "%c" : "\\%03o"), \
-       ((unsigned char)c) & 0xff)
-
-static void
-safeputs(s)
-       const char *s;
-{
-       while (*s) {
-               safeputc(*s);
-               s++;
-       }
-}
-
 void
 telnet_print(register const u_char *sp, u_int length)
 {
diff --git a/util.c b/util.c
index fd8843c376c105101f5d37969be87dbc9e46950c..efb6b0e9547763e33427b855a645f951b07c0fc1 100644 (file)
--- a/util.c
+++ b/util.c
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.64 2000-06-01 01:13:53 assar Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.65 2000-06-03 16:40:36 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -134,47 +134,46 @@ ts_print(register const struct timeval *tvp)
        static unsigned b_sec;
        static unsigned b_usec;
 
-       switch(tflag)
-       {
-               case 1: /* Default */
-                       s = (tvp->tv_sec + thiszone) % 86400;
-                       (void)printf("%02d:%02d:%02d.%06u ",
-                                    s / 3600, (s % 3600) / 60, s % 60,
-                                    (unsigned)tvp->tv_usec);
-                       break;
-               case -1: /* Unix timeval style */
-                       (void)printf("%u.%06u ",
-                                    (unsigned)tvp->tv_sec,
-                                    (unsigned)tvp->tv_usec);
-                       break;
-               case -2:
-                       if (b_sec == 0) {
-                               printf("000000 ");
-                       } else {
-                               int d_usec = tvp->tv_usec - b_usec;
-                               int d_sec = tvp->tv_sec - b_sec;
-                               
-                               while (d_usec < 0) {
-                                       d_usec += 1000000;
-                                       d_sec--;
-                               }
-                               if (d_sec)
-                                       printf("%d. ", d_sec);
-                               printf("%06d ", d_usec);
+       switch(tflag) {
+       case 1: /* Default */
+               s = (tvp->tv_sec + thiszone) % 86400;
+               (void)printf("%02d:%02d:%02d.%06u ",
+                            s / 3600, (s % 3600) / 60, s % 60,
+                            (unsigned)tvp->tv_usec);
+               break;
+       case -1: /* Unix timeval style */
+               (void)printf("%u.%06u ",
+                            (unsigned)tvp->tv_sec,
+                            (unsigned)tvp->tv_usec);
+               break;
+       case -2:
+               if (b_sec == 0) {
+                       printf("000000 ");
+               } else {
+                       int d_usec = tvp->tv_usec - b_usec;
+                       int d_sec = tvp->tv_sec - b_sec;
+                       
+                       while (d_usec < 0) {
+                               d_usec += 1000000;
+                               d_sec--;
                        }
-                       b_sec = tvp->tv_sec;
-                       b_usec = tvp->tv_usec;
-                       break;
-               case -3: /* Default + Date*/
-                       s = (tvp->tv_sec + thiszone) % 86400;
-                       time(&Time);
-                       tm = localtime(&Time);
-                       (void)printf("%02d/%02d/%04d %02d:%02d:%02d.%06u ",
-                                    tm->tm_mon+1, tm->tm_mday,
-                                    tm->tm_year+1900,
-                                    s / 3600, (s % 3600) / 60,
-                                    s % 60, (unsigned)tvp->tv_usec);
-                       break;
+                       if (d_sec)
+                               printf("%d. ", d_sec);
+                       printf("%06d ", d_usec);
+               }
+               b_sec = tvp->tv_sec;
+               b_usec = tvp->tv_usec;
+               break;
+       case -3: /* Default + Date*/
+               s = (tvp->tv_sec + thiszone) % 86400;
+               time(&Time);
+               tm = localtime(&Time);
+               (void)printf("%02d/%02d/%04d %02d:%02d:%02d.%06u ",
+                            tm->tm_mon+1, tm->tm_mday,
+                            tm->tm_year+1900,
+                            s / 3600, (s % 3600) / 60,
+                            s % 60, (unsigned)tvp->tv_usec);
+               break;
        }
 }
 
@@ -186,22 +185,23 @@ ts_print(register const struct timeval *tvp)
 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) {
-       if (secs >= *s) {
-           (void)printf("%d%s", secs / *s, *l);
-           secs -= (secs / *s) * *s;
+       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++;
        }
-       s++; l++;
-    }
 }
 
 /*
@@ -339,3 +339,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("\\%03o", c & 0xff);
+       else
+               printf("%c", c & 0xff);
+}