From 072e016c6c43472e11f939949f7c842bad673d93 Mon Sep 17 00:00:00 2001 From: hannes Date: Fri, 23 Jun 2006 22:20:32 +0000 Subject: [PATCH] code cosmetics: bracketize the on-liners after if statements, proper length decrement for ANSI LMI frames --- print-fr.c | 90 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 36 deletions(-) diff --git a/print-fr.c b/print-fr.c index 713e63ebe..f71aee665 100644 --- a/print-fr.c +++ b/print-fr.c @@ -21,7 +21,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.50 2006-02-11 22:11:40 hannes Exp $ (LBL)"; + "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.51 2006-06-23 22:20:32 hannes Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -741,25 +741,29 @@ q933_print(const u_char *p, u_int length) codeset = p[2]&0x0f; /* extract the codeset */ - if (p[2] == MSG_ANSI_LOCKING_SHIFT) - is_ansi = 1; + if (p[2] == MSG_ANSI_LOCKING_SHIFT) { + is_ansi = 1; + } printf("%s", eflag ? "" : "Q.933, "); /* printing out header part */ printf("%s, codeset %u", is_ansi ? "ANSI" : "CCITT", codeset); - if (p[0]) - printf(", Call Ref: 0x%02x", p[0]); - - if (vflag) - printf(", %s (0x%02x), length %u", - tok2str(fr_q933_msg_values,"unknown message",p[1]), - p[1], - length); - else - printf(", %s", - tok2str(fr_q933_msg_values,"unknown message 0x%02x",p[1])); + if (p[0]) { + printf(", Call Ref: 0x%02x", p[0]); + } + if (vflag) { + printf(", %s (0x%02x), length %u", + tok2str(fr_q933_msg_values, + "unknown message", p[1]), + p[1], + length); + } else { + printf(", %s", + tok2str(fr_q933_msg_values, + "unknown message 0x%02x", p[1])); + } olen = length; /* preserve the original length for non verbose mode */ @@ -767,49 +771,57 @@ q933_print(const u_char *p, u_int length) printf("[|q.933]"); return; } - length -= 2 - is_ansi; + length -= 2 + is_ansi; ptemp += 2 + is_ansi; /* Loop through the rest of IE */ - while (length > sizeof(struct ie_tlv_header_t )) { + while (length > sizeof(struct ie_tlv_header_t)) { ie_p = (struct ie_tlv_header_t *)ptemp; - if (length < sizeof(struct ie_tlv_header_t ) || - length < sizeof(struct ie_tlv_header_t ) + ie_p->ie_len) { - if (vflag) /* not bark if there is just a trailer */ + if (length < sizeof(struct ie_tlv_header_t) || + length < sizeof(struct ie_tlv_header_t) + ie_p->ie_len) { + if (vflag) { /* not bark if there is just a trailer */ printf("\n[|q.933]"); - else + } else { printf(", length %u",olen); + } return; } /* 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) + * are also interestting 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), + 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) + if (ie_p->ie_type == 0 || ie_p->ie_len == 0) { return; + } - if (fr_q933_print_ie_codeset[codeset] != NULL) + 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) + } + + 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) + 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; } - if (!vflag) + if (!vflag) { printf(", length %u",olen); + } } static int @@ -821,24 +833,27 @@ fr_q933_print_ie_codeset5(const struct ie_tlv_header_t *ie_p, const u_char *p) case FR_LMI_ANSI_REPORT_TYPE_IE: /* fall through */ case FR_LMI_CCITT_REPORT_TYPE_IE: - if (vflag) + if (vflag) { printf("%s (%u)", tok2str(fr_lmi_report_type_ie_values,"unknown",p[2]), p[2]); + } return 1; case FR_LMI_ANSI_LINK_VERIFY_IE: /* fall through */ case FR_LMI_CCITT_LINK_VERIFY_IE: case FR_LMI_ANSI_LINK_VERIFY_IE_91: - if (!vflag) + if (!vflag) { printf(", "); + } printf("TX Seq: %3d, RX Seq: %3d", p[2], p[3]); return 1; case FR_LMI_ANSI_PVC_STATUS_IE: /* fall through */ case FR_LMI_CCITT_PVC_STATUS_IE: - if (!vflag) + if (!vflag) { printf(", "); + } /* now parse the DLCI information element. */ if ((ie_p->ie_len < 3) || (p[2] & 0x80) || @@ -847,14 +862,17 @@ fr_q933_print_ie_codeset5(const struct ie_tlv_header_t *ie_p, const u_char *p) ((ie_p->ie_len == 5) && ((p[3] & 0x80) || (p[4] & 0x80) || !(p[5] & 0x80))) || (ie_p->ie_len > 5) || - !(p[ie_p->ie_len + 1] & 0x80)) + !(p[ie_p->ie_len + 1] & 0x80)) { printf("Invalid DLCI IE"); + } dlci = ((p[2] & 0x3F) << 4) | ((p[3] & 0x78) >> 3); - if (ie_p->ie_len == 4) + if (ie_p->ie_len == 4) { dlci = (dlci << 6) | ((p[4] & 0x7E) >> 1); - else if (ie_p->ie_len == 5) + } + else if (ie_p->ie_len == 5) { dlci = (dlci << 13) | (p[4] & 0x7F) | ((p[5] & 0x7E) >> 1); + } printf("DLCI %u: status %s%s", dlci, p[ie_p->ie_len + 1] & 0x8 ? "New, " : "",