- /* lets do the full IE parsing only in verbose mode
- * however some IEs (DLCI Status, Link Verify)
- * are also intereststing in non-verbose mode */
- if (vflag)
- printf("\n\t%s IE (0x%02x), length %u: ",
- tok2str(fr_q933_ie_codesets[codeset],"unknown",ie_p->ie_type),
- ie_p->ie_type,
- ie_p->ie_len);
-
- /* sanity check */
- if (ie_p->ie_type == 0 || ie_p->ie_len == 0)
- return;
-
- if (fr_q933_print_ie_codeset[codeset] != NULL)
- ie_is_known = fr_q933_print_ie_codeset[codeset](ie_p, ptemp);
-
- if (vflag >= 1 && !ie_is_known)
- print_unknown_data(ptemp+2,"\n\t",ie_p->ie_len);
-
- /* do we want to see a hexdump of the IE ? */
- if (vflag> 1 && ie_is_known)
- print_unknown_data(ptemp+2,"\n\t ",ie_p->ie_len);
-
- length = length - ie_p->ie_len - 2;
- ptemp = ptemp + ie_p->ie_len + 2;
+ /*
+ * Get the first octet of the IE.
+ */
+ if (!ND_TTEST_1(p)) {
+ if (!ndo->ndo_vflag) {
+ ND_PRINT(", length %u", olen);
+ }
+ goto trunc;
+ }
+ iecode = GET_U_1(p);
+ p++;
+ length--;
+
+ /* Single-octet IE? */
+ if (IE_IS_SINGLE_OCTET(iecode)) {
+ /*
+ * Yes. Is it a shift?
+ */
+ if (IE_IS_SHIFT(iecode)) {
+ /*
+ * Yes. Is it locking?
+ */
+ if (IE_SHIFT_IS_LOCKING(iecode)) {
+ /*
+ * Yes.
+ */
+ non_locking_shift = 0;
+ } else {
+ /*
+ * No. Remember the current
+ * codeset, so we can revert
+ * to it after the next IE.
+ */
+ non_locking_shift = 1;
+ unshift_codeset = codeset;
+ }
+
+ /*
+ * Get the codeset.
+ */
+ codeset = IE_SHIFT_CODESET(iecode);
+ }
+ } else {
+ /*
+ * No. Get the IE length.
+ */
+ if (length == 0 || !ND_TTEST_1(p)) {
+ if (!ndo->ndo_vflag) {
+ ND_PRINT(", length %u", olen);
+ }
+ goto trunc;
+ }
+ ielength = GET_U_1(p);
+ p++;
+ length--;
+
+ /* lets do the full IE parsing only in verbose mode
+ * however some IEs (DLCI Status, Link Verify)
+ * are also interesting in non-verbose mode */
+ if (ndo->ndo_vflag) {
+ ND_PRINT("\n\t%s IE (0x%02x), length %u: ",
+ tok2str(fr_q933_ie_codesets[codeset],
+ "unknown", iecode),
+ iecode,
+ ielength);
+ }
+
+ /* sanity checks */
+ if (iecode == 0 || ielength == 0) {
+ return;
+ }
+ if (length < ielength || !ND_TTEST_LEN(p, ielength)) {
+ if (!ndo->ndo_vflag) {
+ ND_PRINT(", length %u", olen);
+ }
+ goto trunc;
+ }
+
+ ie_is_known = 0;
+ if (fr_q933_print_ie_codeset[codeset] != NULL) {
+ ie_is_known = fr_q933_print_ie_codeset[codeset](ndo, iecode, ielength, p);
+ }
+
+ if (ie_is_known) {
+ /*
+ * Known IE; do we want to see a hexdump
+ * of it?
+ */
+ if (ndo->ndo_vflag > 1) {
+ /* Yes. */
+ print_unknown_data(ndo, p, "\n\t ", ielength);
+ }
+ } else {
+ /*
+ * Unknown IE; if we're printing verbosely,
+ * print its content in hex.
+ */
+ if (ndo->ndo_vflag >= 1) {
+ print_unknown_data(ndo, p, "\n\t", ielength);
+ }
+ }
+
+ length -= ielength;
+ p += ielength;
+ }
+ }
+ if (!ndo->ndo_vflag) {
+ ND_PRINT(", length %u", olen);