Use consistent indentation; Whitesapce & formatting cleanup.

svn path=/trunk/; revision=32755
This commit is contained in:
Bill Meier 2010-05-11 16:54:55 +00:00
parent 1a474d8264
commit 0fc9115705
5 changed files with 13281 additions and 13257 deletions

File diff suppressed because it is too large Load Diff

View File

@ -92,35 +92,35 @@ static const value_string bittorrent_messages[] = {
};
static const value_string azureus_priorities[] = {
{ 0, "Low" },
{ 1, "Normal" },
{ 2, "High" },
{ 0, NULL }
{ 0, "Low" },
{ 1, "Normal" },
{ 2, "High" },
{ 0, NULL }
};
struct amp_message {
const char *name;
guint32 value;
const char *name;
guint32 value;
};
static const struct amp_message amp_messages[] = {
{ "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 },
{ "AZ_HANDSHAKE", AZUREUS_MESSAGE_HANDSHAKE },
{ "BT_HANDSHAKE", AZUREUS_MESSAGE_BT_HANDSHAKE },
{ "AZ_PEER_EXCHANGE", AZUREUS_MESSAGE_PEER_EXCHANGE },
{ "JPC_HELLO", AZUREUS_MESSAGE_JPC_HELLO },
{ "JPC_REPLY", AZUREUS_MESSAGE_JPC_REPLY },
{ NULL, 0 }
{ "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 },
{ "AZ_HANDSHAKE", AZUREUS_MESSAGE_HANDSHAKE },
{ "BT_HANDSHAKE", AZUREUS_MESSAGE_BT_HANDSHAKE },
{ "AZ_PEER_EXCHANGE", AZUREUS_MESSAGE_PEER_EXCHANGE },
{ "JPC_HELLO", AZUREUS_MESSAGE_JPC_HELLO },
{ "JPC_REPLY", AZUREUS_MESSAGE_JPC_REPLY },
{ NULL, 0 }
};
static dissector_handle_t dissector_handle;
@ -306,260 +306,260 @@ static guint get_bittorrent_pdu_length(packet_info *pinfo _U_, tvbuff_t *tvb, in
}
static int dissect_bencoding_str(tvbuff_t *tvb, packet_info *pinfo _U_,
int offset, int length, proto_tree *tree, proto_item *ti, int treeadd)
int offset, int length, proto_tree *tree, proto_item *ti, int treeadd)
{
guint8 ch;
int stringlen = 0, nextstringlen;
int used;
int izero = 0;
guint8 ch;
int stringlen = 0, nextstringlen;
int used;
int izero = 0;
if (length<2) {
if (tree) {
proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid String");
}
return -1;
}
used = 0;
while (length>=1) {
ch = tvb_get_guint8(tvb, offset+used);
length--;
used++;
if (ch==':' && used>1) {
if (stringlen>length || stringlen<0) {
if (tree) {
proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid String Length");
}
return -1;
}
if (length<2) {
if (tree) {
proto_tree_add_uint(tree, hf_bittorrent_bstr_length, tvb, offset, used, stringlen);
proto_tree_add_item(tree, hf_bittorrent_bstr, tvb, offset+used, stringlen, FALSE);
if (treeadd==1) {
proto_item_append_text(ti, " Key: %s", format_text(ep_tvb_memdup(tvb, offset+used, stringlen), stringlen));
}
if (treeadd==2) {
proto_item_append_text(ti, " Value: %s", format_text(ep_tvb_memdup(tvb, offset+used, stringlen), stringlen));
}
proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid String");
}
return used+stringlen;
}
return -1;
}
if (!izero && ch>='0' && ch<='9') {
if (ch=='0' && used==1) {
izero = 1;
used = 0;
while (length>=1) {
ch = tvb_get_guint8(tvb, offset+used);
length--;
used++;
if (ch==':' && used>1) {
if (stringlen>length || stringlen<0) {
if (tree) {
proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid String Length");
}
return -1;
}
if (tree) {
proto_tree_add_uint(tree, hf_bittorrent_bstr_length, tvb, offset, used, stringlen);
proto_tree_add_item(tree, hf_bittorrent_bstr, tvb, offset+used, stringlen, FALSE);
if (treeadd==1) {
proto_item_append_text(ti, " Key: %s", format_text(ep_tvb_memdup(tvb, offset+used, stringlen), stringlen));
}
if (treeadd==2) {
proto_item_append_text(ti, " Value: %s", format_text(ep_tvb_memdup(tvb, offset+used, stringlen), stringlen));
}
}
return used+stringlen;
}
nextstringlen = (stringlen * 10) + (ch - '0');
if (nextstringlen>=stringlen) {
stringlen = nextstringlen;
continue;
if (!izero && ch>='0' && ch<='9') {
if (ch=='0' && used==1) {
izero = 1;
}
nextstringlen = (stringlen * 10) + (ch - '0');
if (nextstringlen>=stringlen) {
stringlen = nextstringlen;
continue;
}
}
}
if (tree) {
proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid String");
}
return -1;
}
if (tree) {
proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid String");
}
return -1;
}
if (tree) {
proto_tree_add_text(tree, tvb, offset, length, "Truncated Data");
}
return -1;
if (tree) {
proto_tree_add_text(tree, tvb, offset, length, "Truncated Data");
}
return -1;
}
static int dissect_bencoding_int(tvbuff_t *tvb, packet_info *pinfo _U_,
int offset, int length, proto_tree *tree, proto_item *ti, int treeadd)
int offset, int length, proto_tree *tree, proto_item *ti, int treeadd)
{
gint32 ival=0;
int neg = 0;
int izero = 0;
int used;
guint8 ch;
gint32 ival=0;
int neg = 0;
int izero = 0;
int used;
guint8 ch;
if (length<3) {
if (tree) {
proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid Integer");
}
return -1;
}
length--;
used = 1;
while (length>=1) {
ch = tvb_get_guint8(tvb, offset+used);
length--;
used++;
switch (ch) {
case 'e':
if (length<3) {
if (tree) {
if (neg) ival = -ival;
proto_tree_add_int(tree, hf_bittorrent_bint, tvb, offset, used, ival);
if (treeadd==2) {
proto_item_append_text(ti, " Value: %d", ival);
}
}
return used;
case '-':
if (used==2) {
neg = 1;
break;
}
/* Fall through */
default:
if (!(ch=='0' && used==3 && neg)) { /* -0 is invalid */
if (ch=='0' && used==2) { /* as is 0[0-9]+ */
izero = 1;
break;
}
if (!izero && ch>='0' && ch<='9') {
ival = (ival * 10) + (ch - '0');
break;
}
}
if (tree) {
proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid Integer");
proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid Integer");
}
return -1;
}
}
}
if (tree) {
proto_tree_add_text(tree, tvb, offset, length, "Truncated Data");
}
return -1;
length--;
used = 1;
while (length>=1) {
ch = tvb_get_guint8(tvb, offset+used);
length--;
used++;
switch (ch) {
case 'e':
if (tree) {
if (neg) ival = -ival;
proto_tree_add_int(tree, hf_bittorrent_bint, tvb, offset, used, ival);
if (treeadd==2) {
proto_item_append_text(ti, " Value: %d", ival);
}
}
return used;
case '-':
if (used==2) {
neg = 1;
break;
}
/* Fall through */
default:
if (!(ch=='0' && used==3 && neg)) { /* -0 is invalid */
if (ch=='0' && used==2) { /* as is 0[0-9]+ */
izero = 1;
break;
}
if (!izero && ch>='0' && ch<='9') {
ival = (ival * 10) + (ch - '0');
break;
}
}
if (tree) {
proto_tree_add_text(tree, tvb, offset, length, "Decode Aborted: Invalid Integer");
}
return -1;
}
}
if (tree) {
proto_tree_add_text(tree, tvb, offset, length, "Truncated Data");
}
return -1;
}
static int dissect_bencoding_rec(tvbuff_t *tvb, packet_info *pinfo _U_,
int offset, int length, proto_tree *tree, int level, proto_item *treei, int treeadd)
int offset, int length, proto_tree *tree, int level, proto_item *treei, int treeadd)
{
guint8 op;
int oplen = 0, op1len, op2len;
int used;
guint8 op;
int oplen = 0, op1len, op2len;
int used;
proto_item *ti = NULL, *td = NULL;
proto_tree *itree = NULL, *dtree = NULL;
proto_item *ti = NULL, *td = NULL;
proto_tree *itree = NULL, *dtree = NULL;
if (level>10) {
proto_tree_add_text(tree, tvb, offset, -1, "Decode Aborted: Nested Too Deep");
return -1;
}
if (length<1) {
proto_tree_add_text(tree, tvb, offset, -1, "Truncated Data");
return length;
}
if (level>10) {
proto_tree_add_text(tree, tvb, offset, -1, "Decode Aborted: Nested Too Deep");
return -1;
}
if (length<1) {
proto_tree_add_text(tree, tvb, offset, -1, "Truncated Data");
return length;
}
op = tvb_get_guint8(tvb, offset);
if (tree) {
oplen = dissect_bencoding_rec(tvb, pinfo, offset, length, NULL, level, NULL, 0);
if (oplen<0) oplen = length;
}
op = tvb_get_guint8(tvb, offset);
if (tree) {
oplen = dissect_bencoding_rec(tvb, pinfo, offset, length, NULL, level, NULL, 0);
if (oplen<0) oplen = length;
}
switch (op) {
case 'd':
if (tree) {
td = proto_tree_add_item(tree, hf_bittorrent_bdict, tvb, offset, oplen, FALSE);
dtree = proto_item_add_subtree(td, ett_bittorrent_bdict);
}
used = 1;
length--;
while (length>=1) {
op = tvb_get_guint8(tvb, offset+used);
if (op=='e') {
return used+1;
switch (op) {
case 'd':
if (tree) {
td = proto_tree_add_item(tree, hf_bittorrent_bdict, tvb, offset, oplen, FALSE);
dtree = proto_item_add_subtree(td, ett_bittorrent_bdict);
}
op1len = dissect_bencoding_str(tvb, pinfo, offset+used, length, NULL, NULL, 0);
if (op1len<0) {
if (dtree) {
proto_tree_add_text(dtree, tvb, offset+used, -1, "Decode Aborted: Invalid Dictionary Key");
}
return op1len;
}
used = 1;
length--;
op2len = -1;
if (length-op1len>2)
op2len = dissect_bencoding_rec(tvb, pinfo, offset+used+op1len, length-op1len, NULL, level+1, NULL, 0);
if (op2len<0) {
if (dtree) {
proto_tree_add_text(dtree, tvb, offset+used+op1len, -1, "Decode Aborted: Invalid Dictionary Value");
}
return op2len;
}
while (length>=1) {
op = tvb_get_guint8(tvb, offset+used);
if (op=='e') {
return used+1;
}
op1len = dissect_bencoding_str(tvb, pinfo, offset+used, length, NULL, NULL, 0);
if (op1len<0) {
if (dtree) {
proto_tree_add_text(dtree, tvb, offset+used, -1, "Decode Aborted: Invalid Dictionary Key");
}
return op1len;
}
op2len = -1;
if (length-op1len>2)
op2len = dissect_bencoding_rec(tvb, pinfo, offset+used+op1len, length-op1len, NULL, level+1, NULL, 0);
if (op2len<0) {
if (dtree) {
proto_tree_add_text(dtree, tvb, offset+used+op1len, -1, "Decode Aborted: Invalid Dictionary Value");
}
return op2len;
}
if (dtree) {
ti = proto_tree_add_item(dtree, hf_bittorrent_bdict_entry, tvb, offset+used, op1len+op2len, FALSE);
itree = proto_item_add_subtree(ti, ett_bittorrent_bdict_entry);
dissect_bencoding_str(tvb, pinfo, offset+used, length, itree, ti, 1);
dissect_bencoding_rec(tvb, pinfo, offset+used+op1len, length-op1len, itree, level+1, ti, 2);
}
used += op1len+op2len;
length -= op1len+op2len;
}
if (dtree) {
ti = proto_tree_add_item(dtree, hf_bittorrent_bdict_entry, tvb, offset+used, op1len+op2len, FALSE);
itree = proto_item_add_subtree(ti, ett_bittorrent_bdict_entry);
proto_tree_add_text(dtree, tvb, offset+used, -1, "Truncated Data");
}
return -1;
dissect_bencoding_str(tvb, pinfo, offset+used, length, itree, ti, 1);
dissect_bencoding_rec(tvb, pinfo, offset+used+op1len, length-op1len, itree, level+1, ti, 2);
case 'l':
if (tree) {
ti = proto_tree_add_item(tree, hf_bittorrent_blist, tvb, offset, oplen, FALSE);
itree = proto_item_add_subtree(ti, ett_bittorrent_blist);
}
used += op1len+op2len;
length -= op1len+op2len;
}
if (dtree) {
proto_tree_add_text(dtree, tvb, offset+used, -1, "Truncated Data");
}
return -1;
used = 1;
length--;
case 'l':
if (tree) {
ti = proto_tree_add_item(tree, hf_bittorrent_blist, tvb, offset, oplen, FALSE);
itree = proto_item_add_subtree(ti, ett_bittorrent_blist);
}
while (length>=1) {
op = tvb_get_guint8(tvb, offset+used);
used = 1;
length--;
if (op=='e') {
return used+1;
}
while (length>=1) {
op = tvb_get_guint8(tvb, offset+used);
oplen = dissect_bencoding_rec(tvb, pinfo, offset+used, length, itree, level+1, ti, 0);
if (oplen<1) return oplen;
if (op=='e') {
return used+1;
used += oplen;
length -= oplen;
}
if (itree) {
proto_tree_add_text(itree, tvb, offset+used, -1, "Truncated Data");
}
return -1;
case 'i':
return dissect_bencoding_int(tvb, pinfo, offset, length, tree, treei, treeadd);
default:
if (op>='1' && op<='9') {
return dissect_bencoding_str(tvb, pinfo, offset, length, tree, treei, treeadd);
}
oplen = dissect_bencoding_rec(tvb, pinfo, offset+used, length, itree, level+1, ti, 0);
if (oplen<1) return oplen;
if (tree) {
proto_tree_add_text(tree, tvb, offset, -1, "Decode Aborted: Invalid Bencoding");
}
}
used += oplen;
length -= oplen;
}
if (itree) {
proto_tree_add_text(itree, tvb, offset+used, -1, "Truncated Data");
}
return -1;
case 'i':
return dissect_bencoding_int(tvb, pinfo, offset, length, tree, treei, treeadd);
default:
if (op>='1' && op<='9') {
return dissect_bencoding_str(tvb, pinfo, offset, length, tree, treei, treeadd);
}
if (tree) {
proto_tree_add_text(tree, tvb, offset, -1, "Decode Aborted: Invalid Bencoding");
}
}
return -1;
return -1;
}
static void dissect_bencoding(tvbuff_t *tvb, packet_info *pinfo _U_,
int offset, int length, proto_tree *tree)
int offset, int length, proto_tree *tree)
{
dissect_bencoding_rec(tvb, pinfo, offset, length, tree, 0, NULL, 0);
}
@ -586,53 +586,55 @@ static void dissect_bittorrent_message (tvbuff_t *tvb, packet_info *pinfo, proto
type = tvb_get_guint8(tvb, offset + BITTORRENT_HEADER_LENGTH);
if (type==BITTORRENT_MESSAGE_CHOKE && length>4) {
/*
* 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;
/*
* 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;
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) {
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;
doffset = BITTORRENT_HEADER_LENGTH + 4 + typelen + 1;
isamp = 1;
}
break;
}
}
}
prio = tvb_get_guint8(tvb, offset + BITTORRENT_HEADER_LENGTH + 4 + typelen);
if (prio==0 || prio==1 || prio==2) {
type = amp_messages[i].value;
doffset = BITTORRENT_HEADER_LENGTH + 4 + typelen + 1;
isamp = 1;
}
break;
}
}
}
}
msgtype = match_strval(type, bittorrent_messages);
/* if (msgtype == NULL && isamp) {
msgtype = match_strval(type, azureus_messages);
} */
#if 0
if (msgtype == NULL && isamp) {
msgtype = match_strval(type, azureus_messages);
}
#endif
if (msgtype == NULL) {
proto_tree_add_text(tree, tvb, offset, -1, "Continuation data");
col_set_str(pinfo->cinfo, COL_INFO, "Continuation data");
return;
}
} else {
/* not enough bytes of the header, stop here */
return;
/* not enough bytes of the header, stop here */
return;
}
if (isamp) {
ti = proto_tree_add_item(tree, hf_azureus_msg, tvb, offset, length + BITTORRENT_HEADER_LENGTH, FALSE);
ti = proto_tree_add_item(tree, hf_azureus_msg, tvb, offset, length + BITTORRENT_HEADER_LENGTH, FALSE);
} else {
ti = proto_tree_add_item(tree, hf_bittorrent_msg, tvb, offset, length + BITTORRENT_HEADER_LENGTH, FALSE);
ti = proto_tree_add_item(tree, hf_bittorrent_msg, tvb, offset, length + BITTORRENT_HEADER_LENGTH, FALSE);
}
mtree = proto_item_add_subtree(ti, ett_bittorrent_msg);
@ -649,17 +651,17 @@ static void dissect_bittorrent_message (tvbuff_t *tvb, packet_info *pinfo, proto
/* If the tvb_bytes_exist() call above returned FALSE, this will
throw an exception, so we won't use msgtype or type. */
if (isamp) {
proto_tree_add_item(mtree, hf_azureus_msg_type_len, tvb, offset, 4, FALSE);
proto_tree_add_item(mtree, hf_azureus_msg_type, tvb, offset+4, typelen, FALSE);
proto_item_append_text(ti, ": Len %u, %s", length, msgtype);
proto_tree_add_item(mtree, hf_azureus_msg_prio, tvb, offset+4+typelen, 1, FALSE);
offset += 4+typelen+1;
length -= 4+typelen+1;
proto_tree_add_item(mtree, hf_azureus_msg_type_len, tvb, offset, 4, FALSE);
proto_tree_add_item(mtree, hf_azureus_msg_type, tvb, offset+4, typelen, FALSE);
proto_item_append_text(ti, ": Len %u, %s", length, msgtype);
proto_tree_add_item(mtree, hf_azureus_msg_prio, tvb, offset+4+typelen, 1, FALSE);
offset += 4+typelen+1;
length -= 4+typelen+1;
} else {
proto_tree_add_item(mtree, hf_bittorrent_msg_type, tvb, offset, 1, FALSE);
proto_item_append_text(ti, ": Len:%u, %s", length, msgtype);
offset += 1;
length -= 1;
proto_tree_add_item(mtree, hf_bittorrent_msg_type, tvb, offset, 1, FALSE);
proto_item_append_text(ti, ": Len:%u, %s", length, msgtype);
offset += 1;
length -= 1;
}
col_set_str(pinfo->cinfo, COL_INFO, msgtype);
@ -673,25 +675,25 @@ static void dissect_bittorrent_message (tvbuff_t *tvb, packet_info *pinfo, proto
case BITTORRENT_MESSAGE_REQUEST:
case BITTORRENT_MESSAGE_CANCEL:
piece_index = tvb_get_ntohl(tvb, offset);
piece_index = tvb_get_ntohl(tvb, offset);
proto_tree_add_uint(mtree, hf_bittorrent_piece_index, tvb, offset, 4, piece_index); offset += 4;
piece_begin = tvb_get_ntohl(tvb, offset);
piece_begin = tvb_get_ntohl(tvb, offset);
proto_tree_add_uint(mtree, hf_bittorrent_piece_begin, tvb, offset, 4, piece_begin); offset += 4;
piece_length = tvb_get_ntohl(tvb, offset);
piece_length = tvb_get_ntohl(tvb, offset);
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);
if (check_col(pinfo->cinfo, COL_INFO)) {
col_append_fstr(pinfo->cinfo, COL_INFO, ", Piece (Idx:0x%x,Begin:0x%x,Len:0x%x)", piece_index, piece_begin, piece_length);
}
}
break;
case BITTORRENT_MESSAGE_HAVE:
piece_index = tvb_get_ntohl(tvb, offset);
piece_index = tvb_get_ntohl(tvb, offset);
proto_tree_add_item(mtree, hf_bittorrent_piece_index, tvb, offset, 4, FALSE);
proto_item_append_text(ti, ", Piece (Idx:0x%x)", piece_index);
if (check_col(pinfo->cinfo, COL_INFO)) {
col_append_fstr(pinfo->cinfo, COL_INFO, ", Piece (Idx:0x%x)", piece_index);
}
}
break;
case BITTORRENT_MESSAGE_BITFIELD:
@ -699,15 +701,15 @@ static void dissect_bittorrent_message (tvbuff_t *tvb, packet_info *pinfo, proto
proto_item_append_text(ti, ", Len:0x%x", length);
if (check_col(pinfo->cinfo, COL_INFO)) {
col_append_fstr(pinfo->cinfo, COL_INFO, ", Len:0x%x", length);
}
}
break;
case BITTORRENT_MESSAGE_PIECE:
piece_index = tvb_get_ntohl(tvb, offset);
piece_index = tvb_get_ntohl(tvb, offset);
proto_tree_add_uint(mtree, hf_bittorrent_piece_index, tvb, offset, 4, piece_index);
offset += 4;
length -= 4;
piece_begin = tvb_get_ntohl(tvb, offset);
piece_begin = tvb_get_ntohl(tvb, offset);
proto_tree_add_item(mtree, hf_bittorrent_piece_begin, tvb, offset, 4, piece_begin);
offset += 4;
length -= 4;
@ -715,25 +717,25 @@ static void dissect_bittorrent_message (tvbuff_t *tvb, packet_info *pinfo, proto
proto_item_append_text(ti, ", Idx:0x%x,Begin:0x%x,Len:0x%x", piece_index, piece_begin, length);
if (check_col(pinfo->cinfo, COL_INFO)) {
col_append_fstr(pinfo->cinfo, COL_INFO, ", Idx:0x%x,Begin:0x%x,Len:0x%x", piece_index, piece_begin, length);
}
}
break;
case AZUREUS_MESSAGE_HANDSHAKE:
case AZUREUS_MESSAGE_PEER_EXCHANGE:
dissect_bencoding(tvb, pinfo, offset, length, mtree);
break;
dissect_bencoding(tvb, pinfo, offset, length, mtree);
break;
case AZUREUS_MESSAGE_JPC_HELLO:
stringlen = tvb_get_ntohl(tvb, offset);
proto_tree_add_item(mtree, hf_azureus_jpc_addrlen, tvb, offset, 4, FALSE);
proto_tree_add_item(mtree, hf_azureus_jpc_addr, tvb, offset+4, stringlen, FALSE);
proto_tree_add_item(mtree, hf_azureus_jpc_port, tvb, offset+4+stringlen, 4, FALSE);
proto_tree_add_item(mtree, hf_azureus_jpc_session, tvb, offset+4+stringlen+4, 4, FALSE);
break;
stringlen = tvb_get_ntohl(tvb, offset);
proto_tree_add_item(mtree, hf_azureus_jpc_addrlen, tvb, offset, 4, FALSE);
proto_tree_add_item(mtree, hf_azureus_jpc_addr, tvb, offset+4, stringlen, FALSE);
proto_tree_add_item(mtree, hf_azureus_jpc_port, tvb, offset+4+stringlen, 4, FALSE);
proto_tree_add_item(mtree, hf_azureus_jpc_session, tvb, offset+4+stringlen+4, 4, FALSE);
break;
case AZUREUS_MESSAGE_JPC_REPLY:
proto_tree_add_item(mtree, hf_azureus_jpc_session, tvb, offset, 4, FALSE);
break;
proto_tree_add_item(mtree, hf_azureus_jpc_session, tvb, offset, 4, FALSE);
break;
default:
break;
@ -759,12 +761,12 @@ static void dissect_bittorrent_welcome (tvbuff_t *tvb, packet_info *pinfo _U_, p
if(decode_client_information) {
for(i = 0; peer_id[i].id[0] != '\0'; ++i)
{
if(tvb_memeql(tvb, offset, peer_id[i].id, (int)strlen(peer_id[i].id)) == 0) {
version = tvb_get_ephemeral_string(tvb, offset + (int)strlen(peer_id[i].id),
peer_id[i].ver_len);
if(tvb_memeql(tvb, offset, peer_id[i].id, (int)strlen(peer_id[i].id)) == 0) {
version = tvb_get_ephemeral_string(tvb, offset + (int)strlen(peer_id[i].id),
peer_id[i].ver_len);
proto_tree_add_text(tree, tvb, offset, 20, "Client is %s v%s",
peer_id[i].name,
format_text((guchar*)version, peer_id[i].ver_len));
peer_id[i].name,
format_text((guchar*)version, peer_id[i].ver_len));
break;
}
}
@ -828,125 +830,124 @@ proto_register_bittorrent(void)
{
static hf_register_info hf[] = {
{ &hf_bittorrent_field_length,
{ "Field Length", "bittorrent.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
{ "Field Length", "bittorrent.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_prot_name_len,
{ "Protocol Name Length", "bittorrent.protocol.name.length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
{ "Protocol Name Length", "bittorrent.protocol.name.length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_prot_name,
{ "Protocol Name", "bittorrent.protocol.name", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "Protocol Name", "bittorrent.protocol.name", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_reserved,
{ "Reserved Extension Bytes", "bittorrent.reserved", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "Reserved Extension Bytes", "bittorrent.reserved", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_sha1_hash,
{ "SHA1 Hash of info dictionary", "bittorrent.info_hash", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "SHA1 Hash of info dictionary", "bittorrent.info_hash", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_peer_id,
{ "Peer ID", "bittorrent.peer_id", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "Peer ID", "bittorrent.peer_id", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_msg,
{ "Message", "bittorrent.msg", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "Message", "bittorrent.msg", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_msg_len,
{ "Message Length", "bittorrent.msg.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
{ "Message Length", "bittorrent.msg.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_msg_type,
{ "Message Type", "bittorrent.msg.type", FT_UINT8, BASE_DEC, VALS(bittorrent_messages), 0x0, NULL, HFILL }
{ "Message Type", "bittorrent.msg.type", FT_UINT8, BASE_DEC, VALS(bittorrent_messages), 0x0, NULL, HFILL }
},
{ &hf_azureus_msg,
{ "Azureus Message", "bittorrent.azureus_msg", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "Azureus Message", "bittorrent.azureus_msg", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_azureus_msg_type_len,
{ "Message Type Length", "bittorrent.msg.typelen", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
{ "Message Type Length", "bittorrent.msg.typelen", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_azureus_msg_type,
{ "Message Type", "bittorrent.msg.aztype", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "Message Type", "bittorrent.msg.aztype", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_azureus_msg_prio,
{ "Message Priority", "bittorrent.msg.prio", FT_UINT8, BASE_DEC, VALS(azureus_priorities), 0x0, NULL, HFILL }
{ "Message Priority", "bittorrent.msg.prio", FT_UINT8, BASE_DEC, VALS(azureus_priorities), 0x0, NULL, HFILL }
},
{ &hf_bittorrent_bitfield_data,
{ "Bitfield data", "bittorrent.msg.bitfield", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "Bitfield data", "bittorrent.msg.bitfield", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_piece_index,
{ "Piece index", "bittorrent.piece.index", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
{ "Piece index", "bittorrent.piece.index", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_piece_begin,
{ "Begin offset of piece", "bittorrent.piece.begin", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
{ "Begin offset of piece", "bittorrent.piece.begin", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_piece_data,
{ "Data in a piece", "bittorrent.piece.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "Data in a piece", "bittorrent.piece.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_piece_length,
{ "Piece Length", "bittorrent.piece.length", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
{ "Piece Length", "bittorrent.piece.length", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_bstr_length,
{ "String Length", "bittorrent.bstr.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
{ "String Length", "bittorrent.bstr.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_bstr,
{ "String", "bittorrent.bstr", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "String", "bittorrent.bstr", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_bint,
{ "Integer", "bittorrent.bint", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
{ "Integer", "bittorrent.bint", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_bdict,
{ "Dictionary", "bittorrent.bdict", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "Dictionary", "bittorrent.bdict", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_bdict_entry,
{ "Entry", "bittorrent.bdict.entry", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "Entry", "bittorrent.bdict.entry", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_bittorrent_blist,
{ "List", "bittorrent.blist", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "List", "bittorrent.blist", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_azureus_jpc_addrlen,
{ "Cache Address Length", "bittorrent.jpc.addr.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
{ "Cache Address Length", "bittorrent.jpc.addr.length", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_azureus_jpc_addr,
{ "Cache Address", "bittorrent.jpc.addr", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
{ "Cache Address", "bittorrent.jpc.addr", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
},
{ &hf_azureus_jpc_port,
{ "Port", "bittorrent.jpc.port", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
{ "Port", "bittorrent.jpc.port", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_azureus_jpc_session,
{ "Session ID", "bittorrent.jpc.session", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
{ "Session ID", "bittorrent.jpc.session", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
}
};
};
static gint *ett[] = {
&ett_bittorrent,
&ett_bittorrent_msg,
&ett_peer_id,
&ett_bittorrent_bdict,
&ett_bittorrent_bdict_entry,
&ett_bittorrent_blist
};
static gint *ett[] = {
&ett_bittorrent,
&ett_bittorrent_msg,
&ett_peer_id,
&ett_bittorrent_bdict,
&ett_bittorrent_bdict_entry,
&ett_bittorrent_blist
};
module_t *bittorrent_module;
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));
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));
register_dissector("bittorrent.tcp", dissect_bittorrent, proto_bittorrent);
register_dissector("bittorrent.tcp", dissect_bittorrent, proto_bittorrent);
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);
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);
}
void
proto_reg_handoff_bittorrent(void)
{
/* dissector_handle = create_dissector_handle(dissect_bittorrent, proto_bittorrent); */
dissector_handle = find_dissector("bittorrent.tcp");
#if 0
dissector_add("tcp.port", 6881, dissector_handle);
@ -961,3 +962,16 @@ proto_reg_handoff_bittorrent(void)
#endif
heur_dissector_add("tcp", test_bittorrent_packet, proto_bittorrent);
}
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 3
* tab-width: 3
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=3 tabstop=3 expandtab
* :indentSize=3:tabSize=3:noTabs=true:
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff