ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
[Tutor] packet parsing
by other posts by this author
Feb 28 2002 8:53PM messages near this date
RE: [Tutor] Problems with genetically engineering the Print Ogre | Re: [Tutor] packet parsing
Hello,

I'm trying to make the best of my unemployed time and have decided that
implementing an SSH client in Python will keep me occupied for a few
years.

I've just started, and am working on the first non-trivial part (which
appeared REALLY quickly in the IETF draft).

My program connects to the server; the server says, "I'm an SSH server".
My client says, "I'm an SSH client".  The server then sends a variable
length message in SSH Binary Packet Format to initiate a key exchange.

My first question is:  do I need to be concerned about
little/big/network-endian?  Both of my machines are little-endian.  So
when I look at a byte from the SSH server's packet, do I need to do a
network-to-host translation?  Conversely, when I send a byte to the
server, do I need to do a host-to-network translation

My second question is: how do I look at/manipulate bytes of an incoming
network packet?  Or bits even.  Right now, I have the following piece of 
code that receives the SSH server's initial key exchange packet:

    kexrecv = mysock.recv(blocksize) 

I want to directly manipulate the bits/bytes of kexrecv.  Everything
that I've done makes kexrecv into a string.  And I'm having problems
with kexrecv as a string -- I want to deal with it as a binary stream.
(Note:  this might not be the best way to deal with it, but until I have
a good grip on the SSH transport protocol, it's how I prefer to deal
with it -- right now I want to be able to say: "read the first 32 bits,
convert it into a number; read the next 8 bits, convert it into a
number; read the next 128 bits...blah, blah, etc.).

type(kexrecv) results in <type 'str'> 
type(`kexrecv`) results in <type 'str'> 
len(kexrecv) returns nothing
len(`kexrecv`) returns 830
print len(kexrecv) returns 632
print len(`kexrecv`) returns 830

(Yes, I know that the backticks are equivalent to repr() -- I looked it
up on google last night).  I want to deal with kexrecv and not
`kexrecv`.  But I haven't been able to figure it out.

If kexrecv is a string [as type(kexrecv) seems to think] why doesn't
len(kexrecv) return anything?  And if kexrecv is a string, why does
len(`kexrecv`) return a larger value than "print len(kexrecv)"?

Thanks,
Jay





_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:

Remco Gerlich

Remco Gerlich
dman

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved