]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-dhcp6.c
Use more the ND_TTEST_1() macro
[tcpdump] / print-dhcp6.c
index 2894ea8dd96a11833ee1f495cd5b4c9d10601044..5558660afbbec776c60e2e02ccc7810c589b3b35 100644 (file)
@@ -308,7 +308,7 @@ dhcp6opt_print(netdissect_options *ndo,
                        goto trunc;
                opttype = EXTRACT_BE_U_2(&dh6o->dh6opt_type);
                ND_PRINT((ndo, " (%s", tok2str(dh6opt_str, "opt_%u", opttype)));
-               ND_TCHECK2(*(cp + sizeof(*dh6o)), optlen);
+               ND_TCHECK_LEN(cp + sizeof(*dh6o), optlen);
                switch (opttype) {
                case DH6OPT_CLIENTID:
                case DH6OPT_SERVERID:
@@ -325,7 +325,7 @@ dhcp6opt_print(netdissect_options *ndo,
                                            EXTRACT_BE_U_2(tp + 2),
                                            EXTRACT_BE_U_4(tp + 4)));
                                        for (i = 8; i < optlen; i++)
-                                               ND_PRINT((ndo, "%02x", tp[i]));
+                                               ND_PRINT((ndo, "%02x", EXTRACT_U_1(tp + i)));
                                        /*(*/
                                        ND_PRINT((ndo, ")"));
                                } else {
@@ -337,7 +337,7 @@ dhcp6opt_print(netdissect_options *ndo,
                                if (optlen >= 2 + 8) {
                                        ND_PRINT((ndo, " vid "));
                                        for (i = 2; i < 2 + 8; i++)
-                                               ND_PRINT((ndo, "%02x", tp[i]));
+                                               ND_PRINT((ndo, "%02x", EXTRACT_U_1(tp + i)));
                                        /*(*/
                                        ND_PRINT((ndo, ")"));
                                } else {
@@ -350,7 +350,7 @@ dhcp6opt_print(netdissect_options *ndo,
                                        ND_PRINT((ndo, " hwaddr type %u ",
                                            EXTRACT_BE_U_2(tp + 2)));
                                        for (i = 4; i < optlen; i++)
-                                               ND_PRINT((ndo, "%02x", tp[i]));
+                                               ND_PRINT((ndo, "%02x", EXTRACT_U_1(tp + i)));
                                        /*(*/
                                        ND_PRINT((ndo, ")"));
                                } else {
@@ -521,7 +521,7 @@ dhcp6opt_print(netdissect_options *ndo,
                        tp = (const u_char *)(dh6o + 1);
                        ND_PRINT((ndo, " "));
                        for (i = 0; i < optlen && i < 10; i++)
-                               ND_PRINT((ndo, "%02x", tp[i]));
+                               ND_PRINT((ndo, "%02x", EXTRACT_U_1(tp + i)));
                        ND_PRINT((ndo, "...)"));
                        break;
                case DH6OPT_RECONF_MSG:
@@ -617,7 +617,7 @@ dhcp6opt_print(netdissect_options *ndo,
                                break;
                        }
                        tp = (const u_char *)(dh6o + 1);
-                       ND_PRINT((ndo, " %s/%d", ip6addr_string(ndo, tp + 9), tp[8]));
+                       ND_PRINT((ndo, " %s/%d", ip6addr_string(ndo, tp + 9), EXTRACT_U_1(tp + 8)));
                        ND_PRINT((ndo, " pltime:%u vltime:%u",
                            EXTRACT_BE_U_4(tp),
                            EXTRACT_BE_U_4(tp + 4)));
@@ -647,7 +647,7 @@ dhcp6opt_print(netdissect_options *ndo,
                         * Print hex dump first 10 characters.
                         */
                        for (i = 4; i < optlen && i < 14; i++)
-                               ND_PRINT((ndo, "%02x", tp[i]));
+                               ND_PRINT((ndo, "%02x", EXTRACT_U_1(tp + i)));
                        ND_PRINT((ndo, "...)"));
                        break;
                case DH6OPT_LQ_QUERY:
@@ -694,7 +694,7 @@ dhcp6opt_print(netdissect_options *ndo,
                         * Print hex dump first 10 characters.
                         */
                        for (i = 16; i < optlen && i < 26; i++)
-                               ND_PRINT((ndo, "%02x", tp[i]));
+                               ND_PRINT((ndo, "%02x", EXTRACT_U_1(tp + i)));
                        ND_PRINT((ndo, "...)"));
                        break;
                case DH6OPT_NTP_SERVER:
@@ -792,6 +792,7 @@ dhcp6_print(netdissect_options *ndo,
 {
        const struct dhcp6 *dh6;
        const struct dhcp6_relay *dh6relay;
+       uint8_t msgtype;
        const u_char *ep;
        const u_char *extp;
        const char *name;
@@ -805,7 +806,8 @@ dhcp6_print(netdissect_options *ndo,
        dh6 = (const struct dhcp6 *)cp;
        dh6relay = (const struct dhcp6_relay *)cp;
        ND_TCHECK(dh6->dh6_xid);
-       name = tok2str(dh6_msgtype_str, "msgtype-%u", dh6->dh6_msgtype);
+       msgtype = EXTRACT_U_1(dh6->dh6_msgtype);
+       name = tok2str(dh6_msgtype_str, "msgtype-%u", msgtype);
 
        if (!ndo->ndo_vflag) {
                ND_PRINT((ndo, " %s", name));
@@ -815,9 +817,8 @@ dhcp6_print(netdissect_options *ndo,
        /* XXX relay agent messages have to be handled differently */
 
        ND_PRINT((ndo, " %s (", name)); /*)*/
-       if (dh6->dh6_msgtype != DH6_RELAY_FORW &&
-           dh6->dh6_msgtype != DH6_RELAY_REPLY) {
-               ND_PRINT((ndo, "xid=%x", EXTRACT_BE_U_4(&dh6->dh6_xid) & DH6_XIDMASK));
+       if (msgtype != DH6_RELAY_FORW && msgtype != DH6_RELAY_REPLY) {
+               ND_PRINT((ndo, "xid=%x", EXTRACT_BE_U_4(dh6->dh6_xid) & DH6_XIDMASK));
                extp = (const u_char *)(dh6 + 1);
                dhcp6opt_print(ndo, extp, ep);
        } else {                /* relay messages */