[comp.windows.x] X protocol packets

johnr@systech.uucp (John Reed) (12/15/88)

The following data was gathered from "etherfind -x"
It shows the ethernet packets that were being transferred between
an X terminal and a host.

At the time, I was simply running vi in an xterm window.  The output
shows the packets that were transferred when a single character ('k')
was typed on the terminal.

The first data packet is a "KeyPress" event, and is generated from
the terminal.

The 2nd data packet is a "ImageText8" packet, and is generated from
the client host.

I understand that the first 54 bytes of data are the ethernet header
and the tcp stuff.  I am not concerned with this junk.

Can anyone provide me an explanation of the data within the X protocol
message itself?  Like where is the 'k' encoded??
I just do not understand the format of the data within these X message.

Also, what are the last 8 bytes of data in each packet for.  Is this
some kind of tcp trailer??

Using interface ie0
 0.00 TCP from systec.vis.6000 to systec.sun3.2431 seq 616AFE02, ack 9C4E512,
 window 2828, 32 bytes data
 08 00 20 01 c8 7c 00 00 22 ff 00 0b 08 00 45 00
 00 48 8e 46 00 00 3c 06 3e 50 c0 06 99 09 c0 06
 99 03 17 70 09 7f 61 6a fe 02 09 c4 e5 12 50 18
 0b 0c c4 25 00 00 02 12 12 23 0a 7e 9b 16 00 08
 00 6b 00 10 00 09 00 00 00 00 01 5f 00 cd 01 47
 00 65 00 00 01 00 0d 0a 65 61 6c 69 6e 67

 0.01 TCP from systec.sun3.2431 to systec.vis.6000 seq 9C4E512, ack 616AFE22,
 window 4096, 60 bytes data
 00 00 22 ff 00 0b 08 00 20 01 c8 7c 08 00 45 00
 00 64 68 d9 00 00 0f 06 90 a1 c0 06 99 03 c0 06
 99 09 09 7f 17 70 09 c4 e5 12 61 6a fe 22 50 18
 10 00 e9 de 00 00 4c 01 00 05 00 10 00 09 00 10
 00 0a 00 02 01 2a 20 02 00 2a 4c 01 00 05 00 10
 00 09 00 10 00 0a 00 02 01 2a 6b c0 00 14 4c 01
 00 05 00 10 00 09 00 10 00 0c 00 0e 01 2a 20 01
 00 05 0d 0a 65 20 20 79 6f 75


Thanks in advance for anyone willing to help.

John Reed
{uunet,ucsd}!systech!johnr

jim@EXPO.LCS.MIT.EDU (Jim Fulton) (12/16/88)

> Can anyone provide me an explanation of the data within the X protocol
> message itself?  Like where is the 'k' encoded??
> I just do not understand the format of the data within these X message.

Look in your handy Protocol document (sources are provided doc/Protocol/ or
in _X_Window_System:_C_Library_and_Protocol_Reference_ by Scheifler, Gettys,
and Newman) under Section 11 (named Events).  In particular, you want to read
the first section describing KeyPress events (in "The Book", this is on pages
443-444).  The particular bits are described in Appendix F: Protocol Encoding
and are as follows


	1	2			event code
	1	KEYCODE			detail
	2	CARD16			sequence number
	4	TIMESTAMP		time
	4	WINDOW			root
	4	WINDOW			event
	4	WINDOW			child
	2	INT16			root-x
	2	INT16			root-y
	2	INT16			event-x
	2	INT16			event-y
	2	SETofKEYBUTMASK		state


If you are using the C lanuage interface Xlib, you'll only need to deal with
XKeyEvent structures (from <X11/Xlib.h>):

typedef struct {
	int type;		/* of event */
	unsigned long serial;	/* # of last request processed by server */
	Bool send_event;	/* true if this came from a SendEvent request */
	Display *display;	/* Display the event was read from */
	Window window;	        /* "event" window it is reported relative to */
	Window root;	        /* root window that the event occured on */
	Window subwindow;	/* child window */
	Time time;		/* milliseconds */
	int x, y;		/* pointer x, y coordinates in event window */
	int x_root, y_root;	/* coordinates relative to root */
	unsigned int state;	/* key or button mask */
	unsigned int keycode;	/* detail */
	Bool same_screen;	/* same screen flag */
} XKeyEvent;
typedef XKeyEvent XKeyPressedEvent;



> Like where is the 'k' encoded??

The detail field in the protocol request contains a "keycode" which is a
server-dependent number representing the physical key that was pressed just
like make/break codes under other operating systems.  The state field contains
a mask of bits indicating which keyboard modifiers where held down when this
key was pressed. 

Clients are free to use the keycode and state mask directly, although they will
usually translate it into a "keysym" which represents the symbol etched on the
key.  This is usually handled by a library routine (XKeycodeToKeysym in Xlib)
as it involves fetching the keyboard mapping (which is a table containing a
row for each keycode and a column for each modifier) and then looking up the
keysym that corresponds to the <keycode,statemask> pair.

Now, this keysym is still just a number (although keysyms, unlike keycodes, are
specified by the X Protocol).  Applications can then use the keysyms or
translate them into "strings" for various character sets using XLookupString
and XmuLookup*.  However, they should keep in mind that these routines are
designed to be used with specific character sets (e.g. ISO Latin-1 for
XLookupString) and may not return values for arbitrary combinations of
modifiers (esp. function control codes).

Jim Fulton
MIT X Consortium