Re: Packet Construction and Protocol Testing...



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
_______________________________________________
freebsd-net@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • RE: Transfer a sending packet to upper TCP/IP protocol layer in IM
    ... The stack can route the IPv4 packets to the mapped ... encapped IPv4 packet. ... source and destination MAC addresses are the same for both IP versions. ... was assuming that tcpip stack can rebuild the L2 header for the encapped IPv4 ...
    (microsoft.public.development.device.drivers)
  • RE: Transfer a sending packet to upper TCP/IP protocol layer in IM
    ... I suggest you look at the IPv6 gateway standards RFCs if you're interested. ... How is he going to get IPv4 address, ... the destination NIC of IPv6 packet is the same as the destination NIC of my ... was assuming that tcpip stack can rebuild the L2 header for the encapped IPv4 ...
    (microsoft.public.development.device.drivers)
  • RE: Transfer a sending packet to upper TCP/IP protocol layer in IM
    ... He's building a gateway across an IPV4 segment. ... AFAIK, all systems that support IPv6 provide this feature anyway, so that I ... the destination NIC of IPv6 packet is the same as the destination NIC of my ... was assuming that tcpip stack can rebuild the L2 header for the encapped IPv4 ...
    (microsoft.public.development.device.drivers)
  • RE: Transfer a sending packet to upper TCP/IP protocol layer in IM
    ... source and destination MAC addresses are the same for both IP versions. ... the destination NIC of IPv6 packet is the same as the destination NIC of my ... encapped IPv4 packet. ...
    (microsoft.public.development.device.drivers)
  • RE: Transfer a sending packet to upper TCP/IP protocol layer in IM
    ... destination IPv4 address and the original MAC header was built for original ... IPv6 destination IPv6 address. ... The original MAC header is INVALID because my IM driver will assign a new ... After prepending IPv4 header and UDP header to the original IPv6 packet, ...
    (microsoft.public.development.device.drivers)