]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-nsh.c
Merge branch 'master' into fix_udp_frag_badlen
[tcpdump] / print-nsh.c
index 0ad1364c30ca555c065d7e06bde88cad7d49c8c7..17d6256925bd1e4b6a36071bc8de354eb733ab7c 100644 (file)
 /* specification: draft-ietf-sfc-nsh-01 */
 
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
-#include <netdissect-stdinc.h>
+#include "netdissect-stdinc.h"
 
 #include "netdissect.h"
 #include "extract.h"
 
-static const char tstr[] = " [|NSH]";
 static const struct tok nsh_flags [] = {
     { 0x20, "O" },
     { 0x10, "C" },
@@ -48,10 +47,10 @@ static const struct tok nsh_flags [] = {
 void
 nsh_print(netdissect_options *ndo, const u_char *bp, u_int len)
 {
-    int n, vn;
+    u_int n, vn;
     uint8_t ver;
     uint8_t flags;
-    uint8_t length;
+    u_int length;
     uint8_t md_type;
     uint8_t next_protocol;
     uint32_t service_path_id;
@@ -62,33 +61,34 @@ nsh_print(netdissect_options *ndo, const u_char *bp, u_int len)
     uint8_t tlv_len;
     u_int next_len;
 
+    ndo->ndo_protocol = "nsh";
     /* print Base Header and Service Path Header */
     if (len < NSH_BASE_HDR_LEN + NSH_SERVICE_PATH_HDR_LEN)
         goto trunc;
 
     ND_TCHECK_LEN(bp, NSH_BASE_HDR_LEN + NSH_SERVICE_PATH_HDR_LEN);
 
-    ver = (uint8_t)(EXTRACT_U_1(bp) >> 6);
-    flags = EXTRACT_U_1(bp);
+    ver = (uint8_t)(GET_U_1(bp) >> 6);
+    flags = GET_U_1(bp);
     bp += 1;
-    length = EXTRACT_U_1(bp);
+    length = GET_U_1(bp);
     bp += 1;
-    md_type = EXTRACT_U_1(bp);
+    md_type = GET_U_1(bp);
     bp += 1;
-    next_protocol = EXTRACT_U_1(bp);
+    next_protocol = GET_U_1(bp);
     bp += 1;
-    service_path_id = EXTRACT_BE_U_3(bp);
+    service_path_id = GET_BE_U_3(bp);
     bp += 3;
-    service_index = EXTRACT_U_1(bp);
+    service_index = GET_U_1(bp);
     bp += 1;
 
     ND_PRINT("NSH, ");
     if (ndo->ndo_vflag > 1) {
-        ND_PRINT("ver %d, ", ver);
+        ND_PRINT("ver %u, ", ver);
     }
     ND_PRINT("flags [%s], ", bittok2str_nosep(nsh_flags, "none", flags));
     if (ndo->ndo_vflag > 2) {
-        ND_PRINT("length %d, ", length);
+        ND_PRINT("length %u, ", length);
         ND_PRINT("md type 0x%x, ", md_type);
     }
     if (ndo->ndo_vflag > 1) {
@@ -117,22 +117,22 @@ nsh_print(netdissect_options *ndo, const u_char *bp, u_int len)
     if (ndo->ndo_vflag > 2) {
         if (md_type == 0x01) {
             for (n = 0; n < length - 2; n++) {
-                ctx = EXTRACT_BE_U_4(bp);
+                ctx = GET_BE_U_4(bp);
                 bp += NSH_HDR_WORD_SIZE;
-                ND_PRINT("\n        Context[%02d]: 0x%08x", n, ctx);
+                ND_PRINT("\n        Context[%02u]: 0x%08x", n, ctx);
             }
         }
         else if (md_type == 0x02) {
             n = 0;
             while (n < length - 2) {
-                tlv_class = EXTRACT_BE_U_2(bp);
+                tlv_class = GET_BE_U_2(bp);
                 bp += 2;
-                tlv_type  = EXTRACT_U_1(bp);
+                tlv_type  = GET_U_1(bp);
                 bp += 1;
-                tlv_len   = EXTRACT_U_1(bp);
+                tlv_len   = GET_U_1(bp);
                 bp += 1;
 
-                ND_PRINT("\n        TLV Class %d, Type %d, Len %d",
+                ND_PRINT("\n        TLV Class %u, Type %u, Len %u",
                           tlv_class, tlv_type, tlv_len);
 
                 n += 1;
@@ -143,9 +143,9 @@ nsh_print(netdissect_options *ndo, const u_char *bp, u_int len)
                 }
 
                 for (vn = 0; vn < tlv_len; vn++) {
-                    ctx = EXTRACT_BE_U_4(bp);
+                    ctx = GET_BE_U_4(bp);
                     bp += NSH_HDR_WORD_SIZE;
-                    ND_PRINT("\n            Value[%02d]: 0x%08x", vn, ctx);
+                    ND_PRINT("\n            Value[%02u]: 0x%08x", vn, ctx);
                 }
                 n += tlv_len;
             }
@@ -170,7 +170,7 @@ nsh_print(netdissect_options *ndo, const u_char *bp, u_int len)
         ip6_print(ndo, bp, next_len);
         break;
     case 0x3:
-        ether_print(ndo, bp, next_len, ndo->ndo_snapend - bp, NULL, NULL);
+        ether_print(ndo, bp, next_len, ND_BYTES_AVAILABLE_AFTER(bp), NULL, NULL);
         break;
     default:
         ND_PRINT("ERROR: unknown-next-protocol");
@@ -180,6 +180,6 @@ nsh_print(netdissect_options *ndo, const u_char *bp, u_int len)
     return;
 
 trunc:
-    ND_PRINT("%s", tstr);
+    nd_print_trunc(ndo);
 }