]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-rx.c
added "make check"
[tcpdump] / print-rx.c
index 20ea3b33deac2d960176555b864cafbf87376576..23f1d9e0f87db217ae2dc0c24c6422942209f6b2 100644 (file)
@@ -33,8 +33,8 @@
  */
 
 #ifndef lint
-static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-rx.c,v 1.33 2002-09-05 00:00:19 guy Exp $";
+static const char rcsid[] _U_ =
+    "@(#) $Header: /tcpdump/master/tcpdump/print-rx.c,v 1.39 2007-06-15 19:43:39 guy Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -375,6 +375,7 @@ static struct tok rx_ack_reasons[] = {
        { 6,            "ping" },
        { 7,            "ping response" },
        { 8,            "delay" },
+       { 9,            "idle" },
        { 0,            NULL },
 };
 
@@ -398,11 +399,10 @@ static struct rx_cache_entry      rx_cache[RX_CACHE_SIZE];
 
 static int     rx_cache_next = 0;
 static int     rx_cache_hint = 0;
-static void    rx_cache_insert(const u_char *, const struct ip *, int, int);
+static void    rx_cache_insert(const u_char *, const struct ip *, 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 *, int, u_char *);
@@ -418,7 +418,7 @@ static void vol_print(const u_char *, int);
 static void vol_reply_print(const u_char *, int, int32_t);
 static void bos_print(const u_char *, int);
 static void bos_reply_print(const u_char *, int, int32_t);
-static void ubik_print(const u_char *, int);
+static void ubik_print(const u_char *);
 static void ubik_reply_print(const u_char *, int, int32_t);
 
 static void rx_ack_print(const u_char *, int);
