2 * tap-rtspstat March 2011
4 * Stephane GORSE (Orange Labs / France Telecom)
5 * Copied from Jean-Michel FAYARD's works (HTTP)
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #include "epan/packet_info.h"
36 #include "epan/value_string.h"
38 #include <epan/stat_cmd_args.h>
40 #include <epan/dissectors/packet-rtsp.h>
43 /* used to keep track of the statictics for an entire program interface */
44 typedef struct _rtsp_stats_t {
46 GHashTable *hash_responses;
47 GHashTable *hash_requests;
50 /* used to keep track of the stats for a specific response code
51 * for example it can be { 3, 404, "Not Found" ,...}
52 * which means we captured 3 reply rtsp/1.1 404 Not Found */
53 typedef struct _rtsp_response_code_t {
54 guint32 packets; /* 3 */
55 guint response_code; /* 404 */
56 const gchar *name; /* Not Found */
58 } rtsp_response_code_t;
60 /* used to keep track of the stats for a specific request string */
61 typedef struct _rtsp_request_methode_t {
62 gchar *response; /* eg. : SETUP */
65 } rtsp_request_methode_t;
68 /* insert some entries */
70 rtsp_init_hash( rtspstat_t *sp)
74 sp->hash_responses = g_hash_table_new( g_int_hash, g_int_equal);
76 for (i=0 ; rtsp_status_code_vals[i].strptr ; i++ )
78 gint *key = g_malloc (sizeof(gint));
79 rtsp_response_code_t *sc = g_malloc (sizeof(rtsp_response_code_t));
80 *key = rtsp_status_code_vals[i].value;
82 sc->response_code = *key;
83 sc->name=rtsp_status_code_vals[i].strptr;
85 g_hash_table_insert( sc->sp->hash_responses, key, sc);
87 sp->hash_requests = g_hash_table_new( g_str_hash, g_str_equal);
90 rtsp_draw_hash_requests( gchar *key _U_ , rtsp_request_methode_t *data, gchar * format)
94 printf( format, data->response, data->packets);
98 rtsp_draw_hash_responses( gint * key _U_ , rtsp_response_code_t *data, char * format)
101 g_warning("No data available, key=%d\n", *key);
104 if (data->packets==0)
106 /* " RTSP %3d %-35s %9d packets", */
107 printf(format, data->response_code, data->name, data->packets );
112 /* NOT USED at this moment */
115 rtsp_free_hash( gpointer key, gpointer value, gpointer user_data _U_ )
122 rtsp_reset_hash_responses(gchar *key _U_ , rtsp_response_code_t *data, gpointer ptr _U_ )
127 rtsp_reset_hash_requests(gchar *key _U_ , rtsp_request_methode_t *data, gpointer ptr _U_ )
133 rtspstat_reset(void *psp )
137 g_hash_table_foreach( sp->hash_responses, (GHFunc)rtsp_reset_hash_responses, NULL);
138 g_hash_table_foreach( sp->hash_requests, (GHFunc)rtsp_reset_hash_requests, NULL);
143 rtspstat_packet(void *psp , packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
145 const rtsp_info_value_t *value=pri;
146 rtspstat_t *sp=(rtspstat_t *) psp;
148 /* We are only interested in reply packets with a status code */
149 /* Request or reply packets ? */
150 if (value->response_code!=0) {
151 guint *key=g_malloc( sizeof(guint) );
152 rtsp_response_code_t *sc;
154 *key=value->response_code;
155 sc = g_hash_table_lookup(
159 /* non standard status code ; we classify it as others
160 * in the relevant category (Informational,Success,Redirection,Client Error,Server Error)
162 int i = value->response_code;
163 if ((i<100) || (i>=600)) {
167 *key=199; /* Hopefully, this status code will never be used */
181 sc = g_hash_table_lookup(
189 else if (value->request_method){
190 rtsp_request_methode_t *sc;
192 sc = g_hash_table_lookup(
194 value->request_method);
196 sc=g_malloc( sizeof(rtsp_request_methode_t) );
197 sc->response=g_strdup( value->request_method );
200 g_hash_table_insert( sp->hash_requests, sc->response, sc);
212 rtspstat_draw(void *psp )
216 printf("===================================================================\n");
218 printf("RTSP Statistics\n");
220 printf("RTSP Statistics with filter %s\n", sp->filter);
222 printf( "* RTSP Status Codes in reply packets\n");
223 g_hash_table_foreach( sp->hash_responses, (GHFunc)rtsp_draw_hash_responses,
225 printf("* List of RTSP Request methods\n");
226 g_hash_table_foreach( sp->hash_requests, (GHFunc)rtsp_draw_hash_requests,
228 printf("===================================================================\n");
233 /* When called, this function will create a new instance of gtk_rtspstat.
236 gtk_rtspstat_init(const char *optarg,void* userdata _U_)
239 const char *filter=NULL;
240 GString *error_string;
242 if (!strncmp (optarg, "rtsp,stat,", 10)){
248 sp = g_malloc( sizeof(rtspstat_t) );
250 sp->filter=g_strdup(filter);
254 /*g_hash_table_foreach( rtsp_status, (GHFunc)rtsp_reset_hash_responses, NULL);*/
257 error_string = register_tap_listener(
266 /* error, we failed to attach to the tap. clean up */
269 fprintf (stderr, "tshark: Couldn't register rtsp,stat tap: %s\n",
271 g_string_free(error_string, TRUE);
279 register_tap_listener_gtkrtspstat(void)
281 register_stat_cmd_arg("rtsp,stat,", gtk_rtspstat_init,NULL);