diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2016-12-16 01:42:16 +0000 |
---|---|---|
committer | João Valverde <j@v6e.pt> | 2016-12-16 18:18:27 +0000 |
commit | 3649993ded921c521dc2ecb57bddc09bb1f4f8c8 (patch) | |
tree | 347b937f20a5b0c5a2f856fd383fc46f208c0501 /epan/dissectors/packet-6lowpan.c | |
parent | f923009c77f7416d20d60d6dae60d1a2bbd04245 (diff) |
6LoWPAN: Make UDP NHC port endianness code cleaner
Change-Id: I7abb29a8368a91d113038bc878aaf47ed58360bb
Reviewed-on: https://code.wireshark.org/review/19298
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: João Valverde <j@v6e.pt>
Diffstat (limited to 'epan/dissectors/packet-6lowpan.c')
-rw-r--r-- | epan/dissectors/packet-6lowpan.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/epan/dissectors/packet-6lowpan.c b/epan/dissectors/packet-6lowpan.c index abd190baee..8cd3c4f01a 100644 --- a/epan/dissectors/packet-6lowpan.c +++ b/epan/dissectors/packet-6lowpan.c @@ -2047,6 +2047,7 @@ dissect_6lowpan_iphc_nhc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gi gint src_bitlen; gint dst_bitlen; guint8 udp_flags; + guint16 udp_src_port, udp_dst_port; /* Create a tree for the UDP header. */ nhc_tree = proto_tree_add_subtree(tree, tvb, 0, 1, ett_6lowpan_nhc_udp, NULL, "UDP header compression"); @@ -2062,29 +2063,29 @@ dissect_6lowpan_iphc_nhc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gi /* Get and display the ports. */ switch (udp_flags & LOWPAN_NHC_UDP_PORTS) { case LOWPAN_NHC_UDP_PORT_INLINE: - udp.src_port = tvb_get_ntohs(tvb, offset); - udp.dst_port = tvb_get_ntohs(tvb, offset+2); + udp_src_port = tvb_get_ntohs(tvb, offset); + udp_dst_port = tvb_get_ntohs(tvb, offset+2); src_bitlen = 16; dst_bitlen = 16; break; case LOWPAN_NHC_UDP_PORT_8BIT_DST: - udp.src_port = tvb_get_ntohs(tvb, offset); - udp.dst_port = LOWPAN_PORT_8BIT_OFFSET + tvb_get_guint8(tvb, offset + 2); + udp_src_port = tvb_get_ntohs(tvb, offset); + udp_dst_port = LOWPAN_PORT_8BIT_OFFSET + tvb_get_guint8(tvb, offset + 2); src_bitlen = 16; dst_bitlen = 8; break; case LOWPAN_NHC_UDP_PORT_8BIT_SRC: - udp.src_port = LOWPAN_PORT_8BIT_OFFSET + tvb_get_guint8(tvb, offset); - udp.dst_port = tvb_get_ntohs(tvb, offset + 1); + udp_src_port = LOWPAN_PORT_8BIT_OFFSET + tvb_get_guint8(tvb, offset); + udp_dst_port = tvb_get_ntohs(tvb, offset + 1); src_bitlen = 8; dst_bitlen = 16; break; case LOWPAN_NHC_UDP_PORT_12BIT: - udp.src_port = LOWPAN_PORT_12BIT_OFFSET + (tvb_get_guint8(tvb, offset) >> 4); - udp.dst_port = LOWPAN_PORT_12BIT_OFFSET + (tvb_get_guint8(tvb, offset) & 0x0f); + udp_src_port = LOWPAN_PORT_12BIT_OFFSET + (tvb_get_guint8(tvb, offset) >> 4); + udp_dst_port = LOWPAN_PORT_12BIT_OFFSET + (tvb_get_guint8(tvb, offset) & 0x0f); src_bitlen = 4; dst_bitlen = 4; break; @@ -2094,11 +2095,11 @@ dissect_6lowpan_iphc_nhc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gi break; } /* switch */ - proto_tree_add_uint(tree, hf_6lowpan_udp_src, tvb, offset, BITS_TO_BYTE_LEN(offset<<3, src_bitlen), udp.src_port); - proto_tree_add_uint(tree, hf_6lowpan_udp_dst, tvb, offset+(src_bitlen>>3), BITS_TO_BYTE_LEN((offset<<3)+src_bitlen, dst_bitlen), udp.dst_port); + proto_tree_add_uint(tree, hf_6lowpan_udp_src, tvb, offset, BITS_TO_BYTE_LEN(offset<<3, src_bitlen), udp_src_port); + proto_tree_add_uint(tree, hf_6lowpan_udp_dst, tvb, offset+(src_bitlen>>3), BITS_TO_BYTE_LEN((offset<<3)+src_bitlen, dst_bitlen), udp_dst_port); offset += ((src_bitlen + dst_bitlen)>>3); - udp.src_port = g_ntohs(udp.src_port); - udp.dst_port = g_ntohs(udp.dst_port); + udp.src_port = g_htons(udp_src_port); + udp.dst_port = g_htons(udp_dst_port); /* Get and display the checksum. */ if (!(udp_flags & LOWPAN_NHC_UDP_CHECKSUM)) { |