2004-12-01 12:41:43 +00:00
|
|
|
/* packet-bittorrent.c
|
|
|
|
* Routines for bittorrent packet dissection
|
|
|
|
* Copyright (C) 2004 Jelmer Vernooij <jelmer@samba.org>
|
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2004-12-01 12:41:43 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Copied from packet-pop.c
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-12-01 12:41:43 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2004-12-01 12:41:43 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include <epan/conversation.h>
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/strutil.h>
|
|
|
|
|
|
|
|
#include "packet-tcp.h"
|
|
|
|
|
2013-12-14 12:45:57 +00:00
|
|
|
void proto_register_bittorrent(void);
|
|
|
|
void proto_reg_handoff_bittorrent(void);
|
|
|
|
|
2004-12-03 20:51:10 +00:00
|
|
|
/*
|
|
|
|
* See
|
|
|
|
*
|
2005-08-16 05:58:50 +00:00
|
|
|
* http://bittorrent.com/protocol.html
|
|
|
|
* http://wiki.theory.org/BitTorrentSpecification
|
|
|
|
* http://bitconjurer.org/BitTorrent/protocol.html
|
2004-12-03 20:51:10 +00:00
|
|
|
*/
|
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
#define BITTORRENT_MESSAGE_CHOKE 0
|
|
|
|
#define BITTORRENT_MESSAGE_UNCHOKE 1
|
|
|
|
#define BITTORRENT_MESSAGE_INTERESTED 2
|
|
|
|
#define BITTORRENT_MESSAGE_NOT_INTERESTED 3
|
|
|
|
#define BITTORRENT_MESSAGE_HAVE 4
|
|
|
|
#define BITTORRENT_MESSAGE_BITFIELD 5
|
|
|
|
#define BITTORRENT_MESSAGE_REQUEST 6
|
|
|
|
#define BITTORRENT_MESSAGE_PIECE 7
|
|
|
|
#define BITTORRENT_MESSAGE_CANCEL 8
|
|
|
|
#define BITTORRENT_MESSAGE_PORT 9
|
|
|
|
#define BITTORRENT_MESSAGE_EXTENDED 20
|
|
|
|
|
|
|
|
#define BITTORRENT_HEADER_LENGTH 4
|
2004-12-01 12:41:43 +00:00
|
|
|
|
2007-08-15 22:27:52 +00:00
|
|
|
/*
|
2005-12-19 06:48:07 +00:00
|
|
|
* Azureus messages are specified by name so these are made up numbers
|
|
|
|
* for internal identification only.
|
|
|
|
*
|
2007-08-15 22:27:52 +00:00
|
|
|
* Standard BT message types are a single byte, so these won't clash
|
2005-12-19 06:48:07 +00:00
|
|
|
*/
|
|
|
|
#define AZUREUS_MESSAGE_HANDSHAKE 256
|
|
|
|
#define AZUREUS_MESSAGE_KEEP_ALIVE 257
|
|
|
|
#define AZUREUS_MESSAGE_BT_HANDSHAKE 258
|
|
|
|
#define AZUREUS_MESSAGE_PEER_EXCHANGE 259
|
|
|
|
#define AZUREUS_MESSAGE_JPC_HELLO 260
|
|
|
|
#define AZUREUS_MESSAGE_JPC_REPLY 261
|
|
|
|
|
|
|
|
|
2004-12-01 12:41:43 +00:00
|
|
|
static const value_string bittorrent_messages[] = {
|
2012-03-21 18:20:44 +00:00
|
|
|
{ BITTORRENT_MESSAGE_CHOKE, "Choke" },
|
|
|
|
{ BITTORRENT_MESSAGE_UNCHOKE, "Unchoke" },
|
|
|
|
{ BITTORRENT_MESSAGE_INTERESTED, "Interested" },
|
2005-08-16 05:58:50 +00:00
|
|
|
{ BITTORRENT_MESSAGE_NOT_INTERESTED, "Not Interested" },
|
2012-03-21 18:20:44 +00:00
|
|
|
{ BITTORRENT_MESSAGE_HAVE, "Have" },
|
|
|
|
{ BITTORRENT_MESSAGE_BITFIELD, "Bitfield" },
|
|
|
|
{ BITTORRENT_MESSAGE_REQUEST, "Request" },
|
|
|
|
{ BITTORRENT_MESSAGE_PIECE, "Piece" },
|
|
|
|
{ BITTORRENT_MESSAGE_CANCEL, "Cancel" },
|
|
|
|
{ BITTORRENT_MESSAGE_PORT, "Port" },
|
|
|
|
{ BITTORRENT_MESSAGE_EXTENDED, "Extended" },
|
|
|
|
{ AZUREUS_MESSAGE_KEEP_ALIVE, "Keepalive" },
|
|
|
|
{ AZUREUS_MESSAGE_HANDSHAKE, "Azureus Handshake" },
|
|
|
|
{ AZUREUS_MESSAGE_BT_HANDSHAKE, "Azureus BitTorrent Handshake" },
|
|
|
|
{ AZUREUS_MESSAGE_PEER_EXCHANGE, "Azureus Peer Exchange" },
|
|
|
|
{ AZUREUS_MESSAGE_JPC_HELLO, "Azureus PeerCache Hello" },
|
|
|
|
{ AZUREUS_MESSAGE_JPC_REPLY, "Azureus PeerCache Reply" },
|
2005-08-16 05:58:50 +00:00
|
|
|
{ 0, NULL }
|
2004-12-01 12:41:43 +00:00
|
|
|
};
|
|
|
|
|
2005-12-19 06:48:07 +00:00
|
|
|
static const value_string azureus_priorities[] = {
|
2010-05-11 16:54:55 +00:00
|
|
|
{ 0, "Low" },
|
|
|
|
{ 1, "Normal" },
|
|
|
|
{ 2, "High" },
|
|
|
|
{ 0, NULL }
|
2005-12-19 06:48:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct amp_message {
|
2010-05-11 16:54:55 +00:00
|
|
|
const char *name;
|
2012-03-21 18:20:44 +00:00
|
|
|
guint32 value;
|
2005-12-19 06:48:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct amp_message amp_messages[] = {
|
2012-03-21 18:20:44 +00:00
|
|
|
{ "BT_KEEP_ALIVE", AZUREUS_MESSAGE_KEEP_ALIVE },
|
|
|
|
{ "BT_CHOKE", BITTORRENT_MESSAGE_CHOKE },
|
|
|
|
{ "BT_UNCHOKE", BITTORRENT_MESSAGE_UNCHOKE },
|
|
|
|
{ "BT_INTERESTED", BITTORRENT_MESSAGE_INTERESTED },
|
|
|
|
{ "BT_UNINTERESTED", BITTORRENT_MESSAGE_NOT_INTERESTED },
|
|
|
|
{ "BT_HAVE", BITTORRENT_MESSAGE_HAVE },
|
|
|
|
{ "BT_BITFIELD", BITTORRENT_MESSAGE_BITFIELD },
|
|
|
|
{ "BT_REQUEST", BITTORRENT_MESSAGE_REQUEST },
|
|
|
|
{ "BT_PIECE", BITTORRENT_MESSAGE_PIECE },
|
|
|
|
{ "BT_CANCEL", BITTORRENT_MESSAGE_CANCEL },
|
|
|
|
{ "BT_PORT", BITTORRENT_MESSAGE_PORT },
|
|
|
|
{ "BT_EXTENDED", BITTORRENT_MESSAGE_EXTENDED },
|
|
|
|
{ "AZ_HANDSHAKE", AZUREUS_MESSAGE_HANDSHAKE },
|
|
|
|
{ "BT_HANDSHAKE", AZUREUS_MESSAGE_BT_HANDSHAKE },
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "AZ_PEER_EXCHANGE", AZUREUS_MESSAGE_PEER_EXCHANGE },
|
2012-03-21 18:20:44 +00:00
|
|
|
{ "JPC_HELLO", AZUREUS_MESSAGE_JPC_HELLO },
|
|
|
|
{ "JPC_REPLY", AZUREUS_MESSAGE_JPC_REPLY },
|
2010-05-11 16:54:55 +00:00
|
|
|
{ NULL, 0 }
|
2005-12-19 06:48:07 +00:00
|
|
|
};
|
|
|
|
|
2005-08-16 05:58:50 +00:00
|
|
|
static dissector_handle_t dissector_handle;
|
2014-02-03 00:36:50 +00:00
|
|
|
static dissector_handle_t bencode_handle;
|
2004-12-01 12:41:43 +00:00
|
|
|
static int proto_bittorrent = -1;
|
|
|
|
|
2013-01-31 17:55:31 +00:00
|
|
|
/* static gint hf_bittorrent_field_length = -1; */
|
2004-12-01 12:41:43 +00:00
|
|
|
static gint hf_bittorrent_prot_name_len = -1;
|
|
|
|
static gint hf_bittorrent_prot_name = -1;
|
2005-08-16 05:58:50 +00:00
|
|
|
static gint hf_bittorrent_reserved = -1;
|
|
|
|
static gint hf_bittorrent_sha1_hash = -1;
|
|
|
|
static gint hf_bittorrent_peer_id = -1;
|
2005-10-02 15:41:11 +00:00
|
|
|
static gint hf_bittorrent_msg = -1;
|
2005-08-16 05:58:50 +00:00
|
|
|
static gint hf_bittorrent_msg_len = -1;
|
|
|
|
static gint hf_bittorrent_msg_type = -1;
|
2005-12-19 06:48:07 +00:00
|
|
|
static gint hf_azureus_msg = -1;
|
|
|
|
static gint hf_azureus_msg_type_len = -1;
|
|
|
|
static gint hf_azureus_msg_type = -1;
|
|
|
|
static gint hf_azureus_msg_prio = -1;
|
2005-08-16 05:58:50 +00:00
|
|
|
static gint hf_bittorrent_bitfield_data = -1;
|
|
|
|
static gint hf_bittorrent_piece_index = -1;
|
|
|
|
static gint hf_bittorrent_piece_begin = -1;
|
|
|
|
static gint hf_bittorrent_piece_length = -1;
|
|
|
|
static gint hf_bittorrent_piece_data = -1;
|
2005-12-19 06:48:07 +00:00
|
|
|
static gint hf_azureus_jpc_addrlen = -1;
|
|
|
|
static gint hf_azureus_jpc_addr = -1;
|
|
|
|
static gint hf_azureus_jpc_port = -1;
|
|
|
|
static gint hf_azureus_jpc_session = -1;
|
2011-04-19 21:31:02 +00:00
|
|
|
static gint hf_bittorrent_port = -1;
|
|
|
|
static gint hf_bittorrent_extended = -1;
|
2004-12-01 12:41:43 +00:00
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
static gint ett_bittorrent = -1;
|
|
|
|
static gint ett_bittorrent_msg = -1;
|
|
|
|
static gint ett_peer_id = -1;
|
2004-12-01 12:41:43 +00:00
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
static gboolean bittorrent_desegment = TRUE;
|
2005-08-16 05:58:50 +00:00
|
|
|
static gboolean decode_client_information = FALSE;
|
|
|
|
|
|
|
|
struct client_information {
|
2012-03-21 18:20:44 +00:00
|
|
|
char id[5]; /* string length must be <= 4 to allow space for NUL termination byte */
|
|
|
|
char ver_len;
|
|
|
|
const char *name; /* NULL means array entry terminates the array */
|
2005-08-16 05:58:50 +00:00
|
|
|
};
|
2004-12-01 12:41:43 +00:00
|
|
|
|
2005-08-16 05:58:50 +00:00
|
|
|
static struct client_information peer_id[] = {
|
2009-11-16 22:53:11 +00:00
|
|
|
{"-AG", 4, "Ares"},
|
|
|
|
{"-A~", 4, "Ares"},
|
|
|
|
{"-AR", 4, "Arctic"},
|
|
|
|
{"-AT", 4, "Artemis"},
|
|
|
|
{"-AV", 4, "Avicora"},
|
|
|
|
{"-AX", 4, "BitPump"},
|
|
|
|
{"-AZ", 4, "Azureus"},
|
|
|
|
{"-BB", 4, "BitBuddy"},
|
|
|
|
{"-BC", 4, "BitComet"},
|
|
|
|
{"-BF", 4, "Bitflu"},
|
|
|
|
{"-BG", 4, "BTG (uses Rasterbar libtorrent)"},
|
|
|
|
{"-BOW", 3, "Bits on Wheels"},
|
|
|
|
{"-BP", 4, "BitTorrent Pro (Azereus + spyware)"},
|
|
|
|
{"-BR", 4, "BitRocket"},
|
|
|
|
{"-BS", 4, "BTSlave"},
|
|
|
|
{"-BW", 4, "BitWombat"},
|
|
|
|
{"-BX", 4, "Bittorrent X"},
|
|
|
|
{"-CD", 4, "Enhanced CTorrent"},
|
|
|
|
{"-CT", 4, "CTorrent"},
|
|
|
|
{"-DE", 4, "DelugeTorrent"},
|
|
|
|
{"-DP", 4, "Propagate Data Client"},
|
|
|
|
{"-EB", 4, "EBit"},
|
|
|
|
{"-ES", 4, "electric sheep"},
|
|
|
|
{"-FC", 4, "FileCroc"},
|
|
|
|
{"-FG", 4, "FlashGet"},
|
|
|
|
{"-FT", 4, "FoxTorrent"},
|
|
|
|
{"-GS", 4, "GSTorrent"},
|
|
|
|
{"-HK", 4, "Hekate"},
|
|
|
|
{"-HL", 4, "Halite"},
|
|
|
|
{"-HN", 4, "Hydranode"},
|
|
|
|
{"-KG", 4, "KGet"},
|
|
|
|
{"-KT", 4, "KTorrent"},
|
|
|
|
{"-LC", 4, "LeechCraft"},
|
|
|
|
{"-LH", 4, "LH-ABC"},
|
|
|
|
{"-LP", 4, "Lphant"},
|
|
|
|
{"-LT", 4, "libtorrent"},
|
|
|
|
{"-lt", 4, "libTorrent"},
|
|
|
|
{"-LW", 4, "LimeWire"},
|
|
|
|
{"-MO", 4, "MonoTorrent"},
|
|
|
|
{"-MP", 4, "MooPolice"},
|
|
|
|
{"-MR", 4, "Miro"},
|
|
|
|
{"-MT", 4, "MoonlightTorrent"},
|
|
|
|
{"-NE", 4, "BT Next Evolution"},
|
|
|
|
{"-NX", 4, "Net Transport"},
|
|
|
|
{"-OS", 4, "OneSwarm"},
|
|
|
|
{"-OT", 4, "OmegaTorrent"},
|
|
|
|
{"-PD", 4, "Pando"},
|
|
|
|
{"-qB", 4, "qBittorrent"},
|
|
|
|
{"-QD", 4, "QQDownload"},
|
|
|
|
{"-QT", 4, "Qt 4 Torrent example"},
|
|
|
|
{"-RT", 4, "Retriever"},
|
|
|
|
{"-S~", 4, "Shareaza alpha/beta"},
|
|
|
|
{"-SB", 4, "Swiftbit"},
|
|
|
|
{"-SD", 4, "Thunder (aka XunLei)"},
|
|
|
|
{"-SS", 4, "SwarmScope"},
|
|
|
|
{"-ST", 4, "SymTorrent"},
|
|
|
|
{"-st", 4, "sharktorrent"},
|
|
|
|
{"-SZ", 4, "Shareaza"},
|
|
|
|
{"-TN", 4, "TorrentDotNET"},
|
|
|
|
{"-TR", 4, "Transmission"},
|
|
|
|
{"-TS", 4, "Torrentstorm"},
|
|
|
|
{"-TT", 4, "TuoTu"},
|
|
|
|
{"-UL", 4, "uLeecher!"},
|
|
|
|
{"-UM", 4, "(my)Torrent for Mac"},
|
|
|
|
{"-UT", 4, "(my)Torrent"},
|
|
|
|
{"-VG", 4, "Vagaa"},
|
|
|
|
{"-WT", 4, "BitLet"},
|
|
|
|
{"-WY", 4, "FireTorrent"},
|
|
|
|
{"-XL", 4, "Xunlei"},
|
|
|
|
{"-XT", 4, "XanTorrent"},
|
|
|
|
{"-XX", 4, "Xtorrent"},
|
|
|
|
{"-ZT", 4, "ZipTorrent"},
|
|
|
|
{"exbc", 2, "BitComet"},
|
|
|
|
{"OP", 4, "Opera"},
|
|
|
|
{"QVOD", 4, "Qvod"},
|
|
|
|
{"XBT", 3, "XBT Client"},
|
|
|
|
{"A", 3, "ABC"},
|
|
|
|
{"O", 3, "Osprey Permaseed"},
|
|
|
|
{"Q", 3, "BTQueue"},
|
|
|
|
{"R", 3, "Tribler"},
|
|
|
|
{"S", 3, "Shadow's client"},
|
|
|
|
{"T", 3, "BitTornado"},
|
|
|
|
{"U", 3, "UPnP NAT Bit Torrent"},
|
|
|
|
{"", 0, NULL}
|
2005-08-16 05:58:50 +00:00
|
|
|
};
|
2005-07-09 00:44:44 +00:00
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
static guint
|
|
|
|
get_bittorrent_pdu_length(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
|
2004-12-01 12:41:43 +00:00
|
|
|
{
|
2012-03-21 18:20:44 +00:00
|
|
|
guint8 type;
|
2005-08-16 05:58:50 +00:00
|
|
|
guint32 length;
|
|
|
|
|
|
|
|
if (tvb_get_guint8(tvb, offset) == 19 &&
|
2007-03-28 21:55:11 +00:00
|
|
|
tvb_memeql(tvb, offset + 1, "BitTorrent protocol", 19) == 0) {
|
2005-08-16 05:58:50 +00:00
|
|
|
/* Return the length of a Handshake message */
|
2012-03-21 18:20:44 +00:00
|
|
|
return 1 + /* pstrlen */
|
|
|
|
19 + /* pstr */
|
|
|
|
8 + /* reserved */
|
|
|
|
20 + /* SHA1 hash of the info key */
|
|
|
|
20; /* peer id */
|
2005-08-16 05:58:50 +00:00
|
|
|
} else {
|
|
|
|
/* Try to validate the length of the message indicated by the header. */
|
|
|
|
length = tvb_get_ntohl(tvb, offset);
|
|
|
|
if(length == 0) {
|
|
|
|
/* keep-alive - no message ID */
|
|
|
|
return BITTORRENT_HEADER_LENGTH;
|
|
|
|
}
|
|
|
|
/* Do some sanity checking of the message, if we have the ID byte */
|
|
|
|
if(tvb_offset_exists(tvb, offset + BITTORRENT_HEADER_LENGTH)) {
|
|
|
|
type = tvb_get_guint8(tvb, offset + BITTORRENT_HEADER_LENGTH);
|
2011-04-19 21:31:02 +00:00
|
|
|
if((type <= BITTORRENT_MESSAGE_PORT || type == BITTORRENT_MESSAGE_EXTENDED) && length<0x1000000) {
|
2005-08-16 05:58:50 +00:00
|
|
|
/* This seems to be a valid BitTorrent header with a known
|
|
|
|
type identifier */
|
|
|
|
return BITTORRENT_HEADER_LENGTH + length;
|
|
|
|
} else {
|
2005-08-18 01:17:46 +00:00
|
|
|
/* The type is not known, so this message cannot be decoded
|
|
|
|
properly by this dissector. We assume it's continuation
|
|
|
|
data from the middle of a message, and just return the
|
2005-08-18 07:09:43 +00:00
|
|
|
remaining length in the tvbuff so the rest of the tvbuff
|
|
|
|
is displayed as continuation data. */
|
|
|
|
return tvb_length_remaining(tvb, offset);
|
2005-08-16 05:58:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-08-18 01:17:46 +00:00
|
|
|
/* We don't have the type field, so we can't determine
|
|
|
|
whether this is a valid message. For now, we assume
|
|
|
|
it's continuation data from the middle of a message,
|
2005-08-18 07:09:43 +00:00
|
|
|
and just return the remaining length in the tvbuff so
|
|
|
|
the rest of the tvbuff is displayed as continuation
|
|
|
|
data. */
|
|
|
|
return tvb_length_remaining(tvb, offset);
|
2005-08-16 05:58:50 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-01 12:41:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
static void
|
|
|
|
dissect_bittorrent_message (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
2004-12-01 12:41:43 +00:00
|
|
|
{
|
2012-03-21 18:20:44 +00:00
|
|
|
int offset = 0;
|
|
|
|
int i;
|
|
|
|
int isamp = 0;
|
2005-08-16 05:58:50 +00:00
|
|
|
proto_tree *mtree;
|
2012-03-21 18:20:44 +00:00
|
|
|
guint16 type = 0;
|
|
|
|
guint32 typelen = 0;
|
|
|
|
guint8 prio = 0;
|
|
|
|
guint32 length;
|
2005-08-18 01:17:46 +00:00
|
|
|
const char *msgtype = NULL;
|
2005-08-16 05:58:50 +00:00
|
|
|
proto_item *ti;
|
2012-03-21 18:20:44 +00:00
|
|
|
guint32 piece_index, piece_begin, piece_length;
|
|
|
|
guint32 stringlen;
|
2014-02-03 00:36:50 +00:00
|
|
|
tvbuff_t *subtvb;
|
2005-08-16 05:58:50 +00:00
|
|
|
|
2005-08-18 01:17:46 +00:00
|
|
|
if (tvb_bytes_exist(tvb, offset + BITTORRENT_HEADER_LENGTH, 1)) {
|
|
|
|
/* Check for data from the middle of a message. */
|
2005-12-19 06:48:07 +00:00
|
|
|
length = tvb_get_ntohl(tvb, offset);
|
2005-08-18 01:17:46 +00:00
|
|
|
type = tvb_get_guint8(tvb, offset + BITTORRENT_HEADER_LENGTH);
|
2005-12-19 06:48:07 +00:00
|
|
|
|
|
|
|
if (type==BITTORRENT_MESSAGE_CHOKE && length>4) {
|
2010-05-11 16:54:55 +00:00
|
|
|
/*
|
|
|
|
* Choke messages have no payload, so this is likely an Azureus
|
|
|
|
* Messaging Protocol packet
|
|
|
|
*/
|
|
|
|
if (!tvb_bytes_exist(tvb, offset + BITTORRENT_HEADER_LENGTH, 4))
|
|
|
|
return;
|
|
|
|
|
|
|
|
typelen = tvb_get_ntohl(tvb, offset + BITTORRENT_HEADER_LENGTH);
|
|
|
|
if (4+typelen+1<=length) {
|
|
|
|
if (!tvb_bytes_exist(tvb, offset + BITTORRENT_HEADER_LENGTH + 4, typelen+1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for ( i=0 ; amp_messages[i].name ; i++ ) {
|
|
|
|
if (strlen(amp_messages[i].name)==typelen &&
|
|
|
|
tvb_memeql(tvb, offset + BITTORRENT_HEADER_LENGTH + 4,
|
|
|
|
amp_messages[i].name, (int)strlen(amp_messages[i].name))==0) {
|
|
|
|
|
|
|
|
prio = tvb_get_guint8(tvb, offset + BITTORRENT_HEADER_LENGTH + 4 + typelen);
|
|
|
|
if (prio==0 || prio==1 || prio==2) {
|
|
|
|
type = amp_messages[i].value;
|
|
|
|
isamp = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-19 06:48:07 +00:00
|
|
|
}
|
|
|
|
|
2013-03-29 00:26:23 +00:00
|
|
|
msgtype = try_val_to_str(type, bittorrent_messages);
|
2010-05-11 16:54:55 +00:00
|
|
|
#if 0
|
|
|
|
if (msgtype == NULL && isamp) {
|
2013-03-29 00:26:23 +00:00
|
|
|
msgtype = try_val_to_str(type, azureus_messages);
|
2010-05-11 16:54:55 +00:00
|
|
|
}
|
|
|
|
#endif
|
2005-08-18 01:17:46 +00:00
|
|
|
if (msgtype == NULL) {
|
2007-08-15 22:27:52 +00:00
|
|
|
proto_tree_add_text(tree, tvb, offset, -1, "Continuation data");
|
2009-08-09 07:59:51 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "Continuation data");
|
2005-08-18 01:17:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-10-05 06:37:35 +00:00
|
|
|
} else {
|
2010-05-11 16:54:55 +00:00
|
|
|
/* not enough bytes of the header, stop here */
|
|
|
|
return;
|
2005-08-18 01:17:46 +00:00
|
|
|
}
|
|
|
|
|
2005-12-19 06:48:07 +00:00
|
|
|
if (isamp) {
|
2011-10-04 22:44:31 +00:00
|
|
|
ti = proto_tree_add_item(tree, hf_azureus_msg, tvb, offset, length + BITTORRENT_HEADER_LENGTH, ENC_NA);
|
2005-12-19 06:48:07 +00:00
|
|
|
} else {
|
2011-10-04 22:44:31 +00:00
|
|
|
ti = proto_tree_add_item(tree, hf_bittorrent_msg, tvb, offset, length + BITTORRENT_HEADER_LENGTH, ENC_NA);
|
2005-12-19 06:48:07 +00:00
|
|
|
}
|
2005-08-16 05:58:50 +00:00
|
|
|
mtree = proto_item_add_subtree(ti, ett_bittorrent_msg);
|
|
|
|
|
|
|
|
/* Keepalive message */
|
|
|
|
if (length == 0) {
|
2011-09-26 08:25:18 +00:00
|
|
|
proto_tree_add_item(mtree, hf_bittorrent_msg_len, tvb, offset, BITTORRENT_HEADER_LENGTH, ENC_BIG_ENDIAN);
|
2009-08-09 07:59:51 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "KeepAlive");
|
2005-08-16 05:58:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-08-18 01:17:46 +00:00
|
|
|
|
2011-09-26 08:25:18 +00:00
|
|
|
proto_tree_add_item(mtree, hf_bittorrent_msg_len, tvb, offset, BITTORRENT_HEADER_LENGTH, ENC_BIG_ENDIAN);
|
2005-08-18 01:17:46 +00:00
|
|
|
offset += BITTORRENT_HEADER_LENGTH;
|
|
|
|
|
|
|
|
/* If the tvb_bytes_exist() call above returned FALSE, this will
|
|
|
|
throw an exception, so we won't use msgtype or type. */
|
2005-12-19 06:48:07 +00:00
|
|
|
if (isamp) {
|
2011-09-26 08:25:18 +00:00
|
|
|
proto_tree_add_item(mtree, hf_azureus_msg_type_len, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item(mtree, hf_azureus_msg_type, tvb, offset+4, typelen, ENC_ASCII|ENC_NA);
|
2010-05-11 16:54:55 +00:00
|
|
|
proto_item_append_text(ti, ": Len %u, %s", length, msgtype);
|
2011-09-26 08:25:18 +00:00
|
|
|
proto_tree_add_item(mtree, hf_azureus_msg_prio, tvb, offset+4+typelen, 1, ENC_BIG_ENDIAN);
|
2010-05-11 16:54:55 +00:00
|
|
|
offset += 4+typelen+1;
|
|
|
|
length -= 4+typelen+1;
|
2005-12-19 06:48:07 +00:00
|
|
|
} else {
|
2011-09-26 08:25:18 +00:00
|
|
|
proto_tree_add_item(mtree, hf_bittorrent_msg_type, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2010-05-11 16:54:55 +00:00
|
|
|
proto_item_append_text(ti, ": Len:%u, %s", length, msgtype);
|
|
|
|
offset += 1;
|
|
|
|
length -= 1;
|
2005-12-19 06:48:07 +00:00
|
|
|
}
|
2010-01-13 20:32:01 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, msgtype);
|
2005-08-16 05:58:50 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case BITTORRENT_MESSAGE_CHOKE:
|
|
|
|
case BITTORRENT_MESSAGE_UNCHOKE:
|
|
|
|
case BITTORRENT_MESSAGE_INTERESTED:
|
|
|
|
case BITTORRENT_MESSAGE_NOT_INTERESTED:
|
|
|
|
/* No payload */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BITTORRENT_MESSAGE_REQUEST:
|
|
|
|
case BITTORRENT_MESSAGE_CANCEL:
|
2010-05-11 16:54:55 +00:00
|
|
|
piece_index = tvb_get_ntohl(tvb, offset);
|
2005-10-02 15:41:11 +00:00
|
|
|
proto_tree_add_uint(mtree, hf_bittorrent_piece_index, tvb, offset, 4, piece_index); offset += 4;
|
2010-05-11 16:54:55 +00:00
|
|
|
piece_begin = tvb_get_ntohl(tvb, offset);
|
2005-10-02 15:41:11 +00:00
|
|
|
proto_tree_add_uint(mtree, hf_bittorrent_piece_begin, tvb, offset, 4, piece_begin); offset += 4;
|
2010-05-11 16:54:55 +00:00
|
|
|
piece_length = tvb_get_ntohl(tvb, offset);
|
2005-10-02 15:41:11 +00:00
|
|
|
proto_tree_add_uint(mtree, hf_bittorrent_piece_length, tvb, offset, 4, piece_length);
|
|
|
|
proto_item_append_text(ti, ", Piece (Idx:0x%x,Begin:0x%x,Len:0x%x)", piece_index, piece_begin, piece_length);
|
2011-09-26 08:25:18 +00:00
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", Piece (Idx:0x%x,Begin:0x%x,Len:0x%x)", piece_index, piece_begin, piece_length);
|
2011-09-26 08:25:18 +00:00
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
break;
|
2005-08-16 05:58:50 +00:00
|
|
|
|
2011-04-19 21:31:02 +00:00
|
|
|
case BITTORRENT_MESSAGE_PORT:
|
|
|
|
/* port as payload */
|
2012-07-18 22:59:54 +00:00
|
|
|
proto_tree_add_item(mtree, hf_bittorrent_port, tvb, offset, 2, ENC_BIG_ENDIAN);
|
2011-04-19 21:31:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BITTORRENT_MESSAGE_EXTENDED:
|
|
|
|
/* extended message content */
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(mtree, hf_bittorrent_extended, tvb, offset, length, ENC_NA);
|
2011-04-19 21:31:02 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-16 05:58:50 +00:00
|
|
|
case BITTORRENT_MESSAGE_HAVE:
|
2010-05-11 16:54:55 +00:00
|
|
|
piece_index = tvb_get_ntohl(tvb, offset);
|
2011-09-26 08:25:18 +00:00
|
|
|
proto_tree_add_item(mtree, hf_bittorrent_piece_index, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2005-10-02 15:41:11 +00:00
|
|
|
proto_item_append_text(ti, ", Piece (Idx:0x%x)", piece_index);
|
2011-09-26 08:25:18 +00:00
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", Piece (Idx:0x%x)", piece_index);
|
2011-09-26 08:25:18 +00:00
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
break;
|
2005-08-16 05:58:50 +00:00
|
|
|
|
|
|
|
case BITTORRENT_MESSAGE_BITFIELD:
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(mtree, hf_bittorrent_bitfield_data, tvb, offset, length, ENC_NA);
|
2005-10-02 15:41:11 +00:00
|
|
|
proto_item_append_text(ti, ", Len:0x%x", length);
|
2011-09-26 08:25:18 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", Len:0x%x", length);
|
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
break;
|
2005-08-16 05:58:50 +00:00
|
|
|
|
|
|
|
case BITTORRENT_MESSAGE_PIECE:
|
2010-05-11 16:54:55 +00:00
|
|
|
piece_index = tvb_get_ntohl(tvb, offset);
|
2005-10-02 15:41:11 +00:00
|
|
|
proto_tree_add_uint(mtree, hf_bittorrent_piece_index, tvb, offset, 4, piece_index);
|
2005-08-16 05:58:50 +00:00
|
|
|
offset += 4;
|
|
|
|
length -= 4;
|
2010-05-11 16:54:55 +00:00
|
|
|
piece_begin = tvb_get_ntohl(tvb, offset);
|
2011-10-11 15:11:51 +00:00
|
|
|
proto_tree_add_uint(mtree, hf_bittorrent_piece_begin, tvb, offset, 4, piece_begin);
|
2005-08-16 05:58:50 +00:00
|
|
|
offset += 4;
|
|
|
|
length -= 4;
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(mtree, hf_bittorrent_piece_data, tvb, offset, length, ENC_NA);
|
2005-10-02 15:41:11 +00:00
|
|
|
proto_item_append_text(ti, ", Idx:0x%x,Begin:0x%x,Len:0x%x", piece_index, piece_begin, length);
|
2011-09-26 08:25:18 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", Idx:0x%x,Begin:0x%x,Len:0x%x", piece_index, piece_begin, length);
|
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
break;
|
2005-08-16 05:58:50 +00:00
|
|
|
|
2005-12-19 06:48:07 +00:00
|
|
|
case AZUREUS_MESSAGE_HANDSHAKE:
|
|
|
|
case AZUREUS_MESSAGE_PEER_EXCHANGE:
|
2014-02-03 00:36:50 +00:00
|
|
|
subtvb = tvb_new_subset(tvb, offset, length, length);
|
|
|
|
call_dissector(bencode_handle, subtvb, pinfo, mtree);
|
2010-05-11 16:54:55 +00:00
|
|
|
break;
|
2005-12-19 06:48:07 +00:00
|
|
|
|
|
|
|
case AZUREUS_MESSAGE_JPC_HELLO:
|
2010-05-11 16:54:55 +00:00
|
|
|
stringlen = tvb_get_ntohl(tvb, offset);
|
2011-09-26 08:25:18 +00:00
|
|
|
proto_tree_add_item(mtree, hf_azureus_jpc_addrlen, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item(mtree, hf_azureus_jpc_addr, tvb, offset+4, stringlen, ENC_ASCII|ENC_NA);
|
2011-09-26 08:25:18 +00:00
|
|
|
proto_tree_add_item(mtree, hf_azureus_jpc_port, tvb, offset+4+stringlen, 4, ENC_BIG_ENDIAN);
|
|
|
|
proto_tree_add_item(mtree, hf_azureus_jpc_session, tvb, offset+4+stringlen+4, 4, ENC_BIG_ENDIAN);
|
2010-05-11 16:54:55 +00:00
|
|
|
break;
|
2005-12-19 06:48:07 +00:00
|
|
|
|
|
|
|
case AZUREUS_MESSAGE_JPC_REPLY:
|
2011-09-26 08:25:18 +00:00
|
|
|
proto_tree_add_item(mtree, hf_azureus_jpc_session, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2010-05-11 16:54:55 +00:00
|
|
|
break;
|
2005-12-19 06:48:07 +00:00
|
|
|
|
2005-08-16 05:58:50 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-12-01 12:41:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
static int
|
|
|
|
dissect_bittorrent_welcome (tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
|
2004-12-01 12:41:43 +00:00
|
|
|
{
|
2012-03-21 18:20:44 +00:00
|
|
|
int offset = 0;
|
|
|
|
int i;
|
2005-08-16 05:58:50 +00:00
|
|
|
char *version;
|
2007-08-15 22:27:52 +00:00
|
|
|
|
2009-08-09 07:59:51 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "Handshake");
|
2007-08-15 22:27:52 +00:00
|
|
|
|
2011-09-26 08:25:18 +00:00
|
|
|
proto_tree_add_item(tree, hf_bittorrent_prot_name_len, tvb, offset, 1, ENC_BIG_ENDIAN); offset+=1;
|
2011-10-15 18:46:26 +00:00
|
|
|
proto_tree_add_item(tree, hf_bittorrent_prot_name, tvb, offset, 19, ENC_ASCII|ENC_NA); offset += 19;
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(tree, hf_bittorrent_reserved, tvb, offset, 8, ENC_NA); offset += 8;
|
2007-08-15 22:27:52 +00:00
|
|
|
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(tree, hf_bittorrent_sha1_hash, tvb, offset, 20, ENC_NA);
|
2005-08-16 05:58:50 +00:00
|
|
|
offset += 20;
|
|
|
|
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(tree, hf_bittorrent_peer_id, tvb, offset, 20, ENC_NA);
|
2005-08-16 05:58:50 +00:00
|
|
|
if(decode_client_information) {
|
2011-01-31 21:23:35 +00:00
|
|
|
for(i = 0; peer_id[i].name != NULL; ++i)
|
2005-08-16 05:58:50 +00:00
|
|
|
{
|
2010-05-11 16:54:55 +00:00
|
|
|
if(tvb_memeql(tvb, offset, peer_id[i].id, (int)strlen(peer_id[i].id)) == 0) {
|
2013-09-22 15:50:55 +00:00
|
|
|
version = tvb_get_string(wmem_packet_scope(), tvb, offset + (int)strlen(peer_id[i].id),
|
|
|
|
peer_id[i].ver_len);
|
2005-08-16 05:58:50 +00:00
|
|
|
proto_tree_add_text(tree, tvb, offset, 20, "Client is %s v%s",
|
2010-05-11 16:54:55 +00:00
|
|
|
peer_id[i].name,
|
|
|
|
format_text((guchar*)version, peer_id[i].ver_len));
|
2005-08-16 05:58:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offset += 20;
|
2012-03-02 11:07:50 +00:00
|
|
|
return offset;
|
2004-12-01 12:41:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
static
|
2013-11-09 17:46:28 +00:00
|
|
|
int dissect_bittorrent_tcp_pdu (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
|
2004-12-01 12:41:43 +00:00
|
|
|
{
|
2005-08-16 05:58:50 +00:00
|
|
|
proto_item *ti;
|
2007-08-15 22:27:52 +00:00
|
|
|
|
2009-08-09 07:59:51 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "BitTorrent");
|
2007-08-15 22:27:52 +00:00
|
|
|
|
2009-08-09 07:59:51 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "BitTorrent ");
|
2007-08-15 22:27:52 +00:00
|
|
|
|
2011-10-21 02:10:19 +00:00
|
|
|
ti = proto_tree_add_item (tree, proto_bittorrent, tvb, 0, -1, ENC_NA);
|
2005-08-16 05:58:50 +00:00
|
|
|
tree = proto_item_add_subtree(ti, ett_bittorrent);
|
2007-08-15 22:27:52 +00:00
|
|
|
|
2005-08-16 05:58:50 +00:00
|
|
|
if (tvb_get_guint8(tvb, 0) == 19 &&
|
2007-03-28 21:55:11 +00:00
|
|
|
tvb_memeql(tvb, 1, "BitTorrent protocol", 19) == 0) {
|
2005-08-16 05:58:50 +00:00
|
|
|
dissect_bittorrent_welcome(tvb, pinfo, tree);
|
|
|
|
} else {
|
|
|
|
dissect_bittorrent_message(tvb, pinfo, tree);
|
|
|
|
}
|
2005-10-02 15:41:11 +00:00
|
|
|
|
2011-09-26 08:25:18 +00:00
|
|
|
col_append_str(pinfo->cinfo, COL_INFO, " ");
|
|
|
|
col_set_fence(pinfo->cinfo, COL_INFO);
|
|
|
|
|
2013-11-09 17:46:28 +00:00
|
|
|
return tvb_length(tvb);
|
2004-12-01 12:41:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
static
|
2013-11-09 17:46:28 +00:00
|
|
|
int dissect_bittorrent (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
|
2004-12-01 12:41:43 +00:00
|
|
|
{
|
2005-08-16 05:58:50 +00:00
|
|
|
tcp_dissect_pdus(tvb, pinfo, tree, bittorrent_desegment, BITTORRENT_HEADER_LENGTH,
|
2013-11-09 17:46:28 +00:00
|
|
|
get_bittorrent_pdu_length, dissect_bittorrent_tcp_pdu, data);
|
|
|
|
return tvb_length(tvb);
|
2004-12-01 12:41:43 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 18:20:44 +00:00
|
|
|
static
|
|
|
|
gboolean test_bittorrent_packet (tvbuff_t *tvb, packet_info *pinfo,
|
2013-11-09 17:46:28 +00:00
|
|
|
proto_tree *tree, void *data)
|
2004-12-01 12:41:43 +00:00
|
|
|
{
|
2005-08-16 05:58:50 +00:00
|
|
|
conversation_t *conversation;
|
2004-12-01 12:41:43 +00:00
|
|
|
|
2007-11-09 06:01:18 +00:00
|
|
|
if (tvb_length(tvb) >= 20 &&
|
2005-08-16 05:58:50 +00:00
|
|
|
tvb_get_guint8(tvb, 0) == 19 &&
|
2007-03-28 21:55:11 +00:00
|
|
|
tvb_memeql(tvb, 1, "BitTorrent protocol", 19) == 0) {
|
2010-06-07 16:32:21 +00:00
|
|
|
conversation = find_or_create_conversation(pinfo);
|
2005-08-16 05:58:50 +00:00
|
|
|
conversation_set_dissector(conversation, dissector_handle);
|
2004-12-01 12:41:43 +00:00
|
|
|
|
2013-11-09 17:46:28 +00:00
|
|
|
dissect_bittorrent(tvb, pinfo, tree, data);
|
2004-12-01 12:41:43 +00:00
|
|
|
|
2005-08-16 05:58:50 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2004-12-01 12:41:43 +00:00
|
|
|
|
2005-08-16 05:58:50 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-01 12:41:43 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_bittorrent(void)
|
|
|
|
{
|
2005-08-16 05:58:50 +00:00
|
|
|
static hf_register_info hf[] = {
|
2013-01-31 17:55:31 +00:00
|
|
|
#if 0
|
2007-08-15 22:27:52 +00:00
|
|
|
{ &hf_bittorrent_field_length,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Field Length", "bittorrent.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2005-08-16 05:58:50 +00:00
|
|
|
},
|
2013-01-31 17:55:31 +00:00
|
|
|
#endif
|
2005-08-16 05:58:50 +00:00
|
|
|
{ &hf_bittorrent_prot_name_len,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Protocol Name Length", "bittorrent.protocol.name.length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2005-08-16 05:58:50 +00:00
|
|
|
},
|
|
|
|
{ &hf_bittorrent_prot_name,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Protocol Name", "bittorrent.protocol.name", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2005-08-16 05:58:50 +00:00
|
|
|
},
|
|
|
|
{ &hf_bittorrent_reserved,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Reserved Extension Bytes", "bittorrent.reserved", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2005-08-16 05:58:50 +00:00
|
|
|
},
|
|
|
|
{ &hf_bittorrent_sha1_hash,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "SHA1 Hash of info dictionary", "bittorrent.info_hash", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2005-08-16 05:58:50 +00:00
|
|
|
},
|
|
|
|
{ &hf_bittorrent_peer_id,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Peer ID", "bittorrent.peer_id", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2005-08-16 05:58:50 +00:00
|
|
|
},
|
2007-08-15 22:27:52 +00:00
|
|
|
{ &hf_bittorrent_msg,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Message", "bittorrent.msg", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2005-10-02 15:41:11 +00:00
|
|
|
},
|
2005-08-16 05:58:50 +00:00
|
|
|
{ &hf_bittorrent_msg_len,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Message Length", "bittorrent.msg.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2007-08-15 22:27:52 +00:00
|
|
|
},
|
2005-08-16 05:58:50 +00:00
|
|
|
{ &hf_bittorrent_msg_type,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Message Type", "bittorrent.msg.type", FT_UINT8, BASE_DEC, VALS(bittorrent_messages), 0x0, NULL, HFILL }
|
2005-08-16 05:58:50 +00:00
|
|
|
},
|
2005-12-19 06:48:07 +00:00
|
|
|
{ &hf_azureus_msg,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Azureus Message", "bittorrent.azureus_msg", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2005-12-19 06:48:07 +00:00
|
|
|
},
|
|
|
|
{ &hf_azureus_msg_type_len,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Message Type Length", "bittorrent.msg.typelen", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2005-12-19 06:48:07 +00:00
|
|
|
},
|
|
|
|
{ &hf_azureus_msg_type,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Message Type", "bittorrent.msg.aztype", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2005-12-19 06:48:07 +00:00
|
|
|
},
|
|
|
|
{ &hf_azureus_msg_prio,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Message Priority", "bittorrent.msg.prio", FT_UINT8, BASE_DEC, VALS(azureus_priorities), 0x0, NULL, HFILL }
|
2005-12-19 06:48:07 +00:00
|
|
|
},
|
2005-08-16 05:58:50 +00:00
|
|
|
{ &hf_bittorrent_bitfield_data,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Bitfield data", "bittorrent.msg.bitfield", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2005-08-16 05:58:50 +00:00
|
|
|
},
|
|
|
|
{ &hf_bittorrent_piece_index,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Piece index", "bittorrent.piece.index", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
|
2005-08-16 05:58:50 +00:00
|
|
|
},
|
|
|
|
{ &hf_bittorrent_piece_begin,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Begin offset of piece", "bittorrent.piece.begin", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
|
2005-08-16 05:58:50 +00:00
|
|
|
},
|
2007-08-15 22:27:52 +00:00
|
|
|
{ &hf_bittorrent_piece_data,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Data in a piece", "bittorrent.piece.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2005-08-16 05:58:50 +00:00
|
|
|
},
|
|
|
|
{ &hf_bittorrent_piece_length,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Piece Length", "bittorrent.piece.length", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
|
2005-12-19 06:48:07 +00:00
|
|
|
},
|
|
|
|
{ &hf_azureus_jpc_addrlen,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Cache Address Length", "bittorrent.jpc.addr.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2005-12-19 06:48:07 +00:00
|
|
|
},
|
|
|
|
{ &hf_azureus_jpc_addr,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Cache Address", "bittorrent.jpc.addr", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2005-12-19 06:48:07 +00:00
|
|
|
},
|
|
|
|
{ &hf_azureus_jpc_port,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Port", "bittorrent.jpc.port", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
2005-12-19 06:48:07 +00:00
|
|
|
},
|
|
|
|
{ &hf_azureus_jpc_session,
|
2010-05-11 16:54:55 +00:00
|
|
|
{ "Session ID", "bittorrent.jpc.session", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
|
2011-04-19 21:31:02 +00:00
|
|
|
},
|
|
|
|
{ &hf_bittorrent_port,
|
|
|
|
{ "Port", "bittorrent.port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_bittorrent_extended,
|
|
|
|
{ "Extended Message", "bittorrent.extended", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
|
2005-08-16 05:58:50 +00:00
|
|
|
}
|
2010-05-11 16:54:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_bittorrent,
|
|
|
|
&ett_bittorrent_msg,
|
|
|
|
&ett_peer_id,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_t *bittorrent_module;
|
|
|
|
|
|
|
|
proto_bittorrent = proto_register_protocol("BitTorrent", "BitTorrent", "bittorrent");
|
|
|
|
proto_register_field_array(proto_bittorrent, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
|
2013-11-09 17:46:28 +00:00
|
|
|
new_register_dissector("bittorrent.tcp", dissect_bittorrent, proto_bittorrent);
|
2010-05-11 16:54:55 +00:00
|
|
|
|
|
|
|
bittorrent_module = prefs_register_protocol(proto_bittorrent, NULL);
|
|
|
|
prefs_register_bool_preference(bittorrent_module, "desegment",
|
|
|
|
"Reassemble BitTorrent messages spanning multiple TCP segments",
|
|
|
|
"Whether the BitTorrent dissector should reassemble messages spanning multiple TCP segments."
|
|
|
|
" To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
|
|
|
|
&bittorrent_desegment);
|
|
|
|
prefs_register_bool_preference(bittorrent_module, "decode_client",
|
|
|
|
"Decode the peer_id of the handshake messages",
|
|
|
|
"Enabling this will tell which BitTorrent client that produced the handshake message",
|
|
|
|
&decode_client_information);
|
2004-12-01 12:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_bittorrent(void)
|
|
|
|
{
|
2014-02-03 00:36:50 +00:00
|
|
|
bencode_handle = find_dissector("bencode");
|
|
|
|
|
2005-12-19 06:48:07 +00:00
|
|
|
dissector_handle = find_dissector("bittorrent.tcp");
|
|
|
|
#if 0
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_add_uint("tcp.port", 6881, dissector_handle);
|
|
|
|
dissector_add_uint("tcp.port", 6882, dissector_handle);
|
|
|
|
dissector_add_uint("tcp.port", 6883, dissector_handle);
|
|
|
|
dissector_add_uint("tcp.port", 6884, dissector_handle);
|
|
|
|
dissector_add_uint("tcp.port", 6885, dissector_handle);
|
|
|
|
dissector_add_uint("tcp.port", 6886, dissector_handle);
|
|
|
|
dissector_add_uint("tcp.port", 6887, dissector_handle);
|
|
|
|
dissector_add_uint("tcp.port", 6888, dissector_handle);
|
|
|
|
dissector_add_uint("tcp.port", 6889, dissector_handle);
|
2005-12-19 06:48:07 +00:00
|
|
|
#endif
|
2005-08-16 05:58:50 +00:00
|
|
|
heur_dissector_add("tcp", test_bittorrent_packet, proto_bittorrent);
|
2004-12-01 12:41:43 +00:00
|
|
|
}
|
2010-05-11 16:54:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 3
|
2012-03-21 18:20:44 +00:00
|
|
|
* tab-width: 8
|
2010-05-11 16:54:55 +00:00
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
2012-03-21 18:20:44 +00:00
|
|
|
* ex: set shiftwidth=3 tabstop=8 expandtab:
|
|
|
|
* :indentSize=3:tabSize=8:noTabs=true:
|
2010-05-11 16:54:55 +00:00
|
|
|
*/
|