Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9202

Re: parsing packets

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <mhrivnak@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'character,': 0.07; 'specifying': 0.07; 'twisted,': 0.07; 'type,': 0.07; 'bytes,': 0.09; 'function),': 0.09; 'length.': 0.09; 'subject:parsing': 0.09; 'username,': 0.09; 'wrote:': 0.15; '4:59': 0.16; 'bits,': 0.16; 'connect.': 0.16; 'designate': 0.16; 'length,': 0.16; 'out?': 0.16; 'packet': 0.16; 'cc:addr:python-list': 0.16; 'pm,': 0.16; 'this:': 0.16; 'url:blog': 0.16; 'bytes': 0.19; 'cc:2**0': 0.21; 'blog:': 0.22; 'tells': 0.22; 'cc:no real name:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'all:': 0.23; 'null': 0.23; 'parse': 0.23; 'received:209.85.215.46': 0.23; 'received:mail- ew0-f46.google.com': 0.23; 'values.': 0.23; 'byte': 0.25; 'url:wiki': 0.25; 'sender:addr:gmail.com': 0.26; "i'm": 0.27; 'url:mailman': 0.27; '(see': 0.28; 'message-id:@mail.gmail.com': 0.28; 'server': 0.29; 'consist': 0.29; 'cc:addr:python.org': 0.30; 'character.': 0.30; 'construct': 0.30; 'sun,': 0.30; 'version': 0.30; 'notes': 0.31; 'url:listinfo': 0.32; 'michael': 0.32; 'cases': 0.32; 'does': 0.32; 'there': 0.34; 'however,': 0.34; 'curious': 0.35; 'data.': 0.36; 'url:python': 0.37; 'passed': 0.37; 'using': 0.37; 'another': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'something': 0.38; 'two': 0.38; 'put': 0.38; 'data': 0.39; 'url:en': 0.39; 'might': 0.39; 'header': 0.40; 'received:209': 0.40; 'setup': 0.40; 'kind': 0.60; 'your': 0.60; 'url:net': 0.61; 'order': 0.62; 'back': 0.63; 'care,': 0.68; 'receive': 0.68; 'website:': 0.75; 'same:': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=0OnrlBstrpauEuCkKUBBTZaIjn0vhHw9KdkVecyRJEQ=; b=WG1LDkkFLml9H3UAeVdwH91o5NxqrOjCwNynCMfTn406P//8/e0Ei0k2/Dy1B0G8gc dPXjNar+cI84EXckspwx6vXerESYhMoYaqZLx02uiAZ8EX7PcC8gEOObQlQPPK7hyngE SgXV7hQ7GMRzQJnfzN+jIWGi7NnowbGuck0p4=
MIME-Version 1.0
Sender mhrivnak@gmail.com
In-Reply-To <4E1A12B1.8060205@tysdomain.com>
References <4E1A12B1.8060205@tysdomain.com>
Date Sun, 10 Jul 2011 19:33:38 -0400
X-Google-Sender-Auth gb4R2zXMkNYQQAVJ1ZyllJT5a7o
Subject Re: parsing packets
From Michael Hrivnak <mhrivnak@hrivnak.org>
To tyler@tysdomain.com
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.864.1310340827.1164.python-list@python.org> (permalink)
Lines 53
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1310340827 news.xs4all.nl 21759 [2001:888:2000:d::a6]:40701
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:9202

Show key headers only | View raw


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


Thread

Re: parsing packets Michael Hrivnak <mhrivnak@hrivnak.org> - 2011-07-10 19:33 -0400

csiph-web