For proto_tree_add_item(..., proto_xxx, ...)use ENC_NA as the encoding arg.
[obnox/wireshark/wip.git] / epan / dissectors / packet-rtp.c
index c2d6f3e4fa44b5df19b037c94e755a23f001012c..a8f9fdf21b765e59dbbc9dcb62dfa626a85ce70b 100644 (file)
@@ -219,8 +219,6 @@ static dissector_handle_t data_handle;
 void proto_reg_handoff_rtp(void);
 void proto_reg_handoff_pkt_ccc(void);
 
-static gboolean dissect_rtp_heur( tvbuff_t *tvb, packet_info *pinfo,
-    proto_tree *tree );
 static void dissect_rtp( tvbuff_t *tvb, packet_info *pinfo,
     proto_tree *tree );
 static void show_setup_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
@@ -676,11 +674,10 @@ void rtp_add_address(packet_info *pinfo,
 }
 
 static gboolean
-dissect_rtp_heur( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
+dissect_rtp_heur_common( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean check_destport )
 {
-       guint8      octet1, octet2;
+       guint8       octet1;
        unsigned int version;
-       unsigned int payload_type;
        unsigned int offset = 0;
 
        /* This is a heuristic dissector, which means we get all the UDP
@@ -722,25 +719,24 @@ dissect_rtp_heur( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
        }
 
        /* Was it sent to an even-numbered port? */
-       if ((pinfo->destport % 2) != 0) {
+       if (check_destport && ((pinfo->destport % 2) != 0)) {
                return FALSE;
        }
 
-       /* Get the fields in the second octet */
-       octet2 = tvb_get_guint8( tvb, offset + 1 );
-       payload_type = RTP_PAYLOAD_TYPE( octet2 );
+       dissect_rtp( tvb, pinfo, tree );
+       return TRUE;
+}
 
-       /* Check for a sensible payload type
-          (recognised static and preferred dynamic ranges) */
-       if ((payload_type <= PT_H263) ||
-               /* Alex Lindberg - Modified range to use RTP Type Names */
-           (payload_type >= PT_UNDF_96 && payload_type <= PT_UNDF_127)) {
-               dissect_rtp( tvb, pinfo, tree );
-               return TRUE;
-       }
-       else {
-               return FALSE;
-       }
+static gboolean
+dissect_rtp_heur_udp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
+{
+       return dissect_rtp_heur_common(tvb, pinfo, tree, TRUE);
+}
+
+static gboolean
+dissect_rtp_heur_stun( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
+{
+       return dissect_rtp_heur_common(tvb, pinfo, tree, FALSE);
 }
 
 /*
@@ -774,18 +770,18 @@ process_rtp_payload(tvbuff_t *newtvb, packet_info *pinfo, proto_tree *tree,
 #endif
                {
                        if (rtp_tree)
-                               proto_tree_add_item(rtp_tree, hf_srtp_encrypted_payload, newtvb, offset, payload_len, FALSE);
+                               proto_tree_add_item(rtp_tree, hf_srtp_encrypted_payload, newtvb, offset, payload_len, ENC_NA);
                        found_match = TRUE;     /* use this flag to prevent dissection below */
                }
                offset += payload_len;
 
                if (srtp_info->mki_len) {
-                       proto_tree_add_item(rtp_tree, hf_srtp_mki, newtvb, offset, srtp_info->mki_len, FALSE);
+                       proto_tree_add_item(rtp_tree, hf_srtp_mki, newtvb, offset, srtp_info->mki_len, ENC_NA);
                        offset += srtp_info->mki_len;
                }
 
                if (srtp_info->auth_tag_len) {
-                       proto_tree_add_item(rtp_tree, hf_srtp_auth_tag, newtvb, offset, srtp_info->auth_tag_len, FALSE);
+                       proto_tree_add_item(rtp_tree, hf_srtp_auth_tag, newtvb, offset, srtp_info->auth_tag_len, ENC_NA);
                        offset += srtp_info->auth_tag_len;
                }
        }
@@ -809,7 +805,7 @@ process_rtp_payload(tvbuff_t *newtvb, packet_info *pinfo, proto_tree *tree,
                                 * Just add it as data.
                                 */
                                if(found_match==FALSE)
-                                       proto_tree_add_item( rtp_tree, hf_rtp_data, newtvb, 0, -1, FALSE );
+                                       proto_tree_add_item( rtp_tree, hf_rtp_data, newtvb, 0, -1, ENC_NA );
                                return;
                        }
 
@@ -818,7 +814,7 @@ process_rtp_payload(tvbuff_t *newtvb, packet_info *pinfo, proto_tree *tree,
 
        /* if we don't found, it is static OR could be set static from the preferences */
        if (!found_match && !dissector_try_uint(rtp_pt_dissector_table, payload_type, newtvb, pinfo, tree))
-               proto_tree_add_item( rtp_tree, hf_rtp_data, newtvb, 0, -1, FALSE );
+               proto_tree_add_item( rtp_tree, hf_rtp_data, newtvb, 0, -1, ENC_NA );
 
 }
 
@@ -1093,7 +1089,7 @@ dissect_rtp_rfc2198(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
                /* Add a subtree for this header and add items */
                ti = proto_tree_add_text(rfc2198_tree, tvb, offset, (hdr_follow)?4:1, "Header %u", cnt);
                rfc2198_hdr_tree = proto_item_add_subtree(ti, ett_rtp_rfc2198_hdr);
-               proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_follow, tvb, offset, 1, FALSE );
+               proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_follow, tvb, offset, 1, ENC_BIG_ENDIAN );
                proto_tree_add_uint_format(rfc2198_hdr_tree, hf_rtp_payload_type, tvb,
                    offset, 1, octet1, "Payload type: %s (%u)",
                        payload_type_str ? payload_type_str : val_to_str_ext(hdr_new->pt, &rtp_payload_type_vals_ext, "Unknown"),
@@ -1105,8 +1101,8 @@ dissect_rtp_rfc2198(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
 
                /* Timestamp offset and block length don't apply to last header */
                if (hdr_follow) {
-                       proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_tm_off, tvb, offset, 2, FALSE );
-                       proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_bl_len, tvb, offset + 1, 2, FALSE );
+                       proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_tm_off, tvb, offset, 2, ENC_BIG_ENDIAN );
+                       proto_tree_add_item(rfc2198_hdr_tree, hf_rtp_rfc2198_bl_len, tvb, offset + 1, 2, ENC_BIG_ENDIAN );
                        hdr_new->len = tvb_get_ntohs(tvb, offset + 1) & 0x03FF;
                        proto_item_append_text(ti, ", len=%u", hdr_new->len);
                        offset += 3;
