]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-rx.c
Fix the spacing of the UDP checksum reporting.
[tcpdump] / print-rx.c
index 97adf46e22ee65e097c39b665d0850bd49454d73..2fb3d2a8a96213273bdfe563d446342ab52de184 100644 (file)
@@ -13,7 +13,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-rx.c,v 1.13 2000-07-22 17:32:32 assar Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-rx.c,v 1.20 2001-01-10 08:12:01 fenner Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -21,6 +21,7 @@ static const char rcsid[] =
 #endif
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <time.h>
 #include <sys/param.h>
@@ -28,8 +29,6 @@ static const char rcsid[] =
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
 #include <arpa/inet.h>
 
 #include "interface.h"
@@ -41,6 +40,8 @@ static const char rcsid[] =
 
 #include "rx.h"
 
+#include "ip.h"
+
 static struct tok rx_types[] = {
        { RX_PACKET_TYPE_DATA,          "data" },
        { RX_PACKET_TYPE_ACK,           "ack" },
@@ -374,9 +375,10 @@ static void        rx_cache_insert(const u_char *, const struct ip *, int, int);
 static int     rx_cache_find(const struct rx_header *, const struct ip *,
                              int, int32_t *);
 
+static void ack_print(const u_char *, int);
 static void fs_print(const u_char *, int);
 static void fs_reply_print(const u_char *, int, int32_t);
-static void acl_print(u_char *, u_char *);
+static void acl_print(u_char *, int, u_char *);
 static void cb_print(const u_char *, int);
 static void cb_reply_print(const u_char *, int, int32_t);
 static void prot_print(const u_char *, int);
@@ -458,7 +460,9 @@ rx_print(register const u_char *bp, int length, int sport, int dport,
         * as well.
         */
 
-       if (rxh->type == RX_PACKET_TYPE_DATA &&
+       if (rxh->type == RX_PACKET_TYPE_ACK)
+           ack_print(bp, length);
+       else if (rxh->type == RX_PACKET_TYPE_DATA &&
            EXTRACT_32BITS(&rxh->seq) == 1 &&
            rxh->flags & RX_CLIENT_INITIATED) {
 
@@ -726,11 +730,80 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, int sport,
                        printf(" \"%s\"", s); \
                }
 
+static void
+ack_print(register const u_char *bp, int length)
+{
+        u_char nAcks;
+       int i;
+
+       if (vflag <= 1)
+               return;
+
+       if (length <= sizeof(struct rx_header))
+               return;
+
+       bp += sizeof(struct rx_header);
+
+       /*
+        * Packets < firstPacket are implicitly acknowledged and may
+        * be discarded by the sender.
+        *
+        * Packets >= firstPacket+nAcks are implicitly NOT acknowledged.
+        *
+        * No packets with sequence numbers >= firstPacket should be
+        * discarded by the sender (they may thrown out at any time by
+        * the receiver)
+        */
+#define RX_ACK_REASONS "RDOXSprn"
+       /* Requested, Duplicate, Out_of_sequence, eXceeds_window, no_Space,
+        * Ping, ping_Response, No_{progress, particular_reason}.
+        */
+#if 0
+       struct rx_ackPacket {
+         u_short bufferSpace;  /* Skip! */
+         u_short maxSkew;      /* Skip! */
+         u_long  firstPacket;
+         u_long  previousPacket; /* Obsolete! */
+         u_long  serial;       /* Serial that prompted the ack, */
+         u_char  reason;       /* and the reason why. */
+         u_char  nAcks;
+         u_char  acks[RX_MAXACKS]; /* Selective acks (not a bitmap). */
+       };
+#endif
+#define RX_ACK_TYPE_NACK 0
+
+       TCHECK2(bp[0], 8);      /* bufferSpace and maxSkew */
+       bp += 4;
+       printf(" fir %u", (unsigned)EXTRACT_32BITS(bp));
+       bp += 4;
+       TCHECK2(bp[0], 8);      /* previousPacket and serial */
+       bp += 4;
+       printf(" %u", (unsigned)EXTRACT_32BITS(bp));
+       bp += 4;
+       TCHECK2(bp[0], 1);
+       printf("%c", RX_ACK_REASONS[(*bp - 1) & 07u]);
+       bp += 1;                /* reason */
+       TCHECK2(bp[0], 1);
+       nAcks = *bp;
+       bp += 1;                /* nAcks */
+
+       for (i = 0; i < nAcks; i++) {
+           TCHECK2(bp[0], 1);
+           putchar(*bp == RX_ACK_TYPE_NACK? '-' : '*');
+           bp += 1;
+       }
+       
+       return;
+
+trunc:
+       printf(" [|ack]");
+}
+
 /*
  * Handle calls to the AFS file service (fs)
  */
 
-void
+static void
 fs_print(register const u_char *bp, int length)
 {
        int fs_op;
@@ -798,15 +871,16 @@ fs_print(register const u_char *bp, int length)
                        break;
                case 134:       /* Store ACL */
                {
-                       char a[AFSOPAQUEMAX];
+                       char a[AFSOPAQUEMAX+1];
                        FIDOUT();
                        TCHECK2(bp[0], 4);
                        i = EXTRACT_32BITS(bp);
                        bp += sizeof(int32_t);
                        TCHECK2(bp[0], i);
-                       strncpy(a, (char *) bp, min(AFSOPAQUEMAX, i));
+                       i = min(AFSOPAQUEMAX, i);
+                       strncpy(a, (char *) bp, i);
                        a[i] = '\0';
-                       acl_print((u_char *) a, (u_char *) a + i);
+                       acl_print((u_char *) a, sizeof(a), (u_char *) a + i);
                        break;
                }
                case 137:       /* Create file */
@@ -910,14 +984,15 @@ fs_reply_print(register const u_char *bp, int length, int32_t opcode)
                switch (opcode) {
                case 131:       /* Fetch ACL */
                {
-                       char a[AFSOPAQUEMAX];
+                       char a[AFSOPAQUEMAX+1];
                        TCHECK2(bp[0], 4);
                        i = EXTRACT_32BITS(bp);
                        bp += sizeof(int32_t);
                        TCHECK2(bp[0], i);
-                       strncpy(a, (char *) bp, min(AFSOPAQUEMAX, i));
+                       i = min(AFSOPAQUEMAX, i);
+                       strncpy(a, (char *) bp, i);
                        a[i] = '\0';
-                       acl_print((u_char *) a, (u_char *) a + i);
+                       acl_print((u_char *) a, sizeof(a), (u_char *) a + i);
                        break;
                }
                case 137:       /* Create file */
@@ -971,19 +1046,22 @@ trunc:
  */
 
 static void
-acl_print(u_char *s, u_char *end)
+acl_print(u_char *s, int maxsize, u_char *end)
 {
        int pos, neg, acl;
        int n, i;
-       char user[128];
+       char *user;
 
-       if (sscanf((char *) s, "%d %d\n%n", &pos, &neg, &n) != 2)
+       if ((user = (char *)malloc(maxsize)) == NULL)
                return;
+
+       if (sscanf((char *) s, "%d %d\n%n", &pos, &neg, &n) != 2)
+               goto finish;
        
        s += n;
 
        if (s > end)
-               return;
+               goto finish;
 
        /*
         * This wacky order preserves the order used by the "fs" command
@@ -1007,25 +1085,29 @@ acl_print(u_char *s, u_char *end)
 
        for (i = 0; i < pos; i++) {
                if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2)
-                       return;
+                       goto finish;
                s += n;
                printf(" +{%s ", user);
                ACLOUT(acl);
                printf("}");
                if (s > end)
-                       return;
+                       goto finish;
        }
 
        for (i = 0; i < neg; i++) {
                if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2)
-                       return;
+                       goto finish;
                s += n;
                printf(" -{%s ", user);
                ACLOUT(acl);
                printf("}");
                if (s > end)
-                       return;
+                       goto finish;
        }
+
+finish:
+       free(user);
+       return;
 }
 
 #undef ACLOUT
@@ -2252,7 +2334,7 @@ trunc:
  * Handle RX ACK packets.
  */
 
-void
+static void
 rx_ack_print(register const u_char *bp, int length)
 {
        struct rx_ackPacket *rxa;