diff options
author | Bill Meier <wmeier@newsguy.com> | 2009-03-29 15:34:26 +0000 |
---|---|---|
committer | Bill Meier <wmeier@newsguy.com> | 2009-03-29 15:34:26 +0000 |
commit | cba255800652bd06ae6c6db6293c99d0ab36965f (patch) | |
tree | 120272ecb32e51203eb7366f109bbd6468e0d48e /epan/dissectors/packet-ldss.c | |
parent | f8904a216a2b50003287b13bc4fc48eb946a35c9 (diff) | |
download | wireshark-cba255800652bd06ae6c6db6293c99d0ab36965f.tar.gz |
Fix code so changing port pref will work + other small changes:
- Use NULL instead of "" in blurb in hf[];
- Remove unnecessary #includes;
- Make various internal functions static;
- Use tabs consistently for indentation;
- Some reformatting of statements;
svn path=/trunk/; revision=27885
Diffstat (limited to 'epan/dissectors/packet-ldss.c')
-rw-r--r-- | epan/dissectors/packet-ldss.c | 415 |
1 files changed, 207 insertions, 208 deletions
diff --git a/epan/dissectors/packet-ldss.c b/epan/dissectors/packet-ldss.c index 53dfe757ee..bd8c5772ba 100644 --- a/epan/dissectors/packet-ldss.c +++ b/epan/dissectors/packet-ldss.c @@ -40,11 +40,6 @@ #include "config.h" #endif -#include <stdio.h> -#include <stdlib.h> -#include <gmodule.h> -#include <ctype.h> -#include <time.h> #include <math.h> #include <glib.h> #include <string.h> @@ -52,7 +47,6 @@ #include <epan/conversation.h> #include <epan/addr_resolv.h> #include <epan/ipproto.h> -#include <epan/nstime.h> #include <epan/prefs.h> #include <epan/strutil.h> #include <epan/dissectors/packet-tcp.h> @@ -65,33 +59,33 @@ const value_string ldss_message_id_value[] = { - { MESSAGE_ID_NEEDFILE, "Need file" }, - { MESSAGE_ID_WILLSEND, "Will send" }, - { 0, NULL } + { MESSAGE_ID_NEEDFILE, "Need file" }, + { MESSAGE_ID_WILLSEND, "Will send" }, + { 0, NULL } }; /* Message detail is inferred from various contents in the packet */ #define INFERRED_PEERSHUTDOWN 0 -#define INFERRED_SEARCH 1 -#define INFERRED_OFFER 2 -#define INFERRED_PROMISE 3 +#define INFERRED_SEARCH 1 +#define INFERRED_OFFER 2 +#define INFERRED_PROMISE 3 #define INFERRED_WANDOWNLOAD 4 -#define INFERRED_NONE 5 +#define INFERRED_NONE 5 /* Displayed in the info column */ const value_string ldss_inferred_info[] = { - { INFERRED_PEERSHUTDOWN, " - peer shutting down" }, - { INFERRED_SEARCH, " - search" }, - { INFERRED_OFFER, " - offer" }, - { INFERRED_PROMISE, " - promise" }, + { INFERRED_PEERSHUTDOWN, " - peer shutting down" }, + { INFERRED_SEARCH, " - search" }, + { INFERRED_OFFER, " - offer" }, + { INFERRED_PROMISE, " - promise" }, { INFERRED_WANDOWNLOAD, " - WAN download start" }, - { INFERRED_NONE, "" }, + { INFERRED_NONE, "" }, { 0, NULL } }; /* Displayed in the tree as a generated item */ const value_string ldss_inferred_value[] = { - { INFERRED_PEERSHUTDOWN, "Peer shutdown" }, + { INFERRED_PEERSHUTDOWN, "Peer shutdown" }, { INFERRED_SEARCH, "File search" }, { INFERRED_OFFER, "File offer" }, { INFERRED_PROMISE, "Promise (download in progress)" }, @@ -108,11 +102,11 @@ const value_string ldss_inferred_value[] = { const value_string ldss_digest_type_value[] = { - { DIGEST_TYPE_UNKNOWN, "Unknown" }, - { DIGEST_TYPE_MD5, "MD5" }, - { DIGEST_TYPE_SHA1, "SHA1" }, - { DIGEST_TYPE_SHA256, "SHA256" }, - { 0, NULL } + { DIGEST_TYPE_UNKNOWN, "Unknown" }, + { DIGEST_TYPE_MD5, "MD5" }, + { DIGEST_TYPE_SHA1, "SHA1" }, + { DIGEST_TYPE_SHA256, "SHA256" }, + { 0, NULL } }; @@ -121,9 +115,9 @@ const value_string ldss_digest_type_value[] = { const value_string ldss_compression_value[] = { - { COMPRESSION_NONE, "None" }, - { COMPRESSION_GZIP, "gzip" }, - { 0, NULL } + { COMPRESSION_NONE, "None" }, + { COMPRESSION_GZIP, "gzip" }, + { 0, NULL } }; /* Info about a broadcaster */ @@ -206,8 +200,8 @@ static int hf_ldss_transfer_response_time = -1; static int hf_ldss_transfer_completed_in = -1; /* Define the tree for ldss */ -static int ett_ldss_broadcast = -1; -static int ett_ldss_transfer = -1; +static int ett_ldss_broadcast = -1; +static int ett_ldss_transfer = -1; static int ett_ldss_transfer_req = -1; static dissector_handle_t ldss_handle; @@ -232,7 +226,7 @@ prepare_ldss_transfer_conv(ldss_broadcast_t *broadcast) /* Preparation for later push/pull dissection */ transfer_conv = conversation_new (broadcast->num, &broadcast->broadcaster->addr, &broadcast->broadcaster->addr, - PT_TCP, broadcast->broadcaster->port, broadcast->broadcaster->port, NO_ADDR2|NO_PORT2); + PT_TCP, broadcast->broadcaster->port, broadcast->broadcaster->port, NO_ADDR2|NO_PORT2); conversation_add_proto_data(transfer_conv, proto_ldss, transfer_info); conversation_set_dissector(transfer_conv, ldss_handle); } @@ -269,37 +263,37 @@ prepare_ldss_transfer_conv(ldss_broadcast_t *broadcast) * * Peers also notify when they shut down in case any other peer is waiting for * a file. */ -int +static int dissect_ldss_broadcast(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { - guint16 messageID; + guint16 messageID; guint8 digest_type; guint8 compression; - guint32 cookie; - guint8 *digest; - guint64 size; - guint64 offset; - guint32 targetTime; - guint16 port; - guint16 rate; - guint16 messageDetail = INFERRED_NONE; - - proto_tree *ti, *ldss_tree; - - const gchar *packet_type, *packet_detail; + guint32 cookie; + guint8 *digest; + guint64 size; + guint64 offset; + guint32 targetTime; + guint16 port; + guint16 rate; + guint16 messageDetail = INFERRED_NONE; + + proto_tree *ti, *ldss_tree; + + const gchar *packet_type, *packet_detail; - messageID = tvb_get_ntohs (tvb, 0); - digest_type = tvb_get_guint8(tvb, 2); - compression = tvb_get_guint8(tvb, 3); - cookie = tvb_get_ntohl (tvb, 4); - digest = tvb_memdup(tvb, 8, DIGEST_LEN); - size = tvb_get_ntoh64 (tvb, 40); - offset = tvb_get_ntoh64 (tvb, 48); - targetTime = tvb_get_ntohl (tvb, 56); - port = tvb_get_ntohs (tvb, 64); - rate = tvb_get_ntohs (tvb, 66); + messageID = tvb_get_ntohs (tvb, 0); + digest_type = tvb_get_guint8 (tvb, 2); + compression = tvb_get_guint8 (tvb, 3); + cookie = tvb_get_ntohl (tvb, 4); + digest = tvb_memdup (tvb, 8, DIGEST_LEN); + size = tvb_get_ntoh64 (tvb, 40); + offset = tvb_get_ntoh64 (tvb, 48); + targetTime = tvb_get_ntohl (tvb, 56); + port = tvb_get_ntohs (tvb, 64); + rate = tvb_get_ntohs (tvb, 66); - packet_type = val_to_str(messageID, ldss_message_id_value, "unknown"); + packet_type = val_to_str(messageID, ldss_message_id_value, "unknown"); if (messageID == MESSAGE_ID_WILLSEND) { if (cookie == 0) { @@ -325,77 +319,77 @@ dissect_ldss_broadcast(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } else if (messageID == MESSAGE_ID_NEEDFILE) { messageDetail = INFERRED_SEARCH; - } - packet_detail = val_to_str(messageDetail, ldss_inferred_info, "unknown"); + } + packet_detail = val_to_str(messageDetail, ldss_inferred_info, "unknown"); - /* Set the info column */ + /* Set the info column */ if (check_col(pinfo->cinfo, COL_INFO)) { col_add_fstr(pinfo->cinfo, COL_INFO, "LDSS Broadcast (%s%s)", - packet_type, - packet_detail); + packet_type, + packet_detail); } - /* If we have a non-null tree (ie we are building the proto_tree - * instead of just filling out the columns), then give more detail. */ - if (tree) { + /* If we have a non-null tree (ie we are building the proto_tree + * instead of just filling out the columns), then give more detail. */ + if (tree) { ti = proto_tree_add_item(tree, proto_ldss, - tvb, 0, (tvb_length(tvb) > 72) ? tvb_length(tvb) : 72, FALSE); + tvb, 0, (tvb_length(tvb) > 72) ? tvb_length(tvb) : 72, FALSE); ldss_tree = proto_item_add_subtree(ti, ett_ldss_broadcast); ti = proto_tree_add_item(ldss_tree, hf_ldss_message_id, - tvb, 0, 2, FALSE); + tvb, 0, 2, FALSE); ti = proto_tree_add_uint(ldss_tree, hf_ldss_message_detail, - tvb, 0, 0, messageDetail); + tvb, 0, 0, messageDetail); PROTO_ITEM_SET_GENERATED(ti); ti = proto_tree_add_item(ldss_tree, hf_ldss_digest_type, - tvb, 2, 1, FALSE); + tvb, 2, 1, FALSE); ti = proto_tree_add_item(ldss_tree, hf_ldss_compression, - tvb, 3, 1, FALSE); + tvb, 3, 1, FALSE); ti = proto_tree_add_uint_format_value(ldss_tree, hf_ldss_cookie, - tvb, 4, 4, FALSE, - "0x%x%s", - cookie, - (cookie == 0) - ? " - shutdown (promises from this peer are no longer valid)" - : ""); + tvb, 4, 4, FALSE, + "0x%x%s", + cookie, + (cookie == 0) + ? " - shutdown (promises from this peer are no longer valid)" + : ""); ti = proto_tree_add_item(ldss_tree, hf_ldss_digest, - tvb, 8, DIGEST_LEN, FALSE); + tvb, 8, DIGEST_LEN, FALSE); ti = proto_tree_add_item(ldss_tree, hf_ldss_size, - tvb, 40, 8, FALSE); + tvb, 40, 8, FALSE); ti = proto_tree_add_item(ldss_tree, hf_ldss_offset, - tvb, 48, 8, FALSE); + tvb, 48, 8, FALSE); ti = proto_tree_add_uint_format_value(ldss_tree, hf_ldss_target_time, - tvb, 56, 4, FALSE, - "%d:%02d:%02d", - (int)(targetTime / 3600), - (int)((targetTime / 60) % 60), - (int)(targetTime % 60)); + tvb, 56, 4, FALSE, + "%d:%02d:%02d", + (int)(targetTime / 3600), + (int)((targetTime / 60) % 60), + (int)(targetTime % 60)); ti = proto_tree_add_item(ldss_tree, hf_ldss_reserved_1, - tvb, 60, 4, FALSE); + tvb, 60, 4, FALSE); ti = proto_tree_add_uint_format_value(ldss_tree, hf_ldss_port, - tvb, 64, 2, FALSE, - "%d%s", - port, - (messageID == MESSAGE_ID_WILLSEND && - size > 0 && - size == offset) - ? " - file can be pulled at this TCP port" - : (messageID == MESSAGE_ID_NEEDFILE - ? " - file can be pushed to this TCP port" - : "")); + tvb, 64, 2, FALSE, + "%d%s", + port, + (messageID == MESSAGE_ID_WILLSEND && + size > 0 && + size == offset) + ? " - file can be pulled at this TCP port" + : (messageID == MESSAGE_ID_NEEDFILE + ? " - file can be pushed to this TCP port" + : "")); ti = proto_tree_add_uint_format_value(ldss_tree, hf_ldss_rate, - tvb, 66, 2, FALSE, - "%ld", - (rate > 0) - ? (long)floor(exp(rate * G_LN2 / 2048)) - : 0); + tvb, 66, 2, FALSE, + "%ld", + (rate > 0) + ? (long)floor(exp(rate * G_LN2 / 2048)) + : 0); ti = proto_tree_add_item(ldss_tree, hf_ldss_priority, - tvb, 68, 2, FALSE); + tvb, 68, 2, FALSE); ti = proto_tree_add_item(ldss_tree, hf_ldss_property_count, - tvb, 70, 2, FALSE); + tvb, 70, 2, FALSE); if (tvb_length(tvb) > 72) { ti = proto_tree_add_item(ldss_tree, hf_ldss_properties, - tvb, 72, tvb_length(tvb) - 72, FALSE); + tvb, 72, tvb_length(tvb) - 72, FALSE); } } @@ -411,8 +405,8 @@ dissect_ldss_broadcast(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * tracks the highest frame number seen. Handles the case of first frame * being frame zero. */ if (messageDetail != INFERRED_PEERSHUTDOWN && - (highest_num_seen == 0 || - highest_num_seen < pinfo->fd->num)) { + (highest_num_seen == 0 || + highest_num_seen < pinfo->fd->num)) { ldss_broadcast_t *data; @@ -459,7 +453,7 @@ dissect_ldss_broadcast(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * while pushes simply send the file. In practice this works because every * file the implementation sends searches for is on a different TCP port * on the searcher's machine. */ -int +static int dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { conversation_t *transfer_conv; @@ -473,7 +467,7 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* Look for the transfer conversation; this was created during * earlier broadcast dissection (see prepate_ldss_transfer_conv) */ transfer_conv = find_conversation (pinfo->fd->num, &pinfo->src, &pinfo->dst, - PT_TCP, pinfo->srcport, pinfo->destport, 0); + PT_TCP, pinfo->srcport, pinfo->destport, 0); transfer_info = conversation_get_proto_data(transfer_conv, proto_ldss); transfer_tcpinfo = pinfo->private_data; @@ -482,8 +476,8 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * File request only appears on a pull (triggered by an offer - see above * about broadcasts) */ if (transfer_tcpinfo->seq == 1 && - transfer_tcpinfo->lastackseq == 1 && - transfer_info->broadcast->message_id == MESSAGE_ID_WILLSEND) { + transfer_tcpinfo->lastackseq == 1 && + transfer_info->broadcast->message_id == MESSAGE_ID_WILLSEND) { /* LDSS pull transfers look a lot like HTTP. * Sample request: * md5:01234567890123... @@ -499,7 +493,7 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } if (highest_num_seen == 0 || - highest_num_seen < pinfo->fd->num) { + highest_num_seen < pinfo->fd->num) { already_dissected = FALSE; transfer_info->req = se_alloc0(sizeof(ldss_file_request_t)); @@ -508,9 +502,9 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } if (tree) { - ti = proto_tree_add_item(tree, proto_ldss, - tvb, 0, tvb_reported_length(tvb), FALSE); - ldss_tree = proto_item_add_subtree(ti, ett_ldss_transfer); + ti = proto_tree_add_item(tree, proto_ldss, + tvb, 0, tvb_reported_length(tvb), FALSE); + ldss_tree = proto_item_add_subtree(ti, ett_ldss_transfer); } /* Populate digest data into the file struct in the request */ @@ -526,16 +520,16 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) guint digest_type_len; linelen = tvb_find_line_end(tvb, offset, - tvb_ensure_length_remaining(tvb, offset), &next_offset, - FALSE); + tvb_ensure_length_remaining(tvb, offset), &next_offset, + FALSE); /* Include new-line in line */ line = tvb_memdup(tvb, offset, linelen+1); /* XXX - memory leak? */ if (tree) { ti = proto_tree_add_text(ldss_tree, tvb, offset, linelen, - "%s", - tvb_format_text(tvb, offset, next_offset-offset)); + "%s", + tvb_format_text(tvb, offset, next_offset-offset)); line_tree = proto_item_add_subtree(ti, ett_ldss_transfer_req); } @@ -570,7 +564,7 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) transfer_info->req->size = g_ascii_strtoull(line+6, NULL, 10); if (tree) { ti = proto_tree_add_uint64(line_tree, hf_ldss_size, - tvb, offset+6, linelen-6, transfer_info->req->size); + tvb, offset+6, linelen-6, transfer_info->req->size); PROTO_ITEM_SET_GENERATED(ti); } } @@ -580,7 +574,7 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) transfer_info->req->offset = g_ascii_strtoull(line+7, NULL, 10); if (tree) { ti = proto_tree_add_uint64(line_tree, hf_ldss_offset, - tvb, offset+7, linelen-7, transfer_info->req->offset); + tvb, offset+7, linelen-7, transfer_info->req->offset); PROTO_ITEM_SET_GENERATED(ti); } } @@ -590,14 +584,14 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) transfer_info->req->compression = (gint8)strtol(line+13, NULL, 10); /* XXX - bad cast */ if (tree) { ti = proto_tree_add_uint(line_tree, hf_ldss_compression, - tvb, offset+13, linelen-13, transfer_info->req->compression); + tvb, offset+13, linelen-13, transfer_info->req->compression); PROTO_ITEM_SET_GENERATED(ti); } } else { if (tree) { ti = proto_tree_add_text(line_tree, tvb, offset, linelen, - "Unrecognized line ignored"); + "Unrecognized line ignored"); PROTO_ITEM_SET_GENERATED(ti); } } @@ -623,11 +617,11 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_item *ti = NULL; ti = proto_tree_add_uint(line_tree, hf_ldss_digest_type, - tvb, offset, digest_type_len, transfer_info->file->digest_type); + tvb, offset, digest_type_len, transfer_info->file->digest_type); PROTO_ITEM_SET_GENERATED(ti); ti = proto_tree_add_bytes(line_tree, hf_ldss_digest, - tvb, offset+digest_type_len, linelen-digest_type_len, - transfer_info->file->digest); + tvb, offset+digest_type_len, linelen-digest_type_len, + transfer_info->file->digest); PROTO_ITEM_SET_GENERATED(ti); } } @@ -638,7 +632,7 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* Link forwards to the response for this pull. */ if (tree && transfer_info->resp_num != 0) { ti = proto_tree_add_uint(ldss_tree, hf_ldss_response_in, - tvb, 0, 0, transfer_info->resp_num); + tvb, 0, 0, transfer_info->resp_num); PROTO_ITEM_SET_GENERATED(ti); } @@ -657,7 +651,7 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * info from the offer broadcast which triggered this transfer. * If we cannot find the file request, default to the broadcast. */ if (transfer_info->broadcast->message_id == MESSAGE_ID_WILLSEND && - transfer_info->req != NULL) { + transfer_info->req != NULL) { transfer_info->file = transfer_info->req->file; size = transfer_info->req->size; offset = transfer_info->req->offset; @@ -687,22 +681,22 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if (check_col(pinfo->cinfo, COL_INFO)) { col_add_fstr(pinfo->cinfo, COL_INFO, "LDSS File Transfer (Sending file - %s)", - transfer_info->broadcast->message_id == MESSAGE_ID_WILLSEND - ? "pull" - : "push"); + transfer_info->broadcast->message_id == MESSAGE_ID_WILLSEND + ? "pull" + : "push"); } if (tree) { ti = proto_tree_add_item(tree, proto_ldss, - tvb, 0, tvb_reported_length(tvb), FALSE); + tvb, 0, tvb_reported_length(tvb), FALSE); ldss_tree = proto_item_add_subtree(ti, ett_ldss_transfer); ti = proto_tree_add_bytes_format(ldss_tree, hf_ldss_file_data, - tvb, 0, tvb_length(tvb), - tvb_get_ptr (tvb, 0, tvb_length(tvb)), - compression == COMPRESSION_GZIP - ? "Gzip compressed data: %d bytes" - : "File data: %d bytes", - tvb_length(tvb)); + tvb, 0, tvb_length(tvb), + tvb_get_ptr (tvb, 0, tvb_length(tvb)), + compression == COMPRESSION_GZIP + ? "Gzip compressed data: %d bytes" + : "File data: %d bytes", + tvb_length(tvb)); #ifdef HAVE_LIBZ /* Be nice and uncompress the file data. */ if (compression == COMPRESSION_GZIP) { @@ -710,15 +704,15 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) uncomp_tvb = tvb_uncompress(tvb, 0, tvb_length(tvb)); if (uncomp_tvb != NULL) { ti = proto_tree_add_bytes_format_value(ldss_tree, hf_ldss_file_data, - uncomp_tvb, 0, tvb_length(uncomp_tvb), - tvb_get_ptr (uncomp_tvb, 0, tvb_length(uncomp_tvb)), - "Uncompressed data: %d bytes", - tvb_length(uncomp_tvb)); + uncomp_tvb, 0, tvb_length(uncomp_tvb), + tvb_get_ptr (uncomp_tvb, 0, tvb_length(uncomp_tvb)), + "Uncompressed data: %d bytes", + tvb_length(uncomp_tvb)); } } #endif ti = proto_tree_add_uint(ldss_tree, hf_ldss_digest_type, - tvb, 0, 0, transfer_info->file->digest_type); + tvb, 0, 0, transfer_info->file->digest_type); PROTO_ITEM_SET_GENERATED(ti); if (transfer_info->file->digest != NULL) { /* This is ugly. You can't add bytes of nonzero length and have @@ -727,24 +721,24 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * are the digest, which they aren't: they're actually the first 32 * bytes of the file that was sent. */ ti = proto_tree_add_bytes(ldss_tree, hf_ldss_digest, - tvb, 0, DIGEST_LEN, transfer_info->file->digest); + tvb, 0, DIGEST_LEN, transfer_info->file->digest); } PROTO_ITEM_SET_GENERATED(ti); ti = proto_tree_add_uint64(ldss_tree, hf_ldss_size, - tvb, 0, 0, size); + tvb, 0, 0, size); PROTO_ITEM_SET_GENERATED(ti); ti = proto_tree_add_uint64(ldss_tree, hf_ldss_offset, - tvb, 0, 0, offset); + tvb, 0, 0, offset); PROTO_ITEM_SET_GENERATED(ti); ti = proto_tree_add_uint(ldss_tree, hf_ldss_compression, - tvb, 0, 0, compression); + tvb, 0, 0, compression); PROTO_ITEM_SET_GENERATED(ti); /* Link to the request for a pull. */ if (transfer_info->broadcast->message_id == MESSAGE_ID_WILLSEND && - transfer_info->req != NULL && - transfer_info->req->num != 0) { + transfer_info->req != NULL && + transfer_info->req->num != 0) { ti = proto_tree_add_uint(ldss_tree, hf_ldss_response_to, - tvb, 0, 0, transfer_info->req->num); + tvb, 0, 0, transfer_info->req->num); PROTO_ITEM_SET_GENERATED(ti); } } @@ -752,27 +746,27 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* Print the pull response time */ if (transfer_info->broadcast->message_id == MESSAGE_ID_WILLSEND && - transfer_info->req != NULL && - transfer_info->resp_num != 0) { + transfer_info->req != NULL && + transfer_info->resp_num != 0) { nstime_t pull_response_time; nstime_delta(&pull_response_time, &transfer_info->resp_ts, - &transfer_info->req->ts); + &transfer_info->req->ts); ti = proto_tree_add_time(ldss_tree, hf_ldss_transfer_response_time, - tvb, 0, 0, &pull_response_time); + tvb, 0, 0, &pull_response_time); PROTO_ITEM_SET_GENERATED(ti); } /* Link the transfer back to the initiating broadcast. Response time is * calculated as the time from broadcast to completed transfer. */ ti = proto_tree_add_uint(ldss_tree, hf_ldss_initiated_by, - tvb, 0, 0, transfer_info->broadcast->num); + tvb, 0, 0, transfer_info->broadcast->num); PROTO_ITEM_SET_GENERATED(ti); if (transfer_info->resp_num != 0) { nstime_delta(&broadcast_response_time, &transfer_info->resp_ts, - &transfer_info->broadcast->ts); + &transfer_info->broadcast->ts); ti = proto_tree_add_time(ldss_tree, hf_ldss_transfer_completed_in, - tvb, 0, 0, &broadcast_response_time); + tvb, 0, 0, &broadcast_response_time); PROTO_ITEM_SET_GENERATED(ti); } @@ -781,7 +775,7 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * to the addr/port mentioned in the broadcast, because that socket is * still open. */ if (transfer_tcpinfo->seq == 1 && - transfer_tcpinfo->lastackseq == 1) { + transfer_tcpinfo->lastackseq == 1) { prepare_ldss_transfer_conv(transfer_info->broadcast); } @@ -789,7 +783,7 @@ dissect_ldss_transfer (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) return tvb_length(tvb); } -gboolean +static gboolean is_broadcast(address* addr) { static address broadcast_addr; @@ -801,11 +795,11 @@ is_broadcast(address* addr) return ADDRESSES_EQUAL(addr, &broadcast_addr); } -int +static int dissect_ldss (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { if (is_broadcast(&pinfo->dl_dst) && - pinfo->ipproto == IP_PROTO_UDP) { + pinfo->ipproto == IP_PROTO_UDP) { if(check_col(pinfo->cinfo,COL_PROTOCOL)){ col_add_str(pinfo->cinfo,COL_PROTOCOL,"LDSS"); @@ -836,33 +830,33 @@ ldss_init_protocol(void) void proto_register_ldss (void) { - static hf_register_info hf[] = - { { &hf_ldss_message_id, + static hf_register_info hf[] = { + { &hf_ldss_message_id, { "LDSS Message ID", "ldss.ldss_message_id", FT_UINT16, BASE_DEC, ldss_message_id_value, 0x0, - "", HFILL + NULL, HFILL } }, - { &hf_ldss_message_detail, - { "Inferred meaning", + { &hf_ldss_message_detail, + { "Inferred meaning", "ldss.inferred_meaning", FT_UINT16, BASE_DEC, ldss_inferred_value, 0x0, "Inferred meaning of the packet", HFILL - } + } }, { &hf_ldss_digest_type, { "Digest Type", "ldss.digest_type", FT_UINT8, BASE_DEC, ldss_digest_type_value, 0x0, - "", HFILL + NULL, HFILL } }, { &hf_ldss_compression, { "Compressed Format", "ldss.compression", FT_UINT8, BASE_DEC, ldss_compression_value, 0x0, - "", HFILL + NULL, HFILL } }, { &hf_ldss_cookie, @@ -925,74 +919,74 @@ proto_register_ldss (void) { { "Priority", "ldss.priority", FT_UINT16, BASE_DEC, NULL, 0x0, - "", HFILL + NULL, HFILL } }, { &hf_ldss_property_count, { "Property Count", "ldss.property_count", FT_UINT16, BASE_DEC, NULL, 0x0, - "", HFILL + NULL, HFILL } }, { &hf_ldss_properties, { "Properties", "ldss.properties", FT_BYTES, BASE_HEX, NULL, 0x0, - "", HFILL + NULL, HFILL } }, { &hf_ldss_file_data, { "File data", "ldss.file_data", FT_BYTES, BASE_HEX, NULL, 0x0, - "", HFILL + NULL, HFILL } }, - { &hf_ldss_response_in, - { "Response In", - "ldss.response_in", - FT_FRAMENUM, BASE_DEC, NULL, 0x0, - "The response to this file pull request is in this frame", HFILL } + { &hf_ldss_response_in, + { "Response In", + "ldss.response_in", + FT_FRAMENUM, BASE_DEC, NULL, 0x0, + "The response to this file pull request is in this frame", HFILL } }, - { &hf_ldss_response_to, - { "Request In", - "ldss.response_to", - FT_FRAMENUM, BASE_DEC, NULL, 0x0, - "This is a response to the file pull request in this frame", HFILL } + { &hf_ldss_response_to, + { "Request In", + "ldss.response_to", + FT_FRAMENUM, BASE_DEC, NULL, 0x0, + "This is a response to the file pull request in this frame", HFILL } }, - { &hf_ldss_initiated_by, - { "Initiated by", - "ldss.initiated_by", - FT_FRAMENUM, BASE_DEC, NULL, 0x0, - "The broadcast that initiated this file transfer", HFILL } + { &hf_ldss_initiated_by, + { "Initiated by", + "ldss.initiated_by", + FT_FRAMENUM, BASE_DEC, NULL, 0x0, + "The broadcast that initiated this file transfer", HFILL } }, - { &hf_ldss_transfer_response_time, - { "Transfer response time", - "ldss.transfer_response_time", - FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0, - "The time between the request and the response for a pull transfer", HFILL } + { &hf_ldss_transfer_response_time, + { "Transfer response time", + "ldss.transfer_response_time", + FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0, + "The time between the request and the response for a pull transfer", HFILL } }, - { &hf_ldss_transfer_completed_in, - { "Transfer completed in", - "ldss.transfer_completed_in", - FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0, - "The time between requesting the file and completion of the file transfer", HFILL } + { &hf_ldss_transfer_completed_in, + { "Transfer completed in", + "ldss.transfer_completed_in", + FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0, + "The time between requesting the file and completion of the file transfer", HFILL } } - }; + }; - static gint *ett[] = { &ett_ldss_broadcast, &ett_ldss_transfer, &ett_ldss_transfer_req }; + static gint *ett[] = { &ett_ldss_broadcast, &ett_ldss_transfer, &ett_ldss_transfer_req }; - module_t *ldss_module; + module_t *ldss_module; - proto_ldss = proto_register_protocol( "Local Download Sharing Service", + proto_ldss = proto_register_protocol( "Local Download Sharing Service", "LDSS", "ldss"); - proto_register_field_array(proto_ldss, hf, array_length(hf)); - proto_register_subtree_array(ett, array_length(ett)); + proto_register_field_array(proto_ldss, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); - ldss_module = prefs_register_protocol( proto_ldss, + ldss_module = prefs_register_protocol( proto_ldss, proto_reg_handoff_ldss); - prefs_register_uint_preference( ldss_module, "udp_port", + prefs_register_uint_preference( ldss_module, "udp_port", "LDSS UDP Port", "The UDP port on which " "Local Download Sharing Service " @@ -1007,11 +1001,16 @@ proto_register_ldss (void) { void proto_reg_handoff_ldss (void) { - static gboolean ldss_initialized = FALSE; + static guint saved_udp_port_ldss; + static gboolean ldss_initialized = FALSE; - if (!ldss_initialized) { - ldss_handle = new_create_dissector_handle(dissect_ldss, proto_ldss); - dissector_add("udp.port", global_udp_port_ldss, ldss_handle); - ldss_initialized = TRUE; - } + if (!ldss_initialized) { + ldss_handle = new_create_dissector_handle(dissect_ldss, proto_ldss); + ldss_initialized = TRUE; + } + else { + dissector_delete("udp.port", saved_udp_port_ldss, ldss_handle); + } + dissector_add("udp.port", global_udp_port_ldss, ldss_handle); + saved_udp_port_ldss = global_udp_port_ldss; } |