#ifndef lint
static const char rcsid[] _U_ =
- "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.46 2005-08-23 03:15:32 guy 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
/* 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))
flags[0] = p[0] & 0x02; /* populate the first flag fields */
flags[1] = p[1] & 0x0c;
+ flags[2] = 0; /* clear the rest of the flags */
+ flags[3] = 0;
if (p[1] & FR_EA_BIT)
return 0; /* 2-byte Q.922 address */
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
+---------------------------+
{
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;
}
frf15_print(p, length);
break;
+ case NLPID_PPP:
+ ppp_print(p, length);
+ break;
+
default:
if (!eflag)
fr_hdr_print(length + hdr_len, addr_len,
}
+u_int
+mfr_if_print(const struct pcap_pkthdr *h, register const u_char *p)
+{
+ register u_int length = h->len;
+ register u_int caplen = h->caplen;
+
+ TCHECK2(*p, 2); /* minimum frame header length */
+
+ if ((length = mfr_print(p, length)) == 0)
+ return (0);
+ else
+ return length;
+ trunc:
+ printf("[|mfr]");
+ return caplen;
+}
+
+
#define MFR_CTRL_MSG_ADD_LINK 1
#define MFR_CTRL_MSG_ADD_LINK_ACK 2
#define MFR_CTRL_MSG_ADD_LINK_REJ 3
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 */
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
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) ||
((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, " : "",