2 * Routines for bitcoin dissection
3 * Copyright 2011, Christian Svensson <blue@cmd.nu>
4 * Bitcoin address: 15Y2EN5mLnsTt3CZBfgpnZR5SeLwu7WEHz
6 * See https://en.bitcoin.it/wiki/Protocol_specification
8 * Updated 2015, Laurenz Kamp <laurenz.kamp@gmx.de>
11 * -> ping: ping packets now have a nonce.
12 * -> version: If version >= 70002, version messages have a relay flag.
13 * -> Messages with no payload: Added mempool and filterclear messages.
23 * Wireshark - Network traffic analyzer
24 * By Gerald Combs <gerald@wireshark.org>
25 * Copyright 1998 Gerald Combs
27 * SPDX-License-Identifier: GPL-2.0-or-later
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
33 #include <epan/expert.h>
35 #include <wsutil/array.h>
37 #include "packet-tcp.h"
39 #define BITCOIN_MAIN_MAGIC_NUMBER 0xD9B4BEF9
40 #define BITCOIN_TESTNET_MAGIC_NUMBER 0xDAB5BFFA
41 #define BITCOIN_TESTNET3_MAGIC_NUMBER 0x0709110B
43 static const value_string inv_types
[] =
48 { 3, "MSG_FILTERED_BLOCK" },
49 { 4, "MSG_CMPCT_BLOCK" },
51 { 0x40000001, "MSG_WITNESS_TX" },
52 { 0x40000002, "MSG_WITNESS_BLOCK" },
56 static const value_string network_ids
[] =
67 static const value_string reject_ccode
[] =
69 { 0x01, "REJECT_MALFORMED" },
70 { 0x10, "REJECT_INVALID" },
71 { 0x11, "REJECT_OBSOLETE" },
72 { 0x12, "REJECT_DUPLICATE" },
73 { 0x40, "REJECT_NONSTANDARD" },
74 { 0x41, "REJECT_DUST" },
75 { 0x42, "REJECT_INSUFFICIENTFEE" },
76 { 0x43, "REJECT_CHECKPOINT" },
80 static const value_string filterload_nflags
[] =
82 { 0, "BLOOM_UPDATE_NONE" },
83 { 1, "BLOOM_UPDATE_ALL" },
84 { 2, "BLOOM_UPDATE_P2PUBKEY_ONLY" },
89 * Minimum bitcoin identification header.
91 * - Command - 12 bytes
92 * - Payload length - 4 bytes
93 * - Checksum - 4 bytes
95 #define BITCOIN_HEADER_LENGTH 4+12+4+4
97 void proto_register_bitcoin(void);
98 void proto_reg_handoff_bitcoin(void);
100 static dissector_handle_t bitcoin_handle
;
102 static dissector_table_t bitcoin_command_table
;
104 static int proto_bitcoin
;
106 static int hf_address_address
;
107 static int hf_address_port
;
108 static int hf_address_services
;
109 static int hf_bitcoin_checksum
;
110 static int hf_bitcoin_command
;
111 static int hf_bitcoin_length
;
112 static int hf_bitcoin_magic
;
113 static int hf_bitcoin_msg_addr
;
114 static int hf_bitcoin_msg_addrv2
;
115 static int hf_bitcoin_msg_block
;
116 static int hf_bitcoin_msg_feefilter
;
117 static int hf_bitcoin_msg_filteradd
;
118 static int hf_bitcoin_msg_filterload
;
119 static int hf_bitcoin_msg_getblocks
;
120 static int hf_bitcoin_msg_getdata
;
121 static int hf_bitcoin_msg_getheaders
;
122 static int hf_bitcoin_msg_headers
;
123 static int hf_bitcoin_msg_inv
;
124 static int hf_bitcoin_msg_merkleblock
;
125 static int hf_bitcoin_msg_notfound
;
126 static int hf_bitcoin_msg_ping
;
127 static int hf_bitcoin_msg_pong
;
128 static int hf_bitcoin_msg_reject
;
129 static int hf_bitcoin_msg_sendcmpct
;
130 static int hf_bitcoin_msg_tx
;
131 static int hf_bitcoin_msg_version
;
132 static int hf_data_value
;
133 static int hf_data_varint_count16
;
134 static int hf_data_varint_count32
;
135 static int hf_data_varint_count64
;
136 static int hf_data_varint_count8
;
137 static int hf_msg_addr_address
;
138 static int hf_msg_addr_count16
;
139 static int hf_msg_addr_count32
;
140 static int hf_msg_addr_count64
;
141 static int hf_msg_addr_count8
;
142 static int hf_msg_addr_timestamp
;
143 static int hf_msg_addrv2_count16
;
144 static int hf_msg_addrv2_count32
;
145 static int hf_msg_addrv2_count64
;
146 static int hf_msg_addrv2_count8
;
147 static int hf_msg_addrv2_item
;
148 static int hf_msg_addrv2_timestamp
;
149 static int hf_msg_addrv2_services
;
150 static int hf_msg_addrv2_network
;
151 static int hf_msg_addrv2_address_ipv4
;
152 static int hf_msg_addrv2_address_ipv6
;
153 static int hf_msg_addrv2_address_other
;
154 static int hf_msg_addrv2_port
;
155 static int hf_msg_block_bits
;
156 static int hf_msg_block_merkle_root
;
157 static int hf_msg_block_nonce
;
158 static int hf_msg_block_prev_block
;
159 static int hf_msg_block_time
;
160 static int hf_msg_block_transactions16
;
161 static int hf_msg_block_transactions32
;
162 static int hf_msg_block_transactions64
;
163 static int hf_msg_block_transactions8
;
164 static int hf_msg_block_version
;
165 static int hf_msg_feefilter_value
;
166 static int hf_msg_filteradd_data
;
167 static int hf_msg_filterload_filter
;
168 static int hf_msg_filterload_nflags
;
169 static int hf_msg_filterload_nhashfunc
;
170 static int hf_msg_filterload_ntweak
;
171 static int hf_msg_getblocks_count16
;
172 static int hf_msg_getblocks_count32
;
173 static int hf_msg_getblocks_count64
;
174 static int hf_msg_getblocks_count8
;
175 static int hf_msg_getblocks_start
;
176 static int hf_msg_getblocks_stop
;
177 static int hf_msg_getdata_count16
;
178 static int hf_msg_getdata_count32
;
179 static int hf_msg_getdata_count64
;
180 static int hf_msg_getdata_count8
;
181 static int hf_msg_getdata_hash
;
182 static int hf_msg_getdata_type
;
183 static int hf_msg_getheaders_count16
;
184 static int hf_msg_getheaders_count32
;
185 static int hf_msg_getheaders_count64
;
186 static int hf_msg_getheaders_count8
;
187 static int hf_msg_getheaders_start
;
188 static int hf_msg_getheaders_stop
;
189 static int hf_msg_getheaders_version
;
190 static int hf_msg_headers_bits
;
191 static int hf_msg_headers_count16
;
192 static int hf_msg_headers_count32
;
193 static int hf_msg_headers_count64
;
194 static int hf_msg_headers_count8
;
195 static int hf_msg_headers_merkle_root
;
196 static int hf_msg_headers_nonce
;
197 static int hf_msg_headers_prev_block
;
198 static int hf_msg_headers_time
;
199 static int hf_msg_headers_version
;
200 static int hf_msg_inv_count16
;
201 static int hf_msg_inv_count32
;
202 static int hf_msg_inv_count64
;
203 static int hf_msg_inv_count8
;
204 static int hf_msg_inv_hash
;
205 static int hf_msg_inv_type
;
206 static int hf_msg_merkleblock_bits
;
207 static int hf_msg_merkleblock_flags_data
;
208 static int hf_msg_merkleblock_flags_size16
;
209 static int hf_msg_merkleblock_flags_size32
;
210 static int hf_msg_merkleblock_flags_size64
;
211 static int hf_msg_merkleblock_flags_size8
;
212 static int hf_msg_merkleblock_hashes_count16
;
213 static int hf_msg_merkleblock_hashes_count32
;
214 static int hf_msg_merkleblock_hashes_count64
;
215 static int hf_msg_merkleblock_hashes_count8
;
216 static int hf_msg_merkleblock_hashes_hash
;
217 static int hf_msg_merkleblock_merkle_root
;
218 static int hf_msg_merkleblock_nonce
;
219 static int hf_msg_merkleblock_prev_block
;
220 static int hf_msg_merkleblock_time
;
221 static int hf_msg_merkleblock_transactions
;
222 static int hf_msg_merkleblock_version
;
223 static int hf_msg_notfound_count16
;
224 static int hf_msg_notfound_count32
;
225 static int hf_msg_notfound_count64
;
226 static int hf_msg_notfound_count8
;
227 static int hf_msg_notfound_hash
;
228 static int hf_msg_notfound_type
;
229 static int hf_msg_ping_nonce
;
230 static int hf_msg_pong_nonce
;
231 static int hf_msg_reject_ccode
;
232 static int hf_msg_reject_data
;
233 static int hf_msg_reject_message
;
234 static int hf_msg_reject_reason
;
235 static int hf_msg_sendcmpct_announce
;
236 static int hf_msg_sendcmpct_version
;
237 static int hf_msg_tx_in
;
238 static int hf_msg_tx_in_count16
;
239 static int hf_msg_tx_in_count32
;
240 static int hf_msg_tx_in_count64
;
241 static int hf_msg_tx_in_count8
;
242 static int hf_msg_tx_in_prev_outp_hash
;
243 static int hf_msg_tx_in_prev_outp_index
;
244 static int hf_msg_tx_in_prev_output
;
245 static int hf_msg_tx_in_script16
;
246 static int hf_msg_tx_in_script32
;
247 static int hf_msg_tx_in_script64
;
248 static int hf_msg_tx_in_script8
;
249 static int hf_msg_tx_in_seq
;
250 static int hf_msg_tx_in_sig_script
;
251 static int hf_msg_tx_lock_time
;
252 static int hf_msg_tx_out
;
253 static int hf_msg_tx_out_count16
;
254 static int hf_msg_tx_out_count32
;
255 static int hf_msg_tx_out_count64
;
256 static int hf_msg_tx_out_count8
;
257 static int hf_msg_tx_out_script
;
258 static int hf_msg_tx_out_script16
;
259 static int hf_msg_tx_out_script32
;
260 static int hf_msg_tx_out_script64
;
261 static int hf_msg_tx_out_script8
;
262 static int hf_msg_tx_out_value
;
263 static int hf_msg_tx_witness
;
264 static int hf_msg_tx_witness_components16
;
265 static int hf_msg_tx_witness_components32
;
266 static int hf_msg_tx_witness_components64
;
267 static int hf_msg_tx_witness_components8
;
268 static int hf_msg_tx_witness_component
;
269 static int hf_msg_tx_witness_component_length16
;
270 static int hf_msg_tx_witness_component_length32
;
271 static int hf_msg_tx_witness_component_length64
;
272 static int hf_msg_tx_witness_component_length8
;
273 static int hf_msg_tx_witness_component_data
;
274 static int hf_msg_tx_version
;
275 static int hf_msg_tx_flag
;
276 static int hf_msg_version_addr_me
;
277 static int hf_msg_version_addr_you
;
278 static int hf_msg_version_nonce
;
279 static int hf_msg_version_relay
;
280 static int hf_msg_version_services
;
281 static int hf_msg_version_start_height
;
282 static int hf_msg_version_timestamp
;
283 static int hf_msg_version_user_agent
;
284 static int hf_msg_version_version
;
285 static int hf_services_network
;
286 static int hf_services_getutxo
;
287 static int hf_services_bloom
;
288 static int hf_services_witness
;
289 static int hf_services_xthin
;
290 static int hf_services_compactfilters
;
291 static int hf_services_networklimited
;
292 static int hf_services_p2pv2
;
293 static int hf_string_value
;
294 static int hf_string_varint_count16
;
295 static int hf_string_varint_count32
;
296 static int hf_string_varint_count64
;
297 static int hf_string_varint_count8
;
299 static int * const services_hf_flags
[] = {
300 &hf_services_network
,
301 &hf_services_getutxo
,
303 &hf_services_witness
,
305 &hf_services_compactfilters
,
306 &hf_services_networklimited
,
311 static int ett_bitcoin
;
312 static int ett_bitcoin_msg
;
313 static int ett_services
;
314 static int ett_address
;
315 static int ett_string
;
316 static int ett_addr_list
;
317 static int ett_inv_list
;
318 static int ett_getdata_list
;
319 static int ett_notfound_list
;
320 static int ett_getblocks_list
;
321 static int ett_getheaders_list
;
322 static int ett_tx_in_list
;
323 static int ett_tx_in_outp
;
324 static int ett_tx_out_list
;
325 static int ett_tx_witness_list
;
326 static int ett_tx_witness_component_list
;
328 static expert_field ei_bitcoin_command_unknown
;
329 static expert_field ei_bitcoin_address_length
;
330 static expert_field ei_bitcoin_script_len
;
333 static bool bitcoin_desegment
= true;
336 get_bitcoin_pdu_length(packet_info
*pinfo _U_
, tvbuff_t
*tvb
,
337 int offset
, void *data _U_
)
340 length
= BITCOIN_HEADER_LENGTH
;
342 /* add payload length */
343 length
+= tvb_get_letohl(tvb
, offset
+16);
349 format_feefilter_value(char *buf
, int64_t value
) {
350 snprintf(buf
, ITEM_LABEL_LENGTH
, "%.3f sat/B", ((double) value
) / 1000);
354 * Create a sub-tree and fill it with a net_addr structure
357 create_address_tree(tvbuff_t
*tvb
, proto_item
*ti
, uint32_t offset
)
361 tree
= proto_item_add_subtree(ti
, ett_address
);
364 proto_tree_add_bitmask(tree
, tvb
, offset
, hf_address_services
,
365 ett_services
, services_hf_flags
, ENC_LITTLE_ENDIAN
);
369 proto_tree_add_item(tree
, hf_address_address
, tvb
, offset
, 16, ENC_NA
);
373 proto_tree_add_item(tree
, hf_address_port
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
379 * Extract a variable length integer from a tvbuff
382 get_varint(tvbuff_t
*tvb
, const int offset
, int *length
, uint64_t *ret
)
386 /* Note: just throw an exception if not enough bytes are available in the tvbuff */
388 /* calculate variable length */
389 value
= tvb_get_uint8(tvb
, offset
);
400 *ret
= tvb_get_letohs(tvb
, offset
+1);
406 *ret
= tvb_get_letohl(tvb
, offset
+1);
411 *ret
= tvb_get_letoh64(tvb
, offset
+1);
416 static void add_varint_item(proto_tree
*tree
, tvbuff_t
*tvb
, const int offset
, int length
,
417 int hfi8
, int hfi16
, int hfi32
, int hfi64
)
422 proto_tree_add_item(tree
, hfi8
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
425 proto_tree_add_item(tree
, hfi16
, tvb
, offset
+1, 2, ENC_LITTLE_ENDIAN
);
428 proto_tree_add_item(tree
, hfi32
, tvb
, offset
+1, 4, ENC_LITTLE_ENDIAN
);
431 proto_tree_add_item(tree
, hfi64
, tvb
, offset
+1, 8, ENC_LITTLE_ENDIAN
);
437 create_string_tree(proto_tree
*tree
, int hfindex
, tvbuff_t
*tvb
, uint32_t* offset
)
445 /* First is the length of the following string as a varint */
446 get_varint(tvb
, *offset
, &varint_length
, &varint
);
447 string_length
= (int) varint
;
449 ti
= proto_tree_add_item(tree
, hfindex
, tvb
, *offset
, varint_length
+ string_length
, ENC_NA
);
450 subtree
= proto_item_add_subtree(ti
, ett_string
);
453 add_varint_item(subtree
, tvb
, *offset
, varint_length
, hf_string_varint_count8
,
454 hf_string_varint_count16
, hf_string_varint_count32
,
455 hf_string_varint_count64
);
456 *offset
+= varint_length
;
459 proto_tree_add_item(subtree
, hf_string_value
, tvb
, *offset
, string_length
,
461 *offset
+= string_length
;
467 create_data_tree(proto_tree
*tree
, int hfindex
, tvbuff_t
*tvb
, uint32_t* offset
)
475 /* First is the length of the following string as a varint */
476 get_varint(tvb
, *offset
, &varint_length
, &varint
);
477 data_length
= (int) varint
;
479 ti
= proto_tree_add_item(tree
, hfindex
, tvb
, *offset
, varint_length
+ data_length
, ENC_NA
);
480 subtree
= proto_item_add_subtree(ti
, ett_string
);
483 add_varint_item(subtree
, tvb
, *offset
, varint_length
, hf_data_varint_count8
,
484 hf_data_varint_count16
, hf_data_varint_count32
,
485 hf_data_varint_count64
);
486 *offset
+= varint_length
;
489 proto_tree_add_item(subtree
, hf_data_value
, tvb
, *offset
, data_length
,
490 BASE_SHOW_UTF_8_PRINTABLE
);
491 *offset
+= data_length
;
496 /* Note: A number of the following message handlers include code of the form:
500 * for (; count > 0; count--)
502 * proto_tree_add_item9...);
504 * proto_tree_add_item9...);
510 * Issue if 'count' is a very large number:
511 * If 'tree' is NULL, then the result will be effectively (but not really)
512 * an infinite loop. This is true because if 'tree' is NULL then
513 * proto_tree_add_item(tree, ...) is effectively a no-op and will not throw
515 * So: the loop should be executed only when 'tree' is defined so that the
516 * proto_ calls will throw an exception when the tvb is used up;
517 * This should only take a few-hundred loops at most.
518 * https://gitlab.com/wireshark/wireshark/-/issues/8312
522 * Handler for version messages
525 dissect_bitcoin_msg_version(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
531 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_version
, tvb
, offset
, -1, ENC_NA
);
532 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
534 version
= tvb_get_letohl(tvb
, offset
);
536 proto_tree_add_item(tree
, hf_msg_version_version
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
539 proto_tree_add_bitmask(tree
, tvb
, offset
, hf_msg_version_services
,
540 ett_services
, services_hf_flags
, ENC_LITTLE_ENDIAN
);
543 proto_tree_add_item(tree
, hf_msg_version_timestamp
, tvb
, offset
, 8, ENC_TIME_SECS_NSECS
|ENC_LITTLE_ENDIAN
);
546 ti
= proto_tree_add_item(tree
, hf_msg_version_addr_you
, tvb
, offset
, 26, ENC_NA
);
547 create_address_tree(tvb
, ti
, offset
);
552 ti
= proto_tree_add_item(tree
, hf_msg_version_addr_me
, tvb
, offset
, 26, ENC_NA
);
553 create_address_tree(tvb
, ti
, offset
);
556 proto_tree_add_item(tree
, hf_msg_version_nonce
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
559 create_string_tree(tree
, hf_msg_version_user_agent
, tvb
, &offset
);
564 proto_tree_add_item(tree
, hf_msg_version_start_height
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
568 if (version
>= 70002)
570 proto_tree_add_item(tree
, hf_msg_version_relay
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
578 * Handler for address messages
581 dissect_bitcoin_msg_addr(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
588 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_addr
, tvb
, offset
, -1, ENC_NA
);
589 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
591 get_varint(tvb
, offset
, &length
, &count
);
592 add_varint_item(tree
, tvb
, offset
, length
, hf_msg_addr_count8
, hf_msg_addr_count16
,
593 hf_msg_addr_count32
, hf_msg_addr_count64
);
596 for (; count
> 0; count
--)
600 ti
= proto_tree_add_item(tree
, hf_msg_addr_address
, tvb
, offset
, 30, ENC_NA
);
601 subtree
= create_address_tree(tvb
, ti
, offset
+4);
603 proto_tree_add_item(subtree
, hf_msg_addr_timestamp
, tvb
, offset
, 4, ENC_TIME_SECS
|ENC_LITTLE_ENDIAN
);
612 * Handler for addrv2 messages
615 dissect_bitcoin_msg_addrv2(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
622 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_addrv2
, tvb
, offset
, -1, ENC_NA
);
623 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
625 get_varint(tvb
, offset
, &length
, &count
);
626 add_varint_item(tree
, tvb
, offset
, length
, hf_msg_addrv2_count8
, hf_msg_addrv2_count16
,
627 hf_msg_addrv2_count32
, hf_msg_addrv2_count64
);
630 for (; count
> 0; count
--)
633 proto_item
*sti_services
;
637 uint64_t address_length
;
639 sti
= proto_tree_add_item(tree
, hf_msg_addrv2_item
, tvb
, offset
, -1, ENC_NA
);
640 subtree
= proto_item_add_subtree(sti
, ett_addr_list
);
642 proto_tree_add_item(subtree
, hf_msg_addrv2_timestamp
, tvb
, offset
, 4, ENC_TIME_SECS
|ENC_LITTLE_ENDIAN
);
645 get_varint(tvb
, offset
, &length
, &services
);
646 sti_services
= proto_tree_add_bitmask_value(subtree
, tvb
, offset
, hf_msg_addrv2_services
,
647 ett_services
, services_hf_flags
, services
);
648 proto_item_set_len(sti_services
, length
);
651 network
= tvb_get_uint8(tvb
, offset
);
652 proto_tree_add_item(subtree
, hf_msg_addrv2_network
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
655 get_varint(tvb
, offset
, &length
, &address_length
);
661 proto_tree_add_item(subtree
, hf_msg_addrv2_address_ipv4
, tvb
, offset
, (unsigned) address_length
, ENC_NA
);
662 if (address_length
!= 4) {
663 proto_tree_add_expert(subtree
, pinfo
, &ei_bitcoin_address_length
,
664 tvb
, offset
, (unsigned) address_length
);
669 proto_tree_add_item(subtree
, hf_msg_addrv2_address_ipv6
, tvb
, offset
, (unsigned) address_length
, ENC_NA
);
670 if (address_length
!= 16) {
671 proto_tree_add_expert(subtree
, pinfo
, &ei_bitcoin_address_length
,
672 tvb
, offset
, (unsigned) address_length
);
677 proto_tree_add_item(subtree
, hf_msg_addrv2_address_other
, tvb
, offset
, (unsigned) address_length
, ENC_NA
);
682 * The above should make sure that the addition won't overflow.
683 * XXX - but what if address length fits in an unsigned int but
686 offset
+= (int)address_length
;
688 proto_tree_add_item(subtree
, hf_msg_addrv2_port
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
691 proto_item_set_end(sti
, tvb
, offset
);
698 * Handler for inventory messages
701 dissect_bitcoin_msg_inv(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
708 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_inv
, tvb
, offset
, -1, ENC_NA
);
709 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
711 get_varint(tvb
, offset
, &length
, &count
);
712 add_varint_item(tree
, tvb
, offset
, length
, hf_msg_inv_count8
, hf_msg_inv_count16
,
713 hf_msg_inv_count32
, hf_msg_inv_count64
);
717 for (; count
> 0; count
--)
721 subtree
= proto_tree_add_subtree(tree
, tvb
, offset
, 36, ett_inv_list
, NULL
, "Inventory vector");
723 proto_tree_add_item(subtree
, hf_msg_inv_type
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
726 proto_tree_add_item(subtree
, hf_msg_inv_hash
, tvb
, offset
, 32, ENC_NA
);
734 * Handler for getdata messages
737 dissect_bitcoin_msg_getdata(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
744 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_getdata
, tvb
, offset
, -1, ENC_NA
);
745 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
747 get_varint(tvb
, offset
, &length
, &count
);
748 add_varint_item(tree
, tvb
, offset
, length
, hf_msg_getdata_count8
, hf_msg_getdata_count16
,
749 hf_msg_getdata_count32
, hf_msg_getdata_count64
);
753 for (; count
> 0; count
--)
757 subtree
= proto_tree_add_subtree(tree
, tvb
, offset
, 36, ett_getdata_list
, NULL
, "Inventory vector");
759 proto_tree_add_item(subtree
, hf_msg_getdata_type
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
762 proto_tree_add_item(subtree
, hf_msg_getdata_hash
, tvb
, offset
, 32, ENC_NA
);
770 * Handler for notfound messages
773 dissect_bitcoin_msg_notfound(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
780 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_notfound
, tvb
, offset
, -1, ENC_NA
);
781 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
783 get_varint(tvb
, offset
, &length
, &count
);
784 add_varint_item(tree
, tvb
, offset
, length
, hf_msg_notfound_count8
, hf_msg_notfound_count16
,
785 hf_msg_notfound_count32
, hf_msg_notfound_count64
);
789 for (; count
> 0; count
--)
793 subtree
= proto_tree_add_subtree(tree
, tvb
, offset
, 36, ett_notfound_list
, NULL
, "Inventory vector");
795 proto_tree_add_item(subtree
, hf_msg_notfound_type
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
798 proto_tree_add_item(subtree
, hf_msg_notfound_hash
, tvb
, offset
, 32, ENC_NA
);
806 * Handler for getblocks messages
809 dissect_bitcoin_msg_getblocks(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
816 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_getblocks
, tvb
, offset
, -1, ENC_NA
);
817 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
819 /* why the protocol version is sent here nobody knows */
820 proto_tree_add_item(tree
, hf_msg_version_version
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
823 get_varint(tvb
, offset
, &length
, &count
);
824 add_varint_item(tree
, tvb
, offset
, length
, hf_msg_getblocks_count8
, hf_msg_getblocks_count16
,
825 hf_msg_getblocks_count32
, hf_msg_getblocks_count64
);
829 for (; count
> 0; count
--)
831 proto_tree_add_item(tree
, hf_msg_getblocks_start
, tvb
, offset
, 32, ENC_NA
);
835 proto_tree_add_item(tree
, hf_msg_getblocks_stop
, tvb
, offset
, 32, ENC_NA
);
842 * Handler for getheaders messages
846 dissect_bitcoin_msg_getheaders(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
853 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_getheaders
, tvb
, offset
, -1, ENC_NA
);
854 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
856 proto_tree_add_item(tree
, hf_msg_headers_version
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
859 get_varint(tvb
, offset
, &length
, &count
);
860 add_varint_item(tree
, tvb
, offset
, length
, hf_msg_getheaders_count8
, hf_msg_getheaders_count16
,
861 hf_msg_getheaders_count32
, hf_msg_getheaders_count64
);
865 for (; count
> 0; count
--)
867 proto_tree_add_item(tree
, hf_msg_getheaders_start
, tvb
, offset
, 32, ENC_NA
);
871 proto_tree_add_item(tree
, hf_msg_getheaders_stop
, tvb
, offset
, 32, ENC_NA
);
878 * Handler for tx message body
881 dissect_bitcoin_msg_tx_common(tvbuff_t
*tvb
, uint32_t offset
, packet_info
*pinfo
, proto_tree
*tree
, unsigned msgnum
)
889 rti
= proto_tree_add_item(tree
, hf_bitcoin_msg_tx
, tvb
, offset
, -1, ENC_NA
);
891 rti
= proto_tree_add_none_format(tree
, hf_bitcoin_msg_tx
, tvb
, offset
, -1, "Tx message [ %4d ]", msgnum
);
893 tree
= proto_item_add_subtree(rti
, ett_bitcoin_msg
);
895 proto_tree_add_item(tree
, hf_msg_tx_version
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
898 /* If present, "flag" always starts with 0x00. */
899 /* Otherwise we proceed straight to "in_count". */
900 uint8_t flag
= tvb_get_uint8(tvb
, offset
);
902 proto_tree_add_item(tree
, hf_msg_tx_flag
, tvb
, offset
, 2, ENC_NA
);
907 get_varint(tvb
, offset
, &count_length
, &in_count
);
908 add_varint_item(tree
, tvb
, offset
, count_length
, hf_msg_tx_in_count8
, hf_msg_tx_in_count16
,
909 hf_msg_tx_in_count32
, hf_msg_tx_in_count64
);
911 offset
+= count_length
;
914 * [36] previous_output outpoint
915 * [1+] script length var_int
916 * [ ?] signature script uchar[]
917 * [ 4] sequence uint32_t
919 * outpoint (aka previous output)
921 * [ 4] index uint32_t
924 for (uint64_t idx
= 0; idx
< in_count
; idx
++)
927 proto_tree
*prevtree
;
930 uint64_t script_length
;
931 uint32_t scr_len_offset
;
933 scr_len_offset
= offset
+36;
934 get_varint(tvb
, scr_len_offset
, &count_length
, &script_length
);
936 /* A funny script_length won't cause an exception since the field type is FT_NONE */
937 ti
= proto_tree_add_item(tree
, hf_msg_tx_in
, tvb
, offset
,
938 36 + count_length
+ (unsigned)script_length
+ 4, ENC_NA
);
939 subtree
= proto_item_add_subtree(ti
, ett_tx_in_list
);
941 /* previous output */
942 pti
= proto_tree_add_item(subtree
, hf_msg_tx_in_prev_output
, tvb
, offset
, 36, ENC_NA
);
943 prevtree
= proto_item_add_subtree(pti
, ett_tx_in_outp
);
945 proto_tree_add_item(prevtree
, hf_msg_tx_in_prev_outp_hash
, tvb
, offset
, 32, ENC_NA
);
948 proto_tree_add_item(prevtree
, hf_msg_tx_in_prev_outp_index
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
950 /* end previous output */
952 add_varint_item(subtree
, tvb
, offset
, count_length
, hf_msg_tx_in_script8
, hf_msg_tx_in_script16
,
953 hf_msg_tx_in_script32
, hf_msg_tx_in_script64
);
955 offset
+= count_length
;
957 if ((offset
+ script_length
) > INT_MAX
) {
958 proto_tree_add_expert(tree
, pinfo
, &ei_bitcoin_script_len
,
959 tvb
, scr_len_offset
, count_length
);
963 proto_tree_add_item(subtree
, hf_msg_tx_in_sig_script
, tvb
, offset
, (unsigned)script_length
, ENC_NA
);
964 offset
+= (unsigned)script_length
;
966 proto_tree_add_item(subtree
, hf_msg_tx_in_seq
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
971 get_varint(tvb
, offset
, &count_length
, &out_count
);
972 add_varint_item(tree
, tvb
, offset
, count_length
, hf_msg_tx_out_count8
, hf_msg_tx_out_count16
,
973 hf_msg_tx_out_count32
, hf_msg_tx_out_count64
);
975 offset
+= count_length
;
979 * [1+] script length [var_int]
982 for (; out_count
> 0; out_count
--)
986 uint64_t script_length
;
987 uint32_t scr_len_offset
;
989 scr_len_offset
= offset
+8;
990 get_varint(tvb
, scr_len_offset
, &count_length
, &script_length
);
992 /* A funny script_length won't cause an exception since the field type is FT_NONE */
993 ti
= proto_tree_add_item(tree
, hf_msg_tx_out
, tvb
, offset
,
994 8 + count_length
+ (unsigned)script_length
, ENC_NA
);
995 subtree
= proto_item_add_subtree(ti
, ett_tx_out_list
);
997 proto_tree_add_item(subtree
, hf_msg_tx_out_value
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
1000 add_varint_item(subtree
, tvb
, offset
, count_length
, hf_msg_tx_out_script8
, hf_msg_tx_out_script16
,
1001 hf_msg_tx_out_script32
, hf_msg_tx_out_script64
);
1003 offset
+= count_length
;
1005 if ((offset
+ script_length
) > INT_MAX
) {
1006 proto_tree_add_expert(tree
, pinfo
, &ei_bitcoin_script_len
,
1007 tvb
, scr_len_offset
, count_length
);
1011 proto_tree_add_item(subtree
, hf_msg_tx_out_script
, tvb
, offset
, (unsigned)script_length
, ENC_NA
);
1012 offset
+= (unsigned)script_length
;
1018 for (; in_count
> 0; in_count
--)
1021 proto_tree
*subtree
;
1023 ti
= proto_tree_add_item(tree
, hf_msg_tx_witness
, tvb
, offset
, -1, ENC_NA
);
1024 subtree
= proto_item_add_subtree(ti
, ett_tx_witness_list
);
1026 // count of witness data components
1027 int component_count_length
;
1028 uint64_t component_count
;
1030 get_varint(tvb
, offset
, &component_count_length
, &component_count
);
1031 add_varint_item(subtree
, tvb
, offset
, component_count_length
, hf_msg_tx_witness_components8
,
1032 hf_msg_tx_witness_components16
, hf_msg_tx_witness_components32
,
1033 hf_msg_tx_witness_components64
);
1034 offset
+= component_count_length
;
1036 for (; component_count
> 0; component_count
--)
1039 proto_tree
*subsubtree
;
1041 int component_size_length
;
1042 uint64_t component_size
;
1044 get_varint(tvb
, offset
, &component_size_length
, &component_size
);
1046 subti
= proto_tree_add_item(subtree
, hf_msg_tx_witness_component
, tvb
, offset
,
1047 component_size_length
+ (int) component_size
, ENC_NA
);
1048 subsubtree
= proto_item_add_subtree(subti
, ett_tx_witness_component_list
);
1050 add_varint_item(subsubtree
, tvb
, offset
, component_size_length
, hf_msg_tx_witness_component_length8
,
1051 hf_msg_tx_witness_component_length16
, hf_msg_tx_witness_component_length32
,
1052 hf_msg_tx_witness_component_length64
);
1053 offset
+= component_size_length
;
1055 proto_tree_add_item(subsubtree
, hf_msg_tx_witness_component_data
, tvb
, offset
, (int) component_size
, ENC_NA
);
1056 offset
+= (uint32_t)component_size
;
1059 proto_item_set_end(ti
, tvb
, offset
);
1063 proto_tree_add_item(tree
, hf_msg_tx_lock_time
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1066 /* needed for block nesting */
1067 proto_item_set_len(rti
, offset
);
1073 * Handler for tx message
1076 dissect_bitcoin_msg_tx(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
1078 return dissect_bitcoin_msg_tx_common(tvb
, 0, pinfo
, tree
, 0);
1083 * Handler for block messages
1086 dissect_bitcoin_msg_block(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
1092 uint32_t offset
= 0;
1095 * [ 4] version uint32_t
1096 * [32] prev_block char[32]
1097 * [32] merkle_root char[32]
1098 * [ 4] timestamp uint32_t A unix timestamp ... (Currently limited to dates before the year 2106!)
1099 * [ 4] bits uint32_t
1100 * [ 4] nonce uint32_t
1101 * [ ?] txn_count var_int
1102 * [ ?] txns tx[] Block transactions, in format of "tx" command
1105 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_block
, tvb
, offset
, -1, ENC_NA
);
1106 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
1108 proto_tree_add_item(tree
, hf_msg_block_version
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1111 proto_tree_add_item(tree
, hf_msg_block_prev_block
, tvb
, offset
, 32, ENC_NA
);
1114 proto_tree_add_item(tree
, hf_msg_block_merkle_root
, tvb
, offset
, 32, ENC_NA
);
1117 proto_tree_add_item(tree
, hf_msg_block_time
, tvb
, offset
, 4, ENC_TIME_SECS
|ENC_LITTLE_ENDIAN
);
1120 proto_tree_add_item(tree
, hf_msg_block_bits
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1123 proto_tree_add_item(tree
, hf_msg_block_nonce
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1126 get_varint(tvb
, offset
, &length
, &count
);
1127 add_varint_item(tree
, tvb
, offset
, length
, hf_msg_block_transactions8
, hf_msg_block_transactions16
,
1128 hf_msg_block_transactions32
, hf_msg_block_transactions64
);
1133 for (; count
>0 && offset
<INT_MAX
; count
--)
1136 offset
= dissect_bitcoin_msg_tx_common(tvb
, offset
, pinfo
, tree
, msgnum
);
1143 * Handler for headers messages
1146 dissect_bitcoin_msg_headers(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
1151 uint32_t offset
= 0;
1153 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_headers
, tvb
, offset
, -1, ENC_NA
);
1154 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
1156 get_varint(tvb
, offset
, &length
, &count
);
1157 add_varint_item(tree
, tvb
, offset
, length
, hf_msg_headers_count8
, hf_msg_headers_count16
,
1158 hf_msg_headers_count32
, hf_msg_headers_count64
);
1162 for (; count
> 0; count
--)
1164 proto_tree
*subtree
;
1167 subtree
= proto_tree_add_subtree(tree
, tvb
, offset
, -1, ett_bitcoin_msg
, NULL
, "Header");
1169 proto_tree_add_item(subtree
, hf_msg_headers_version
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1172 proto_tree_add_item(subtree
, hf_msg_headers_prev_block
, tvb
, offset
, 32, ENC_NA
);
1175 proto_tree_add_item(subtree
, hf_msg_headers_merkle_root
, tvb
, offset
, 32, ENC_NA
);
1178 proto_tree_add_item(subtree
, hf_msg_headers_time
, tvb
, offset
, 4, ENC_TIME_SECS
|ENC_LITTLE_ENDIAN
);
1181 proto_tree_add_item(subtree
, hf_msg_headers_bits
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1184 proto_tree_add_item(subtree
, hf_msg_headers_nonce
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1187 get_varint(tvb
, offset
, &length
, &txcount
);
1189 add_varint_item(subtree
, tvb
, offset
, length
, hf_msg_headers_count8
, hf_msg_headers_count16
,
1190 hf_msg_headers_count32
, hf_msg_headers_count64
);
1194 proto_item_set_len(subtree
, 80 + length
);
1201 * Handler for ping messages
1204 dissect_bitcoin_msg_ping(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
1207 uint32_t offset
= 0;
1209 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_ping
, tvb
, offset
, -1, ENC_NA
);
1210 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
1212 proto_tree_add_item(tree
, hf_msg_ping_nonce
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
1219 * Handler for pong messages
1222 dissect_bitcoin_msg_pong(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
1225 uint32_t offset
= 0;
1227 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_pong
, tvb
, offset
, -1, ENC_NA
);
1228 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
1230 proto_tree_add_item(tree
, hf_msg_pong_nonce
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
1237 * Handler for reject messages
1240 dissect_bitcoin_msg_reject(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
1243 uint32_t offset
= 0;
1245 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_reject
, tvb
, offset
, -1, ENC_NA
);
1246 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
1248 create_string_tree(tree
, hf_msg_reject_message
, tvb
, &offset
);
1250 proto_tree_add_item(tree
, hf_msg_reject_ccode
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
1253 create_string_tree(tree
, hf_msg_reject_reason
, tvb
, &offset
);
1255 if ((tvb_reported_length(tvb
) - offset
) > 0)
1257 proto_tree_add_item(tree
, hf_msg_reject_data
, tvb
, offset
, tvb_reported_length(tvb
) - offset
, ENC_NA
);
1264 * Handler for feefilter messages
1267 dissect_bitcoin_msg_feefilter(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
1270 uint32_t offset
= 0;
1272 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_feefilter
, tvb
, offset
, -1, ENC_NA
);
1273 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
1275 proto_tree_add_item(tree
, hf_msg_feefilter_value
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
1282 * Handler for filterload messages
1285 dissect_bitcoin_msg_filterload(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
1288 uint32_t offset
= 0;
1290 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_filterload
, tvb
, offset
, -1, ENC_NA
);
1291 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
1293 create_data_tree(tree
, hf_msg_filterload_filter
, tvb
, &offset
);
1295 proto_tree_add_item(tree
, hf_msg_filterload_nhashfunc
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1298 proto_tree_add_item(tree
, hf_msg_filterload_ntweak
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1301 proto_tree_add_item(tree
, hf_msg_filterload_nflags
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
1308 * Handler for filteradd messages
1311 dissect_bitcoin_msg_filteradd(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
1314 uint32_t offset
= 0;
1316 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_filteradd
, tvb
, offset
, -1, ENC_NA
);
1317 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
1319 create_data_tree(tree
, hf_msg_filteradd_data
, tvb
, &offset
);
1325 * Handler for merkleblock messages
1329 dissect_bitcoin_msg_merkleblock(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
1332 proto_item
*subtree
;
1335 uint32_t offset
= 0;
1337 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_merkleblock
, tvb
, offset
, -1, ENC_NA
);
1338 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
1340 proto_tree_add_item(tree
, hf_msg_merkleblock_version
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1343 proto_tree_add_item(tree
, hf_msg_merkleblock_prev_block
, tvb
, offset
, 32, ENC_NA
);
1346 proto_tree_add_item(tree
, hf_msg_merkleblock_merkle_root
, tvb
, offset
, 32, ENC_NA
);
1349 proto_tree_add_item(tree
, hf_msg_merkleblock_time
, tvb
, offset
, 4, ENC_TIME_SECS
|ENC_LITTLE_ENDIAN
);
1352 proto_tree_add_item(tree
, hf_msg_merkleblock_bits
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1355 proto_tree_add_item(tree
, hf_msg_merkleblock_nonce
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1358 proto_tree_add_item(tree
, hf_msg_merkleblock_transactions
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
1361 get_varint(tvb
, offset
, &length
, &count
);
1363 subtree
= proto_tree_add_subtree(tree
, tvb
, offset
, -1, ett_bitcoin_msg
, NULL
, "Hashes");
1365 add_varint_item(subtree
, tvb
, offset
, length
, hf_msg_merkleblock_hashes_count8
, hf_msg_merkleblock_hashes_count16
,
1366 hf_msg_merkleblock_hashes_count32
, hf_msg_merkleblock_hashes_count64
);
1369 for (; count
> 0; count
--)
1371 proto_tree_add_item(subtree
, hf_msg_merkleblock_hashes_hash
, tvb
, offset
, 32, ENC_NA
);
1375 get_varint(tvb
, offset
, &length
, &count
);
1377 subtree
= proto_tree_add_subtree(tree
, tvb
, offset
, -1, ett_bitcoin_msg
, NULL
, "Flags");
1379 add_varint_item(subtree
, tvb
, offset
, length
, hf_msg_merkleblock_flags_size8
, hf_msg_merkleblock_flags_size16
,
1380 hf_msg_merkleblock_flags_size32
, hf_msg_merkleblock_flags_size64
);
1383 /* The cast to unsigned is save because bitcoin messages are always smaller than 0x02000000 bytes. */
1384 proto_tree_add_item(subtree
, hf_msg_merkleblock_flags_data
, tvb
, offset
, (unsigned)count
, BASE_SHOW_UTF_8_PRINTABLE
);
1385 offset
+= (uint32_t)count
;
1391 * Handler for sendcmpct messages
1395 dissect_bitcoin_msg_sendcmpct(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
, void *data _U_
)
1398 uint32_t offset
= 0;
1400 ti
= proto_tree_add_item(tree
, hf_bitcoin_msg_sendcmpct
, tvb
, offset
, -1, ENC_NA
);
1401 tree
= proto_item_add_subtree(ti
, ett_bitcoin_msg
);
1403 proto_tree_add_item(tree
, hf_msg_sendcmpct_announce
, tvb
, offset
, 1, ENC_NA
);
1406 proto_tree_add_item(tree
, hf_msg_sendcmpct_version
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
1413 * Handler for unimplemented or payload-less messages
1416 dissect_bitcoin_msg_empty(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree _U_
, void *data _U_
)
1418 return tvb_captured_length(tvb
);
1421 static int dissect_bitcoin_tcp_pdu(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
1424 uint32_t offset
= 0;
1425 const uint8_t* command
;
1426 dissector_handle_t command_handle
;
1428 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "Bitcoin");
1430 ti
= proto_tree_add_item(tree
, proto_bitcoin
, tvb
, 0, -1, ENC_NA
);
1431 tree
= proto_item_add_subtree(ti
, ett_bitcoin
);
1433 /* add basic protocol data */
1434 proto_tree_add_item(tree
, hf_bitcoin_magic
, tvb
, 0, 4, ENC_BIG_ENDIAN
);
1435 proto_tree_add_item_ret_string(tree
, hf_bitcoin_command
, tvb
, 4, 12, ENC_ASCII
|ENC_NA
, pinfo
->pool
, &command
);
1436 proto_tree_add_item(tree
, hf_bitcoin_length
, tvb
, 16, 4, ENC_LITTLE_ENDIAN
);
1437 proto_tree_add_checksum(tree
, tvb
, 20, hf_bitcoin_checksum
, -1, NULL
, pinfo
, 0, ENC_BIG_ENDIAN
, PROTO_CHECKSUM_NO_FLAGS
);
1441 command_handle
= dissector_get_string_handle(bitcoin_command_table
, command
);
1442 if (command_handle
!= NULL
)
1444 /* handle command specific message part */
1447 col_append_sep_str(pinfo
->cinfo
, COL_INFO
, ", ", command
);
1448 tvb_sub
= tvb_new_subset_remaining(tvb
, offset
);
1449 call_dissector(command_handle
, tvb_sub
, pinfo
, tree
);
1453 /* no handler found */
1454 col_append_sep_str(pinfo
->cinfo
, COL_INFO
, ", ", "[unknown command]");
1456 expert_add_info(pinfo
, ti
, &ei_bitcoin_command_unknown
);
1459 return tvb_reported_length(tvb
);
1463 dissect_bitcoin(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
1465 col_clear(pinfo
->cinfo
, COL_INFO
);
1466 tcp_dissect_pdus(tvb
, pinfo
, tree
, bitcoin_desegment
, BITCOIN_HEADER_LENGTH
,
1467 get_bitcoin_pdu_length
, dissect_bitcoin_tcp_pdu
, data
);
1469 return tvb_reported_length(tvb
);
1473 dissect_bitcoin_heur(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
1475 uint32_t magic_number
;
1476 conversation_t
*conversation
;
1478 if (tvb_captured_length(tvb
) < 4)
1481 magic_number
= tvb_get_letohl(tvb
, 0);
1482 if ((magic_number
!= BITCOIN_MAIN_MAGIC_NUMBER
) &&
1483 (magic_number
!= BITCOIN_TESTNET_MAGIC_NUMBER
) &&
1484 (magic_number
!= BITCOIN_TESTNET3_MAGIC_NUMBER
))
1487 /* Ok: This connection should always use the bitcoin dissector */
1488 conversation
= find_or_create_conversation(pinfo
);
1489 conversation_set_dissector(conversation
, bitcoin_handle
);
1491 dissect_bitcoin(tvb
, pinfo
, tree
, data
);
1496 proto_register_bitcoin(void)
1498 static hf_register_info hf
[] = {
1499 { &hf_bitcoin_magic
,
1500 { "Packet magic", "bitcoin.magic",
1501 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
1504 { &hf_bitcoin_command
,
1505 { "Command name", "bitcoin.command",
1506 FT_STRING
, BASE_NONE
, NULL
, 0x0,
1509 { &hf_bitcoin_length
,
1510 { "Payload Length", "bitcoin.length",
1511 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1514 { &hf_bitcoin_checksum
,
1515 { "Payload checksum", "bitcoin.checksum",
1516 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
1519 { &hf_bitcoin_msg_version
,
1520 { "Version message", "bitcoin.version",
1521 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1524 { &hf_msg_version_version
,
1525 { "Protocol version", "bitcoin.version.version",
1526 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1529 { &hf_msg_version_services
,
1530 { "Node services", "bitcoin.version.services",
1531 FT_UINT64
, BASE_HEX
, NULL
, 0x0,
1534 { &hf_msg_version_timestamp
,
1535 { "Node timestamp", "bitcoin.version.timestamp",
1536 FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
, NULL
, 0x0,
1539 { &hf_msg_version_addr_me
,
1540 { "Address of emitting node", "bitcoin.version.addr_me",
1541 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1544 { &hf_msg_version_addr_you
,
1545 { "Address as receiving node", "bitcoin.version.addr_you",
1546 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1549 { &hf_msg_version_nonce
,
1550 { "Random nonce", "bitcoin.version.nonce",
1551 FT_UINT64
, BASE_HEX
, NULL
, 0x0,
1554 { &hf_msg_version_user_agent
,
1555 { "User agent", "bitcoin.version.user_agent",
1556 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1559 { &hf_msg_version_start_height
,
1560 { "Block start height", "bitcoin.version.start_height",
1561 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1564 { &hf_msg_version_relay
,
1565 { "Relay flag", "bitcoin.version.relay",
1566 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1569 { &hf_msg_addr_count8
,
1570 { "Count", "bitcoin.addr.count",
1571 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1574 { &hf_msg_addr_count16
,
1575 { "Count", "bitcoin.addr.count",
1576 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
1579 { &hf_msg_addr_count32
,
1580 { "Count", "bitcoin.addr.count",
1581 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1584 { &hf_msg_addr_count64
,
1585 { "Count", "bitcoin.addr.count64",
1586 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1589 { &hf_bitcoin_msg_addr
,
1590 { "Address message", "bitcoin.addr",
1591 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1594 { &hf_msg_addr_address
,
1595 { "Address", "bitcoin.addr.address",
1596 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1599 { &hf_msg_addr_timestamp
,
1600 { "Address timestamp", "bitcoin.addr.timestamp",
1601 FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
, NULL
, 0x0,
1604 { &hf_msg_addrv2_count8
,
1605 { "Count", "bitcoin.addrv2.count",
1606 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1609 { &hf_msg_addrv2_count16
,
1610 { "Count", "bitcoin.addrv2.count",
1611 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
1614 { &hf_msg_addrv2_count32
,
1615 { "Count", "bitcoin.addrv2.count",
1616 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1619 { &hf_msg_addrv2_count64
,
1620 { "Count", "bitcoin.addrv2.count64",
1621 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1624 { &hf_msg_addrv2_item
,
1625 { "Address", "bitcoin.addrv2.item",
1626 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1629 { &hf_msg_addrv2_timestamp
,
1630 { "Timestamp", "bitcoin.addrv2.timestamp",
1631 FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
, NULL
, 0x0,
1634 { &hf_msg_addrv2_services
,
1635 { "Node services", "bitcoin.addrv2.services",
1636 FT_UINT64
, BASE_HEX
, NULL
, 0x0,
1639 { &hf_msg_addrv2_network
,
1640 { "Node network", "bitcoin.addrv2.network",
1641 FT_UINT8
, BASE_DEC
, VALS(network_ids
), 0x0,
1644 { &hf_msg_addrv2_address_ipv4
,
1645 { "Node address", "bitcoin.addrv2.address.ipv4",
1646 FT_IPv4
, BASE_NONE
, NULL
, 0x0,
1649 { &hf_msg_addrv2_address_ipv6
,
1650 { "Node address", "bitcoin.addrv2.address.ipv6",
1651 FT_IPv6
, BASE_NONE
, NULL
, 0x0,
1654 { &hf_msg_addrv2_address_other
,
1655 { "Node address", "bitcoin.addrv2.address.other",
1656 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1659 { &hf_msg_addrv2_port
,
1660 { "Node port", "bitcoin.addrv2.port",
1661 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
1664 { &hf_bitcoin_msg_addrv2
,
1665 { "Addrv2 message", "bitcoin.addrv2",
1666 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1669 { &hf_msg_inv_count8
,
1670 { "Count", "bitcoin.inv.count",
1671 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1674 { &hf_msg_inv_count16
,
1675 { "Count", "bitcoin.inv.count",
1676 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
1679 { &hf_msg_inv_count32
,
1680 { "Count", "bitcoin.inv.count",
1681 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1684 { &hf_msg_inv_count64
,
1685 { "Count", "bitcoin.inv.count64",
1686 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1689 { &hf_bitcoin_msg_inv
,
1690 { "Inventory message", "bitcoin.inv",
1691 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1695 { "Type", "bitcoin.inv.type",
1696 FT_UINT32
, BASE_DEC
, VALS(inv_types
), 0x0,
1700 { "Data hash", "bitcoin.inv.hash",
1701 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1704 { &hf_bitcoin_msg_getdata
,
1705 { "Getdata message", "bitcoin.getdata",
1706 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1709 { &hf_msg_getdata_count8
,
1710 { "Count", "bitcoin.getdata.count",
1711 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1714 { &hf_msg_getdata_count16
,
1715 { "Count", "bitcoin.getdata.count",
1716 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
1719 { &hf_msg_getdata_count32
,
1720 { "Count", "bitcoin.getdata.count",
1721 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1724 { &hf_msg_getdata_count64
,
1725 { "Count", "bitcoin.getdata.count64",
1726 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1729 { &hf_msg_getdata_type
,
1730 { "Type", "bitcoin.getdata.type",
1731 FT_UINT32
, BASE_DEC
, VALS(inv_types
), 0x0,
1734 { &hf_msg_getdata_hash
,
1735 { "Data hash", "bitcoin.getdata.hash",
1736 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1739 { &hf_msg_notfound_count8
,
1740 { "Count", "bitcoin.notfound.count",
1741 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1744 { &hf_msg_notfound_count16
,
1745 { "Count", "bitcoin.notfound.count",
1746 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
1749 { &hf_msg_notfound_count32
,
1750 { "Count", "bitcoin.notfound.count",
1751 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1754 { &hf_msg_notfound_count64
,
1755 { "Count", "bitcoin.notfound.count64",
1756 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1759 { &hf_bitcoin_msg_notfound
,
1760 { "Getdata message", "bitcoin.notfound",
1761 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1764 { &hf_msg_notfound_type
,
1765 { "Type", "bitcoin.notfound.type",
1766 FT_UINT32
, BASE_DEC
, VALS(inv_types
), 0x0,
1769 { &hf_msg_notfound_hash
,
1770 { "Data hash", "bitcoin.notfound.hash",
1771 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1774 { &hf_msg_getblocks_count8
,
1775 { "Count", "bitcoin.getblocks.count",
1776 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1779 { &hf_msg_getblocks_count16
,
1780 { "Count", "bitcoin.getblocks.count",
1781 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
1784 { &hf_msg_getblocks_count32
,
1785 { "Count", "bitcoin.getblocks.count",
1786 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1789 { &hf_msg_getblocks_count64
,
1790 { "Count", "bitcoin.getblocks.count64",
1791 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1794 { &hf_bitcoin_msg_getblocks
,
1795 { "Getdata message", "bitcoin.getblocks",
1796 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1799 { &hf_msg_getblocks_start
,
1800 { "Starting hash", "bitcoin.getblocks.hash_start",
1801 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1804 { &hf_msg_getblocks_stop
,
1805 { "Stopping hash", "bitcoin.getblocks.hash_stop",
1806 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1809 { &hf_msg_getheaders_count8
,
1810 { "Count", "bitcoin.getheaders.count",
1811 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1814 { &hf_msg_getheaders_count16
,
1815 { "Count", "bitcoin.getheaders.count",
1816 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
1819 { &hf_msg_getheaders_count32
,
1820 { "Count", "bitcoin.getheaders.count",
1821 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1824 { &hf_msg_getheaders_count64
,
1825 { "Count", "bitcoin.getheaders.count64",
1826 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1829 { &hf_msg_getheaders_version
,
1830 { "Protocol version", "bitcoin.headers.version",
1831 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1834 { &hf_bitcoin_msg_getheaders
,
1835 { "Getheaders message", "bitcoin.getheaders",
1836 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1839 { &hf_msg_getheaders_start
,
1840 { "Starting hash", "bitcoin.getheaders.hash_start",
1841 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1844 { &hf_msg_getheaders_stop
,
1845 { "Stopping hash", "bitcoin.getheaders.hash_stop",
1846 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1849 { &hf_msg_tx_in_count8
,
1850 { "Input Count", "bitcoin.tx.input_count",
1851 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1854 { &hf_msg_tx_in_count16
,
1855 { "Input Count", "bitcoin.tx.input_count",
1856 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
1859 { &hf_msg_tx_in_count32
,
1860 { "Input Count", "bitcoin.tx.input_count",
1861 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1864 { &hf_msg_tx_in_count64
,
1865 { "Input Count", "bitcoin.tx.input_count64",
1866 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1869 { &hf_bitcoin_msg_tx
,
1870 { "Tx message", "bitcoin.tx",
1871 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1874 { &hf_msg_tx_version
,
1875 { "Transaction version", "bitcoin.tx.version",
1876 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1880 { "Flag", "bitcoin.tx.flag",
1881 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1884 { &hf_msg_tx_in_script8
,
1885 { "Script Length", "bitcoin.tx.in.script_length",
1886 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1889 { &hf_msg_tx_in_script16
,
1890 { "Script Length", "bitcoin.tx.in.script_length",
1891 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
1894 { &hf_msg_tx_in_script32
,
1895 { "Script Length", "bitcoin.tx.in.script_length",
1896 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1899 { &hf_msg_tx_in_script64
,
1900 { "Script Length", "bitcoin.tx.in.script_length64",
1901 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1905 { "Transaction input", "bitcoin.tx.in",
1906 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1909 { &hf_msg_tx_in_prev_output
,
1910 { "Previous output", "bitcoin.tx.in.prev_output",
1911 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1914 { &hf_msg_tx_in_prev_outp_hash
,
1915 { "Hash", "bitcoin.tx.in.prev_output.hash",
1916 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1919 { &hf_msg_tx_in_prev_outp_index
,
1920 { "Index", "bitcoin.tx.in.prev_output.index",
1921 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1924 { &hf_msg_tx_in_sig_script
,
1925 { "Signature script", "bitcoin.tx.in.sig_script",
1926 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1929 { &hf_msg_tx_in_seq
,
1930 { "Sequence", "bitcoin.tx.in.seq",
1931 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1934 { &hf_msg_tx_out_count8
,
1935 { "Output Count", "bitcoin.tx.output_count",
1936 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1939 { &hf_msg_tx_out_count16
,
1940 { "Output Count", "bitcoin.tx.output_count",
1941 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
1944 { &hf_msg_tx_out_count32
,
1945 { "Output Count", "bitcoin.tx.output_count",
1946 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1949 { &hf_msg_tx_out_count64
,
1950 { "Output Count", "bitcoin.tx.output_count64",
1951 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1955 { "Transaction output", "bitcoin.tx.out",
1956 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1959 { &hf_msg_tx_out_value
,
1960 { "Value", "bitcoin.tx.out.value",
1961 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1964 { &hf_msg_tx_out_script8
,
1965 { "Script Length", "bitcoin.tx.out.script_length",
1966 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1969 { &hf_msg_tx_out_script16
,
1970 { "Script Length", "bitcoin.tx.out.script_length",
1971 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
1974 { &hf_msg_tx_out_script32
,
1975 { "Script Length", "bitcoin.tx.out.script_length",
1976 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1979 { &hf_msg_tx_out_script64
,
1980 { "Script Length", "bitcoin.tx.out.script_length64",
1981 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
1984 { &hf_msg_tx_out_script
,
1985 { "Script", "bitcoin.tx.out.script",
1986 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
1989 { &hf_msg_tx_witness
,
1990 { "Transaction witness", "bitcoin.tx.witness",
1991 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1994 { &hf_msg_tx_witness_components8
,
1995 { "Number of components", "bitcoin.tx.witness.component_count",
1996 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1999 { &hf_msg_tx_witness_components16
,
2000 { "Number of components", "bitcoin.tx.witness.component_count",
2001 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
2004 { &hf_msg_tx_witness_components32
,
2005 { "Number of components", "bitcoin.tx.witness.component_count",
2006 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2009 { &hf_msg_tx_witness_components64
,
2010 { "Number of components", "bitcoin.tx.witness.component_count64",
2011 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
2014 { &hf_msg_tx_witness_component
,
2015 { "Witness component", "bitcoin.tx.witness.component",
2016 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2019 { &hf_msg_tx_witness_component_length8
,
2020 { "Length", "bitcoin.tx.witness.component.length",
2021 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
2024 { &hf_msg_tx_witness_component_length16
,
2025 { "Length", "bitcoin.tx.witness.component.length",
2026 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
2029 { &hf_msg_tx_witness_component_length32
,
2030 { "Length", "bitcoin.tx.witness.component.length",
2031 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2034 { &hf_msg_tx_witness_component_length64
,
2035 { "Length", "bitcoin.tx.witness.component.length64",
2036 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
2039 { &hf_msg_tx_witness_component_data
,
2040 { "Data", "bitcoin.tx.witness.component.data",
2041 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
2044 { &hf_msg_tx_lock_time
,
2045 { "Block lock time or block ID", "bitcoin.tx.lock_time",
2046 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2049 { &hf_msg_block_transactions8
,
2050 { "Number of transactions", "bitcoin.block.num_transactions",
2051 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
2054 { &hf_msg_block_transactions16
,
2055 { "Number of transactions", "bitcoin.block.num_transactions",
2056 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
2059 { &hf_msg_block_transactions32
,
2060 { "Number of transactions", "bitcoin.block.num_transactions",
2061 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2064 { &hf_msg_block_transactions64
,
2065 { "Number of transactions", "bitcoin.block.num_transactions64",
2066 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
2069 { &hf_bitcoin_msg_block
,
2070 { "Block message", "bitcoin.block",
2071 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2074 { &hf_msg_block_version
,
2075 { "Block version", "bitcoin.block.version",
2076 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2079 { &hf_msg_block_prev_block
,
2080 { "Previous block", "bitcoin.block.prev_block",
2081 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
2084 { &hf_msg_block_merkle_root
,
2085 { "Merkle root", "bitcoin.block.merkle_root",
2086 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
2089 { &hf_msg_block_time
,
2090 { "Block timestamp", "bitcoin.block.timestamp",
2091 FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
, NULL
, 0x0,
2094 { &hf_msg_block_bits
,
2095 { "Bits", "bitcoin.block.bits",
2096 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
2099 { &hf_msg_block_nonce
,
2100 { "Nonce", "bitcoin.block.nonce",
2101 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
2104 { &hf_bitcoin_msg_headers
,
2105 { "Headers message", "bitcoin.headers",
2106 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2109 { &hf_msg_headers_version
,
2110 { "Block version", "bitcoin.headers.version",
2111 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2114 { &hf_msg_headers_prev_block
,
2115 { "Previous block", "bitcoin.headers.prev_block",
2116 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
2119 { &hf_msg_headers_merkle_root
,
2120 { "Merkle root", "bitcoin.headers.merkle_root",
2121 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
2124 { &hf_msg_headers_time
,
2125 { "Block timestamp", "bitcoin.headers.timestamp",
2126 FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
, NULL
, 0x0,
2129 { &hf_msg_headers_bits
,
2130 { "Bits", "bitcoin.headers.bits",
2131 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
2134 { &hf_msg_headers_nonce
,
2135 { "Nonce", "bitcoin.headers.nonce",
2136 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
2139 { &hf_msg_headers_count8
,
2140 { "Count", "bitcoin.headers.count",
2141 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
2144 { &hf_msg_headers_count16
,
2145 { "Count", "bitcoin.headers.count",
2146 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
2149 { &hf_msg_headers_count32
,
2150 { "Count", "bitcoin.headers.count",
2151 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2154 { &hf_msg_headers_count64
,
2155 { "Count", "bitcoin.headers.count64",
2156 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
2159 { &hf_bitcoin_msg_ping
,
2160 { "Ping message", "bitcoin.ping",
2161 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2164 { &hf_msg_ping_nonce
,
2165 { "Random nonce", "bitcoin.ping.nonce",
2166 FT_UINT64
, BASE_HEX
, NULL
, 0x0,
2169 { &hf_bitcoin_msg_pong
,
2170 { "Pong message", "bitcoin.pong",
2171 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2174 { &hf_msg_pong_nonce
,
2175 { "Random nonce", "bitcoin.pong.nonce",
2176 FT_UINT64
, BASE_HEX
, NULL
, 0x0,
2179 { &hf_bitcoin_msg_reject
,
2180 { "Reject message", "bitcoin.reject",
2181 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2184 { &hf_msg_reject_message
,
2185 { "Message rejected", "bitcoin.reject.message",
2186 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2189 { &hf_msg_reject_reason
,
2190 { "Reason", "bitcoin.reject.reason",
2191 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2194 { &hf_msg_reject_ccode
,
2195 { "CCode", "bitcoin.reject.ccode",
2196 FT_UINT8
, BASE_HEX
, VALS(reject_ccode
), 0x0,
2199 { &hf_msg_reject_data
,
2200 { "Data", "bitcoin.reject.data",
2201 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
2204 { &hf_bitcoin_msg_sendcmpct
,
2205 { "Sendcmpct message", "bitcoin.sendcmpct",
2206 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2209 { &hf_msg_sendcmpct_announce
,
2210 { "Announce", "bitcoin.sendcmpct.announce",
2211 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
2214 { &hf_msg_sendcmpct_version
,
2215 { "Version", "bitcoin.sendcmpct.version",
2216 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
2219 { &hf_bitcoin_msg_feefilter
,
2220 { "Feefilter message", "bitcoin.feefilter",
2221 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2224 { &hf_msg_feefilter_value
,
2225 { "Minimal fee", "bitcoin.feefilter.value",
2226 FT_UINT64
, BASE_CUSTOM
, CF_FUNC(format_feefilter_value
), 0x0,
2229 { &hf_bitcoin_msg_filterload
,
2230 { "Filterload message", "bitcoin.filterload",
2231 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2234 { &hf_msg_filterload_filter
,
2235 { "Filter", "bitcoin.filterload.filter",
2236 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2239 { &hf_msg_filterload_nhashfunc
,
2240 { "nHashFunc", "bitcoin.filterload.nhashfunc",
2241 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2244 { &hf_msg_filterload_ntweak
,
2245 { "nTweak", "bitcoin.filterload.ntweak",
2246 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
2249 { &hf_msg_filterload_nflags
,
2250 { "nFlags", "bitcoin.filterload.nflags",
2251 FT_UINT8
, BASE_HEX
, VALS(filterload_nflags
), 0x0,
2254 { &hf_bitcoin_msg_filteradd
,
2255 { "Filteradd message", "bitcoin.filteradd",
2256 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2259 { &hf_msg_filteradd_data
,
2260 { "Data", "bitcoin.filteradd.data",
2261 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2264 { &hf_bitcoin_msg_merkleblock
,
2265 { "Merkleblock message", "bitcoin.merkleblock",
2266 FT_NONE
, BASE_NONE
, NULL
, 0x0,
2269 { &hf_msg_merkleblock_transactions
,
2270 { "Number of transactions", "bitcoin.merkleblock.num_transactions",
2271 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2274 { &hf_msg_merkleblock_version
,
2275 { "Block version", "bitcoin.merkleblock.version",
2276 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2279 { &hf_msg_merkleblock_prev_block
,
2280 { "Previous block", "bitcoin.merkleblock.prev_block",
2281 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
2284 { &hf_msg_merkleblock_merkle_root
,
2285 { "Merkle root", "bitcoin.merkleblock.merkle_root",
2286 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
2289 { &hf_msg_merkleblock_time
,
2290 { "Block timestamp", "bitcoin.merkleblock.timestamp",
2291 FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
, NULL
, 0x0,
2294 { &hf_msg_merkleblock_bits
,
2295 { "Bits", "bitcoin.merkleblock.bits",
2296 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
2299 { &hf_msg_merkleblock_nonce
,
2300 { "Nonce", "bitcoin.merkleblock.nonce",
2301 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
2304 { &hf_msg_merkleblock_hashes_count8
,
2305 { "Count", "bitcoin.merkleblock.hashes.count",
2306 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
2309 { &hf_msg_merkleblock_hashes_count16
,
2310 { "Count", "bitcoin.merkleblock.hashes.count",
2311 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
2314 { &hf_msg_merkleblock_hashes_count32
,
2315 { "Count", "bitcoin.merkleblock.hashes.count",
2316 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2319 { &hf_msg_merkleblock_hashes_count64
,
2320 { "Count", "bitcoin.merkleblock.hashes.count64",
2321 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
2324 { &hf_msg_merkleblock_hashes_hash
,
2325 { "Hash", "bitcoin.merkleblock.hashes.hash",
2326 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
2329 { &hf_msg_merkleblock_flags_size8
,
2330 { "Size", "bitcoin.merkleblock.flags.count",
2331 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
2334 { &hf_msg_merkleblock_flags_size16
,
2335 { "Size", "bitcoin.merkleblock.flags.count",
2336 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
2339 { &hf_msg_merkleblock_flags_size32
,
2340 { "Size", "bitcoin.merkleblock.flags.count",
2341 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2344 { &hf_msg_merkleblock_flags_size64
,
2345 { "Size", "bitcoin.merkleblock.flags.count64",
2346 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
2349 { &hf_msg_merkleblock_flags_data
,
2350 { "Data", "bitcoin.merkleblock.flags.data",
2351 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
2354 { &hf_services_network
,
2355 { "Network node", "bitcoin.services.network",
2356 FT_BOOLEAN
, 32, TFS(&tfs_set_notset
), 0x00000001,
2359 { &hf_services_getutxo
,
2360 { "Getutxo node", "bitcoin.services.getutxo",
2361 FT_BOOLEAN
, 32, TFS(&tfs_set_notset
), 0x00000002,
2364 { &hf_services_bloom
,
2365 { "Bloom filter node", "bitcoin.services.bloom",
2366 FT_BOOLEAN
, 32, TFS(&tfs_set_notset
), 0x00000004,
2369 { &hf_services_witness
,
2370 { "Witness node", "bitcoin.services.witness",
2371 FT_BOOLEAN
, 32, TFS(&tfs_set_notset
), 0x00000008,
2374 { &hf_services_xthin
,
2375 { "Xtreme Thinblocks node", "bitcoin.services.xthin",
2376 FT_BOOLEAN
, 32, TFS(&tfs_set_notset
), 0x00000010,
2379 { &hf_services_compactfilters
,
2380 { "Compact filters node", "bitcoin.services.compactfilters",
2381 FT_BOOLEAN
, 32, TFS(&tfs_set_notset
), 0x00000040,
2384 { &hf_services_networklimited
,
2385 { "Limited network node", "bitcoin.services.networklimited",
2386 FT_BOOLEAN
, 32, TFS(&tfs_set_notset
), 0x00000400,
2389 { &hf_services_p2pv2
,
2390 { "Version 2 P2P node", "bitcoin.services.p2pv2",
2391 FT_BOOLEAN
, 32, TFS(&tfs_set_notset
), 0x00000800,
2394 { &hf_address_services
,
2395 { "Node services", "bitcoin.address.services",
2396 FT_UINT64
, BASE_HEX
, NULL
, 0x0,
2399 { &hf_address_address
,
2400 { "Node address", "bitcoin.address.address",
2401 FT_IPv6
, BASE_NONE
, NULL
, 0x0,
2405 { "Node port", "bitcoin.address.port",
2406 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
2410 { "String value", "bitcoin.string.value",
2411 FT_STRING
, BASE_NONE
, NULL
, 0x0,
2414 { &hf_string_varint_count8
,
2415 { "Count", "bitcoin.string.count",
2416 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
2419 { &hf_string_varint_count16
,
2420 { "Count", "bitcoin.string.count",
2421 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
2424 { &hf_string_varint_count32
,
2425 { "Count", "bitcoin.string.count",
2426 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2429 { &hf_string_varint_count64
,
2430 { "Count", "bitcoin.string.count64",
2431 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
2435 { "Data", "bitcoin.data.value",
2436 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
2439 { &hf_data_varint_count8
,
2440 { "Count", "bitcoin.data.count",
2441 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
2444 { &hf_data_varint_count16
,
2445 { "Count", "bitcoin.data.count",
2446 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
2449 { &hf_data_varint_count32
,
2450 { "Count", "bitcoin.data.count",
2451 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
2454 { &hf_data_varint_count64
,
2455 { "Count", "bitcoin.data.count64",
2456 FT_UINT64
, BASE_DEC
, NULL
, 0x0,
2461 static int *ett
[] = {
2471 &ett_getblocks_list
,
2472 &ett_getheaders_list
,
2476 &ett_tx_witness_list
,
2477 &ett_tx_witness_component_list
,
2480 static ei_register_info ei
[] = {
2481 { &ei_bitcoin_command_unknown
, { "bitcoin.command.unknown", PI_PROTOCOL
, PI_WARN
, "Unknown command", EXPFILL
}},
2482 { &ei_bitcoin_address_length
, { "bitcoin.address_length.invalid", PI_MALFORMED
, PI_WARN
, "Address length does not match network type", EXPFILL
}},
2483 { &ei_bitcoin_script_len
, { "bitcoin.script_length.invalid", PI_MALFORMED
, PI_ERROR
, "script_len too large", EXPFILL
}}
2486 module_t
*bitcoin_module
;
2487 expert_module_t
* expert_bitcoin
;
2489 proto_bitcoin
= proto_register_protocol("Bitcoin protocol", "Bitcoin", "bitcoin");
2491 proto_register_subtree_array(ett
, array_length(ett
));
2492 proto_register_field_array(proto_bitcoin
, hf
, array_length(hf
));
2494 expert_bitcoin
= expert_register_protocol(proto_bitcoin
);
2495 expert_register_field_array(expert_bitcoin
, ei
, array_length(ei
));
2497 bitcoin_command_table
= register_dissector_table("bitcoin.command", "Bitcoin Command", proto_bitcoin
, FT_STRING
, STRING_CASE_SENSITIVE
);
2499 bitcoin_handle
= register_dissector("bitcoin", dissect_bitcoin
, proto_bitcoin
);
2501 bitcoin_module
= prefs_register_protocol(proto_bitcoin
, NULL
);
2502 prefs_register_bool_preference(bitcoin_module
, "desegment",
2503 "Desegment all Bitcoin messages spanning multiple TCP segments",
2504 "Whether the Bitcoin dissector should desegment all messages"
2505 " spanning multiple TCP segments",
2506 &bitcoin_desegment
);
2511 proto_reg_handoff_bitcoin(void)
2513 dissector_handle_t command_handle
;
2515 dissector_add_for_decode_as_with_preference("tcp.port", bitcoin_handle
);
2517 heur_dissector_add( "tcp", dissect_bitcoin_heur
, "Bitcoin over TCP", "bitcoin_tcp", proto_bitcoin
, HEURISTIC_ENABLE
);
2519 /* Register all of the commands */
2520 command_handle
= create_dissector_handle( dissect_bitcoin_msg_version
, proto_bitcoin
);
2521 dissector_add_string("bitcoin.command", "version", command_handle
);
2522 command_handle
= create_dissector_handle( dissect_bitcoin_msg_addr
, proto_bitcoin
);
2523 dissector_add_string("bitcoin.command", "addr", command_handle
);
2524 command_handle
= create_dissector_handle( dissect_bitcoin_msg_addrv2
, proto_bitcoin
);
2525 dissector_add_string("bitcoin.command", "addrv2", command_handle
);
2526 command_handle
= create_dissector_handle( dissect_bitcoin_msg_inv
, proto_bitcoin
);
2527 dissector_add_string("bitcoin.command", "inv", command_handle
);
2528 command_handle
= create_dissector_handle( dissect_bitcoin_msg_getdata
, proto_bitcoin
);
2529 dissector_add_string("bitcoin.command", "getdata", command_handle
);
2530 command_handle
= create_dissector_handle( dissect_bitcoin_msg_getblocks
, proto_bitcoin
);
2531 dissector_add_string("bitcoin.command", "getblocks", command_handle
);
2532 command_handle
= create_dissector_handle( dissect_bitcoin_msg_getheaders
, proto_bitcoin
);
2533 dissector_add_string("bitcoin.command", "getheaders", command_handle
);
2534 command_handle
= create_dissector_handle( dissect_bitcoin_msg_tx
, proto_bitcoin
);
2535 dissector_add_string("bitcoin.command", "tx", command_handle
);
2536 command_handle
= create_dissector_handle( dissect_bitcoin_msg_block
, proto_bitcoin
);
2537 dissector_add_string("bitcoin.command", "block", command_handle
);
2538 command_handle
= create_dissector_handle( dissect_bitcoin_msg_ping
, proto_bitcoin
);
2539 dissector_add_string("bitcoin.command", "ping", command_handle
);
2540 command_handle
= create_dissector_handle( dissect_bitcoin_msg_pong
, proto_bitcoin
);
2541 dissector_add_string("bitcoin.command", "pong", command_handle
);
2542 command_handle
= create_dissector_handle( dissect_bitcoin_msg_notfound
, proto_bitcoin
);
2543 dissector_add_string("bitcoin.command", "notfound", command_handle
);
2544 command_handle
= create_dissector_handle( dissect_bitcoin_msg_reject
, proto_bitcoin
);
2545 dissector_add_string("bitcoin.command", "reject", command_handle
);
2546 command_handle
= create_dissector_handle( dissect_bitcoin_msg_headers
, proto_bitcoin
);
2547 dissector_add_string("bitcoin.command", "headers", command_handle
);
2548 command_handle
= create_dissector_handle( dissect_bitcoin_msg_feefilter
, proto_bitcoin
);
2549 dissector_add_string("bitcoin.command", "feefilter", command_handle
);
2550 command_handle
= create_dissector_handle( dissect_bitcoin_msg_filterload
, proto_bitcoin
);
2551 dissector_add_string("bitcoin.command", "filterload", command_handle
);
2552 command_handle
= create_dissector_handle( dissect_bitcoin_msg_filteradd
, proto_bitcoin
);
2553 dissector_add_string("bitcoin.command", "filteradd", command_handle
);
2554 command_handle
= create_dissector_handle( dissect_bitcoin_msg_merkleblock
, proto_bitcoin
);
2555 dissector_add_string("bitcoin.command", "merkleblock", command_handle
);
2556 command_handle
= create_dissector_handle( dissect_bitcoin_msg_sendcmpct
, proto_bitcoin
);
2557 dissector_add_string("bitcoin.command", "sendcmpct", command_handle
);
2559 /* messages with no payload */
2560 command_handle
= create_dissector_handle( dissect_bitcoin_msg_empty
, proto_bitcoin
);
2561 dissector_add_string("bitcoin.command", "verack", command_handle
);
2562 dissector_add_string("bitcoin.command", "getaddr", command_handle
);
2563 dissector_add_string("bitcoin.command", "mempool", command_handle
);
2564 dissector_add_string("bitcoin.command", "filterclear", command_handle
);
2565 dissector_add_string("bitcoin.command", "sendaddrv2", command_handle
);
2566 dissector_add_string("bitcoin.command", "sendheaders", command_handle
);
2567 dissector_add_string("bitcoin.command", "wtxidrelay", command_handle
);
2569 /* messages not implemented */
2570 /* command_handle = create_dissector_handle( dissect_bitcoin_msg_empty, proto_bitcoin ); */
2571 dissector_add_string("bitcoin.command", "checkorder", command_handle
);
2572 dissector_add_string("bitcoin.command", "submitorder", command_handle
);
2573 dissector_add_string("bitcoin.command", "reply", command_handle
);
2574 dissector_add_string("bitcoin.command", "alert", command_handle
);
2578 * Editor modelines - https://www.wireshark.org/tools/modelines.html
2583 * indent-tabs-mode: nil
2586 * vi: set shiftwidth=2 tabstop=8 expandtab:
2587 * :indentSize=2:tabSize=8:noTabs=true: