Robert Daniel Pickard | 8 Mar 2006 19:50
Picon

Payload vs. fields_desc in packet construction

Hi all,

When building a packet that has data in a specific format, is it  
better to have that
data be part of the payload or can the fields_desc array be used?

For example; Protocol Foo sends three bytes in a packet. Each byte is  
interpreted
by the protocol independantly.

from scapy import *;

class Foo(Packet):

   name = "Foo";

   value1 = 0;
   value2 = 0;
   value3 = 0;

   payload = None;

   def packPayload(self):
     self.payload = str(self.value1 <<  2) + \
                    str(self.value2 << 1) + \
                    str( self.value3);
     return self.payload;

class Foo2(Packet):

   name = "Foo2";

   fields_desc = [ByteField('value1',0),
                  ByteField('value2',0),
                  ByteField('value3',0)];

   def setValue1(self, value):
     self.value1 = value;

   def setValue2(self, value):
     self.value2 = value;

   def setValue3(self, value):
     self.value3 = value;

Is one of these 'more correct' then the other? Will they send out  
equivalent data on the wire?

Also can anyone point me toward code that does some more complex  
packet construction then
the example on the Scapy page for building your own tools?

Thanks,
Robert Daniel Pickard

---------------------------------------------------------------------
Desinscription: envoyez un message a: scapy.ml-unsubscribe <at> secdev.org
Pour obtenir de l'aide, ecrivez a: scapy.ml-help <at> secdev.org


Gmane