title: Scapy: How to access a Custom Layer
body: <p>I am trying to understand how to add a custom dissector in Scapy. I am using Python 3.4 and Scapy3 if that has any bearing on the result.</p>
  
  <p>I have a stupid class, and the <strong>packet.show2()</strong> command correctly renders the nested packet. But I can not access the new Layers field values.</p>
  
  <p>Scary Class and bind_layer follows...</p>
  
  <pre><code>from scapy.all import *
  #Create simple Class
  class DUMBO(Packet):
      fields_desc = [
          ShortField('ears',0),
          ShortField('legs',0),
          ShortField('trunk',0)
      ]
  #Inform TCP that ports 9898 are this protocol
  bind_layers(TCP, DUMBO, sport=9898, dport=9898)
  </code></pre>
  
  <p>I make a packet like this</p>
  
  <pre><code>#Make a Packet
  pack=IP()/TCP(sport=9898, dport=9898)/Raw(load=b'\x00\x02\x00\x04\x00\x01')
  </code></pre>
  
  <p>Looking at the Packet I have created using ls yields</p>
  
  <pre><code>version    : BitField             = 4               (4)
  ihl        : BitField             = None            (None)
  tos        : XByteField           = 0               (0)
  len        : ShortField           = None            (None)
  id         : ShortField           = 1               (1)
  flags      : FlagsField           = 0               (0)
  frag       : BitField             = 0               (0)
  ttl        : ByteField            = 64              (64)
  proto      : ByteEnumField        = 6               (0)
  chksum     : XShortField          = None            (None)
  src        : Emph                 = '127.0.0.1'     (None)
  dst        : Emph                 = '127.0.0.1'     ('127.0.0.1')
  options    : PacketListField      = []              ([])
  --
  sport      : ShortEnumField       = 9898            (20)
  dport      : ShortEnumField       = 9898            (80)
  seq        : IntField             = 0               (0)
  ack        : IntField             = 0               (0)
  dataofs    : BitField             = None            (None)
  reserved   : BitField             = 0               (0)
  flags      : FlagsField           = 2               (2)
  window     : ShortField           = 8192            (8192)
  chksum     : XShortField          = None            (None)
  urgptr     : ShortField           = 0               (0)
  options    : TCPOptionsField      = {}              ({})
  --
  load       : StrField             = b'\x00\x02\x00\x04\x00\x01' (b'')
  </code></pre>
  
  <p>And display it using Show2 it all looks good</p>
  
  <pre><code>pack.show2()
  
  
  ###[ IP ]###
    version   = 4
    ihl       = 5
    tos       = 0x0
    len       = 46
    id        = 1
    flags     = 
    frag      = 0
    ttl       = 64
    proto     = tcp
    chksum    = 0x7cc7
    src       = 127.0.0.1
    dst       = 127.0.0.1
    \options   \
  ###[ TCP ]###
       sport     = monkeycom
       dport     = monkeycom
       seq       = 0
       ack       = 0
       dataofs   = 5
       reserved  = 0
       flags     = S
       window    = 8192
       chksum    = 0x447f
       urgptr    = 0
       options   = []
  ###[ DUMBO ]###
          ears      = 2
          legs      = 4
          trunk     = 1
  </code></pre>
  
  <p>I now want to access the <strong>DUMBO</strong> Layer fields</p>
  
  <p>But
        PACK[DUMBO].ears </p>
  
  <p>Is not correct - as the packet when displayed as pack.show() still has the Payload as Raw....</p>
  
  <p>What am I missing ??</p>