I thought it would be useful to print the ICMP echo request/reply
payload timeval struct.  This is a first try at that.  I'm sure there
are issues with this, but I thought I'd see what folks thought about
it.  This also prints ICMP id.

19:40:49.917201 IP (tos 0x0, ttl 255, len 84) 172.31.1.53 > 64.58.79.230: icmp 64: 
echo request id 847 seq 0 time 07/29/2002 19:43:32.597118 
19:40:50.031097 IP (tos 0x0, ttl 231, len 84) 64.58.79.230 > 172.31.1.53: icmp 64: 
echo reply id 847 seq 0 time 07/29/2002 19:43:32.597118

Index: interface.h
===================================================================
RCS file: /tcpdump/master/tcpdump/interface.h,v
retrieving revision 1.192
diff -u -r1.192 interface.h
--- interface.h 2002/07/21 20:48:26     1.192
+++ interface.h 2002/07/30 02:41:02
@@ -154,6 +154,7 @@
 #define TCHECK(var) TCHECK2(var, sizeof(var))
 
 extern void ts_print(const struct timeval *);
+extern const char *ts_format(int tval, const struct timeval *);
 extern void relts_print(int);
 
 extern int fn_print(const u_char *, const u_char *);
Index: print-icmp.c
===================================================================
RCS file: /tcpdump/master/tcpdump/print-icmp.c,v
retrieving revision 1.67
diff -u -r1.67 print-icmp.c
--- print-icmp.c        2002/07/21 21:03:07     1.67
+++ print-icmp.c        2002/07/30 02:41:03
@@ -284,15 +284,24 @@
        switch (dp->icmp_type) {
 
        case ICMP_ECHO:
-               TCHECK(dp->icmp_seq);
-               (void)snprintf(buf, sizeof(buf), "echo request seq %u",
-                       (unsigned)ntohs(dp->icmp_seq));
-               break;
-
        case ICMP_ECHOREPLY:
                TCHECK(dp->icmp_seq);
-               (void)snprintf(buf, sizeof(buf), "echo reply seq %u",
+               (void)snprintf(buf, sizeof(buf), "echo %s id %u seq %u",
+                       dp->icmp_type == ICMP_ECHO ?
+                       "request" : "reply",
+                       (unsigned)ntohs(dp->icmp_id),
                        (unsigned)ntohs(dp->icmp_seq));
+               if (vflag) {
+                       struct timeval tv;
+
+                       TCHECK2(dp->icmp_data[0], sizeof tv);
+                       /* XXX long */
+                       tv.tv_sec = EXTRACT_32BITS(&dp->icmp_data[0]);
+                       tv.tv_usec = EXTRACT_32BITS(&dp->icmp_data[sizeof tv.tv_sec]);
+                       /* XXX sane time? */
+                       strlcat(buf, " time ", sizeof(buf));
+                       strlcat(buf, ts_format(-3, &tv), sizeof(buf));
+               }
                break;
 
        case ICMP_UNREACH:
Index: util.c
===================================================================
RCS file: /tcpdump/master/tcpdump/util.c,v
retrieving revision 1.76
diff -u -r1.76 util.c
--- util.c      2002/07/18 00:04:12     1.76
+++ util.c      2002/07/30 02:41:10
@@ -121,27 +121,38 @@
 void
 ts_print(register const struct timeval *tvp)
 {
+       if (tflag != 0)
+               (void)printf("%s", ts_format(tflag, tvp));
+}
+
+const char *ts_format(int tflag, register const struct timeval *tvp)
+{
+       static char buf[100];
+       char buf2[100];
        register int s;
        struct tm *tm;
        time_t Time;
        static unsigned b_sec;
        static unsigned b_usec;
 
+       buf[0] = '\0';
        switch(tflag) {
+       case 0: /* XXX thiszone */
        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);
+               (void)snprintf(buf, sizeof(buf),
+                       "%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);
+               (void)snprintf(buf, sizeof(buf), "%u.%06u ",
+                       (unsigned)tvp->tv_sec,
+                       (unsigned)tvp->tv_usec);
                break;
        case -2:
                if (b_sec == 0) {
-                       printf("000000 ");
+                       (void)snprintf(buf, sizeof(buf), "000000 ");
                } else {
                        int d_usec = tvp->tv_usec - b_usec;
                        int d_sec = tvp->tv_sec - b_sec;
@@ -151,8 +162,11 @@
                                d_sec--;
                        }
                        if (d_sec)
-                               printf("%d. ", d_sec);
-                       printf("%06d ", d_usec);
+                               (void)snprintf(buf, sizeof(buf),
+                                       "%d. ", d_sec);
+                       (void)snprintf(buf2, sizeof(buf2),
+                               "%06d ", d_usec);
+                       strlcat(buf, buf2, sizeof(buf));
                }
                b_sec = tvp->tv_sec;
                b_usec = tvp->tv_usec;
@@ -161,13 +175,15 @@
                s = (tvp->tv_sec + thiszone) % 86400;
                Time = (tvp->tv_sec + thiszone) - s;
                tm  = gmtime (&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);
+               (void)snprintf(buf, sizeof(buf),
+                       "%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;
        }
+       return buf;
 }
 
 /*
-
This is the TCPDUMP workers list. It is archived at
http://www.tcpdump.org/lists/workers/index.html
To unsubscribe use mailto:[EMAIL PROTECTED]?body=unsubscribe

Reply via email to