Ethereal-dev: Re: [ethereal-dev] ldap dissector

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

From: Guy Harris <gharris@xxxxxxxxxxxx>
Date: Tue, 21 Mar 2000 02:25:33 -0800
> static int read_length(const u_char *pd, int offset, frame_data *fd, proto_tree *tree, int hf_id, long *len)
> {
>   long t = 0;
>   const u_char *p = pd + offset;
>   long length = 0;
>   int item_length;
> 
>   length = t = *p++;
>   if (t & 0x80)
>   {
>     t &= 0x7f;
>     length = 0;
>     while (t--)
>     {
>       length <<= 8;
>       length |= *p++;
>     }
>   }
>   
>   if (len)
>     *len = length;
> 
>   item_length = (p - pd) - offset;
> 
>   if (tree)
>     proto_tree_add_item(tree, hf_id, offset, item_length, length);
> 
>   return item_length;
> }

That looks suspiciously similar, in part, to "asn1_length_decode()" in
"asn1.c".  I suspect other ASN.1-reading code is similar to other
routines in "asn1.c".

You might want to look at the SNMP dissector, and the ASN1 code in
"asn1.c" - as LDAP is ASN.1-based, you might as well use the existing
ASN.1 code in Ethereal if possible (and, if not, look at modifying so
that it *is* possible; the reason why the ASN.1 code is in a separate
file from "packet-snmp.c" is so that it *can* be used by other
ASN.1-based protocols, and when I took the GXSNMP ASN.1 code and put it
into Ethereal, LDAP was one of the protocols I was thinking of...).