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

Type Packet

object --+
         |
        Packet

Known Subclasses:
Accept, ActivateCallPlane, Address, Aggregator, AH, ARP, ASPath, ASPathSegment, AtomicAggregate, Attribute, Auth, Auth, Authentication, AVP, BGP, BGP4MPMessage, Call, CallInfo, CallState, Capability, CDP, Chunk, ClearPromptStatus, CloseReceiveChannel, ClusterList, Communities, Community, Datagram, DHCP, Diameter, DisplayPromptStatus, DisplayText, DNS, DTP, Echo, Echo, Error, ESP, Ethernet, FileHdr, FLAP, GRE, Gzip, GzipExtra, H225, HSRP, ICMP, ICMP6, IE, IGMP, IP, IP6, IPX, Keepalive, KeypadButton, LocalPref, Loopback, Message, MPReachNLRI, MPUnreachNLRI, MRTHeader, MultiExitDisc, NetflowBase, NetflowRecordBase, NextHop, Notification, NTP, Open, OpenReceiveChannel, OpenReceiveChannelAck, Origin, OriginatorID, OSPF, Parameter, PIM, PktHdr, Pmap, PPP, PPPoE, Q, QQ3Packet, QQ5Packet, QQBasicPacket, Quote, RADIUS, Reject, Reply, ReservedCommunity, RIP, RouteGeneric, RouteIPV4, RouteIPV6, RouteRefresh, RPC, RTE, RTP, SCCP, SCTP, SelectStartKeys, Session, SetLamp, SetSpeakerMode, SLL, SMB, SNAC, SRE, SSL2, SSL3, StartMediaTransmission, StartTone, StopMediaTransmission, STP, STUN, TCP, TFTP, TLV, TNS, TPKT, UDP, Update, VRRP, YHOO, YMSG

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

__hdr__ should be defined as a list of (name, structfmt, default) tuples
__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!')

Method Summary
  __init__(self, *args, **kwargs)
Packet constructor with ([buf], [field=val,...]) prototype.
  __getitem__(self, k)
  __len__(self)
  __repr__(self)
  __str__(self)
  pack(self)
Return packed header + self.data string.
  pack_hdr(self)
Return packed header string.
  unpack(self, buf)
Unpack packet header fields from buf, and set self.data.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name...
  __getattribute__(...)
x.__getattribute__('name') <==> x.name...
  __hash__(x)
x.__hash__() <==> hash(x)...
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T...
  __reduce__(...)
helper for pickle...
  __reduce_ex__(...)
helper for pickle...
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value...

Method Details

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

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:
__builtin__.object.__init__

pack(self)

Return packed header + self.data string.

pack_hdr(self)

Return packed header string.

unpack(self, buf)

Unpack packet header fields from buf, and set self.data.

Generated by Epydoc 2.1 on Sun Oct 1 11:24:15 2006 http://epydoc.sf.net