Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9202
| References | <4E1A12B1.8060205@tysdomain.com> |
|---|---|
| Date | 2011-07-10 19:33 -0400 |
| Subject | Re: parsing packets |
| From | Michael Hrivnak <mhrivnak@hrivnak.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.864.1310340827.1164.python-list@python.org> (permalink) |
In order to find the end of the packet, include a field that is the packet length. This is what IP packets do to find the end of their header. http://en.wikipedia.org/wiki/IPv4#Header And the TCP header (see "data offset") does the same: http://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure Of course in both cases they are specifying the header length, not including a data payload. However, it sounds like you might not have a payload, so your entire packet might consist of header-like data. Michael On Sun, Jul 10, 2011 at 4:59 PM, Littlefield, Tyler <tyler@tysdomain.com> wrote: > Hello all: > I'm working on a server that will need to parse packets sent from a client, > and construct it's own packets. > The setup is something like this: the first two bytes is the type of the > packet. > So, lets say we have a packet set to connect. There are two types of connect > packet: a auth packet and a connect packet. > The connect packet then has two bytes with the type, another byte that notes > that it is a connect packet, and 4 bytes that contains the version of the > client. > The auth packet has the two bytes that tells what packet it is, one byte > denoting that it is an auth packet, then the username, a NULL character, and > a password and a NULL character. > > With all of this said, I'm kind of curious how I would 1) parse out > something like this (I am using twisted, so it'll just be passed to my > Receive function), and how I get the length of the packet with multiple NULL > values. I'm also looking to build a packet and send it back out, is there > something that will allow me to designate two bytes, set individual bits, > then put it altogether in a packet to be sent out? > > -- > > Take care, > Ty > my website: > http://tds-solutions.net > my blog: > http://tds-solutions.net/blog > skype: st8amnd127 > My programs don't have bugs; they're randomly added features! > > -- > http://mail.python.org/mailman/listinfo/python-list >
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: parsing packets Michael Hrivnak <mhrivnak@hrivnak.org> - 2011-07-10 19:33 -0400
csiph-web