Philippe Biondi | 9 Mar 2006 17:19

Re: Payload vs. fields_desc in packet construction

On Wed, 8 Mar 2006, Robert Daniel Pickard wrote:

> 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?

I dont understand why

class Foo2(Packet):
     name = "Foo2";
     fields_desc = [ByteField('value1',0),
                    ByteField('value2',0),
                    ByteField('value3',0)];

is not exactly what you want ?

--

-- 
Philippe Biondi <phil <at>  secdev.org>      SecDev.org
Computer Security/R&D                   http://www.secdev.org
PGP KeyID:3D9A43E2  FingerPrint:C40A772533730E39330DC0985EE8FF5F3D9A43E2

---------------------------------------------------------------------
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