Hi,
Here is an example of how I organize my header and C files.
Similar to what has been proposed, but helps me understand
whats going on..
Any comments / Frank..
<snip from clcoip.h>
#undef NEW_INTERFACE /* top dissector called with tbvuffs */
#ifdef NEW_INTERFACE
void dissect_clcoip(tvbuff_t *, packet_info *, proto_tree *); /* new
interface */
#else
void dissect_clcoip(const u_char *, int, frame_data *, proto_tree *); /*
old interafce */
#endif;
<end snip from clcoip.h>
<snip from clcoip.c>
/* Code to actually dissect the packets */
#ifdef NEW_INTERFACE
void dissect_clcoip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
guint msgtype; /* need here, as must update COL_INFO before */
/* the if(tree) code */
#else
void dissect_clcoip(const u_char *pd, int offset, frame_data *fd,
proto_tree *tree) {
tvbuff_t *tvb;
packet_info *pinfo = π
guint msgtype; /* need here, as must update COL_INFO before */
/* the if(tree) code */
tvb = tvb_new_subset(pinfo->compat_top_tvb, offset,
pinfo->captured_len - offset, pinfo->len - offset );
/* or use tvb_create_from_top macro instead */
#endif
Gilbert Ramirez wrote:
>
> In a previous e-mail I suggested the usage of
>
> tvbuff_t *tvb = tvb_new_subset(pi.compat_top_tvb, offset, -1, -1);
>
> to create a tvbuff for a dissector which did not accept a tvbuff in its
> argument list (all of the dissector-table dissectors).
>
> This suggestion is wrong, because some dissectors (ethernet!) can modify
> the length of their packet data. That is, some ethernet packets have a trailer,
> so those trailing bytes are excluded from the next tvbuff
> (and are subtracted from pi.len and pi.captured_len).
>
> The correct usage is more like:
>
> tvb_new_subset(pi.compat_top_tvb, offset, pi.captured_len - offset,
> pi.len - offset);
>
> To make this easier to use, I have added a macro called tvb_create_from_top() to
> tvbuff.h (which is automatically included in each dissector through packet.h)
>
> It takes one argument, the name of your offset variable. (Some authors use 'offset',
> some use 'o').
>
> Here's an example from dissect_ipx():
>
> #if 0
> void
> dissect_ipx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
> {
> #else
> void
> dissect_ipx(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
> {
> packet_info *pinfo = π
> tvbuff_t *tvb = tvb_create_from_top(offset);
> #endif
>
> I have documented this change in doc/README.tvbuff, and have modifed all the
> dissectors that needed this change.
>
> --gilbert
--
EUS/GN/V/Z Frank Singleton ASO Americas BSS
Office : +1 972 583 3251 ECN 800 33251
Pager : +1 800 651 1184 Email : eusfrsi@xxxxxxxxxxxxxxx
Amateur Radio: VK3FCS/KM5WS Email : frank.singleton@xxxxxxxxxxxx
Hardware: HP Omnibook 4150 running Redhat Linux 6.2 (2.2.14 kernel).