]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-token.c
OpenFlow: Have a function for each message type.
[tcpdump] / print-token.c
index ff2a38415a601fc2c6d9638795faa045c8c9c4c3..38f56eae894c7553e3a71295bbd4d81c1ed23b13 100644 (file)
 /* \summary: Token Ring printer */
 
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
-#include <netdissect-stdinc.h>
+#include "netdissect-stdinc.h"
 
 #include <string.h>
 
 #define TOKEN_HDRLEN           14
 #define ROUTING_SEGMENT_MAX    16
 #define IS_SOURCE_ROUTED(trp)  ((trp)->token_shost[0] & 0x80)
-#define FRAME_TYPE(trp)                ((EXTRACT_U_1((trp)->token_fc) & 0xC0) >> 6)
+#define FRAME_TYPE(trp)                ((GET_U_1((trp)->token_fc) & 0xC0) >> 6)
 #define TOKEN_FC_LLC           1
 
-#define BROADCAST(trp)         ((EXTRACT_BE_U_2((trp)->token_rcf) & 0xE000) >> 13)
-#define RIF_LENGTH(trp)                ((EXTRACT_BE_U_2((trp)->token_rcf) & 0x1f00) >> 8)
-#define DIRECTION(trp)         ((EXTRACT_BE_U_2((trp)->token_rcf) & 0x0080) >> 7)
-#define LARGEST_FRAME(trp)     ((EXTRACT_BE_U_2((trp)->token_rcf) & 0x0070) >> 4)
-#define RING_NUMBER(trp, x)    ((EXTRACT_BE_U_2((trp)->token_rseg[x]) & 0xfff0) >> 4)
-#define BRIDGE_NUMBER(trp, x)  ((EXTRACT_BE_U_2((trp)->token_rseg[x]) & 0x000f))
+#define BROADCAST(trp)         ((GET_BE_U_2((trp)->token_rcf) & 0xE000) >> 13)
+#define RIF_LENGTH(trp)                ((GET_BE_U_2((trp)->token_rcf) & 0x1f00) >> 8)
+#define DIRECTION(trp)         ((GET_BE_U_2((trp)->token_rcf) & 0x0080) >> 7)
+#define LARGEST_FRAME(trp)     ((GET_BE_U_2((trp)->token_rcf) & 0x0070) >> 4)
+#define RING_NUMBER(trp, x)    ((GET_BE_U_2((trp)->token_rseg[x]) & 0xfff0) >> 4)
+#define BRIDGE_NUMBER(trp, x)  (GET_BE_U_2((trp)->token_rseg[x]) & 0x000f)
 #define SEGMENT_COUNT(trp)     ((int)((RIF_LENGTH(trp) - 2) / 2))
 
 struct token_header {
@@ -89,10 +89,9 @@ struct token_header {
        nd_uint16_t  token_rseg[ROUTING_SEGMENT_MAX];
 };
 
-static const char tstr[] = "[|token-ring]";
 
 /* Extract src, dst addresses */
-static inline void
+static void
 extract_token_addrs(const struct token_header *trp, char *fsrc, char *fdst)
 {
        memcpy(fdst, (const char *)trp->token_dhost, 6);
@@ -102,7 +101,7 @@ extract_token_addrs(const struct token_header *trp, char *fsrc, char *fdst)
 /*
  * Print the TR MAC header
  */
-static inline void
+static void
 token_hdr_print(netdissect_options *ndo,
                 const struct token_header *trp, u_int length,
                 const u_char *fsrc, const u_char *fdst)
@@ -113,12 +112,12 @@ token_hdr_print(netdissect_options *ndo,
        dstname = etheraddr_string(ndo, fdst);
 
        if (!ndo->ndo_qflag)
-               ND_PRINT((ndo, "%02x %02x ",
-                      EXTRACT_U_1(trp->token_ac),
-                      EXTRACT_U_1(trp->token_fc)));
-       ND_PRINT((ndo, "%s > %s, length %u: ",
+               ND_PRINT("%02x %02x ",
+                      GET_U_1(trp->token_ac),
+                      GET_U_1(trp->token_fc));
+       ND_PRINT("%s > %s, length %u: ",
               srcname, dstname,
-              length));
+              length);
 }
 
 static const char *broadcast_indicator[] = {
@@ -153,10 +152,11 @@ token_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen
        u_int route_len = 0, hdr_len = TOKEN_HDRLEN;
        int seg;
 
+       ndo->ndo_protocol = "token";
        trp = (const struct token_header *)p;
 
        if (caplen < TOKEN_HDRLEN) {
-               ND_PRINT((ndo, "%s", tstr));
+               nd_print_trunc(ndo);
                return hdr_len;
        }
 
@@ -174,29 +174,30 @@ token_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen
                        token_hdr_print(ndo, trp, length, srcmac, dstmac);
 
                if (caplen < TOKEN_HDRLEN + 2) {
-                       ND_PRINT((ndo, "%s", tstr));
+                       nd_print_trunc(ndo);
                        return hdr_len;
                }
                route_len = RIF_LENGTH(trp);
                hdr_len += route_len;
                if (caplen < hdr_len) {
-                       ND_PRINT((ndo, "%s", tstr));
+                       nd_print_trunc(ndo);
                        return hdr_len;
                }
                if (ndo->ndo_vflag) {
-                       ND_PRINT((ndo, "%s ", broadcast_indicator[BROADCAST(trp)]));
-                       ND_PRINT((ndo, "%s", direction[DIRECTION(trp)]));
+                       ND_PRINT("%s ", broadcast_indicator[BROADCAST(trp)]);
+                       ND_PRINT("%s", direction[DIRECTION(trp)]);
 
                        for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
-                               ND_PRINT((ndo, " [%d:%d]", RING_NUMBER(trp, seg),
-                                   BRIDGE_NUMBER(trp, seg)));
+                               ND_PRINT(" [%u:%u]", RING_NUMBER(trp, seg),
+                                   BRIDGE_NUMBER(trp, seg));
                } else {
-                       ND_PRINT((ndo, "rt = %x", EXTRACT_BE_U_2(trp->token_rcf)));
+                       ND_PRINT("rt = %x", GET_BE_U_2(trp->token_rcf));
 
                        for (seg = 0; seg < SEGMENT_COUNT(trp); seg++)
-                               ND_PRINT((ndo, ":%x", EXTRACT_BE_U_2(trp->token_rseg[seg])));
+                               ND_PRINT(":%x",
+                                        GET_BE_U_2(trp->token_rseg[seg]));
                }
-               ND_PRINT((ndo, " (%s) ", largest_frame[LARGEST_FRAME(trp)]));
+               ND_PRINT(" (%s) ", largest_frame[LARGEST_FRAME(trp)]);
        } else {
                if (ndo->ndo_eflag)
                        token_hdr_print(ndo, trp, length, srcmac, dstmac);
@@ -241,8 +242,9 @@ token_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen
  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
  * is the number of bytes actually captured.
  */
-u_int
+void
 token_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
 {
-       return (token_print(ndo, p, h->len, h->caplen));
+       ndo->ndo_protocol = "token";
+       ndo->ndo_ll_hdr_len += token_print(ndo, p, h->len, h->caplen);
 }