@@ -1216,7 +1212,7 @@ dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
                    "Unknown RTP version %u", version);
 
                if ( tree ) {
-                       ti = proto_tree_add_item( tree, proto_rtp, tvb, offset, -1, FALSE );
+                       ti = proto_tree_add_item( tree, proto_rtp, tvb, offset, -1, ENC_NA );
                        rtp_tree = proto_item_add_subtree( ti, ett_rtp );
 
                        proto_tree_add_uint( rtp_tree, hf_rtp_version, tvb,
@@ -1334,7 +1330,7 @@ dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
        if ( tree ) {
                proto_tree *item;
                /* Create RTP protocol tree */
-               ti = proto_tree_add_item(tree, proto_rtp, tvb, offset, -1, FALSE );
+               ti = proto_tree_add_item(tree, proto_rtp, tvb, offset, -1, ENC_NA );
                rtp_tree = proto_item_add_subtree(ti, ett_rtp );
 
                /* Conversation setup info */
@@ -1385,7 +1381,7 @@ dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
        if ( csrc_count > 0 ) {
                if ( tree ) {
                        ti = proto_tree_add_item(rtp_tree, hf_rtp_csrc_items, tvb, offset,
-                                                csrc_count * 4, FALSE);
+                                                csrc_count * 4, ENC_NA);
                        proto_item_append_text(ti, " (%u items)", csrc_count);
                        rtp_csrc_tree = proto_item_add_subtree( ti, ett_csrc_list );
                }
@@ -1411,7 +1407,7 @@ dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
                offset += 2;
                if ( hdr_extension > 0 ) {
                        if ( tree ) {
-                               ti = proto_tree_add_item(rtp_tree, hf_rtp_hdr_exts, tvb, offset, hdr_extension * 4, FALSE);
+                               ti = proto_tree_add_item(rtp_tree, hf_rtp_hdr_exts, tvb, offset, hdr_extension * 4, ENC_NA);
                                rtp_hext_tree = proto_item_add_subtree( ti, ett_hdr_ext );
                        }
 
@@ -1494,7 +1490,7 @@ dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
                         * data.
                         */
                        if ( tree ) proto_tree_add_item( rtp_tree, hf_rtp_padding_data,
-                           tvb, offset, padding_count - 1, FALSE );
+                           tvb, offset, padding_count - 1, ENC_NA );
                        offset += padding_count - 1;
                }
                /*
@@ -1502,7 +1498,7 @@ dissect_rtp( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
                 * count.
                 */
                if ( tree ) proto_tree_add_item( rtp_tree, hf_rtp_padding_count,
-                   tvb, offset, 1, FALSE );
+                   tvb, offset, 1, ENC_BIG_ENDIAN );
        }
        else {
                /*
@@ -1625,10 +1621,10 @@ dissect_pkt_ccc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        proto_tree *pkt_ccc_tree      = NULL;
 
        if ( tree ) {
-               ti = proto_tree_add_item(tree, proto_pkt_ccc, tvb, 0, 12, FALSE);
+               ti = proto_tree_add_item(tree, proto_pkt_ccc, tvb, 0, 12, ENC_NA);
                pkt_ccc_tree = proto_item_add_subtree(ti, ett_pkt_ccc);
 
-               proto_tree_add_item(pkt_ccc_tree, hf_pkt_ccc_id, tvb, 0, 4, FALSE);
+               proto_tree_add_item(pkt_ccc_tree, hf_pkt_ccc_id, tvb, 0, 4, ENC_BIG_ENDIAN);
                proto_tree_add_item(pkt_ccc_tree, hf_pkt_ccc_ts, tvb, 4, 8,
                                    ENC_TIME_NTP|ENC_BIG_ENDIAN);
        }
@@ -2183,8 +2179,8 @@ proto_reg_handoff_rtp(void)
 
                dissector_add_handle("udp.port", rtp_handle);  /* for 'decode-as' */
                dissector_add_string("rtp_dyn_payload_type", "red", rtp_rfc2198_handle);
-               heur_dissector_add( "udp", dissect_rtp_heur, proto_rtp);
-               heur_dissector_add("stun", dissect_rtp_heur, proto_rtp);
+               heur_dissector_add( "udp", dissect_rtp_heur_udp,  proto_rtp);
+               heur_dissector_add("stun", dissect_rtp_heur_stun, proto_rtp);
 
                data_handle = find_dissector("data");
                classicstun_handle = find_dissector("classicstun");