diff options
author | Martin Nyhus <martin.nyhus@gmx.com> | 2020-11-10 08:39:53 +0000 |
---|---|---|
committer | Wireshark GitLab Utility <6629907-ws-gitlab-utility@users.noreply.gitlab.com> | 2020-11-10 08:39:53 +0000 |
commit | 8e9309714794914165e7bfb1e33182a71dd1388d (patch) | |
tree | 772bcb1f52ce80396ac9356a9e41e4ad01dc3077 /epan/dissectors/packet-bt-dht.c | |
parent | 3730eb251ffb25b1c527f913f1bb9362fddc014d (diff) |
bt-dht: don't iterate on strings in values
Each peer in a get_peers response has its own entry in the list, unlike
the way nodes are represented, so if we see a string_len we don't
recognize (like 18 for IPv6 peers) treating it as several IPv4 peers
doesn't make sense.
Diffstat (limited to 'epan/dissectors/packet-bt-dht.c')
-rw-r--r-- | epan/dissectors/packet-bt-dht.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/epan/dissectors/packet-bt-dht.c b/epan/dissectors/packet-bt-dht.c index 78ee7261e8..8eb9efd1cc 100644 --- a/epan/dissectors/packet-bt-dht.c +++ b/epan/dissectors/packet-bt-dht.c @@ -264,9 +264,9 @@ dissect_bt_dht_values(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint { string_len = bencoded_string_length(tvb, &offset); - /* 4 bytes ip, 2 bytes port */ - for( ; string_len>=6; string_len-=6, offset+=6 ) + if (string_len == 6) { + /* 4 bytes ip, 2 bytes port */ peer_index += 1; value_ti = proto_tree_add_item( sub_tree, hf_bt_dht_peer, tvb, offset, 6, ENC_NA ); @@ -277,14 +277,28 @@ dissect_bt_dht_values(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint proto_item_append_text(value_ti, " (IP/Port: %s", tvb_ip_to_str(tvb, offset)); proto_tree_add_item( value_tree, hf_port, tvb, offset+4, 2, ENC_BIG_ENDIAN); proto_item_append_text(value_ti, ":%u)", tvb_get_ntohs( tvb, offset+4 )); + } + else if (string_len == 18) + { + /* 16 bytes ip, 2 bytes port */ + peer_index += 1; + value_ti = proto_tree_add_item( sub_tree, hf_bt_dht_peer, tvb, offset, 18, ENC_NA ); + proto_item_append_text(value_ti, " %d", peer_index); + value_tree = proto_item_add_subtree( value_ti, ett_bt_dht_peers); + + proto_tree_add_item( value_tree, hf_ip6, tvb, offset, 16, ENC_NA); + proto_item_append_text(value_ti, " (IPv6/Port: [%s]", tvb_ip6_to_str(tvb, offset)); + proto_tree_add_item( value_tree, hf_port, tvb, offset+16, 2, ENC_BIG_ENDIAN); + proto_item_append_text(value_ti, ":%u)", tvb_get_ntohs( tvb, offset+16 )); } - /* truncated data */ - if( string_len>0 ) + else { + /* truncated data */ proto_tree_add_item( tree, hf_truncated_data, tvb, offset, string_len, ENC_NA ); - offset += string_len; } + + offset += string_len; } if (tvb_get_guint8(tvb,offset)=='e') { /* list ending delimiter */ @@ -293,7 +307,7 @@ dissect_bt_dht_values(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint } proto_item_set_text( ti, "%s: %d peers", label, peer_index ); - col_append_fstr( pinfo->cinfo, COL_INFO, "reply=%d peers ", peer_index ); + col_append_fstr( pinfo->cinfo, COL_INFO, " reply=%d peers", peer_index ); *result = wmem_strdup_printf(wmem_packet_scope(), "%d peers", peer_index); return offset; @@ -361,7 +375,7 @@ dissect_bt_dht_nodes(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset += string_len; } proto_item_set_text( ti, "%s: %d nodes", label, node_index ); - col_append_fstr( pinfo->cinfo, COL_INFO, " reply=%d nodes ", node_index ); + col_append_fstr( pinfo->cinfo, COL_INFO, " reply=%d nodes", node_index ); *result = wmem_strdup_printf(wmem_packet_scope(), "%d", node_index); return offset; |