python - Scapy show2() packet problem -


i'm trying create scapy layers , want them adapt size on fly. use following code:

class foo(packet): name = "testpacket" fields_desc = [          bytefield("length", none),          bytefield("byte2", none),          bytefield("byte3", none),          bytefield("byte4", none),          bytefield("byte5", none),          bytefield("byte6", none),          bytefield("byte7", none),          bytefield("byte8", none),          bytefield("byte9", none),          bytefield("byte10", none),          bytefield("byte11", none)           ]       def post_build(self, p, pay):      if self.length none:          if self.byte11 not none:              x = 0xa          elif self.byte10 not none:              x = 0x9          elif self.byte9 not none:              x = 0x8          elif self.byte8 not none:              x = 0x7          elif self.byte7 not none:              x = 0x6          elif self.byte6 not none:              x = 0x5          elif self.byte5 not none:              x = 0x4          elif self.byte4 not none:              x = 0x3          elif self.byte3 not none:              x = 0x2          elif self.byte2 not none:              x = 0x1              print "byte2 set, x %s"%(x,)         else:              x = 0x0      p = p[:0] + struct.pack(">b", x)     p += pay     return p 

when following in scapy interpreter: >>> aa=foo(); aa.byte2=0x14; aa.show2(); get:

>>> aa=foo(); aa.byte2=0x14; aa.show2(); aa.show(); ###[ testpacket ]###   length= 1   byte2= none   byte3= none   byte4= none   byte5= none   byte6= none   byte7= none   byte8= none   byte9= none   byte10= none   byte11= none ###[ testpacket ]###   length= none   byte2= 20   byte3= none   byte4= none   byte5= none   byte6= none   byte7= none   byte8= none   byte9= none   byte10= none   byte11= none 

now, according understanding, show2() should compute length of packet etc. in case, should set length and byte2. unfortunatelly not case. idea i'm doing wrong? have been searching bug several hours now, , i'm out of ideas :-s suggestion welcome.

with best regards

martin, understanding mistaken... .show2() computes packet after assembly. .show() not supposed calculate length... example, ip...

>>> scapy.all import ip >>> bar = ip(dst='4.2.2.2')/"yo mama ugly.  ugly.  aaahhhhhh eyes" 

results of .show2()...

>>> bar.show2() ###[ ip ]###   version   = 4l   ihl       = 5l   tos       = 0x0   len       = 65   id        = 1   flags     =   frag      = 0l   ttl       = 64   proto     = ip   chksum    = 0x6b45   src       = 10.109.61.6   dst       = 4.2.2.2   \options   \ ###[ raw ]###      load      = 'yo mama ugly.  ugly.  aaahhhhhh eyes' >>> 

results of .show()... notice ihl, len , chksum none..

>>> bar.show() ###[ ip ]###   version   = 4   ihl       = none  <-------   tos       = 0x0   len       = none  <-------   id        = 1   flags     =   frag      = 0   ttl       = 64   proto     = ip   chksum    = none  <-------   src       = 10.109.61.6   dst       = 4.2.2.2   \options   \ ###[ raw ]###      load      = 'yo mama ugly.  ugly.  aaahhhhhh eyes' >>> 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -