* Routines for X11 dissection
* Copyright 2000, Christophe Tronche <ch.tronche@computer.org>
*
- * $Id: packet-x11.c,v 1.11 2000/08/13 14:09:11 deniel Exp $
+ * $Id: packet-x11.c,v 1.24 2001/10/26 18:28:16 gram Exp $
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@unicom.net>
+ * By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
*
* Copied from README.developer
/* Initialize the protocol and registered fields */
static int proto_x11 = -1;
-#include "packet-x11-declarations.h"
+#include "x11-declarations.h"
/* Initialize the subtree pointers */
static gint ett_x11 = -1;
static int cur_offset; /* The current offset in the frame */
static int next_offset = 0; /* Offset of the next request in the frame */
-static tvbuff_t *tvb = NULL;
static gboolean little_endian = TRUE;
static proto_tree *t = NULL;
#define VALUE16(tvb, offset) (little_endian ? tvb_get_letohs(tvb, offset) : tvb_get_ntohs(tvb, offset))
#define VALUE32(tvb, offset) (little_endian ? tvb_get_letohl(tvb, offset) : tvb_get_ntohl(tvb, offset))
-#define FIELD8(name) (field8(hf_x11_##name))
-#define FIELD16(name) (field16(hf_x11_##name))
-#define FIELD32(name) (field32(hf_x11_##name))
+#define FIELD8(name) (field8(tvb, hf_x11_##name))
+#define FIELD16(name) (field16(tvb, hf_x11_##name))
+#define FIELD32(name) (field32(tvb, hf_x11_##name))
#define BITFIELD(TYPE, position, name) {\
if (lastMask._value & proto_registrar_get_nth(hf_x11_##position##_##name) -> bitmask) {\
if (lastMask._value & proto_registrar_get_nth(hf_x11_##position##_mask##_##name) -> bitmask)\
proto_tree_add_boolean(lastMask._tree, hf_x11_##position##_mask##_##name, tvb, lastMask._offset, lastMask._zone, lastMask._value); }
-#define ATOM(name) { atom(t, hf_x11_##name); }
-#define BITGRAVITY(name) { gravity(#name, hf_x11_##name, "Forget"); }
-#define BITMASK8(name) { bitmask(hf_x11_##name##_mask, 1); }
-#define BITMASK16(name) { bitmask(hf_x11_##name##_mask, 2); }
-#define BITMASK32(name) { bitmask(hf_x11_##name##_mask, 4); }
-#define BOOL(name) (add_boolean(#name, hf_x11_##name))
+#define ATOM(name) { atom(tvb, t, hf_x11_##name); }
+#define BITGRAVITY(name) { gravity(tvb, #name, hf_x11_##name, "Forget"); }
+#define BITMASK8(name) { bitmask(tvb, hf_x11_##name##_mask, 1); }
+#define BITMASK16(name) { bitmask(tvb, hf_x11_##name##_mask, 2); }
+#define BITMASK32(name) { bitmask(tvb, hf_x11_##name##_mask, 4); }
+#define BOOL(name) (add_boolean(tvb, #name, hf_x11_##name))
#define BUTTON(name) { FIELD8(name); }
#define CARD8(name) { FIELD8(name); }
#define CARD16(name) (FIELD16(name))
#define CARD32(name) (FIELD32(name))
-#define COLOR_FLAGS(name) { colorFlags(t); }
+#define COLOR_FLAGS(name) { colorFlags(tvb, t); }
#define COLORMAP(name) { FIELD32(name); }
#define CURSOR(name) { FIELD32(name); }
#define DRAWABLE(name) { FIELD32(name); }
#define INT8(name) { FIELD8(name); }
#define INT16(name) { FIELD16(name); }
#define KEYCODE(name) { FIELD8(name); }
-#define LISTofARC(name) { listOfArc(hf_x11_##name, (next_offset - cur_offset) / 12); }
-#define LISTofATOM(name, length) { listOfAtom(hf_x11_##name, (length) / 4); }
-#define LISTofBYTE(name, length) { listOfByte(hf_x11_##name, (length)); }
-#define LISTofCARD8(name, length) { listOfByte(hf_x11_##name, (length)); }
-#define LISTofCARD32(name, length) { listOfCard32(hf_x11_##name, hf_x11_##name##_item, (length) / 4); }
-#define LISTofCOLORITEM(name, length) { listOfColorItem(hf_x11_##name, (length) / 12); }
-#define LISTofKEYCODE(name, length) { listOfKeycode(hf_x11_##name, (length)); }
+#define LISTofARC(name) { listOfArc(tvb, hf_x11_##name, (next_offset - cur_offset) / 12); }
+#define LISTofATOM(name, length) { listOfAtom(tvb, hf_x11_##name, (length) / 4); }
+#define LISTofBYTE(name, length) { listOfByte(tvb, hf_x11_##name, (length)); }
+#define LISTofCARD8(name, length) { listOfByte(tvb, hf_x11_##name, (length)); }
+#define LISTofCARD32(name, length) { listOfCard32(tvb, hf_x11_##name, hf_x11_##name##_item, (length) / 4); }
+#define LISTofCOLORITEM(name, length) { listOfColorItem(tvb, hf_x11_##name, (length) / 12); }
+#define LISTofKEYCODE(name, length) { listOfKeycode(tvb, hf_x11_##name, (length)); }
#define LISTofKEYSYM(name, keycode_count, keysyms_per_keycode) { \
- listOfKeysyms(hf_x11_##name, hf_x11_##name##_item, (keycode_count), (keysyms_per_keycode)); }
-#define LISTofPOINT(name, length) { listOfPoint(hf_x11_##name, (length) / 4); }
-#define LISTofRECTANGLE(name) { listOfRectangle(hf_x11_##name, (next_offset - cur_offset) / 8); }
-#define LISTofSEGMENT(name) { listOfSegment(hf_x11_##name, (next_offset - cur_offset) / 8); }
-#define LISTofSTRING8(name, length) { listOfString8(hf_x11_##name, hf_x11_##name##_string, (length)); }
-#define LISTofTEXTITEM8(name) { listOfTextItem(hf_x11_##name, FALSE); }
-#define LISTofTEXTITEM16(name) { listOfTextItem(hf_x11_##name, TRUE); }
+ listOfKeysyms(tvb, hf_x11_##name, hf_x11_##name##_item, (keycode_count), (keysyms_per_keycode)); }
+#define LISTofPOINT(name, length) { listOfPoint(tvb, hf_x11_##name, (length) / 4); }
+#define LISTofRECTANGLE(name) { listOfRectangle(tvb, hf_x11_##name, (next_offset - cur_offset) / 8); }
+#define LISTofSEGMENT(name) { listOfSegment(tvb, hf_x11_##name, (next_offset - cur_offset) / 8); }
+#define LISTofSTRING8(name, length) { listOfString8(tvb, hf_x11_##name, hf_x11_##name##_string, (length)); }
+#define LISTofTEXTITEM8(name) { listOfTextItem(tvb, hf_x11_##name, FALSE); }
+#define LISTofTEXTITEM16(name) { listOfTextItem(tvb, hf_x11_##name, TRUE); }
#define OPCODE() { opcode = FIELD8(opcode); }
#define PIXMAP(name) { FIELD32(name); }
-#define REQUEST_LENGTH() (requestLength())
-#define SETofEVENT(name) { setOfEvent(); }
-#define SETofDEVICEEVENT(name) { setOfDeviceEvent();}
-#define SETofKEYMASK(name) { setOfKeyMask(); }
-#define SETofPOINTEREVENT(name) { setOfPointerEvent(); }
-#define STRING8(name, length) { string8(#name, hf_x11_##name, length); }
-#define STRING16(name, length) { string16(hf_x11_##name, hf_x11_##name##_bytes, length); }
-#define TIMESTAMP(name){ timestamp(#name, hf_x11_##name); }
+#define REQUEST_LENGTH() (requestLength(tvb))
+#define SETofEVENT(name) { setOfEvent(tvb); }
+#define SETofDEVICEEVENT(name) { setOfDeviceEvent(tvb);}
+#define SETofKEYMASK(name) { setOfKeyMask(tvb); }
+#define SETofPOINTEREVENT(name) { setOfPointerEvent(tvb); }
+#define STRING8(name, length) { string8(tvb, #name, hf_x11_##name, length); }
+#define STRING16(name, length) { string16(tvb, hf_x11_##name, hf_x11_##name##_bytes, length); }
+#define TIMESTAMP(name){ timestamp(tvb, #name, hf_x11_##name); }
#define UNDECODED(x) { proto_tree_add_item(t, hf_x11_undecoded, tvb, cur_offset, x, little_endian); p += x; }
#define UNUSED(x) { proto_tree_add_item(t, hf_x11_unused, tvb, cur_offset, x, little_endian); cur_offset += x; }
#define PAD() { if (next_offset - cur_offset > 0) proto_tree_add_item(t, hf_x11_unused, tvb, cur_offset, next_offset - cur_offset, little_endian); cur_offset = next_offset; }
#define WINDOW(name) { FIELD32(name); }
-#define WINGRAVITY(name) { gravity(#name, hf_x11_##name, "Unmap"); }
+#define WINGRAVITY(name) { gravity(tvb, #name, hf_x11_##name, "Unmap"); }
#define VISUALID(name) { gint32 v = VALUE32(tvb, cur_offset); \
proto_tree_add_uint_format(t, hf_x11_##name, tvb, cur_offset, 4, v, "Visualid: 0x%08x%s", v, \
*** ***
************************************************************************/
-static void atom(proto_tree *t, int hf)
+static void atom(tvbuff_t *tvb, proto_tree *t, int hf)
{
const char *interpretation = NULL;
else if (v)
interpretation = "Not a predefined atom";
else {
- struct header_field_info *hfi = proto_registrar_get_nth(hf);
+ header_field_info *hfi = proto_registrar_get_nth(hf);
if (hfi -> strings)
interpretation = match_strval(v, cVALS(hfi -> strings));
}
if (!interpretation) interpretation = "error in Xlib client program ?";
- proto_tree_add_uint_format(t, hf, tvb, cur_offset, 4, v, "%s: %d (%s)",
+ proto_tree_add_uint_format(t, hf, tvb, cur_offset, 4, v, "%s: %u (%s)",
proto_registrar_get_nth(hf) -> name, v, interpretation);
cur_offset += 4;
}
-static void bitmask(int hf, int size)
+static void bitmask(tvbuff_t *tvb, int hf, int size)
{
lastMask._value = size == 2 ? VALUE16(tvb, cur_offset) : VALUE32(tvb, cur_offset);
lastMask._offset = cur_offset;
cur_offset += size;
}
-static guint32 add_boolean(const char *nameAsChar, int hf)
+static guint32 add_boolean(tvbuff_t *tvb, const char *nameAsChar, int hf)
{
guint32 v = VALUE8(tvb, cur_offset);
proto_tree_add_boolean(t, hf, tvb, cur_offset, 1, v);
return v;
}
-static void colorFlags(proto_tree *t)
+static void colorFlags(tvbuff_t *tvb, proto_tree *t)
{
unsigned do_red_green_blue = VALUE8(tvb, cur_offset);
proto_tree *tt;
cur_offset++;
}
-static void gravity(const char *nameAsChar, int hf, const char *nullInterpretation)
+static void gravity(tvbuff_t *tvb, const char *nameAsChar, int hf, const char *nullInterpretation)
{
guint8 v = VALUE8(tvb, cur_offset);
if (!v)
cur_offset += 1;
}
-static void listOfArc(int hf, int length)
+static void listOfArc(tvbuff_t *tvb, int hf, int length)
{
proto_tree *tt = proto_tree_add_item(t, hf, tvb, cur_offset, length * 8, little_endian);
while(length--) {
gint16 angle1 = VALUE16(tvb, cur_offset + 8);
gint16 angle2 = VALUE16(tvb, cur_offset + 10);
- proto_tree *ttt = proto_tree_add_protocol_format(tt, hf_x11_arc, tvb, cur_offset, 12,
- "arc: %dx%d+%d+%d, angle %d -> %d (%f° -> %f°)",
+ proto_tree *ttt = proto_tree_add_none_format(tt, hf_x11_arc, tvb, cur_offset, 12,
+ "arc: %dx%d+%d+%d, angle %d -> %d (%f degrees -> %f degrees)",
width, height, x, y, angle1, angle2,
angle1 / 64.0, angle2 / 64.0);
proto_tree_add_int(ttt, hf_x11_arc_x, tvb, cur_offset, 2, x); cur_offset += 2;
}
}
-static void listOfAtom(int hf, int length)
+static void listOfAtom(tvbuff_t *tvb, int hf, int length)
{
proto_tree *tt = proto_tree_add_item(t, hf, tvb, cur_offset, length * 4, little_endian);
while(length--) {
/* List runs past end of message. */
return;
}
- atom(tt, hf_x11_properties_item);
+ atom(tvb, tt, hf_x11_properties_item);
}
}
-static void listOfByte(int hf, int length)
+static void listOfByte(tvbuff_t *tvb, int hf, int length)
{
if (cur_offset + length > next_offset) {
/* List runs past end of message. */
length = next_offset - cur_offset;
}
if (length <= 0) length = 1;
- proto_tree_add_bytes(t, hf, tvb, cur_offset, length, tvb_get_ptr(tvb, cur_offset, length));
+ proto_tree_add_item(t, hf, tvb, cur_offset, length, little_endian);
cur_offset += length;
}
-static void listOfCard32(int hf, int hf_item, int length)
+static void listOfCard32(tvbuff_t *tvb, int hf, int hf_item, int length)
{
proto_tree *tt = proto_tree_add_item(t, hf, tvb, cur_offset, length * 4, little_endian);
while(length--) {
}
}
-static void listOfColorItem(int hf, int length)
+static void listOfColorItem(tvbuff_t *tvb, int hf, int length)
{
proto_tree *tt = proto_tree_add_item(t, hf, tvb, cur_offset, length * 8, little_endian);
while(length--) {
if (do_red_green_blue & 0x2) { bp += sprintf(bp, "%sgreen = %d", sep, green); sep = ", "; }
if (do_red_green_blue & 0x4) bp += sprintf(bp, "%sblue = %d", sep, blue);
- ttt = proto_tree_add_protocol_format(tt, hf_x11_coloritem, tvb, cur_offset, 12, "%s", buffer);
+ ttt = proto_tree_add_none_format(tt, hf_x11_coloritem, tvb, cur_offset, 12, "%s", buffer);
proto_tree_add_item(ttt, hf_x11_coloritem_pixel, tvb, cur_offset, 4, little_endian); cur_offset += 4;
proto_tree_add_item(ttt, hf_x11_coloritem_red, tvb, cur_offset, 2, little_endian); cur_offset += 2;
proto_tree_add_item(ttt, hf_x11_coloritem_green, tvb, cur_offset, 2, little_endian); cur_offset += 2;
proto_tree_add_item(ttt, hf_x11_coloritem_blue, tvb, cur_offset, 2, little_endian); cur_offset += 2;
- colorFlags(ttt);
+ colorFlags(tvb, ttt);
proto_tree_add_item(ttt, hf_x11_coloritem_unused, tvb, cur_offset, 1, little_endian); cur_offset++;
}
}
static const char *modifiers[] = { "Shift", "Lock", "Control", "Mod1", "Mod2", "Mod3", "Mod4", "Mod5" };
-static void listOfKeycode(int hf, int length)
+static void listOfKeycode(tvbuff_t *tvb, int hf, int length)
{
char buffer[1024];
proto_tree *tt = proto_tree_add_item(t, hf, tvb, cur_offset, length * 8, little_endian);
}
}
-static void listOfKeysyms(int hf, int hf_item, int keycode_count, int keysyms_per_keycode)
+static void listOfKeysyms(tvbuff_t *tvb, int hf, int hf_item, int keycode_count, int keysyms_per_keycode)
{
proto_tree *tt = proto_tree_add_item(t, hf, tvb, cur_offset, keycode_count * keysyms_per_keycode * 4, little_endian);
proto_tree *ttt;
bp += sprintf(bp, " %s", keysymString(VALUE32(tvb, cur_offset + i * 4)));
}
*bp = '\0';
- ttt = proto_tree_add_protocol_format(tt, hf_item, tvb, cur_offset, keysyms_per_keycode * 4,
+ ttt = proto_tree_add_none_format(tt, hf_item, tvb, cur_offset, keysyms_per_keycode * 4,
"%s", buffer);
for(i = keysyms_per_keycode; i; i--) {
guint32 v = VALUE32(tvb, cur_offset);
}
}
-static void listOfPoint(int hf, int length)
+static void listOfPoint(tvbuff_t *tvb, int hf, int length)
{
proto_tree *tt = proto_tree_add_item(t, hf, tvb, cur_offset, length * 4, little_endian);
while(length--) {
x = VALUE16(tvb, cur_offset);
y = VALUE16(tvb, cur_offset + 2);
- ttt = proto_tree_add_protocol_format(tt, hf_x11_point, tvb, cur_offset, 4, "point: (%d,%d)", x, y);
+ ttt = proto_tree_add_none_format(tt, hf_x11_point, tvb, cur_offset, 4, "point: (%d,%d)", x, y);
proto_tree_add_int(ttt, hf_x11_point_x, tvb, cur_offset, 2, x); cur_offset += 2;
proto_tree_add_int(ttt, hf_x11_point_y, tvb, cur_offset, 2, y); cur_offset += 2;
}
}
-static void listOfRectangle(int hf, int length)
+static void listOfRectangle(tvbuff_t *tvb, int hf, int length)
{
proto_tree *tt = proto_tree_add_item(t, hf, tvb, cur_offset, length * 8, little_endian);
while(length--) {
width = VALUE16(tvb, cur_offset + 4);
height = VALUE16(tvb, cur_offset + 6);
- ttt = proto_tree_add_protocol_format(tt, hf_x11_rectangle, tvb, cur_offset, 8,
+ ttt = proto_tree_add_none_format(tt, hf_x11_rectangle, tvb, cur_offset, 8,
"rectangle: %dx%d+%d+%d", width, height, x, y);
proto_tree_add_int(ttt, hf_x11_rectangle_x, tvb, cur_offset, 2, x); cur_offset += 2;
proto_tree_add_int(ttt, hf_x11_rectangle_y, tvb, cur_offset, 2, y); cur_offset += 2;
}
}
-static void listOfSegment(int hf, int length)
+static void listOfSegment(tvbuff_t *tvb, int hf, int length)
{
proto_tree *tt = proto_tree_add_item(t, hf, tvb, cur_offset, length * 8, little_endian);
while(length--) {
x2 = VALUE16(tvb, cur_offset + 4);
y2 = VALUE16(tvb, cur_offset + 6);
- ttt = proto_tree_add_protocol_format(tt, hf_x11_segment, tvb, cur_offset, 8,
+ ttt = proto_tree_add_none_format(tt, hf_x11_segment, tvb, cur_offset, 8,
"segment: (%d,%d)-(%d,%d)", x1, y1, x2, y2);
proto_tree_add_item(ttt, hf_x11_segment_x1, tvb, cur_offset, 2, little_endian); cur_offset += 2;
proto_tree_add_item(ttt, hf_x11_segment_y1, tvb, cur_offset, 2, little_endian); cur_offset += 2;
*dest++ = '\0';
}
-static void listOfString8(int hf, int hf_item, int length)
+static void listOfString8(tvbuff_t *tvb, int hf, int hf_item, int length)
{
char *s = NULL;
- int allocated = 0;
+ guint allocated = 0;
proto_tree *tt;
int i;
while(length--) {
unsigned l = VALUE8(tvb, cur_offset);
- if (allocated < l + 1) {
+ if (allocated < (l + 1)) {
/* g_realloc doesn't work ??? */
g_free(s);
s = g_malloc(l + 1);
#define STRING16_MAX_DISPLAYED_LENGTH 150
-static int stringIsActuallyAn8BitString(int offset, unsigned length)
+static int stringIsActuallyAn8BitString(tvbuff_t *tvb, int offset, unsigned length)
{
if (length > STRING16_MAX_DISPLAYED_LENGTH) length = STRING16_MAX_DISPLAYED_LENGTH;
for(; length > 0; cur_offset += 2, length--) {
/* length is the length of the _byte_zone_ (that is, twice the length of the string) */
-static void string16_with_buffer_preallocated(proto_tree *t, int hf, int hf_bytes,
+static void string16_with_buffer_preallocated(tvbuff_t *tvb, proto_tree *t,
+ int hf, int hf_bytes,
int offset, unsigned length,
char **s, int *sLength)
{
int truncated = FALSE;
unsigned l = length / 2;
- if (stringIsActuallyAn8BitString(offset, l)) {
+ if (stringIsActuallyAn8BitString(tvb, offset, l)) {
char *dp;
int soffset = offset;
truncated = TRUE;
l = STRING16_MAX_DISPLAYED_LENGTH;
}
- if (*sLength < l + 3) {
+ if (*sLength < (int) l + 3) {
g_free(*s);
*s = g_malloc(l + 3);
*sLength = l + 3;
proto_tree_add_string_format(t, hf, tvb, offset, length, tvb_get_ptr(tvb, offset, length), "%s: %s",
proto_registrar_get_nth(hf) -> name, *s);
} else
- proto_tree_add_bytes(t, hf_bytes, tvb, offset, length, tvb_get_ptr(tvb, offset, length));
+ proto_tree_add_item(t, hf_bytes, tvb, offset, length, little_endian);
}
-static void listOfTextItem(int hf, int sizeIs16)
+static void listOfTextItem(tvbuff_t *tvb, int hf, int sizeIs16)
{
int allocated = 0;
char *s = NULL;
proto_tree *ttt;
gint8 delta = VALUE8(tvb, cur_offset + 1);
if (sizeIs16) l += l;
- if (allocated < l + 1) {
+ if ((unsigned) allocated < l + 1) {
/* g_realloc doesn't work ??? */
g_free(s);
s = g_malloc(l + 1);
allocated = l + 1;
}
stringCopy(s, tvb_get_ptr(tvb, cur_offset + 2, l), l);
- ttt = proto_tree_add_protocol_format(tt, hf_x11_textitem_string, tvb, cur_offset, l + 2,
+ ttt = proto_tree_add_none_format(tt, hf_x11_textitem_string, tvb, cur_offset, l + 2,
"textitem (string): delta = %d, \"%s\"",
delta, s);
proto_tree_add_item(ttt, hf_x11_textitem_string_delta, tvb, cur_offset + 1, 1, little_endian);
if (sizeIs16)
- string16_with_buffer_preallocated(ttt, hf_x11_textitem_string_string16,
+ string16_with_buffer_preallocated(tvb, ttt, hf_x11_textitem_string_string16,
hf_x11_textitem_string_string16_bytes,
cur_offset + 2, l,
&s, &allocated);
g_free(s);
}
-static guint32 field8(int hf)
+static guint32 field8(tvbuff_t *tvb, int hf)
{
guint32 v = VALUE8(tvb, cur_offset);
- struct header_field_info *hfi = proto_registrar_get_nth(hf);
+ header_field_info *hfi = proto_registrar_get_nth(hf);
gchar *enumValue = NULL;
gchar *nameAsChar = hfi -> name;
if (hfi -> strings)
enumValue = match_strval(v, cVALS(hfi -> strings));
if (enumValue)
- proto_tree_add_uint_format(t, hf, tvb, cur_offset, 1, v, "%s: %d (%s)", nameAsChar, v, enumValue);
+ proto_tree_add_uint_format(t, hf, tvb, cur_offset, 1, v, "%s: %u (%s)", nameAsChar, v, enumValue);
else
proto_tree_add_item(t, hf, tvb, cur_offset, 1, little_endian);
cur_offset += 1;
return v;
}
-static guint32 field16(int hf)
+static guint32 field16(tvbuff_t *tvb, int hf)
{
guint32 v = VALUE16(tvb, cur_offset);
proto_tree_add_item(t, hf, tvb, cur_offset, 2, v);
return v;
}
-static guint32 field32(int hf)
+static guint32 field32(tvbuff_t *tvb, int hf)
{
guint32 v = VALUE32(tvb, cur_offset);
- struct header_field_info *hfi = proto_registrar_get_nth(hf);
+ header_field_info *hfi = proto_registrar_get_nth(hf);
gchar *enumValue = NULL;
gchar *nameAsChar = hfi -> name;
proto_tree_add_uint_format(t, hf, tvb, cur_offset, 4, v, "%s: 0x%08x (%s)", nameAsChar, v, enumValue);
else
proto_tree_add_uint_format(t, hf, tvb, cur_offset, 4, v,
- hfi -> display == BASE_DEC ? "%s: %d" : "%s : 0x%08x",
+ hfi -> display == BASE_DEC ? "%s: %u" : "%s: 0x%08x",
nameAsChar, v);
cur_offset += 4;
return v;
}
-static void gcAttributes(void)
+static void gcAttributes(tvbuff_t *tvb)
{
BITMASK32(gc_value);
BITFIELD(ENUM8, gc_value_mask, function);
BITFIELD(ENUM8, gc_value_mask, arc_mode);
}
-static void gcMask(void)
+static void gcMask(tvbuff_t *tvb)
{
BITMASK32(gc_value);
FLAG(gc_value, function);
FLAG(gc_value, arc_mode);
}
-static guint32 requestLength(void)
+static guint32 requestLength(tvbuff_t *tvb)
{
guint32 res = VALUE16(tvb, cur_offset) * 4;
proto_tree_add_uint(t, hf_x11_request_length, tvb, cur_offset, 2, res);
return res;
}
-static void setOfEvent(void)
+static void setOfEvent(tvbuff_t *tvb)
{
struct maskStruct save = lastMask;
BITMASK32(event);
lastMask = save;
}
-static void setOfDeviceEvent(void)
+static void setOfDeviceEvent(tvbuff_t *tvb)
{
struct maskStruct save = lastMask;
BITMASK32(do_not_propagate);
lastMask = save;
}
-static void setOfKeyMask(void)
+static void setOfKeyMask(tvbuff_t *tvb)
{
struct maskStruct save = lastMask;
lastMask._value = VALUE16(tvb, cur_offset);
cur_offset += 2;
}
-static void setOfPointerEvent(void)
+static void setOfPointerEvent(tvbuff_t *tvb)
{
struct maskStruct save = lastMask;
BITMASK16(pointer_event);
lastMask = save;
}
-static void string8(const char *nameAsChar, int hf, unsigned length)
+static void string8(tvbuff_t *tvb, const char *nameAsChar, int hf, unsigned length)
{
char *s = g_malloc(length + 1);
stringCopy(s, tvb_get_ptr(tvb, cur_offset, length), length);
/* The length is the length of the _byte_zone_ (twice the length of the string) */
-static void string16(int hf, int hf_bytes, unsigned length)
+static void string16(tvbuff_t *tvb, int hf, int hf_bytes, unsigned length)
{
char *s = NULL;
unsigned l = 0;
length += length;
- string16_with_buffer_preallocated(t, hf, hf_bytes, cur_offset, length, &s, &l);
+ string16_with_buffer_preallocated(tvb, t, hf, hf_bytes, cur_offset, length, &s, &l);
g_free(s);
cur_offset += length;
}
-static void timestamp(const char *nameAsChar, int hf)
+static void timestamp(tvbuff_t *tvb, const char *nameAsChar, int hf)
{
guint32 v = VALUE32(tvb, cur_offset);
if (!v)
cur_offset += 4;
}
-static void windowAttributes(void)
+static void windowAttributes(tvbuff_t *tvb)
{
BITMASK32(window_value);
BITFIELD(PIXMAP, window_value_mask, background_pixmap);
*** ***
************************************************************************/
-static int dissect_x11_request_loop(proto_tree *root)
+static int dissect_x11_request_loop(tvbuff_t *tvb, proto_tree *root)
{
int left = tvb_reported_length(tvb), nextLeft;
proto_item *ti;
CARD16(border_width);
ENUM16(window_class);
VISUALID(visual);
- windowAttributes();
+ windowAttributes(tvb);
break;
case 2: /* ChangeWindowAttributes */
UNUSED(1);
REQUEST_LENGTH();
WINDOW(window);
- windowAttributes();
+ windowAttributes(tvb);
break;
case 3: /* GetWindowAttributes */
REQUEST_LENGTH();
GCONTEXT(cid);
DRAWABLE(drawable);
- gcAttributes();
+ gcAttributes(tvb);
break;
case 56: /* ChangeGC */
UNUSED(1);
REQUEST_LENGTH();
GCONTEXT(gc);
- gcAttributes();
+ gcAttributes(tvb);
break;
case 57: /* CopyGC */
REQUEST_LENGTH();
GCONTEXT(src_gc);
GCONTEXT(dst_gc);
- gcMask();
+ gcMask(tvb);
break;
case 58: /* SetDashes */
}
static gboolean
-guess_byte_ordering(tvbuff_t *tvb)
+guess_byte_ordering(tvbuff_t *tvb, packet_info *pinfo)
{
/* With X the client gives the byte ordering for the protocol,
and the port on the server tells us we're speaking X. */
int le, be, decision, decisionToCache;
- address *addr = pi.srcport == pi.match_port ? &pi.net_dst : &pi.net_src;
+ gboolean is_reply = (pinfo->srcport == pinfo->match_port);
+ address *addr = is_reply ? &pinfo->net_dst : &pinfo->net_src;
gint32 cache = GPOINTER_TO_INT(g_tree_lookup(byte_ordering_cache, addr));
if (cache) return cache > 0 ? TRUE : FALSE;
- if (pi.srcport == pi.match_port) return TRUE; /* We don't try to guess on a reply / event for now */
+ if (is_reply) return TRUE; /* We don't try to guess on a reply / event for now */
le = x_endian_match(tvb, tvb_get_letohs);
be = x_endian_match(tvb, tvb_get_ntohs);
/*
fprintf(stderr, "packet %d\tle %d\tbe %d\tlittle_endian %d\tcache %d\n",
- pi.fd -> num, le, be, decision, decisionToCache);
+ pinfo->fd -> num, le, be, decision, decisionToCache);
*/
return decision;
}
************************************************************************/
static void
-dissect_x11_request(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
+dissect_x11_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
/* Set up structures we will need to add the protocol subtree and manage it */
proto_item *ti;
proto_tree *x11_tree;
int left;
-/* Make entries in Protocol column and Info column on summary display */
- if (check_col(fd, COL_PROTOCOL))
- col_add_str(fd, COL_PROTOCOL, "X11");
-
/* This field shows up as the "Info" column in the display; you should make
it, if possible, summarize what's in the packet, so that a user looking
- at the list of packets can tell what type of packet it is.
-
- "col_add_fstr()" can be used instead of "col_add_str()"; it takes
- "printf()"-like arguments. */
- if (check_col(fd, COL_INFO))
- col_add_str(fd, COL_INFO, "X11 request");
+ at the list of packets can tell what type of packet it is. */
+ if (check_col(pinfo->fd, COL_INFO))
+ col_set_str(pinfo->fd, COL_INFO, "X11 request");
/* In the interest of speed, if "tree" is NULL, don't do any work not
necessary to generate protocol tree items. */
if (!tree) return;
-/* NOTE: The offset and length values in the previous call to
- "proto_tree_add_item()" define what data bytes to highlight in the hex
- display window when the line in the protocol tree display
- corresponding to that item is selected.
-
- END_OF_FRAME is a handy way to highlight all data from the offset to
- the end of the packet. */
- ti = proto_tree_add_item(tree, proto_x11, NullTVB, offset, END_OF_FRAME, FALSE);
+ ti = proto_tree_add_item(tree, proto_x11, tvb, 0,
+ tvb_length(tvb), FALSE);
x11_tree = proto_item_add_subtree(ti, ett_x11);
-/* Code to process the packet goes here */
-
- tvb = tvb_create_from_top(offset);
cur_offset = 0;
- little_endian = guess_byte_ordering(tvb);
- left = dissect_x11_request_loop(x11_tree);
+ little_endian = guess_byte_ordering(tvb, pinfo);
+ left = dissect_x11_request_loop(tvb, x11_tree);
if (left)
- old_dissect_data(pd, offset + cur_offset, fd, x11_tree);
+ dissect_data(tvb, cur_offset, pinfo, x11_tree);
}
static void
-dissect_x11_event(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
+dissect_x11_event(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
/* Set up structures we will need to add the protocol subtree and manage it */
proto_item *ti;
proto_tree *x11_tree;
-/* Make entries in Protocol column and Info column on summary display */
- if (check_col(fd, COL_PROTOCOL))
- col_add_str(fd, COL_PROTOCOL, "X11");
-
/* This field shows up as the "Info" column in the display; you should make
it, if possible, summarize what's in the packet, so that a user looking
- at the list of packets can tell what type of packet it is.
-
- "col_add_fstr()" can be used instead of "col_add_str()"; it takes
- "printf()"-like arguments. */
- if (check_col(fd, COL_INFO))
- col_add_str(fd, COL_INFO, "X11 event");
+ at the list of packets can tell what type of packet it is. */
+ if (check_col(pinfo->fd, COL_INFO))
+ col_set_str(pinfo->fd, COL_INFO, "X11 event");
/* In the interest of speed, if "tree" is NULL, don't do any work not
necessary to generate protocol tree items. */
if (tree) {
-/* NOTE: The offset and length values in the previous call to
- "proto_tree_add_item()" define what data bytes to highlight in the hex
- display window when the line in the protocol tree display
- corresponding to that item is selected.
-
- END_OF_FRAME is a handy way to highlight all data from the offset to
- the end of the packet. */
- ti = proto_tree_add_item(tree, proto_x11, NullTVB, offset, END_OF_FRAME, FALSE);
+ ti = proto_tree_add_item(tree, proto_x11, tvb, 0,
+ tvb_length(tvb), FALSE);
x11_tree = proto_item_add_subtree(ti, ett_x11);
/* Code to process the packet goes here */
- old_dissect_data(pd, offset, fd, tree);
+ dissect_data(tvb, 0, pinfo, x11_tree);
}
}
static void
-dissect_x11(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
+dissect_x11(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
-
- OLD_CHECK_DISPLAY_AS_DATA(proto_x11, pd, offset, fd, tree);
-
- pi.current_proto = "X11";
- if (pi.destport == TCP_PORT_X11 || pi.destport == TCP_PORT_X11_2 || pi.destport == TCP_PORT_X11_3)
- dissect_x11_request(pd, offset, fd, tree);
+ if (check_col(pinfo->fd, COL_PROTOCOL))
+ col_set_str(pinfo->fd, COL_PROTOCOL, "X11");
+
+ if (pinfo->match_port == pinfo->destport)
+ dissect_x11_request(tvb, pinfo, tree);
else
- dissect_x11_event(pd, offset, fd, tree);
+ dissect_x11_event(tvb, pinfo, tree);
}
/* Register the protocol with Ethereal */
{ &hf_x11_FIELDABBREV,
{ "FIELDNAME", "x11.FIELDABBREV",
FIELDTYPE, FIELDBASE, FIELDCONVERT, BITMASK,
- "FIELDDESCR" }
+ "FIELDDESCR", HFILL }
},
*/
-#include "packet-x11-register-info.h"
+#include "x11-register-info.h"
};
/* Setup protocol subtree array */
};
/* Register the protocol name and description */
- proto_x11 = proto_register_protocol("X11", "x11");
+ proto_x11 = proto_register_protocol("X11", "X11", "x11");
/* Required function calls to register the header fields and subtrees used */
proto_register_field_array(proto_x11, hf, array_length(hf));
void
proto_reg_handoff_x11(void)
{
- old_dissector_add("tcp.port", TCP_PORT_X11, dissect_x11);
- old_dissector_add("tcp.port", TCP_PORT_X11_2, dissect_x11);
- old_dissector_add("tcp.port", TCP_PORT_X11_3, dissect_x11);
+ dissector_add("tcp.port", TCP_PORT_X11, dissect_x11, proto_x11);
+ dissector_add("tcp.port", TCP_PORT_X11_2, dissect_x11, proto_x11);
+ dissector_add("tcp.port", TCP_PORT_X11_3, dissect_x11, proto_x11);
}