]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-rip.c
Update .gitignore for other configurations
[tcpdump] / print-rip.c
index 2c3613551f6d8c35774466f447061b1afa47298d..2d4bc21100b54ff323d7c2c3b9326831bdbfc013 100644 (file)
@@ -37,7 +37,6 @@
 
 #include "af.h"
 
-static const char tstr[] = "[|rip]";
 
 /*
  * RFC 1058 and RFC 2453 header of packet.
@@ -190,6 +189,7 @@ rip_entry_print_v1(netdissect_options *ndo, const u_char *p,
        /* RFC 1058 */
        if (remaining < RIP_ROUTELEN)
                return (0);
+       ND_TCHECK_SIZE(ni);
        family = EXTRACT_BE_U_2(ni->rip_family);
        if (family != BSD_AFNUM_INET && family != 0) {
                ND_PRINT("\n\t AFI %s, ", tok2str(bsd_af_values, "Unknown (%u)", family));
@@ -213,6 +213,8 @@ rip_entry_print_v1(netdissect_options *ndo, const u_char *p,
                ipaddr_string(ndo, ni->rip_dest),
                EXTRACT_BE_U_4(ni->rip_metric));
        return (RIP_ROUTELEN);
+trunc:
+       return 0;
 }
 
 static unsigned
@@ -225,6 +227,7 @@ rip_entry_print_v2(netdissect_options *ndo, const u_char *p,
 
        if (remaining < sizeof(*eh))
                return (0);
+       ND_TCHECK_SIZE(eh);
        family = EXTRACT_BE_U_2(eh->rip_family);
        if (family == 0xFFFF) { /* variable-sized authentication structures */
                uint16_t auth_type = EXTRACT_BE_U_2(eh->rip_tag);
@@ -233,12 +236,13 @@ rip_entry_print_v2(netdissect_options *ndo, const u_char *p,
                remaining -= sizeof(*eh);
                if (auth_type == 2) {
                        ND_PRINT("\n\t  Simple Text Authentication data: ");
-                       if (fn_printzp(ndo, p, RIP_AUTHLEN, p + remaining))
+                       if (nd_printzp(ndo, p, RIP_AUTHLEN, p + remaining))
                                return (0);
                } else if (auth_type == 3) {
                        const struct rip_auth_crypto_v2 *ch;
 
                        ch = (const struct rip_auth_crypto_v2 *)p;
+                       ND_TCHECK_SIZE(ch);
                        if (remaining < sizeof(*ch))
                                return (0);
                        ND_PRINT("\n\t  Auth header:");
@@ -263,6 +267,7 @@ rip_entry_print_v2(netdissect_options *ndo, const u_char *p,
                 print_unknown_data(ndo, p + sizeof(*eh), "\n\t  ", RIP_ROUTELEN - sizeof(*eh));
        } else { /* BSD_AFNUM_INET or AFI 0 */
                ni = (const struct rip_netinfo_v2 *)p;
+               ND_TCHECK_SIZE(ni);
                if (remaining < sizeof(*ni))
                        return (0);
                ND_PRINT("\n\t  AFI %s, %15s/%-2d, tag 0x%04x, metric: %u, next-hop: ",
@@ -277,6 +282,8 @@ rip_entry_print_v2(netdissect_options *ndo, const u_char *p,
                        ND_PRINT("self");
        }
        return (RIP_ROUTELEN);
+trunc:
+       return 0;
 }
 
 void
@@ -289,21 +296,23 @@ rip_print(netdissect_options *ndo,
        u_int i, j;
        unsigned entry_size;
 
+       ndo->ndo_protocol = "rip";
        if (ndo->ndo_snapend < dat) {
-               ND_PRINT(" %s", tstr);
+               nd_print_trunc(ndo);
                return;
        }
        i = ndo->ndo_snapend - dat;
        if (i > length)
                i = length;
        if (i < sizeof(*rp)) {
-               ND_PRINT(" %s", tstr);
+               nd_print_trunc(ndo);
                return;
        }
        i -= sizeof(*rp);
 
        rp = (const struct rip *)dat;
 
+       ND_TCHECK_SIZE(rp);
        vers = EXTRACT_U_1(rp->rip_vers);
        ND_PRINT("%sRIPv%u",
                (ndo->ndo_vflag >= 1) ? "\n\t" : "",
@@ -348,7 +357,7 @@ rip_print(netdissect_options *ndo,
                                entry_size = rip_entry_print_v1(ndo, p, i);
                                if (entry_size == 0) {
                                        /* Error */
-                                       ND_PRINT("%s", tstr);
+                                       nd_print_trunc(ndo);
                                        break;
                                }
                                p += entry_size;
@@ -364,7 +373,7 @@ rip_print(netdissect_options *ndo,
                                entry_size = rip_entry_print_v2(ndo, p, i);
                                if (entry_size == 0) {
                                        /* Error */
-                                       ND_PRINT("%s", tstr);
+                                       nd_print_trunc(ndo);
                                        break;
                                }
 #if 0
@@ -403,4 +412,6 @@ rip_print(netdissect_options *ndo,
                if (!print_unknown_data(ndo, (const uint8_t *)rp, "\n\t", length))
                        return;
        }
+trunc:
+       return;
 }