Package dpkt :: Module dpkt :: Class Packet
[hide private]
[frames] | no frames]

Class Packet

source code

object --+    
         |    
   ??.Temp --+
             |
            Packet
Known Subclasses:

Base packet class, with metaclass magic to generate members from self.__hdr__.

Attributes:
    __hdr__: Packet header should be defined as a list of 
             (name, structfmt, default) tuples.
    __byte_order__: Byte order, can be set to override the default ('>')

Example:
>>> class Foo(Packet):
...   __hdr__ = (('foo', 'I', 1), ('bar', 'H', 2), ('baz', '4s', 'quux'))
...
>>> foo = Foo(bar=3)
>>> foo
Foo(bar=3)
>>> str(foo)
'quux'
>>> foo.bar
3
>>> foo.baz
'quux'
>>> foo.foo = 7
>>> foo.baz = 'whee'
>>> foo
Foo(baz='whee', foo=7, bar=3)
>>> Foo('hello, world!')
Foo(baz=' wor', foo=1751477356L, bar=28460, data='ld!')

Instance Methods [hide private]
 
__bytes__(self) source code
 
__getitem__(self, k) source code
 
__init__(self, *args, **kwargs)
Packet constructor with ([buf], [field=val,...]) prototype.
source code
 
__len__(self) source code
 
__repr__(self)
repr(x)
source code
 
__str__(self)
str(x)
source code
 
pack(self)
Return packed header + self.data string.
source code
 
pack_hdr(self)
Return packed header string.
source code
 
unpack(self, buf)
Unpack packet header fields from buf, and set self.data.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 
Packet constructor with ([buf], [field=val,...]) prototype.

Arguments:

buf -- optional packet buffer to unpack

Optional keyword arguments correspond to members to set
(matching fields in self.__hdr__, or 'data').

Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 
repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 
str(x)

Overrides: object.__str__
(inherited documentation)