aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-bittorrent.c
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2005-07-09 00:44:44 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2005-07-09 00:44:44 +0000
commit7387fe6b603036ef5e12f55ff239f4c47afb8c15 (patch)
tree3521975098453f46aa762b589956ff9ea3496982 /epan/dissectors/packet-bittorrent.c
parent7e37aa5f2c424b6d5572a52cfc2918272f02e4b3 (diff)
Find the BitTorrent dissector immediately after registering it, and save
the handle, rather than finding it every time we need it. Just make a guint8 array with the BitTorrent magic string length followed by the string, and use "tvb_memeql()" to test against that - it handles checking to make sure there's enough data in the tvbuff (if not, it returns -1 as a "no match" indication) and then checks all of the first 20 bytes in one operation. Clean up white space. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@14882 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'epan/dissectors/packet-bittorrent.c')
-rw-r--r--epan/dissectors/packet-bittorrent.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/epan/dissectors/packet-bittorrent.c b/epan/dissectors/packet-bittorrent.c
index 9aa9472c5e..e57d13928e 100644
--- a/epan/dissectors/packet-bittorrent.c
+++ b/epan/dissectors/packet-bittorrent.c
@@ -90,6 +90,8 @@ static gint ett_bittorrent_msg = -1;
static gboolean bittorrent_desegment = TRUE;
+static dissector_handle_t bittorrent_handle;
+
static guint get_bittorrent_pdu_length(tvbuff_t *tvb, int offset)
{
if (tvb_get_guint8(tvb, offset) == 19) {
@@ -166,6 +168,7 @@ static void dissect_bittorrent_message (tvbuff_t *tvb, packet_info *pinfo, proto
static void dissect_bittorrent_welcome (tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
{
int offset = 0;
+
if (check_col(pinfo->cinfo, COL_INFO)) {
col_set_str(pinfo->cinfo, COL_INFO, "BitTorrent Handshake");
}
@@ -181,11 +184,11 @@ static void dissect_bittorrent_tcp_pdu (tvbuff_t *tvb, packet_info *pinfo, proto
{
proto_item *ti;
- if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
- col_set_str(pinfo->cinfo, COL_PROTOCOL, "BitTorrent");
- }
+ if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
+ col_set_str(pinfo->cinfo, COL_PROTOCOL, "BitTorrent");
+ }
- if (check_col(pinfo->cinfo, COL_INFO)) {
+ if (check_col(pinfo->cinfo, COL_INFO)) {
col_set_str(pinfo->cinfo, COL_INFO, "BitTorrent Peer-To-Peer connection");
}
@@ -205,27 +208,24 @@ static void dissect_bittorrent (tvbuff_t *tvb, packet_info *pinfo, proto_tree *t
tcp_dissect_pdus(tvb, pinfo, tree, bittorrent_desegment, 4, get_bittorrent_pdu_length, dissect_bittorrent_tcp_pdu);
}
+static const guint8 bittorrent_magic[20] = {
+ 19,
+ 'B', 'i', 't', 'T', 'o', 'r', 'r', 'e', 'n', 't',
+ ' ', 'p', 'r', 'o', 't', 'o', 'c', 'o', 'l'
+};
+
static gboolean test_bittorrent_packet (tvbuff_t *tvb, packet_info *pinfo,
proto_tree *tree)
{
conversation_t *conversation;
- if (!tvb_bytes_exist(tvb, 0, 20))
- return FALSE;
-
- if (tvb_get_guint8(tvb, 0) != 19) {
- return FALSE;
- }
-
- if (tvb_memeql(tvb, 1, "BitTorrent protocol", 19) == -1) {
+ if (tvb_memeql(tvb, 0, bittorrent_magic, sizeof bittorrent_magic) == -1) {
return FALSE;
}
conversation = conversation_new (pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
- DISSECTOR_ASSERT(find_dissector("bittorrent"));
-
- conversation_set_dissector(conversation, find_dissector("bittorrent"));
+ conversation_set_dissector(conversation, bittorrent_handle);
dissect_bittorrent(tvb, pinfo, tree);
@@ -304,5 +304,6 @@ void
proto_reg_handoff_bittorrent(void)
{
register_dissector("bittorrent", dissect_bittorrent, proto_bittorrent);
+ bittorrent_handle = find_dissector("bittorrent");
heur_dissector_add("tcp", test_bittorrent_packet, proto_bittorrent);
}