Ethereal-dev: [ethereal-dev] Status of Protocol Description Language

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Richard Sharpe <sharpe@xxxxxxxxxx>
Date: Wed, 04 Aug 1999 22:37:47 +0900
Hi,

just a word on how this is going.

I have redeveloped my parser, but it still needs work.

The advantages of this approach are that code generation is now explicit. 
By hiding the action routines in include files and changing the contents of
the include files, it should be possible to generate code for Ethereal and
for Samba testing applications.

My language has provision for repeating fields and structures, for
structures whose length or repeat count depends on other fields, for
different structure layouts depending on fields before them, and for
fields/structures that are pointed to by other fields.

The following is an example of a description file:

-------------------------Simple Description File-----------------------------
action act2 {
  my($obj) = shift;
  
  print "void\ndissect_",$obj->{name},"(const u_char *pd, int offset*,
frame_data *fd, proto_tree *tree, int max_data)\n";
  print "{\n\n";

  print "  proto_tree\t  *smb_tree = tree\;\n";
  tree_walk_leaves($obj, act5);

  print "\n\n";
}

action act3 {
  my($obj) = shift;
  my($sn) = squeeze_name($obj->{name});
  print "  ", $sn, " = GSHORT(pd, offset)\;\n\n";
  print "  if (tree) \{\n\n";
  print "    proto_tree_add_text(smb_tree, offset, 2, \"", $obj->{name}, ":
%i (%04x)\",", $sn, ", ", $sn, ")\;\n\n";
  print " \}\n\n";
  print "  offset += 1\;\n\n";
} 

action act4 {

  print "\}\n\n";

}

action act5 {

  my($obj) = shift;

#  print "Act5 called ...\n";

  if ($obj->{type} =~ /^UCHAR$/) {

    print "    guint8  \t     ", squeeze_name($obj->{name}), "\;\n";
  
  }

  return 1;

}

# The description section proper, this is not for real
proto smb [act2()] {
  UCHAR Marker 1 = 0xFF [act3()];
  UCHAR Marker 2 = 0x01 [act3()];

} [act4()];
--------------------------------------8<------------------------------

The above definition file generates the following C code ...

void
dissect_smb(const u_char *pd, int offset*, frame_data *fd, proto_tree
*tree, int max_data)
{

 proto_tree	 *smb_tree = tree;
 guint8 	 Marker1;
 guint8 	 Marker2;


 Marker1 = GSHORT(pd, offset);

 if (tree) {

 proto_tree_add_text(smb_tree, offset, 2, "Marker 1: %i (%04x)",Marker1,
Marker1);

 }

 offset += 1;

 Marker2 = GSHORT(pd, offset);

 if (tree) {

 proto_tree_add_text(smb_tree, offset, 2, "Marker 2: %i (%04x)",Marker2,
Marker2);

 }

 offset += 1;

}



Regards
-------
Richard Sharpe, sharpe@xxxxxxxxxx, NS Computer Software and Services P/L,
Samba (Team member www.samba.org), Ethereal (Team member www.zing.org)
Co-author, SAMS Teach Yourself Samba in 24 Hours