aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>1999-09-26 20:31:51 +0000
committerGuy Harris <guy@alum.mit.edu>1999-09-26 20:31:51 +0000
commit63edea877fe8e3dfeea259d91f72bf830609d5ed (patch)
tree98fd5cf856fa1cdb9e97667c4edd4053e1905f4f
parenta673e8bb2c256140c69d31c502fd732f78533f72 (diff)
Have "get_xdlc_control()" and "dissect_xdlc_control()" return the
xDLC control field, so that its caller can not only determine from it whether the frame has a payload, but can also determine how long the control field is. Put macros in "xdlc.h" to determine both of those. Have "capture_llc()" and "dissect_llc()" use that information appropriately. svn path=/trunk/; revision=727
-rw-r--r--packet-llc.c26
-rw-r--r--xdlc.c67
-rw-r--r--xdlc.h45
3 files changed, 71 insertions, 67 deletions
diff --git a/packet-llc.c b/packet-llc.c
index 76aeb58af8..ab02829dcb 100644
--- a/packet-llc.c
+++ b/packet-llc.c
@@ -2,7 +2,7 @@
* Routines for IEEE 802.2 LLC layer
* Gilbert Ramirez <gramirez@tivoli.com>
*
- * $Id: packet-llc.c,v 1.21 1999/08/23 23:24:35 guy Exp $
+ * $Id: packet-llc.c,v 1.22 1999/09/26 20:31:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@unicom.net>
@@ -163,7 +163,7 @@ void
capture_llc(const u_char *pd, int offset, guint32 cap_len, packet_counts *ld) {
int is_snap;
- int has_payload;
+ guint16 control;
guint16 etype;
capture_func_t *capture;
@@ -184,10 +184,10 @@ capture_llc(const u_char *pd, int offset, guint32 cap_len, packet_counts *ld) {
* extended operation, so we don't need to determine whether
* it's basic or extended operation; is that the case?
*/
- has_payload = get_xdlc_control(pd, offset+2, pd[offset+1] & 0x01, TRUE);
+ control = get_xdlc_control(pd, offset+2, pd[offset+1] & 0x01, TRUE);
if (is_snap) {
- if (has_payload) {
+ if (XDLC_HAS_PAYLOAD(control)) {
/*
* This frame has a payload to be analyzed.
*/
@@ -197,14 +197,14 @@ capture_llc(const u_char *pd, int offset, guint32 cap_len, packet_counts *ld) {
}
}
else {
- if (has_payload) {
+ if (XDLC_HAS_PAYLOAD(control)) {
/*
* This frame has a payload to be analyzed.
*/
capture = sap_capture_func(pd[offset]);
/* non-SNAP */
- offset += 3;
+ offset += XDLC_CONTROL_LEN(control, TRUE);
if (capture) {
capture(pd, offset, cap_len, ld);
@@ -220,9 +220,9 @@ void
dissect_llc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
proto_tree *llc_tree = NULL;
- proto_item *ti;
+ proto_item *ti = NULL;
int is_snap;
- int has_payload;
+ guint16 control;
guint16 etype;
dissect_func_t *dissect;
@@ -255,8 +255,10 @@ dissect_llc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
* extended operation, so we don't need to determine whether
* it's basic or extended operation; is that the case?
*/
- has_payload = dissect_xdlc_control(pd, offset+2, fd, llc_tree,
+ control = dissect_xdlc_control(pd, offset+2, fd, llc_tree,
hf_llc_ctrl, pd[offset+1] & 0x01, TRUE);
+ if (tree)
+ proto_item_set_len(ti, XDLC_CONTROL_LEN(control, TRUE));
/*
* XXX - do we want to append the SAP information to the stuff
@@ -271,7 +273,7 @@ dissect_llc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
proto_tree_add_item(llc_tree, hf_llc_oui, offset+3, 3,
pd[offset+3] << 16 | pd[offset+4] << 8 | pd[offset+5]);
}
- if (has_payload) {
+ if (XDLC_HAS_PAYLOAD(control)) {
/*
* This frame has a payload to be analyzed.
*/
@@ -288,14 +290,14 @@ dissect_llc(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
val_to_str(pd[offset], sap_vals, "%02x"));
}
- if (has_payload) {
+ if (XDLC_HAS_PAYLOAD(control)) {
/*
* This frame has a payload to be analyzed.
*/
dissect = sap_dissect_func(pd[offset]);
/* non-SNAP */
- offset += 3;
+ offset += XDLC_CONTROL_LEN(control, TRUE);
if (dissect) {
dissect(pd, offset, fd, tree);
diff --git a/xdlc.c b/xdlc.c
index e0203a602e..c5e0cdfcc8 100644
--- a/xdlc.c
+++ b/xdlc.c
@@ -2,7 +2,7 @@
* Routines for use by various SDLC-derived protocols, such as HDLC
* and its derivatives LAPB, IEEE 802.2 LLC, etc..
*
- * $Id: xdlc.c,v 1.8 1999/09/26 13:34:10 gram Exp $
+ * $Id: xdlc.c,v 1.9 1999/09/26 20:31:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@unicom.net>
@@ -66,31 +66,6 @@
#define XDLC_REJ 0x08 /* Reject */
#define XDLC_SREJ 0x0C /* Selective reject */
-/*
- * U-format modifiers.
- */
-#define XDLC_U_MODIFIER_MASK 0xEC
-#define XDLC_UI 0x00 /* Unnumbered Information */
-#define XDLC_UP 0x20 /* Unnumbered Poll */
-#define XDLC_DISC 0x40 /* Disconnect (command) */
-#define XDLC_RD 0x40 /* Request Disconnect (response) */
-#define XDLC_UA 0x60 /* Unnumbered Acknowledge */
-#define XDLC_SNRM 0x80 /* Set Normal Response Mode */
-#define XDLC_TEST 0xE0 /* Test */
-#define XDLC_SIM 0x04 /* Set Initialization Mode (command) */
-#define XDLC_RIM 0x04 /* Request Initialization Mode (response) */
-#define XDLC_FRMR 0x84 /* Frame reject */
-#define XDLC_CFGR 0xC4 /* Configure */
-#define XDLC_SARM 0x0C /* Set Asynchronous Response Mode (command) */
-#define XDLC_DM 0x0C /* Disconnected mode (response) */
-#define XDLC_SABM 0x2C /* Set Asynchronous Balanced Mode */
-#define XDLC_SARME 0x4C /* Set Asynchronous Response Mode Extended */
-#define XDLC_SABME 0x6C /* Set Asynchronous Balanced Mode Extended */
-#define XDLC_RESET 0x8C /* Reset */
-#define XDLC_XID 0xAC /* Exchange identification */
-#define XDLC_SNRME 0xCC /* Set Normal Response Mode Extended */
-#define XDLC_BCN 0xEC /* Beacon */
-
static const value_string stype_vals[] = {
{ XDLC_RR, "Receiver ready" },
{ XDLC_RNR, "Receiver not ready" },
@@ -192,10 +167,15 @@ get_xdlc_control(const u_char *pd, int offset, int is_response, int is_extended)
switch (pd[offset] & 0x03) {
case XDLC_S:
+ default:
/*
- * Supervisory frame - no higher-layer payload.
+ * Supervisory or Information frame.
*/
- return FALSE;
+ if (is_extended)
+ control = pletohs(&pd[offset]);
+ else
+ control = pd[offset];
+ break;
case XDLC_U:
/*
@@ -209,18 +189,9 @@ get_xdlc_control(const u_char *pd, int offset, int is_response, int is_extended)
* need for it to be 2 bytes in extended operation.
*/
control = pd[offset];
-
- /*
- * This frame has payload only if it's a UI frame.
- */
- return (control & XDLC_U_MODIFIER_MASK) == XDLC_UI;
-
- default:
- /*
- * Information frame - has higher-layer payload.
- */
- return TRUE;
+ break;
}
+ return control;
}
int
@@ -321,11 +292,7 @@ dissect_xdlc_control(const u_char *pd, int offset, frame_data *fd,
"Supervisory frame", NULL));
}
}
-
- /*
- * Supervisory frames have no higher-layer payload to be analyzed.
- */
- return FALSE;
+ break;
case XDLC_U:
/*
@@ -375,11 +342,7 @@ dissect_xdlc_control(const u_char *pd, int offset, frame_data *fd,
decode_boolean_bitfield(control, 0x03, 1*8,
"Unnumbered frame", NULL));
}
-
- /*
- * This frame has payload only if it's a UI frame.
- */
- return (control & XDLC_U_MODIFIER_MASK) == XDLC_UI;
+ break;
default:
/*
@@ -444,10 +407,6 @@ dissect_xdlc_control(const u_char *pd, int offset, frame_data *fd,
NULL, "Information frame"));
}
}
-
- /*
- * Information frames have higher-layer payload to be analyzed.
- */
- return TRUE;
}
+ return control;
}
diff --git a/xdlc.h b/xdlc.h
index 69fb908c34..d3092719c0 100644
--- a/xdlc.h
+++ b/xdlc.h
@@ -2,7 +2,7 @@
* Define *DLC frame types, and routine to dissect the control field of
* a *DLC frame.
*
- * $Id: xdlc.h,v 1.3 1999/08/23 23:24:36 guy Exp $
+ * $Id: xdlc.h,v 1.4 1999/09/26 20:31:51 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@unicom.net>
@@ -32,6 +32,49 @@
#define XDLC_S 0x01 /* Supervisory frames */
#define XDLC_U 0x03 /* Unnumbered frames */
+/*
+ * U-format modifiers.
+ */
+#define XDLC_U_MODIFIER_MASK 0xEC
+#define XDLC_UI 0x00 /* Unnumbered Information */
+#define XDLC_UP 0x20 /* Unnumbered Poll */
+#define XDLC_DISC 0x40 /* Disconnect (command) */
+#define XDLC_RD 0x40 /* Request Disconnect (response) */
+#define XDLC_UA 0x60 /* Unnumbered Acknowledge */
+#define XDLC_SNRM 0x80 /* Set Normal Response Mode */
+#define XDLC_TEST 0xE0 /* Test */
+#define XDLC_SIM 0x04 /* Set Initialization Mode (command) */
+#define XDLC_RIM 0x04 /* Request Initialization Mode (response) */
+#define XDLC_FRMR 0x84 /* Frame reject */
+#define XDLC_CFGR 0xC4 /* Configure */
+#define XDLC_SARM 0x0C /* Set Asynchronous Response Mode (command) */
+#define XDLC_DM 0x0C /* Disconnected mode (response) */
+#define XDLC_SABM 0x2C /* Set Asynchronous Balanced Mode */
+#define XDLC_SARME 0x4C /* Set Asynchronous Response Mode Extended */
+#define XDLC_SABME 0x6C /* Set Asynchronous Balanced Mode Extended */
+#define XDLC_RESET 0x8C /* Reset */
+#define XDLC_XID 0xAC /* Exchange identification */
+#define XDLC_SNRME 0xCC /* Set Normal Response Mode Extended */
+#define XDLC_BCN 0xEC /* Beacon */
+
+/*
+ * This macro takes the control field of an xDLC frame, as returned by
+ * "get_xdlc_control()" or "dissect_xdlc_control()", and evaluates to
+ * TRUE if the frame has a payload (i.e., if it's an Information or
+ * Unnumbered Information frame) and FALSE if it doesn't.
+ */
+#define XDLC_HAS_PAYLOAD(control) \
+ ((control) == XDLC_I || (control) == (XDLC_UI|XDLC_U))
+
+/*
+ * This macro takes the control field of an xDLC frame, and a flag saying
+ * whether we're doing basic or extended operation, and evaluates to
+ * the length of that field (if it's an Unnumbered frame, or we're not
+ * in extended mode, it's 3 bytes long, otherwise it's 4 bytes long).
+ */
+#define XDLC_CONTROL_LEN(control, is_extended) \
+ (((control) == XDLC_U || !(is_extended)) ? 3 : 4)
+
int get_xdlc_control(const u_char *pd, int offset, int is_response,
int extended);