@@ -489,9 +489,7 @@ rx_print(register const u_char *bp, int length, int sport, int dport,
         * as well.
         */
 
-       if (rxh->type == RX_PACKET_TYPE_ACK)
-           ack_print(bp, length);
-       else if (rxh->type == RX_PACKET_TYPE_DATA &&
+       if (rxh->type == RX_PACKET_TYPE_DATA &&
            EXTRACT_32BITS(&rxh->seq) == 1 &&
            rxh->flags & RX_CLIENT_INITIATED) {
 
@@ -500,7 +498,7 @@ rx_print(register const u_char *bp, int length, int sport, int dport,
                 * have a chance to print out replies
                 */
 
-               rx_cache_insert(bp, (const struct ip *) bp2, dport, length);
+               rx_cache_insert(bp, (const struct ip *) bp2, dport);
 
                switch (dport) {
                        case FS_RX_PORT:        /* AFS file service */
@@ -586,8 +584,7 @@ rx_print(register const u_char *bp, int length, int sport, int dport,
  */
 
 static void
-rx_cache_insert(const u_char *bp, const struct ip *ip, int dport,
-               int length)
+rx_cache_insert(const u_char *bp, const struct ip *ip, int dport)
 {
        struct rx_cache_entry *rxent;
        const struct rx_header *rxh = (const struct rx_header *) bp;
@@ -766,75 +763,6 @@ rx_cache_find(const struct rx_header *rxh, const struct ip *ip, int sport,
                        printf("\""); \
                }
 
-static void
-ack_print(register const u_char *bp, int length)
-{
-        u_char nAcks;
-       int i;
-
-       if (vflag <= 1)
-               return;
-
-       if (length <= (int)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)
  */
@@ -1085,6 +1013,7 @@ acl_print(u_char *s, int maxsize, u_char *end)
        int pos, neg, acl;
        int n, i;
        char *user;
+       char fmt[1024];
 
        if ((user = (char *)malloc(maxsize)) == NULL)
                return;
@@ -1118,7 +1047,8 @@ acl_print(u_char *s, int maxsize, u_char *end)
                printf("a");
 
        for (i = 0; i < pos; i++) {
-               if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2)
+               snprintf(fmt, sizeof(fmt), "%%%ds %%d\n%%n", maxsize - 1);
+               if (sscanf((char *) s, fmt, user, &acl, &n) != 2)
                        goto finish;
                s += n;
                printf(" +{");
@@ -1131,7 +1061,8 @@ acl_print(u_char *s, int maxsize, u_char *end)
        }
 
        for (i = 0; i < neg; i++) {
-               if (sscanf((char *) s, "%s %d\n%n", user, &acl, &n) != 2)
+               snprintf(fmt, sizeof(fmt), "%%%ds %%d\n%%n", maxsize - 1);
+               if (sscanf((char *) s, fmt, user, &acl, &n) != 2)
                        goto finish;
                s += n;
                printf(" -{");
@@ -1308,7 +1239,7 @@ prot_print(register const u_char *bp, int length)
        printf(" pt");
 
        if (is_ubik(pt_op)) {
-               ubik_print(bp, length);
+               ubik_print(bp);
                return;
        }
 
@@ -1562,7 +1493,7 @@ vldb_print(register const u_char *bp, int length)
        printf(" vldb");
 
        if (is_ubik(vldb_op)) {
-               ubik_print(bp, length);
+               ubik_print(bp);
                return;
        }
        printf(" call %s", tok2str(vldb_req, "op#%d", vldb_op));
@@ -1841,7 +1772,7 @@ kauth_print(register const u_char *bp, int length)
        printf(" kauth");
 
        if (is_ubik(kauth_op)) {
-               ubik_print(bp, length);
+               ubik_print(bp);
                return;
        }
 
@@ -2195,7 +2126,7 @@ is_ubik(u_int32_t opcode)
  */
 
 static void
-ubik_print(register const u_char *bp, int length)
+ubik_print(register const u_char *bp)
 {
        int ubik_op;
        int32_t temp;
@@ -2371,6 +2302,7 @@ rx_ack_print(register const u_char *bp, int length)
 {
        struct rx_ackPacket *rxa;
        int i, start, last;
+       u_int32_t firstPacket;
 
        if (length < (int)sizeof(struct rx_header))
                return;
@@ -2399,8 +2331,9 @@ rx_ack_print(register const u_char *bp, int length)
                       (int) EXTRACT_16BITS(&rxa->bufferSpace),
                       (int) EXTRACT_16BITS(&rxa->maxSkew));
 
+       firstPacket = EXTRACT_32BITS(&rxa->firstPacket);
        printf(" first %d serial %d reason %s",
-              EXTRACT_32BITS(&rxa->firstPacket), EXTRACT_32BITS(&rxa->serial),
+              firstPacket, EXTRACT_32BITS(&rxa->serial),
               tok2str(rx_ack_reasons, "#%d", (int) rxa->reason));
 
        /*
@@ -2443,7 +2376,7 @@ rx_ack_print(register const u_char *bp, int length)
 
                                if (last == -2) {
                                        printf(" acked %d",
-                                              rxa->firstPacket + i);
+                                              firstPacket + i);
                                        start = i;
                                }
 
@@ -2457,7 +2390,7 @@ rx_ack_print(register const u_char *bp, int length)
                                 */
 
                                else if (last != i - 1) {
-                                       printf(",%d", rxa->firstPacket + i);
+                                       printf(",%d", firstPacket + i);
                                        start = i;
                                }
 
@@ -2483,7 +2416,7 @@ rx_ack_print(register const u_char *bp, int length)
                                 * range.
                                 */
                        } else if (last == i - 1 && start != last)
-                               printf("-%d", rxa->firstPacket + i - 1);
+                               printf("-%d", firstPacket + i - 1);
 
                /*
                 * So, what's going on here?  We ran off the end of the
@@ -2497,7 +2430,7 @@ rx_ack_print(register const u_char *bp, int length)
                 */
 
                if (last == i - 1 && start != last)
-                       printf("-%d", rxa->firstPacket + i - 1);
+                       printf("-%d", firstPacket + i - 1);
 
                /*
                 * Same as above, just without comments
@@ -2507,18 +2440,18 @@ rx_ack_print(register const u_char *bp, int length)
                        if (rxa->acks[i] == RX_ACK_TYPE_NACK) {
                                if (last == -2) {
                                        printf(" nacked %d",
-                                              rxa->firstPacket + i);
+                                              firstPacket + i);
                                        start = i;
                                } else if (last != i - 1) {
-                                       printf(",%d", rxa->firstPacket + i);
+                                       printf(",%d", firstPacket + i);
                                        start = i;
                                }
                                last = i;
                        } else if (last == i - 1 && start != last)
-                               printf("-%d", rxa->firstPacket + i - 1);
+                               printf("-%d", firstPacket + i - 1);
 
                if (last == i - 1 && start != last)
-                       printf("-%d", rxa->firstPacket + i - 1);
+                       printf("-%d", firstPacket + i - 1);
 
                bp += rxa->nAcks;
        }