summaryrefslogtreecommitdiffstats
path: root/contrib/tcpdump/print-fr.c
diff options
context:
space:
mode:
authorrpaulo <rpaulo@FreeBSD.org>2009-03-21 18:30:25 +0000
committerrpaulo <rpaulo@FreeBSD.org>2009-03-21 18:30:25 +0000
commita7b30869205bc30a0462ffd9bc6c77fe4d980bd0 (patch)
tree9e93e51a04c09c3b9b900ef6611b8bbd1290f26f /contrib/tcpdump/print-fr.c
parent739eecddb9401ad5ef572c94f0764de2aa04e074 (diff)
parent10d55b9ccc041d249d91faedc3bd1139626bf444 (diff)
downloadFreeBSD-src-a7b30869205bc30a0462ffd9bc6c77fe4d980bd0.zip
FreeBSD-src-a7b30869205bc30a0462ffd9bc6c77fe4d980bd0.tar.gz
Merge tcpdump 4.0.0 from the vendor branch.
Diffstat (limited to 'contrib/tcpdump/print-fr.c')
-rw-r--r--contrib/tcpdump/print-fr.c115
1 files changed, 72 insertions, 43 deletions
diff --git a/contrib/tcpdump/print-fr.c b/contrib/tcpdump/print-fr.c
index abc3cd7..d0956f6 100644
--- a/contrib/tcpdump/print-fr.c
+++ b/contrib/tcpdump/print-fr.c
@@ -23,7 +23,7 @@
#ifndef lint
static const char rcsid[] _U_ =
- "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.32.2.15 2006/02/01 14:39:56 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
@@ -102,7 +102,7 @@ struct tok frf_flag_values[] = {
/* Finds out Q.922 address length, DLCI and flags. Returns 0 on success
* save the flags dep. on address length
*/
-static int parse_q922_addr(const u_char *p, u_int *dlci, u_int *sdlcore,
+static int parse_q922_addr(const u_char *p, u_int *dlci,
u_int *addr_len, u_int8_t *flags)
{
if ((p[0] & FR_EA_BIT))
@@ -132,14 +132,26 @@ static int parse_q922_addr(const u_char *p, u_int *dlci, u_int *sdlcore,
flags[3] = p[0] & 0x02;
- if (p[0] & 0x02)
- *sdlcore = p[0] >> 2;
- else
- *dlci = (*dlci << 6) | (p[0] >> 2);
+ *dlci = (*dlci << 6) | (p[0] >> 2);
return 0;
}
+char *q922_string(const u_char *p) {
+
+ static u_int dlci, addr_len;
+ static u_int8_t flags[4];
+ static char buffer[sizeof("DLCI xxxxxxxxxx")];
+ memset(buffer, 0, sizeof(buffer));
+
+ if (parse_q922_addr(p, &dlci, &addr_len, flags) == 0){
+ snprintf(buffer, sizeof(buffer), "DLCI %u", dlci);
+ }
+
+ return buffer;
+}
+
+
/* Frame Relay packet structure, with flags and CRC removed
+---------------------------+
@@ -224,13 +236,12 @@ fr_print(register const u_char *p, u_int length)
{
u_int16_t extracted_ethertype;
u_int dlci;
- u_int sdlcore;
u_int addr_len;
u_int16_t nlpid;
u_int hdr_len;
u_int8_t flags[4];
- if (parse_q922_addr(p, &dlci, &sdlcore, &addr_len, flags)) {
+ if (parse_q922_addr(p, &dlci, &addr_len, flags)) {
printf("Q.922, invalid address");
return 0;
}
@@ -732,25 +743,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 */
@@ -758,49 +773,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
@@ -812,24 +835,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) ||
@@ -838,14 +864,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, " : "",
OpenPOWER on IntegriCloud