]> The Tcpdump Group git mirrors - tcpdump/commitdiff
mobile: Modernize packet parsing
authorFrancois-Xavier Le Bail <[email protected]>
Fri, 12 May 2023 16:29:25 +0000 (18:29 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Fri, 12 May 2023 16:34:04 +0000 (18:34 +0200)
Use ND_TCHECK_SIZE() and enable ND_LONGJMP_FROM_TCHECK.
Use ND_ICHECK_U() for length check and add standard "invalid" section.
Use nd_print_protocol().

print-mobile.c

index 528da79c9f3e88734bdb7e1d05597ef7c963ec02..2dc4d77f49d9fb123a0c849a458187038f83f2a4 100644 (file)
@@ -44,6 +44,7 @@
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "addrtoname.h"
 #include "extract.h"
@@ -73,11 +74,10 @@ mobile_print(netdissect_options *ndo, const u_char *bp, u_int length)
        ndo->ndo_protocol = "mobile";
        mob = (const struct mobile_ip *)bp;
 
-       if (length < MOBILE_SIZE || !ND_TTEST_SIZE(mob)) {
-               nd_print_trunc(ndo);
-               return;
-       }
-       ND_PRINT("mobile: ");
+       ND_ICHECK_U(length, <, MOBILE_SIZE);
+       ND_TCHECK_SIZE(mob);
+       nd_print_protocol(ndo);
+       ND_PRINT(": ");
 
        proto = GET_BE_U_2(mob->proto);
        crc =  GET_BE_U_2(mob->hcheck);
@@ -101,4 +101,7 @@ mobile_print(netdissect_options *ndo, const u_char *bp, u_int length)
        if (in_cksum(vec, 1)!=0) {
                ND_PRINT(" (bad checksum %u)", crc);
        }
+       return;
+invalid:
+       nd_print_invalid(ndo);
 }