[Tutor] packet parsing
Thu, 28 Feb 2002 17:43:26 -0500
On Thu, Feb 28, 2002 at 10:34:49PM +0100, Remco Gerlich wrote:
| On 0, email@example.com wrote:
| > OK, that makes sense. But how do I peel of individual bytes? (I just
| > played with lstrip and am not having any luck -- but this is probably my
| > lack of knowledge).
| kexrecv is the first byte, kexrecv the second, etc.
| for byte ik kexrecv:
| print ord(byte)
| To see the integer values.
In addition, look at the 'struct' module. It contains methods to
treat strings as packed binary data. For example,
# turn my PyInt object into a bitstream :
s = struct.pack( "> i " , 13 )
# turn the bitsequence into a PyInt so I can perform mathmatical
# operations on it :
i = struct.unpack( "> i " , "\x00\x00\x00\x0d" )[ 0 ]
(note that in this example, s will have the value that is passed to
unpack() as a literal)
Try it out! :-). And read the docs too.
If we claim we have not sinned, we make Him out to be a liar and His
Word has no place in our lives.
I John 1:10