Ethereal-dev: Re: [Ethereal-dev] Creating a new Dissector

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

From: Richard Sharpe <rsharpe@xxxxxxxxxx>
Date: Mon, 7 Oct 2002 13:06:54 +0930 (CST)
On Mon, 7 Oct 2002, pevee wrote:

> Hi,
> 
>    Here is a segment of code...I did used tvb_get_ntohl();
> 
> =============================================
> static int ac_user_ip = -1;
> 
> guint32         user_ip;        //user ip defined
> 
>  tvb_memcpy(tvb, (guint8 *)&iph, offset, sizeof(e_ip));
>         iph.ip_len = g_ntohs(iph.ip_len);
>         iph.ip_id  = g_ntohs(iph.ip_id);
>         iph.ip_off = g_ntohs(iph.ip_off);
>         iph.ip_sum = g_ntohs(iph.ip_sum);

Hmmm, are you replacing the IP layer, or running atop the IP layer?
 
>  //retrieve the User IP Address from the packet
>         user_ip = tvb_get_ntohl(tvb, offset);
>         proto_tree_add_ipv4 (ac_tree, ac_user_ip, tvb, offset + 4, -4,
> user_ip);

I suspect that ntohl and add_ipv4 are fighting with each other! Change the 
ntohl to one that does not do byte swapping and see what happens.

Anyway, why aren't you using proto_tree_add_item(...) and specifying an 
hf_xyz that refers to an FT_IPv4 item?

Regards
-----
Richard Sharpe, rsharpe@xxxxxxxxxx, rsharpe@xxxxxxxxx, 
sharpe@xxxxxxxxxxxx, http://www.richardsharpe.com