diff options
author | Bill Meier <wmeier@newsguy.com> | 2015-01-30 13:49:59 -0500 |
---|---|---|
committer | Bill Meier <wmeier@newsguy.com> | 2015-01-30 19:04:32 +0000 |
commit | eda485ea53c7ac77470f47e886b6513f28f0c20b (patch) | |
tree | 6b5adad845db04d441bb5a177f0ce8fe6cb92346 /epan/dissectors/packet-applemidi.c | |
parent | 7b929e2ff78c5196e5ab7c4413b0eae1b542e445 (diff) |
Cleanup:
Including:
tvb_length...() ==> tvb_reported_length...()
Remove some dead initializers;
Localize some variables;
Whitespace.
Change-Id: Ide9490f248d558bb7e3af96a1fc17d8f911de4ef
Reviewed-on: https://code.wireshark.org/review/6862
Reviewed-by: Bill Meier <wmeier@newsguy.com>
Diffstat (limited to 'epan/dissectors/packet-applemidi.c')
-rw-r--r-- | epan/dissectors/packet-applemidi.c | 149 |
1 files changed, 73 insertions, 76 deletions
diff --git a/epan/dissectors/packet-applemidi.c b/epan/dissectors/packet-applemidi.c index ea7062e9aa..8a9c424dc2 100644 --- a/epan/dissectors/packet-applemidi.c +++ b/epan/dissectors/packet-applemidi.c @@ -116,6 +116,7 @@ static const char applemidi_unknown_command[] = "unknown command: 0x%04x"; static void dissect_applemidi_common( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint16 command ) { + proto_item *ti; guint16 seq_num; guint8 count; guint8 *name; @@ -130,103 +131,100 @@ dissect_applemidi_common( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, g col_add_fstr( pinfo->cinfo, COL_INFO, "%s", val_to_str( command, applemidi_commands, applemidi_unknown_command ) ); - /* if ( tree ) */ { - proto_item *ti; - ti = proto_tree_add_item( tree, proto_applemidi, tvb, 0, -1, ENC_NA ); - applemidi_tree = proto_item_add_subtree( ti, ett_applemidi ); + ti = proto_tree_add_item( tree, proto_applemidi, tvb, 0, -1, ENC_NA ); + applemidi_tree = proto_item_add_subtree( ti, ett_applemidi ); - proto_tree_add_item( applemidi_tree, hf_applemidi_signature, tvb, offset, 2, ENC_BIG_ENDIAN ); - offset += 2; + proto_tree_add_item( applemidi_tree, hf_applemidi_signature, tvb, offset, 2, ENC_BIG_ENDIAN ); + offset += 2; - proto_tree_add_item( applemidi_tree, hf_applemidi_command, tvb, offset, 2, ENC_BIG_ENDIAN ); - offset += 2; + proto_tree_add_item( applemidi_tree, hf_applemidi_command, tvb, offset, 2, ENC_BIG_ENDIAN ); + offset += 2; - /* the format of packets for "IN", "NO", "OK" and "BY" is identical and contains - * the protocol version, a random number generated by the initiator of the session, - * the SSRC that is used by the respective sides RTP-entity and optionally the - * name of the participant */ - if ( ( APPLEMIDI_COMMAND_INVITATION == command ) || - ( APPLEMIDI_COMMAND_INVITATION_REJECTED == command ) || - ( APLLEMIDI_COMMAND_INVITATION_ACCEPTED == command ) || - ( APPLEMIDI_COMMAND_ENDSESSION == command ) ) { + /* the format of packets for "IN", "NO", "OK" and "BY" is identical and contains + * the protocol version, a random number generated by the initiator of the session, + * the SSRC that is used by the respective sides RTP-entity and optionally the + * name of the participant */ + if ( ( APPLEMIDI_COMMAND_INVITATION == command ) || + ( APPLEMIDI_COMMAND_INVITATION_REJECTED == command ) || + ( APLLEMIDI_COMMAND_INVITATION_ACCEPTED == command ) || + ( APPLEMIDI_COMMAND_ENDSESSION == command ) ) { - proto_tree_add_item( applemidi_tree, hf_applemidi_protocol_version, tvb, offset, 4, ENC_BIG_ENDIAN ); - offset += 4; + proto_tree_add_item( applemidi_tree, hf_applemidi_protocol_version, tvb, offset, 4, ENC_BIG_ENDIAN ); + offset += 4; - proto_tree_add_item( applemidi_tree, hf_applemidi_token, tvb, offset, 4, ENC_BIG_ENDIAN ); - offset += 4; + proto_tree_add_item( applemidi_tree, hf_applemidi_token, tvb, offset, 4, ENC_BIG_ENDIAN ); + offset += 4; - proto_tree_add_item( applemidi_tree, hf_applemidi_ssrc, tvb, offset, 4, ENC_BIG_ENDIAN ); - offset += 4; + proto_tree_add_item( applemidi_tree, hf_applemidi_ssrc, tvb, offset, 4, ENC_BIG_ENDIAN ); + offset += 4; - len = tvb_reported_length(tvb) - offset; + len = tvb_reported_length(tvb) - offset; - /* Name is optional */ - if ( len > 0 ) { - name = tvb_get_string_enc( wmem_packet_scope(), tvb, offset, len, ENC_UTF_8|ENC_NA ); - string_size = (gint)( strlen( name ) + 1 ); - proto_tree_add_item( applemidi_tree, hf_applemidi_name, tvb, offset, string_size, ENC_UTF_8|ENC_NA ); - col_append_fstr( pinfo->cinfo, COL_INFO, ": peer = \"%s\"", name ); - offset += string_size; - } + /* Name is optional */ + if ( len > 0 ) { + name = tvb_get_string_enc( wmem_packet_scope(), tvb, offset, len, ENC_UTF_8|ENC_NA ); + string_size = (gint)( strlen( name ) + 1 ); + proto_tree_add_item( applemidi_tree, hf_applemidi_name, tvb, offset, string_size, ENC_UTF_8|ENC_NA ); + col_append_fstr( pinfo->cinfo, COL_INFO, ": peer = \"%s\"", name ); + offset += string_size; + } /* the synchronization packet contains three 64bit timestamps, and a value to define how * many of the timestamps transmitted are valid */ - } else if ( APPLEMIDI_COMMAND_SYNCHRONIZATION == command ) { - proto_tree_add_item( applemidi_tree, hf_applemidi_ssrc, tvb, offset, 4, ENC_BIG_ENDIAN ); - offset += 4; + } else if ( APPLEMIDI_COMMAND_SYNCHRONIZATION == command ) { + proto_tree_add_item( applemidi_tree, hf_applemidi_ssrc, tvb, offset, 4, ENC_BIG_ENDIAN ); + offset += 4; - count = tvb_get_guint8( tvb, offset ); - proto_tree_add_item( applemidi_tree, hf_applemidi_count, tvb, offset, 1, ENC_BIG_ENDIAN ); - col_append_fstr( pinfo->cinfo, COL_INFO, ": count = %u", count ); - offset += 1; + count = tvb_get_guint8( tvb, offset ); + proto_tree_add_item( applemidi_tree, hf_applemidi_count, tvb, offset, 1, ENC_BIG_ENDIAN ); + col_append_fstr( pinfo->cinfo, COL_INFO, ": count = %u", count ); + offset += 1; - proto_tree_add_item( applemidi_tree, hf_applemidi_padding, tvb, offset, 3, ENC_BIG_ENDIAN ); - offset += 3; + proto_tree_add_item( applemidi_tree, hf_applemidi_padding, tvb, offset, 3, ENC_BIG_ENDIAN ); + offset += 3; - proto_tree_add_item( applemidi_tree, hf_applemidi_timestamp1, tvb, offset, 8, ENC_BIG_ENDIAN ); - offset += 8; + proto_tree_add_item( applemidi_tree, hf_applemidi_timestamp1, tvb, offset, 8, ENC_BIG_ENDIAN ); + offset += 8; - proto_tree_add_item( applemidi_tree, hf_applemidi_timestamp2, tvb, offset, 8, ENC_BIG_ENDIAN ); - offset += 8; + proto_tree_add_item( applemidi_tree, hf_applemidi_timestamp2, tvb, offset, 8, ENC_BIG_ENDIAN ); + offset += 8; - proto_tree_add_item( applemidi_tree, hf_applemidi_timestamp3, tvb, offset, 8, ENC_BIG_ENDIAN ); - offset += 8; + proto_tree_add_item( applemidi_tree, hf_applemidi_timestamp3, tvb, offset, 8, ENC_BIG_ENDIAN ); + offset += 8; /* With the receiver feedback packet, the recipient can tell the sender up to what sequence * number in the RTP-stream the packets have been received; this can be used to shorten the * recovery-journal-section in the RTP-session */ - } else if ( APPLEMIDI_COMMAND_RECEIVER_FEEDBACK == command ) { - proto_tree_add_item( applemidi_tree, hf_applemidi_ssrc, tvb, offset, 4, ENC_BIG_ENDIAN ); - offset += 4; - - ti = proto_tree_add_item( applemidi_tree, hf_applemidi_sequence_num, tvb, offset, 4, ENC_BIG_ENDIAN ); - /* Apple includes a 32bit sequence-number, but the RTP-packet only specifies 16bit. - * this subtree and subitem are added to be able to associate the sequence-number - * here easier with the one specified in the corresponding RTP-packet */ - applemidi_tree_seq_num = proto_item_add_subtree( ti, ett_applemidi_seq_num ); - seq_num = tvb_get_ntohs( tvb, offset ); - proto_tree_add_uint( applemidi_tree_seq_num, hf_applemidi_rtp_sequence_num, tvb, offset, 2, seq_num ); - offset += 4; - - col_append_fstr( pinfo->cinfo, COL_INFO, ": seq = %u", seq_num ); + } else if ( APPLEMIDI_COMMAND_RECEIVER_FEEDBACK == command ) { + proto_tree_add_item( applemidi_tree, hf_applemidi_ssrc, tvb, offset, 4, ENC_BIG_ENDIAN ); + offset += 4; + + ti = proto_tree_add_item( applemidi_tree, hf_applemidi_sequence_num, tvb, offset, 4, ENC_BIG_ENDIAN ); + /* Apple includes a 32bit sequence-number, but the RTP-packet only specifies 16bit. + * this subtree and subitem are added to be able to associate the sequence-number + * here easier with the one specified in the corresponding RTP-packet */ + applemidi_tree_seq_num = proto_item_add_subtree( ti, ett_applemidi_seq_num ); + seq_num = tvb_get_ntohs( tvb, offset ); + proto_tree_add_uint( applemidi_tree_seq_num, hf_applemidi_rtp_sequence_num, tvb, offset, 2, seq_num ); + offset += 4; + + col_append_fstr( pinfo->cinfo, COL_INFO, ": seq = %u", seq_num ); /* With the bitrate receive limit packet, the recipient can tell the sender to limit the transmission to a certain bitrate. This is important if the peer is a gateway to a hardware-device that only supports a certain speed. Like the MIDI 1.0 DIN-cable MIDI-implementation which is limited to 31250. */ - } else if ( APPLEMIDI_COMMAND_BITRATE_RECEIVE_LIMIT == command ) { - proto_tree_add_item( applemidi_tree, hf_applemidi_ssrc, tvb, offset, 4, ENC_BIG_ENDIAN ); - offset += 4; + } else if ( APPLEMIDI_COMMAND_BITRATE_RECEIVE_LIMIT == command ) { + proto_tree_add_item( applemidi_tree, hf_applemidi_ssrc, tvb, offset, 4, ENC_BIG_ENDIAN ); + offset += 4; - proto_tree_add_item( applemidi_tree, hf_applemidi_rtp_bitrate_limit, - tvb, offset, 4, ENC_BIG_ENDIAN ); - offset += 4; - } - /* If there is any remaining data (possibly because an unknown command was encountered), - * we just dump it here */ - len = tvb_length_remaining( tvb, offset ); - if ( len > 0 ) { - proto_tree_add_item( applemidi_tree, hf_applemidi_unknown_data, tvb, offset, len, ENC_NA ); - } + proto_tree_add_item( applemidi_tree, hf_applemidi_rtp_bitrate_limit, + tvb, offset, 4, ENC_BIG_ENDIAN ); + offset += 4; + } + /* If there is any remaining data (possibly because an unknown command was encountered), + * we just dump it here */ + len = tvb_reported_length_remaining( tvb, offset ); + if ( len > 0 ) { + proto_tree_add_item( applemidi_tree, hf_applemidi_unknown_data, tvb, offset, len, ENC_NA ); } } @@ -282,10 +280,9 @@ dissect_applemidi_heur( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi guint16 command; conversation_t *p_conv; - /*struct _rtp_conversation_info *p_conv_data = NULL;*/ - rtp_dyn_payload_t *rtp_dyn_payload = NULL; + rtp_dyn_payload_t *rtp_dyn_payload; - if ( tvb_length( tvb ) < 4) + if ( tvb_captured_length( tvb ) < 4) return FALSE; /* not enough bytes to check */ if ( !test_applemidi( tvb, &command, FALSE ) ) { |