]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-egp.c
icmp: clean up the extension code and comments.
[tcpdump] / print-egp.c
index 28adf7de166b0860c02df80f2ddd7849ab004424..526e36dde6563167559d04dbfca20b06d5d85445 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "addrtoname.h"
 #include "extract.h"
@@ -179,7 +180,7 @@ egpnr_print(netdissect_options *ndo,
                /* Pickup host part of gateway address */
                addr = 0;
                if (length < 4 - netlen)
-                       goto trunc;
+                       goto invalid;
                ND_TCHECK_LEN(cp, 4 - netlen);
                switch (netlen) {
 
@@ -199,19 +200,19 @@ egpnr_print(netdissect_options *ndo,
                addr |= net;
                length -= 4 - netlen;
                if (length < 1)
-                       goto trunc;
+                       goto invalid;
                distances = GET_U_1(cp);
                cp++;
                length--;
                ND_PRINT(" %s %s ",
                       gateways < intgw ? "int" : "ext",
-                      ipaddr_string(ndo, (const u_char *)&addr));
+                      ipaddr_string(ndo, (const u_char *)&addr)); /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
 
                comma = "";
                ND_PRINT("(");
                while (distances != 0) {
                        if (length < 2)
-                               goto trunc;
+                               goto invalid;
                        ND_PRINT("%sd%u:", comma, GET_U_1(cp));
                        cp++;
                        comma = ", ";
@@ -221,26 +222,26 @@ egpnr_print(netdissect_options *ndo,
                        while (networks != 0) {
                                /* Pickup network number */
                                if (length < 1)
-                                       goto trunc;
+                                       goto invalid;
                                addr = ((uint32_t) GET_U_1(cp)) << 24;
                                cp++;
                                length--;
                                if (IN_CLASSB(addr)) {
                                        if (length < 1)
-                                               goto trunc;
+                                               goto invalid;
                                        addr |= ((uint32_t) GET_U_1(cp)) << 16;
                                        cp++;
                                        length--;
                                } else if (!IN_CLASSA(addr)) {
                                        if (length < 2)
-                                               goto trunc;
+                                               goto invalid;
                                        addr |= ((uint32_t) GET_U_1(cp)) << 16;
                                        cp++;
                                        addr |= ((uint32_t) GET_U_1(cp)) << 8;
                                        cp++;
                                        length -= 2;
                                }
-                               ND_PRINT(" %s", ipaddr_string(ndo, (const u_char *)&addr));
+                               ND_PRINT(" %s", ipaddr_string(ndo, (const u_char *)&addr)); /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
                                networks--;
                        }
                        distances--;
@@ -248,8 +249,8 @@ egpnr_print(netdissect_options *ndo,
                ND_PRINT(")");
        }
        return;
-trunc:
-       nd_print_trunc(ndo);
+invalid:
+       nd_print_invalid(ndo);
 }
 
 void
@@ -264,10 +265,8 @@ egp_print(netdissect_options *ndo,
 
        ndo->ndo_protocol = "egp";
        egp = (const struct egp_packet *)bp;
-       if (length < sizeof(*egp) || !ND_TTEST_SIZE(egp)) {
-               nd_print_trunc(ndo);
-               return;
-       }
+       ND_ICHECKMSG_ZU("packet length", length, <, sizeof(*egp));
+       ND_TCHECK_SIZE(egp);
 
        version = GET_U_1(egp->egp_version);
         if (!ndo->ndo_vflag) {
@@ -369,4 +368,7 @@ egp_print(netdissect_options *ndo,
                ND_PRINT(" %s", tok2str(egp_reasons_str, "[reason %u]", GET_BE_U_2(egp->egp_reason)));
                break;
        }
+       return;
+invalid:
+       nd_print_invalid(ndo);
 }