diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-08-08 18:09:00 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-08-09 01:09:34 +0000 |
commit | ebff85fdbbe9667f469e18686ad945f634be2682 (patch) | |
tree | 325c6cf517f4644339d26bd7f0e57ff2c4097e7b /epan/dissectors/packet-nhrp.c | |
parent | fe74e319c0d27fb516577ce521719fba973e8113 (diff) |
Clean up Internet checksum handling.
Add macros to set entries of a vec_t, one for use when you have a
pointer to private data, and one for use when you have data in a tvbuff.
The latter wraps the use of tvb_get_ptr(), so that you're not directly
calling it in a dissector.
Move ip_checksum() to epan/in_cksum.c, and add an ip_checksum_tvb() that
wraps the use of tvb_get_ptr().
In the CARP dissector, give the length variable an unsigned type -
there's no benefit to it being signed, and that requires some casts to
be thrown around.
In the DCCP dissector, check only against the coverage length to see if
we have enough data, combine the "should we check the checksum?" check
with the "*can* we check the checksum?" check in a single if, and throw
a dissector assertion if the source network address type isn't IPv4 or
IPv6.
Get rid of inclues of <epan/in_cksum.h> in dissectors that don't use any
of the Internet checksum routines.
In the HIP dissector, make sure we have the data to calculate the
checksum before doing so.
Change-Id: I2f9674775dbb54c533d33082632809f7d32ec8ae
Reviewed-on: https://code.wireshark.org/review/3517
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/dissectors/packet-nhrp.c')
-rw-r--r-- | epan/dissectors/packet-nhrp.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/epan/dissectors/packet-nhrp.c b/epan/dissectors/packet-nhrp.c index 16222359f2..66d240d23e 100644 --- a/epan/dissectors/packet-nhrp.c +++ b/epan/dissectors/packet-nhrp.c @@ -275,12 +275,11 @@ typedef struct _e_nhrp { guint8 ar_sstl; } e_nhrp_hdr; -static guint16 nhrp_checksum(const guint8 *ptr, int len) +static guint16 nhrp_checksum(tvbuff_t *tvb, int len) { vec_t cksum_vec[1]; - cksum_vec[0].ptr = ptr; - cksum_vec[0].len = len; + SET_CKSUM_VEC_TVB(cksum_vec[0], tvb, 0, len); return in_cksum(&cksum_vec[0], 1); } @@ -377,8 +376,7 @@ static void dissect_nhrp_hdr(tvbuff_t *tvb, rx_chksum = tvb_get_ntohs(tvb, offset); if (tvb_bytes_exist(tvb, 0, total_len)) { - ipcsum = nhrp_checksum(tvb_get_ptr(tvb, 0, total_len), - total_len); + ipcsum = nhrp_checksum(tvb, total_len); if (ipcsum == 0) { proto_tree_add_uint_format_value(nhrp_tree, hf_nhrp_hdr_chksum, tvb, offset, 2, rx_chksum, "0x%04x [correct]", rx_chksum); |