]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-token.c
Add SunATM support, based on code from Yen Yen Lim at North Dakota State
[tcpdump] / print-token.c
index 0f4afedbd1725f93c5d99bb15a9801d831339b63..033bf6507d15e5c239de04a2beb9a98844fd6dd5 100644 (file)
@@ -25,7 +25,7 @@
  */
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.14 2002-04-07 09:50:33 guy Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-token.c,v 1.16 2002-06-11 17:08:57 itojun Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -101,19 +101,19 @@ static const char *largest_frame[] = {
        "??"
 };
 
-void
+u_int
 token_print(const u_char *p, u_int length, u_int caplen)
 {
        const struct token_header *trp;
        u_short extracted_ethertype;
        struct ether_header ehdr;
-       u_int route_len = 0, seg;
+       u_int route_len = 0, hdr_len = TOKEN_HDRLEN, seg;
 
        trp = (const struct token_header *)p;
 
        if (caplen < TOKEN_HDRLEN) {
                printf("[|token-ring]");
-               goto out;
+               return hdr_len;
        }
        /*
         * Get the TR addresses into a canonical form
@@ -145,13 +145,13 @@ token_print(const u_char *p, u_int length, u_int caplen)
                if (vflag) {
                        printf("%s ", broadcast_indicator[BROADCAST(trp)]);
                        printf("%s", direction[DIRECTION(trp)]);
-     
+
                        for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
                                printf(" [%d:%d]", RING_NUMBER(trp, seg),
                                    BRIDGE_NUMBER(trp, seg));
                } else {
                        printf("rt = %x", ntohs(trp->token_rcf));
+
                        for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
                                printf(":%x", ntohs(trp->token_rseg[seg]));
                }
@@ -162,9 +162,10 @@ token_print(const u_char *p, u_int length, u_int caplen)
        }
 
        /* Skip over token ring MAC header and routing information */
-       length -= TOKEN_HDRLEN + route_len;
-       p += TOKEN_HDRLEN + route_len;
-       caplen -= TOKEN_HDRLEN + route_len;
+       hdr_len += route_len;
+       length -= hdr_len;
+       p += hdr_len;
+       caplen -= hdr_len;
 
        /* Frame Control field determines interpretation of packet */
        extracted_ethertype = 0;
@@ -193,10 +194,7 @@ token_print(const u_char *p, u_int length, u_int caplen)
                if (!xflag && !qflag)
                        default_print(p, caplen);
        }
-       if (xflag)
-               default_print(p, caplen);
-out:
-       putchar('\n');
+       return (hdr_len);
 }
 
 /*
@@ -210,11 +208,21 @@ token_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
 {
        u_int caplen = h->caplen;
        u_int length = h->len;
+       u_int hdr_len;
 
        ++infodelay;
        ts_print(&h->ts);
 
-       token_print(p, length, caplen);
+       hdr_len = token_print(p, length, caplen);
+
+       /*
+        * If "-x" was specified, print stuff past the Token Ring header,
+        * if there's anything to print.
+        */
+       if (xflag && caplen > hdr_len)
+               default_print(p + hdr_len, caplen - hdr_len);
+
+       putchar('\n');
 
        --infodelay;
        if (infoprint)