Ethereal-dev: Re: [Ethereal-dev] Searching for packets with incorrect checksums

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

From: Guy Harris <guy@xxxxxxxxxx>
Date: Tue, 18 Dec 2001 10:54:48 -0800 (PST)
> Dear Guy, Dear all,

"Guy" is a member of "all", so it's not necessary to CC either my home
or my work e-mail address on mail to "ethereal-dev" or "ethereal-users".

> Currently I'm calculating the checksum in the dissector and display it
> with proto_tree_add_uint_format. I'm trying also to insert in the tree
> a boolean variable with proto_tree_add_item (or the hidden version) and
> provide a boolean variable as a parameter, which describes oof the 
> checksum
> is right. But this bit is not part of the packet, of course. How can I 
> do it?

The same way the IP dissector does it:

    if (ipsum == 0) {
	proto_tree_add_uint_format(ip_tree, hf_ip_checksum, tvb,
		offset + 10, 2, iph.ip_sum,
		"Header checksum: 0x%04x (correct)", iph.ip_sum);
    }
    else {
	proto_tree_add_item_hidden(ip_tree, hf_ip_checksum_bad, tvb,
		offset + 10, 2, TRUE);
	proto_tree_add_uint_format(ip_tree, hf_ip_checksum, tvb,
		offset + 10, 2, iph.ip_sum,
		"Header checksum: 0x%04x (incorrect, should be 0x%04x)",
		iph.ip_sum, in_cksum_shouldbe(iph.ip_sum, ipsum));
    }

	...

	static hf_register_info hf[] = {
                
			...

		{ &hf_ip_checksum,
		{ "Header checksum",	"ip.checksum", FT_UINT16, BASE_HEX,
			NULL, 0x0, "", HFILL }},

		{ &hf_ip_checksum_bad,
		{ "Bad Header checksum",	"ip.checksum_bad", FT_BOOLEAN,
			BASE_NONE, NULL, 0x0, "", HFILL }},

			...

	};