]> The Tcpdump Group git mirrors - tcpdump/commitdiff
IGMP: Deduplicate multicast trace printing code.
authorDenis Ovsienko <[email protected]>
Wed, 30 Sep 2020 02:36:06 +0000 (03:36 +0100)
committerDenis Ovsienko <[email protected]>
Wed, 30 Sep 2020 13:52:46 +0000 (14:52 +0100)
Instead of having two functions that differ only in the prefix they
print have one function that accepts the prefix as an additional
argument.

print-igmp.c

index 8c5bc15d59ebde0270f618b64cbc3b5502af0909..771189945efbc50ea36a9a94e005cdbf083668ab 100644 (file)
@@ -109,6 +109,7 @@ static const struct tok igmpv3report2str[] = {
 
 static void
 print_mtrace(netdissect_options *ndo,
+             const char *typename,
              const u_char *bp, u_int len)
 {
     const struct tr_query *tr = (const struct tr_query *)(bp + 8);
@@ -118,29 +119,8 @@ print_mtrace(netdissect_options *ndo,
        ND_PRINT(" [invalid len %u]", len);
        return;
     }
-    ND_PRINT("mtrace %u: %s to %s reply-to %s",
-        GET_BE_U_3(tr->tr_qid),
-        GET_IPADDR_STRING(tr->tr_src), GET_IPADDR_STRING(tr->tr_dst),
-        GET_IPADDR_STRING(tr->tr_raddr));
-    if (IN_CLASSD(GET_BE_U_4(tr->tr_raddr)))
-        ND_PRINT(" with-ttl %u", GET_U_1(tr->tr_rttl));
-    return;
-trunc:
-    nd_print_trunc(ndo);
-}
-
-static void
-print_mresp(netdissect_options *ndo,
-            const u_char *bp, u_int len)
-{
-    const struct tr_query *tr = (const struct tr_query *)(bp + 8);
-
-    ND_TCHECK_SIZE(tr);
-    if (len < 8 + sizeof (struct tr_query)) {
-       ND_PRINT(" [invalid len %u]", len);
-       return;
-    }
-    ND_PRINT("mresp %u: %s to %s reply-to %s",
+    ND_PRINT("%s %u: %s to %s reply-to %s",
+        typename,
         GET_BE_U_3(tr->tr_qid),
         GET_IPADDR_STRING(tr->tr_src), GET_IPADDR_STRING(tr->tr_dst),
         GET_IPADDR_STRING(tr->tr_raddr));
@@ -314,10 +294,10 @@ igmp_print(netdissect_options *ndo,
         pimv1_print(ndo, bp, len);
         break;
     case 0x1e:
-        print_mresp(ndo, bp, len);
+        print_mtrace(ndo, "mresp", bp, len);
         break;
     case 0x1f:
-        print_mtrace(ndo, bp, len);
+        print_mtrace(ndo, "mtrace", bp, len);
         break;
     default:
         ND_PRINT("igmp-%u", GET_U_1(bp));