]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-forces.c
DNS: Sync types with IANA
[tcpdump] / print-forces.c
index 9a3229dd8b289564e8f13fb22acef19460ff54f8..e6b52d6b27eb2b526e572cdf6b3a3633308f8ce2 100644 (file)
@@ -388,7 +388,7 @@ struct forces_tlv {
        nd_uint16_t length;
 };
 
-#define F_ALN_LEN(len) ( ((len)+ForCES_ALNL-1) & ~(ForCES_ALNL-1) )
+#define F_ALN_LEN(len) roundup2(len, ForCES_ALNL)
 #define        GET_TOP_TLV(fhdr) ((const struct forces_tlv *)((fhdr) + sizeof (struct forcesh)))
 #define TLV_SET_LEN(len)  (F_ALN_LEN(TLV_HDRL) + (len))
 #define TLV_DATA(tlvp)   ((const void*)(((const char*)(tlvp)) + TLV_SET_LEN(0)))
@@ -710,7 +710,7 @@ fdatatlv_print(netdissect_options *ndo,
        if (ndo->ndo_vflag >= 3) {
                char *ib = indent_pr(indent + 2, 1);
                ND_PRINT("%s[", ib + 1);
-               hex_print_with_offset(ndo, ib, tdp, rlen, 0);
+               hex_print(ndo, ib, tdp, rlen);
                ND_PRINT("\n%s]", ib + 1);
        }
        return 0;
@@ -741,29 +741,23 @@ sdatailv_print(netdissect_options *ndo,
 #endif
                char *ib = indent_pr(indent, 1);
                const u_char *tdp = (const u_char *) ILV_DATA(ilv);
-               ND_TCHECK_SIZE(ilv);
                invilv = ilv_valid(ndo, ilv, rlen);
                if (invilv) {
-                       ND_PRINT("%s[", ib + 1);
-                       hex_print_with_offset(ndo, ib, tdp, rlen, 0);
-                       ND_PRINT("\n%s]\n", ib + 1);
+                       ND_PRINT("Error: %s, rlen %u\n",
+                                tok2str(ForCES_TLV_err, NULL, invilv), rlen);
                        return -1;
                }
                if (ndo->ndo_vflag >= 3) {
                        u_int ilvl = GET_BE_U_4(ilv->length);
                        ND_PRINT("\n%s ILV: type %x length %u\n", ib + 1,
                                  GET_BE_U_4(ilv->type), ilvl);
-                       hex_print_with_offset(ndo, "\t\t[", tdp, ilvl-ILV_HDRL, 0);
+                       hex_print(ndo, "\t\t[", tdp, ilvl-ILV_HDRL);
                }
 
                ilv = GO_NXT_ILV(ilv, rlen);
        }
 
        return 0;
-
-trunc:
-       nd_print_trunc(ndo);
-       return -1;
 }
 
 static int
