make dissect_ber_choice take a guint* that will return the
[obnox/wireshark/wip.git] / epan / dissectors / packet-media.c
1 /* packet-media.c
2  * Routines for displaying an undissected media type (default case),
3  * based on the generic "data" dissector.
4  *
5  * (C) Olivier Biot, 2004
6  *
7  * $Id$
8  *
9  * Refer to the AUTHORS file or the AUTHORS section in the man page
10  * for contacting the author(s) of this file.
11  *
12  * Ethereal - Network traffic analyzer
13  * By Gerald Combs <gerald@ethereal.com>
14  * Copyright 1998 Gerald Combs
15  *
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
29  */
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include <glib.h>
36 #include <epan/packet.h>
37
38 /* proto_media cannot be static because it's referenced in the
39  * print routines
40  */
41 int proto_media = -1;
42
43 static void
44 dissect_media(tvbuff_t *tvb, packet_info *pinfo , proto_tree *tree)
45 {
46     int bytes;
47
48     /* Add media type to the INFO column if it is visible */
49     if (check_col(pinfo->cinfo, COL_INFO)) {
50         col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)", pinfo->match_string);
51     }
52
53     if (tree) {
54         bytes = tvb_length_remaining(tvb, 0);
55         if (bytes > 0) {
56             if (pinfo->private_data) {
57                 /* The media type has parameters */
58                 proto_tree_add_protocol_format(tree, proto_media, tvb, 0, bytes,
59                     "Media Type: %s; %s (%d byte%s)",
60                     pinfo->match_string, (char *)pinfo->private_data,
61                     bytes, plurality(bytes, "", "s"));
62             } else {
63                 /* The media type has no parameters */
64                 proto_tree_add_protocol_format(tree, proto_media, tvb, 0, bytes,
65                     "Media Type: %s (%d byte%s)",
66                     pinfo->match_string,
67                     bytes, plurality(bytes, "", "s"));
68             }
69         }
70     }
71 }
72
73 void
74 proto_register_media(void)
75 {
76     proto_media = proto_register_protocol (
77             "Media Type",       /* name */
78             "Media",            /* short name */
79             "media"             /* abbrev */
80             );
81     register_dissector("media", dissect_media, proto_media);
82
83     /*
84      * "Media" is used to dissect something whose normal dissector
85      * is disabled, so it cannot itself be disabled.
86      */
87     proto_set_cant_toggle(proto_media);
88 }