Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Jul 2006 11:05:40 +0900
From:      gnn@freebsd.org
To:        "Andrew R. Reiter" <arr@watson.org>
Cc:        freebsd-net@freebsd.org
Subject:   Re: Packet Construction and Protocol Testing...
Message-ID:  <m2irlrpv9n.wl%gnn@neville-neil.com>
In-Reply-To: <20060720104748.R94787@fledge.watson.org>
References:  <m2bqrkr5a5.wl%gnn@neville-neil.com> <20060720104748.R94787@fledge.watson.org>

next in thread | previous in thread | raw e-mail | index | archive | help
At Thu, 20 Jul 2006 10:48:14 -0400 (EDT),
Andrew R. Reiter wrote:
> 
> 
> Aren't there already tools for doing this -- libnet / libdnet that both 
> have py wrappers?

I looked at all those, and more, but they miss an important point.
That is, in PCS you define a packet like this (from
pcs/packets/ipv4.py):

    def __init__(self, bytes = None):
        """ define the fields of an IPv4 packet, from RFC 791
        This version does not include options."""
        version = pcs.Field("version", 4, default = 4)
        hlen = pcs.Field("hlen", 4)
        tos = pcs.Field("tos", 8)
        length = pcs.Field("length", 16)
        id = pcs.Field("id", 16)
        flags = pcs.Field("flags", 3)
        offset = pcs.Field("offset", 13)
        ttl = pcs.Field("ttl", 8, default = 64)
        protocol = pcs.Field("protocol", 8)
        checksum = pcs.Field("checksum", 16)
        src = pcs.Field("src", 32)
        dst = pcs.Field("dst", 32)
        pcs.Packet.__init__(self,
                            [version, hlen, tos, length, id, flags, offset,
                             ttl, protocol, checksum, src, dst],
                            bytes = bytes)
        # Description MUST be set after the PCS layer init
        self.description = "IPv4"

which creates a properties in the object to hold the named field.
This is what makes it possible to do:

ip = ipv4()
ip.ttl = 64
ip.src = inet_pton("128.32.1.1")

etc. in your program.  Also note that the bit lengths can be odd, such
as getting the 13 bit offset field.  So, PCS is doing all the packing
and unpacking of the bytes for you.  I intend to put in automatic
bounds checking in an upcoming version.

There is much more about this in the documentation, docs/pcs.pdf in
the package.

Future versions will allow import/export to various formats as well,
such as XML, so that defining packets will be even easier as will
writing tools.

Later,
George



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?m2irlrpv9n.wl%gnn>