@@ -809,10 +803,8 @@ pkeyitlv_print(netdissect_options *ndo,
        uint16_t type, tll;
        u_int invtlv;
 
-       ND_TCHECK_1(tdp);
        id = GET_BE_U_4(tdp);
        ND_PRINT("%sKeyinfo: Key 0x%x\n", ib, id);
-       ND_TCHECK_SIZE(kdtlv);
        type = GET_BE_U_2(kdtlv->type);
        tll = GET_BE_U_2(kdtlv->length);
        invtlv = tlv_valid(tll, len);
@@ -831,10 +823,6 @@ pkeyitlv_print(netdissect_options *ndo,
        tll = GET_BE_U_2(kdtlv->length);
        dp = (const u_char *) TLV_DATA(kdtlv);
        return fdatatlv_print(ndo, dp, tll, op_msk, indent);
-
-trunc:
-       nd_print_trunc(ndo);
-       return -1;
 }
 
 #define PTH_DESC_SIZE 12
@@ -930,7 +918,6 @@ pdatacnt_print(netdissect_options *ndo,
                u_int aln;
                u_int invtlv;
 
-               ND_TCHECK_SIZE(pdtlv);
                type = GET_BE_U_2(pdtlv->type);
                tlvl = GET_BE_U_2(pdtlv->length);
                invtlv = tlv_valid(tlvl, len);
@@ -979,8 +966,8 @@ pdatacnt_print(netdissect_options *ndo,
                               type, tlvl);
 pd_err:
                        if (tlvl) {
-                                hex_print_with_offset(ndo, "Bad Data val\n\t  [",
-                                                     pptr, len, 0);
+                                hex_print(ndo, "Bad Data val\n\t  [",
+                                         pptr, len);
                                ND_PRINT("]\n");
 
                                return -1;
@@ -1034,7 +1021,7 @@ pdata_print(netdissect_options *ndo,
        if (len < minsize) {
                ND_PRINT("\t\t\ttruncated IDs expected %uB got %uB\n", minsize,
                       len);
-               hex_print_with_offset(ndo, "\t\t\tID Data[", pptr, len, 0);
+               hex_print(ndo, "\t\t\tID Data[", pptr, len);
                ND_PRINT("]\n");
                return -1;
        }
@@ -1070,7 +1057,6 @@ genoptlv_print(netdissect_options *ndo,
        u_int invtlv;
        char *ib = indent_pr(indent, 0);
 
-       ND_TCHECK_SIZE(pdtlv);
        type = GET_BE_U_2(pdtlv->type);
        tlvl = GET_BE_U_2(pdtlv->length);
        invtlv = tlv_valid(tlvl, len);
@@ -1100,10 +1086,6 @@ genoptlv_print(netdissect_options *ndo,
                ND_PRINT("\t\t\tInvalid ForCES TLV type=%x", type);
                return -1;
        }
-
-trunc:
-       nd_print_trunc(ndo);
-       return -1;
 }
 
 static int
@@ -1119,7 +1101,6 @@ recpdoptlv_print(netdissect_options *ndo,
                char *ib;
                const u_char *dp;
 
-               ND_TCHECK_SIZE(pdtlv);
                tlvl = GET_BE_U_2(pdtlv->length);
                invtlv = tlv_valid(tlvl, len);
                if (invtlv) {
@@ -1154,10 +1135,6 @@ recpdoptlv_print(netdissect_options *ndo,
        }
 
        return 0;
-
-trunc:
-       nd_print_trunc(ndo);
-       return -1;
 }
 
 static int
@@ -1169,7 +1146,7 @@ invoptlv_print(netdissect_options *ndo,
 
        if (ndo->ndo_vflag >= 3) {
                ND_PRINT("%sData[", ib + 1);
-               hex_print_with_offset(ndo, ib, pptr, len, 0);
+               hex_print(ndo, ib, pptr, len);
                ND_PRINT("%s]\n", ib);
        }
        return -1;
@@ -1190,7 +1167,6 @@ otlv_print(netdissect_options *ndo,
         * lfbselect_print() has ensured that GET_BE_U_2(otlv->length)
         * >= TLV_HDRL.
         */
-       ND_TCHECK_SIZE(otlv);
        type = GET_BE_U_2(otlv->type);
        tll = GET_BE_U_2(otlv->length) - TLV_HDRL;
        ops = get_forces_optlv_h(type);
@@ -1213,10 +1189,6 @@ otlv_print(netdissect_options *ndo,
                 rc = ops->print(ndo, dp, tll, ops->op_msk, indent + 1);
         }
        return rc;
-
-trunc:
-       nd_print_trunc(ndo);
-       return -1;
 }
 
 #define ASTDLN 4
@@ -1239,7 +1211,6 @@ asttlv_print(netdissect_options *ndo,
                ND_PRINT("illegal ASTresult-TLV: %u bytes!\n", dlen);
                return -1;
        }
-       ND_TCHECK_4(pptr);
        rescode = GET_BE_U_4(pptr);
        if (rescode > ASTMCD) {
                ND_PRINT("illegal ASTresult result code: %u!\n", rescode);
@@ -1271,10 +1242,6 @@ asttlv_print(netdissect_options *ndo,
                ND_PRINT("(%x)\n%s", rescode, ib);
        }
        return 0;
-
-trunc:
-       nd_print_trunc(ndo);
-       return -1;
 }
 
 #define ASRDLN 4
@@ -1297,7 +1264,6 @@ asrtlv_print(netdissect_options *ndo,
                ND_PRINT("illegal ASRresult-TLV: %u bytes!\n", dlen);
                return -1;
        }
-       ND_TCHECK_4(pptr);
        rescode = GET_BE_U_4(pptr);
 
        if (rescode > ASRMCD) {
@@ -1324,10 +1290,6 @@ asrtlv_print(netdissect_options *ndo,
                ND_PRINT("(%x)\n%s", rescode, ib);
        }
        return 0;
-
-trunc:
-       nd_print_trunc(ndo);
-       return -1;
 }
 
 #if 0
@@ -1365,18 +1327,13 @@ print_metailv(netdissect_options *ndo,
         * ILV) >= ILV_HDRL.
         */
        rlen = GET_BE_U_4(ilv->length) - ILV_HDRL;
-       ND_TCHECK_SIZE(ilv);
        ND_PRINT("%sMetaID 0x%x length %u\n", ib, GET_BE_U_4(ilv->type),
                  GET_BE_U_4(ilv->length));
        if (ndo->ndo_vflag >= 3) {
-               hex_print_with_offset(ndo, "\t\t[", ILV_DATA(ilv), rlen, 0);
+               hex_print(ndo, "\t\t[", ILV_DATA(ilv), rlen);
                ND_PRINT(" ]\n");
        }
        return 0;
-
-trunc:
-       nd_print_trunc(ndo);
-       return -1;
 }
 
 static int
@@ -1398,7 +1355,6 @@ print_metatlv(netdissect_options *ndo,
        rlen = dlen;
        ND_PRINT("\n%s METADATA length %u\n", ib, rlen);
        while (rlen != 0) {
-               ND_TCHECK_SIZE(ilv);
                invilv = ilv_valid(ndo, ilv, rlen);
                if (invilv) {
                        break;
@@ -1414,10 +1370,6 @@ print_metatlv(netdissect_options *ndo,
        }
 
        return 0;
-
-trunc:
-       nd_print_trunc(ndo);
-       return -1;
 }
 
 
@@ -1436,7 +1388,7 @@ print_reddata(netdissect_options *ndo,
 
        if (ndo->ndo_vflag >= 3) {
                ND_PRINT("\t\t[");
-               hex_print_with_offset(ndo, "\n\t\t", pptr, rlen, 0);
+               hex_print(ndo, "\n\t\t", pptr, rlen);
                ND_PRINT("\n\t\t]");
        }
 
@@ -1469,7 +1421,6 @@ redirect_print(netdissect_options *ndo,
        while (rlen != 0) {
                uint16_t type, tlvl;
 
-               ND_TCHECK_SIZE(tlv);
                type = GET_BE_U_2(tlv->type);
                tlvl = GET_BE_U_2(tlv->length);
                invtlv = tlv_valid(tlvl, rlen);
@@ -1508,10 +1459,6 @@ redirect_print(netdissect_options *ndo,
        }
 
        return 0;
-
-trunc:
-       nd_print_trunc(ndo);
-       return -1;
 }
 
 #define OP_OFF 8
@@ -1562,7 +1509,6 @@ lfbselect_print(netdissect_options *ndo,
        while (rlen != 0) {
                uint16_t type, tlvl;
 
-               ND_TCHECK_SIZE(otlv);
                type = GET_BE_U_2(otlv->type);
                tlvl = GET_BE_U_2(otlv->length);
                invtlv = tlv_valid(tlvl, rlen);
@@ -1643,7 +1589,6 @@ forces_type_print(netdissect_options *ndo,
        while (rlen != 0) {
                uint16_t type, tlvl;
 
-               ND_TCHECK_SIZE(tltlv);
                type = GET_BE_U_2(tltlv->type);
                tlvl = GET_BE_U_2(tltlv->length);
                invtlv = tlv_valid(tlvl, rlen);
@@ -1689,10 +1634,6 @@ forces_type_print(netdissect_options *ndo,
        }
 
        return 0;
-
-trunc:
-       nd_print_trunc(ndo);
-       return -1;
 }
 
 void
@@ -1730,7 +1671,6 @@ forces_print(netdissect_options *ndo,
                goto error;
        }
 
-       ND_TCHECK_4(pptr + 20);
        flg_raw = GET_BE_U_4(pptr + 20);
        if (ndo->ndo_vflag >= 1) {
                ND_PRINT("\n\tForCES Version %u len %uB flags 0x%08x ",
@@ -1758,14 +1698,14 @@ forces_print(netdissect_options *ndo,
        rc = forces_type_print(ndo, pptr, fhdr, mlen, tops);
        if (rc < 0) {
 error:
-               hex_print_with_offset(ndo, "\n\t[", pptr, len, 0);
+               hex_print(ndo, "\n\t[", pptr, len);
                ND_PRINT("\n\t]");
                return;
        }
 
        if (ndo->ndo_vflag >= 4) {
                ND_PRINT("\n\t  Raw ForCES message\n\t [");
-               hex_print_with_offset(ndo, "\n\t ", pptr, len, 0);
+               hex_print(ndo, "\n\t ", pptr, len);
                ND_PRINT("\n\t ]");
        }
        return;