2 * Routines for SDP packet disassembly (RFC 2327)
4 * Jason Lango <jal@netapp.com>
5 * Liberally copied from packet-http.c, by Guy Harris <guy@alum.mit.edu>
7 * $Id: packet-sdp.c,v 1.45 2004/01/16 19:51:55 guy Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
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.
33 #include <sys/types.h>
34 #ifdef HAVE_SYS_SOCKET_H
35 #include <sys/socket.h>
37 #ifdef HAVE_NETINET_IN_H
38 # include <netinet/in.h>
40 #ifdef HAVE_ARPA_INET_H
41 #include <arpa/inet.h>
43 #ifdef NEED_INET_ATON_H
44 # include <epan/inet_aton.h>
48 #include <epan/packet.h>
49 #include <epan/conversation.h>
50 #include <epan/strutil.h>
52 static dissector_handle_t rtp_handle=NULL;
53 static dissector_handle_t rtcp_handle=NULL;
55 static int proto_sdp = -1;
57 /* Top level fields */
58 static int hf_protocol_version = -1;
59 static int hf_owner = -1;
60 static int hf_session_name = -1;
61 static int hf_session_info = -1;
62 static int hf_uri = -1;
63 static int hf_email = -1;
64 static int hf_phone = -1;
65 static int hf_connection_info = -1;
66 static int hf_bandwidth = -1;
67 static int hf_timezone = -1;
68 static int hf_encryption_key = -1;
69 static int hf_session_attribute = -1;
70 static int hf_media_attribute = -1;
71 static int hf_time = -1;
72 static int hf_repeat_time = -1;
73 static int hf_media = -1;
74 static int hf_media_title = -1;
75 static int hf_unknown = -1;
76 static int hf_invalid = -1;
78 /* hf_owner subfields*/
79 static int hf_owner_username = -1;
80 static int hf_owner_sessionid = -1;
81 static int hf_owner_version = -1;
82 static int hf_owner_network_type = -1;
83 static int hf_owner_address_type = -1;
84 static int hf_owner_address = -1;
86 /* hf_connection_info subfields */
87 static int hf_connection_info_network_type = -1;
88 static int hf_connection_info_address_type = -1;
89 static int hf_connection_info_connection_address = -1;
90 static int hf_connection_info_ttl = -1;
91 static int hf_connection_info_num_addr = -1;
93 /* hf_bandwidth subfields */
94 static int hf_bandwidth_modifier = -1;
95 static int hf_bandwidth_value = -1;
97 /* hf_time subfields */
98 static int hf_time_start = -1;
99 static int hf_time_stop = -1;
101 /* hf_repeat_time subfield */
102 static int hf_repeat_time_interval = -1;
103 static int hf_repeat_time_duration = -1;
104 static int hf_repeat_time_offset = -1;
106 /* hf_timezone subfields */
107 static int hf_timezone_time = -1;
108 static int hf_timezone_offset = -1;
110 /* hf_encryption_key subfields */
111 static int hf_encryption_key_type = -1;
112 static int hf_encryption_key_data = -1;
114 /* hf_session_attribute subfields */
115 static int hf_session_attribute_field = -1;
116 static int hf_session_attribute_value = -1;
118 /* hf_media subfields */
119 static int hf_media_media = -1;
120 static int hf_media_port = -1;
121 static int hf_media_portcount = -1;
122 static int hf_media_proto = -1;
123 static int hf_media_format = -1;
125 /* hf_session_attribute subfields */
126 static int hf_media_attribute_field = -1;
127 static int hf_media_attribute_value = -1;
130 static int ett_sdp = -1;
131 static int ett_sdp_owner = -1;
132 static int ett_sdp_connection_info = -1;
133 static int ett_sdp_bandwidth = -1;
134 static int ett_sdp_time = -1;
135 static int ett_sdp_repeat_time = -1;
136 static int ett_sdp_timezone = -1;
137 static int ett_sdp_encryption_key = -1;
138 static int ett_sdp_session_attribute = -1;
139 static int ett_sdp_media = -1;
140 static int ett_sdp_media_attribute = -1;
143 #define SDP_MAX_RTP_CHANNELS 4
146 char *connection_address;
147 char *connection_type;
148 char *media_port[SDP_MAX_RTP_CHANNELS];
149 char *media_proto[SDP_MAX_RTP_CHANNELS];
153 /* static functions */
155 static void call_sdp_subdissector(tvbuff_t *tvb, int hf, proto_tree* ti,
156 transport_info_t *transport_info);
158 /* Subdissector functions */
159 static void dissect_sdp_owner(tvbuff_t *tvb, proto_item* ti);
160 static void dissect_sdp_connection_info(tvbuff_t *tvb, proto_item* ti,
161 transport_info_t *transport_info);
162 static void dissect_sdp_bandwidth(tvbuff_t *tvb, proto_item *ti);
163 static void dissect_sdp_time(tvbuff_t *tvb, proto_item* ti);
164 static void dissect_sdp_repeat_time(tvbuff_t *tvb, proto_item* ti);
165 static void dissect_sdp_timezone(tvbuff_t *tvb, proto_item* ti);
166 static void dissect_sdp_encryption_key(tvbuff_t *tvb, proto_item * ti);
167 static void dissect_sdp_session_attribute(tvbuff_t *tvb, proto_item *ti);
168 static void dissect_sdp_media(tvbuff_t *tvb, proto_item *ti,
169 transport_info_t *transport_info);
170 static void dissect_sdp_media_attribute(tvbuff_t *tvb, proto_item *ti);
173 dissect_sdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
175 proto_tree *sdp_tree;
176 proto_item *ti, *sub_ti;
180 gboolean in_media_description;
189 conversation_t *conv=NULL;
191 transport_info_t transport_info;
193 guint32 ipv4_address=0;
195 gboolean is_rtp=FALSE;
196 gboolean is_ipv4_addr=FALSE;
197 struct in_addr ipaddr;
200 /* Initialise RTP channel info */
201 transport_info.connection_address=NULL;
202 transport_info.connection_type=NULL;
203 for (n=0; n < SDP_MAX_RTP_CHANNELS; n++)
205 transport_info.media_port[n]=NULL;
206 transport_info.media_proto[n]=NULL;
208 transport_info.media_count = 0;
212 * As RFC 2327 says, "SDP is purely a format for session
213 * description - it does not incorporate a transport protocol,
214 * and is intended to use different transport protocols as
215 * appropriate including the Session Announcement Protocol,
216 * Session Initiation Protocol, Real-Time Streaming Protocol,
217 * electronic mail using the MIME extensions, and the
218 * Hypertext Transport Protocol."
220 * We therefore don't set the protocol or info columns;
221 * instead, we append to them, so that we don't erase
222 * what the protocol inside which the SDP stuff resides
225 if (check_col(pinfo->cinfo, COL_PROTOCOL))
226 col_append_str(pinfo->cinfo, COL_PROTOCOL, "/SDP");
228 if (check_col(pinfo->cinfo, COL_INFO)) {
229 /* XXX: Needs description. */
230 col_append_str(pinfo->cinfo, COL_INFO, ", with session description");
233 ti = proto_tree_add_item(tree, proto_sdp, tvb, offset, -1, FALSE);
234 sdp_tree = proto_item_add_subtree(ti, ett_sdp);
237 * Show the SDP message a line at a time.
239 in_media_description = FALSE;
240 while (tvb_reported_length_remaining(tvb, offset) > 0) {
242 * Find the end of the line.
244 linelen = tvb_find_line_end_unquoted(tvb, offset, -1,
248 * Line must contain at least e.g. "v=".
253 type = tvb_get_guint8(tvb,offset);
254 delim = tvb_get_guint8(tvb,offset + 1);
256 proto_tree_add_item(sdp_tree,hf_invalid,tvb, offset,
258 offset = next_offset;
267 hf = hf_protocol_version;
273 hf = hf_session_name;
276 if (in_media_description) {
280 hf = hf_session_info;
293 hf = hf_connection_info;
306 in_media_description = TRUE;
309 hf = hf_encryption_key;
312 if (in_media_description) {
313 hf = hf_media_attribute;
316 hf = hf_session_attribute;
327 if (hf == hf_unknown)
329 string = tvb_get_string(tvb, offset + tokenoffset,
330 linelen - tokenoffset);
331 sub_ti = proto_tree_add_string_format(sdp_tree,hf,tvb, offset,
334 proto_registrar_get_name(hf),
336 linelen - tokenoffset));
338 call_sdp_subdissector(tvb_new_subset(tvb,offset+tokenoffset,
340 linelen-tokenoffset),
341 hf,sub_ti,&transport_info),
342 offset = next_offset;
346 /* Now look, if we have strings collected.
347 * Try to convert ipv4 addresses and ports into binary format,
348 * so we can use them to detect rtp and rtcp streams.
349 * Don't forget to free the strings!
352 for (n = 0; n < transport_info.media_count; n++)
354 if(transport_info.media_port[n]!=NULL) {
355 ipv4_port = atol(transport_info.media_port[n]);
356 g_free(transport_info.media_port[n]);
358 if(transport_info.media_proto[n]!=NULL) {
359 /* Check if media protocol is RTP */
360 is_rtp = (strcmp(transport_info.media_proto[n],"RTP/AVP")==0);
361 g_free(transport_info.media_proto[n]);
363 if(transport_info.connection_address!=NULL) {
364 if(transport_info.connection_type!=NULL &&
365 strcmp(transport_info.connection_type,"IP4")==0) {
366 if(inet_aton(transport_info.connection_address, &ipaddr)
368 /* connection_address could be converted to a valid ipv4 address*/
370 ipv4_address = ipaddr.s_addr;
375 /* Add rtp and rtcp conversation, if available */
376 if((!pinfo->fd->flags.visited) && ipv4_address!=0 && ipv4_port!=0 && is_rtp && is_ipv4_addr){
377 src_addr.type=AT_IPv4;
379 src_addr.data=(char *)&ipv4_address;
382 conv=find_conversation(&src_addr, &src_addr, PT_UDP, ipv4_port, ipv4_port, NO_ADDR_B|NO_PORT_B);
384 conv=conversation_new(&src_addr, &src_addr, PT_UDP, ipv4_port, ipv4_port, NO_ADDR2|NO_PORT2);
385 conversation_set_dissector(conv, rtp_handle);
391 conv=find_conversation(&src_addr, &src_addr, PT_UDP, ipv4_port, ipv4_port, NO_ADDR_B|NO_PORT_B);
393 conv=conversation_new(&src_addr, &src_addr, PT_UDP, ipv4_port, ipv4_port, NO_ADDR2|NO_PORT2);
394 conversation_set_dissector(conv, rtcp_handle);
400 /* Free up 'connection info' strings */
401 if(transport_info.connection_address) {
402 g_free(transport_info.connection_address);
404 if(transport_info.connection_type!=NULL) {
405 g_free(transport_info.connection_type);
409 datalen = tvb_length_remaining(tvb, offset);
411 proto_tree_add_text(sdp_tree, tvb, offset, datalen,
412 "Data (%d bytes)", datalen);
417 call_sdp_subdissector(tvbuff_t *tvb, int hf, proto_tree* ti,
418 transport_info_t *transport_info){
420 dissect_sdp_owner(tvb,ti);
421 } else if ( hf == hf_connection_info) {
422 dissect_sdp_connection_info(tvb,ti,transport_info);
423 } else if ( hf == hf_bandwidth) {
424 dissect_sdp_bandwidth(tvb,ti);
425 } else if ( hf == hf_time) {
426 dissect_sdp_time(tvb,ti);
427 } else if ( hf == hf_repeat_time ){
428 dissect_sdp_repeat_time(tvb,ti);
429 } else if ( hf == hf_timezone ) {
430 dissect_sdp_timezone(tvb,ti);
431 } else if ( hf == hf_encryption_key ) {
432 dissect_sdp_encryption_key(tvb,ti);
433 } else if ( hf == hf_session_attribute ){
434 dissect_sdp_session_attribute(tvb,ti);
435 } else if ( hf == hf_media ) {
436 dissect_sdp_media(tvb,ti,transport_info);
437 } else if ( hf == hf_media_attribute ){
438 dissect_sdp_media_attribute(tvb,ti);
443 dissect_sdp_owner(tvbuff_t *tvb, proto_item *ti){
444 proto_tree *sdp_owner_tree;
445 gint offset,next_offset,tokenlen;
451 sdp_owner_tree = proto_item_add_subtree(ti,ett_sdp_owner);
453 /* Find the username */
454 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
455 if( next_offset == -1 )
457 tokenlen = next_offset - offset;
459 proto_tree_add_item(sdp_owner_tree,hf_owner_username,tvb, offset,tokenlen,
461 offset = next_offset + 1;
463 /* Find the session id */
464 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
465 if( next_offset == -1 )
467 tokenlen = next_offset - offset;
469 proto_tree_add_item(sdp_owner_tree,hf_owner_sessionid, tvb,
470 offset,tokenlen,FALSE);
471 offset = next_offset + 1;
473 /* Find the version */
474 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
475 if( next_offset == -1 )
477 tokenlen = next_offset - offset;
479 proto_tree_add_item(sdp_owner_tree,hf_owner_version, tvb,
480 offset,tokenlen,FALSE);
481 offset = next_offset + 1;
483 /* Find the network type */
484 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
485 if( next_offset == -1 )
487 tokenlen = next_offset - offset;
489 proto_tree_add_item(sdp_owner_tree,hf_owner_network_type, tvb,
490 offset,tokenlen,FALSE);
491 offset = next_offset + 1;
493 /* Find the address type */
494 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
495 if( next_offset == -1 )
497 tokenlen = next_offset - offset;
499 proto_tree_add_item(sdp_owner_tree,hf_owner_address_type, tvb,
500 offset,tokenlen,FALSE);
501 offset = next_offset + 1;
503 /* Find the address */
504 proto_tree_add_item(sdp_owner_tree,hf_owner_address, tvb, offset, -1, FALSE);
508 * XXX - this can leak memory if an exception is thrown after we've fetched
512 dissect_sdp_connection_info(tvbuff_t *tvb, proto_item* ti,
513 transport_info_t *transport_info){
514 proto_tree *sdp_connection_info_tree;
515 gint offset,next_offset,tokenlen;
521 sdp_connection_info_tree = proto_item_add_subtree(ti,
522 ett_sdp_connection_info);
524 /* Find the network type */
525 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
526 if( next_offset == -1 )
528 tokenlen = next_offset - offset;
530 proto_tree_add_item(sdp_connection_info_tree,
531 hf_connection_info_network_type,tvb,
532 offset,tokenlen,FALSE);
533 offset = next_offset + 1;
535 /* Find the address type */
536 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
537 if( next_offset == -1 )
539 tokenlen = next_offset - offset;
540 /* Save connection address type */
541 transport_info->connection_type = tvb_get_string(tvb, offset, tokenlen);
544 proto_tree_add_item(sdp_connection_info_tree,
545 hf_connection_info_address_type,tvb,
546 offset,tokenlen,FALSE);
547 offset = next_offset + 1;
549 /* Find the connection address */
550 /* XXX - what if there's a <number of addresses> value? */
551 next_offset = tvb_find_guint8(tvb,offset,-1,'/');
552 if( next_offset == -1){
553 tokenlen = -1; /* end of tvbuff */
554 /* Save connection address */
555 transport_info->connection_address =
556 tvb_get_string(tvb, offset, tvb_length_remaining(tvb, offset));
558 tokenlen = next_offset - offset;
559 /* Save connection address */
560 transport_info->connection_address = tvb_get_string(tvb, offset, tokenlen);
563 proto_tree_add_item(sdp_connection_info_tree,
564 hf_connection_info_connection_address, tvb,
565 offset,tokenlen,FALSE);
566 if(next_offset != -1){
567 offset = next_offset + 1;
568 next_offset = tvb_find_guint8(tvb,offset,-1,'/');
569 if( next_offset == -1){
570 tokenlen = -1; /* end of tvbuff */
572 tokenlen = next_offset - offset;
574 proto_tree_add_item(sdp_connection_info_tree,
575 hf_connection_info_ttl,tvb,offset,tokenlen,FALSE);
576 if(next_offset != -1){
577 offset = next_offset + 1;
578 proto_tree_add_item(sdp_connection_info_tree,
579 hf_connection_info_num_addr, tvb,
586 dissect_sdp_bandwidth(tvbuff_t *tvb, proto_item *ti){
587 proto_tree * sdp_bandwidth_tree;
588 gint offset, next_offset, tokenlen;
594 sdp_bandwidth_tree = proto_item_add_subtree(ti,ett_sdp_bandwidth);
596 /* find the modifier */
597 next_offset = tvb_find_guint8(tvb,offset,-1,':');
599 if( next_offset == -1)
602 tokenlen = next_offset - offset;
604 proto_tree_add_item(sdp_bandwidth_tree, hf_bandwidth_modifier,
605 tvb, offset, tokenlen, FALSE);
607 offset = next_offset + 1;
609 proto_tree_add_item(sdp_bandwidth_tree, hf_bandwidth_value,
610 tvb, offset, -1, FALSE);
614 static void dissect_sdp_time(tvbuff_t *tvb, proto_item* ti){
615 proto_tree *sdp_time_tree;
616 gint offset,next_offset, tokenlen;
622 sdp_time_tree = proto_item_add_subtree(ti,ett_sdp_time);
625 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
626 if( next_offset == -1 )
629 tokenlen = next_offset - offset;
630 proto_tree_add_item(sdp_time_tree, hf_time_start, tvb,
631 offset, tokenlen, FALSE);
634 offset = next_offset + 1;
635 proto_tree_add_item(sdp_time_tree, hf_time_stop, tvb,
639 static void dissect_sdp_repeat_time(tvbuff_t *tvb, proto_item* ti){
640 proto_tree *sdp_repeat_time_tree;
641 gint offset,next_offset, tokenlen;
647 sdp_repeat_time_tree = proto_item_add_subtree(ti,ett_sdp_time);
650 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
651 if( next_offset == -1 )
654 tokenlen = next_offset - offset;
655 proto_tree_add_item(sdp_repeat_time_tree, hf_repeat_time_interval, tvb,
656 offset, tokenlen, FALSE);
659 offset = next_offset + 1;
660 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
661 if( next_offset == -1 )
664 tokenlen = next_offset - offset;
665 proto_tree_add_item(sdp_repeat_time_tree,hf_repeat_time_duration, tvb,
666 offset, tokenlen, FALSE);
670 offset = next_offset +1;
671 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
672 if(next_offset != -1){
673 tokenlen = next_offset - offset;
675 tokenlen = -1; /* end of tvbuff */
677 proto_tree_add_item(sdp_repeat_time_tree, hf_repeat_time_offset,
678 tvb, offset, tokenlen, FALSE);
679 } while( next_offset != -1 );
683 dissect_sdp_timezone(tvbuff_t *tvb, proto_item* ti){
684 proto_tree* sdp_timezone_tree;
685 gint offset, next_offset, tokenlen;
690 sdp_timezone_tree = proto_item_add_subtree(ti,ett_sdp_timezone);
693 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
694 if(next_offset == -1)
696 tokenlen = next_offset - offset;
698 proto_tree_add_item(sdp_timezone_tree,hf_timezone_time,tvb,
699 offset, tokenlen, FALSE);
700 offset = next_offset + 1;
701 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
702 if(next_offset != -1){
703 tokenlen = next_offset - offset;
705 tokenlen = -1; /* end of tvbuff */
707 proto_tree_add_item(sdp_timezone_tree,hf_timezone_offset,tvb,
708 offset, tokenlen, FALSE);
709 offset = next_offset + 1;
710 } while (next_offset != -1);
715 static void dissect_sdp_encryption_key(tvbuff_t *tvb, proto_item * ti){
716 proto_tree *sdp_encryption_key_tree;
717 gint offset, next_offset, tokenlen;
723 sdp_encryption_key_tree = proto_item_add_subtree(ti,ett_sdp_encryption_key);
725 next_offset = tvb_find_guint8(tvb,offset,-1,':');
727 if(next_offset == -1)
730 tokenlen = next_offset - offset;
732 proto_tree_add_item(sdp_encryption_key_tree,hf_encryption_key_type,
733 tvb, offset, tokenlen, FALSE);
735 offset = next_offset + 1;
736 proto_tree_add_item(sdp_encryption_key_tree,hf_encryption_key_data,
737 tvb, offset, -1, FALSE);
743 static void dissect_sdp_session_attribute(tvbuff_t *tvb, proto_item * ti){
744 proto_tree *sdp_session_attribute_tree;
745 gint offset, next_offset, tokenlen;
751 sdp_session_attribute_tree = proto_item_add_subtree(ti,
752 ett_sdp_session_attribute);
754 next_offset = tvb_find_guint8(tvb,offset,-1,':');
756 if(next_offset == -1)
759 tokenlen = next_offset - offset;
761 proto_tree_add_item(sdp_session_attribute_tree,
762 hf_session_attribute_field,
763 tvb, offset, tokenlen, FALSE);
765 offset = next_offset + 1;
766 proto_tree_add_item(sdp_session_attribute_tree,
767 hf_session_attribute_value,
768 tvb, offset, -1, FALSE);
773 dissect_sdp_media(tvbuff_t *tvb, proto_item *ti,
774 transport_info_t *transport_info){
775 proto_tree *sdp_media_tree;
776 gint offset, next_offset, tokenlen;
782 sdp_media_tree = proto_item_add_subtree(ti,ett_sdp_media);
784 next_offset = tvb_find_guint8(tvb,offset, -1, ' ');
786 if(next_offset == -1)
789 tokenlen = next_offset - offset;
791 proto_tree_add_item(sdp_media_tree, hf_media_media, tvb,
792 offset, tokenlen, FALSE);
794 offset = next_offset + 1;
796 next_offset = tvb_find_guint8(tvb,offset, -1, ' ');
797 if(next_offset == -1)
799 tokenlen = next_offset - offset;
800 next_offset = tvb_find_guint8(tvb,offset, tokenlen, '/');
802 if(next_offset != -1){
803 tokenlen = next_offset - offset;
805 transport_info->media_port[transport_info->media_count] = tvb_get_string(tvb, offset, tokenlen);
807 proto_tree_add_item(sdp_media_tree, hf_media_port, tvb,
808 offset, tokenlen, FALSE);
809 offset = next_offset + 1;
810 next_offset = tvb_find_guint8(tvb,offset, -1, ' ');
811 if(next_offset == -1)
813 tokenlen = next_offset - offset;
814 proto_tree_add_item(sdp_media_tree, hf_media_portcount, tvb,
815 offset, tokenlen, FALSE);
816 offset = next_offset + 1;
818 next_offset = tvb_find_guint8(tvb,offset, -1, ' ');
820 if(next_offset == -1)
822 tokenlen = next_offset - offset;
824 transport_info->media_port[transport_info->media_count] = tvb_get_string(tvb, offset, tokenlen);
826 /* XXX Remember Port */
827 proto_tree_add_item(sdp_media_tree, hf_media_port, tvb,
828 offset, tokenlen, FALSE);
829 offset = next_offset + 1;
832 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
834 if( next_offset == -1)
837 tokenlen = next_offset - offset;
838 /* Save port protocol */
839 transport_info->media_proto[transport_info->media_count] = tvb_get_string(tvb, offset, tokenlen);
841 /* XXX Remember Protocol */
842 proto_tree_add_item(sdp_media_tree, hf_media_proto, tvb,
843 offset, tokenlen, FALSE);
846 offset = next_offset + 1;
847 next_offset = tvb_find_guint8(tvb,offset,-1,' ');
849 if(next_offset == -1){
850 tokenlen = tvb_length_remaining(tvb, offset); /* End of tvbuff */
852 break; /* Nothing more left */
854 tokenlen = next_offset - offset;
857 proto_tree_add_item(sdp_media_tree, hf_media_format, tvb,
858 offset, tokenlen, FALSE);
859 } while (next_offset != -1);
861 /* Increase the count of media channels, but don't walk off the end
863 if (transport_info->media_count < (SDP_MAX_RTP_CHANNELS-1)){
864 transport_info->media_count++;
867 /* XXX Dissect traffic to "Port" as "Protocol"
868 * Remember this Port/Protocol pair so we can tear it down again later
869 * Actually, it's harder than that:
870 * We need to find out the address of the other side first and it
871 * looks like that info can be found in SIP headers only.
876 static void dissect_sdp_media_attribute(tvbuff_t *tvb, proto_item * ti){
877 proto_tree *sdp_media_attribute_tree;
878 gint offset, next_offset, tokenlen;
884 sdp_media_attribute_tree = proto_item_add_subtree(ti,
885 ett_sdp_media_attribute);
887 next_offset = tvb_find_guint8(tvb,offset,-1,':');
889 if(next_offset == -1)
892 tokenlen = next_offset - offset;
894 proto_tree_add_item(sdp_media_attribute_tree,
895 hf_media_attribute_field,
896 tvb, offset, tokenlen, FALSE);
898 offset = next_offset + 1;
899 proto_tree_add_item(sdp_media_attribute_tree,
900 hf_media_attribute_value,
901 tvb, offset, -1, FALSE);
906 proto_register_sdp(void)
908 static hf_register_info hf[] = {
909 { &hf_protocol_version,
910 { "Session Description Protocol Version (v)",
911 "sdp.version", FT_STRING, BASE_NONE,NULL,0x0,
912 "Session Description Protocol Version", HFILL }},
914 { "Owner/Creator, Session Id (o)",
915 "sdp.owner", FT_STRING, BASE_NONE, NULL, 0x0,
916 "Owner/Creator, Session Id", HFILL}},
918 { "Session Name (s)",
919 "sdp.session_name", FT_STRING, BASE_NONE,NULL, 0x0,
920 "Session Name", HFILL }},
922 { "Session Information (i)",
923 "sdp.session_info", FT_STRING, BASE_NONE, NULL, 0x0,
924 "Session Information", HFILL }},
926 { "URI of Description (u)",
927 "sdp.uri", FT_STRING, BASE_NONE,NULL, 0x0,
928 "URI of Description", HFILL }},
930 { "E-mail Address (e)",
931 "sdp.email", FT_STRING, BASE_NONE, NULL, 0x0,
932 "E-mail Address", HFILL }},
934 { "Phone Number (p)",
935 "sdp.phone", FT_STRING, BASE_NONE, NULL, 0x0,
936 "Phone Number", HFILL }},
937 { &hf_connection_info,
938 { "Connection Information (c)",
939 "sdp.connection_info", FT_STRING, BASE_NONE, NULL, 0x0,
940 "Connection Information", HFILL }},
942 { "Bandwidth Information (b)",
943 "sdp.bandwidth", FT_STRING, BASE_NONE, NULL, 0x0,
944 "Bandwidth Information", HFILL }},
946 { "Time Zone Adjustments (z)",
947 "sdp.timezone", FT_STRING, BASE_NONE, NULL, 0x0,
948 "Time Zone Adjustments", HFILL }},
949 { &hf_encryption_key,
950 { "Encryption Key (k)",
951 "sdp.encryption_key", FT_STRING, BASE_NONE, NULL, 0x0,
952 "Encryption Key", HFILL }},
953 { &hf_session_attribute,
954 { "Session Attribute (a)",
955 "sdp.session_attr", FT_STRING, BASE_NONE, NULL, 0x0,
956 "Session Attribute", HFILL }},
957 { &hf_media_attribute,
958 { "Media Attribute (a)",
959 "sdp.media_attr", FT_STRING, BASE_NONE, NULL, 0x0,
960 "Media Attribute", HFILL }},
962 { "Time Description, active time (t)",
963 "sdp.time", FT_STRING, BASE_NONE, NULL, 0x0,
964 "Time Description, active time", HFILL }},
967 "sdp.repeat_time", FT_STRING, BASE_NONE, NULL, 0x0,
968 "Repeat Time", HFILL }},
970 { "Media Description, name and address (m)",
971 "sdp.media", FT_STRING, BASE_NONE, NULL, 0x0,
972 "Media Description, name and address", HFILL }},
975 "sdp.media_title",FT_STRING, BASE_NONE, NULL, 0x0,
976 "Media Title", HFILL }},
979 "sdp.unknown",FT_STRING, BASE_NONE, NULL, 0x0,
983 "sdp.invalid",FT_STRING, BASE_NONE, NULL, 0x0,
984 "Invalid line", HFILL }},
985 { &hf_owner_username,
987 "sdp.owner.username",FT_STRING, BASE_NONE, NULL, 0x0,
988 "Owner Username", HFILL }},
989 { &hf_owner_sessionid,
991 "sdp.owner.sessionid",FT_STRING, BASE_NONE, NULL, 0x0,
992 "Session ID", HFILL }},
995 "sdp.owner.version",FT_STRING, BASE_NONE, NULL, 0x0,
996 "Session Version", HFILL }},
997 { &hf_owner_network_type,
998 { "Owner Network Type",
999 "sdp.owner.network_type",FT_STRING, BASE_NONE, NULL, 0x0,
1000 "Owner Network Type", HFILL }},
1001 { &hf_owner_address_type,
1002 { "Owner Address Type",
1003 "sdp.owner.address_type",FT_STRING, BASE_NONE, NULL, 0x0,
1004 "Owner Address Type", HFILL }},
1005 { &hf_owner_address,
1007 "sdp.owner.address",FT_STRING, BASE_NONE, NULL, 0x0,
1008 "Owner Address", HFILL }},
1009 { &hf_connection_info_network_type,
1010 { "Connection Network Type",
1011 "sdp.connection_info.network_type",FT_STRING, BASE_NONE, NULL, 0x0,
1012 "Connection Network Type", HFILL }},
1013 { &hf_connection_info_address_type,
1014 { "Connection Address Type",
1015 "sdp.connection_info.address_type",FT_STRING, BASE_NONE, NULL, 0x0,
1016 "Connection Address Type", HFILL }},
1017 { &hf_connection_info_connection_address,
1018 { "Connection Address",
1019 "sdp.connection_info.address",FT_STRING, BASE_NONE, NULL, 0x0,
1020 "Connection Address", HFILL }},
1021 { &hf_connection_info_ttl,
1023 "sdp.connection_info.ttl",FT_STRING, BASE_NONE, NULL, 0x0,
1024 "Connection TTL", HFILL }},
1025 { &hf_connection_info_num_addr,
1026 { "Connection Number of Addresses",
1027 "sdp.connection_info.num_addr",FT_STRING, BASE_NONE, NULL, 0x0,
1028 "Connection Number of Addresses", HFILL }},
1029 { &hf_bandwidth_modifier,
1030 { "Bandwidth Modifier",
1031 "sdp.bandwidth.modifier",FT_STRING, BASE_NONE, NULL, 0x0,
1032 "Bandwidth Modifier", HFILL }},
1033 { &hf_bandwidth_value,
1034 { "Bandwidth Value",
1035 "sdp.bandwidth.value",FT_STRING, BASE_NONE, NULL, 0x0,
1036 "Bandwidth Value", HFILL }},
1038 { "Session Start Time",
1039 "sdp.time.start",FT_STRING, BASE_NONE, NULL, 0x0,
1040 "Session Start Time", HFILL }},
1042 { "Session Stop Time",
1043 "sdp.time.stop",FT_STRING, BASE_NONE, NULL, 0x0,
1044 "Session Stop Time", HFILL }},
1045 { &hf_repeat_time_interval,
1046 { "Repeat Interval",
1047 "sdp.repeat_time.interval",FT_STRING, BASE_NONE, NULL, 0x0,
1048 "Repeat Interval", HFILL }},
1049 { &hf_repeat_time_duration,
1050 { "Repeat Duration",
1051 "sdp.repeat_time.duration",FT_STRING, BASE_NONE, NULL, 0x0,
1052 "Repeat Duration", HFILL }},
1053 { &hf_repeat_time_offset,
1055 "sdp.repeat_time.offset",FT_STRING, BASE_NONE, NULL, 0x0,
1056 "Repeat Offset", HFILL }},
1057 { &hf_timezone_time,
1059 "sdp.timezone.time",FT_STRING, BASE_NONE, NULL, 0x0,
1060 "Timezone Time", HFILL }},
1061 { &hf_timezone_offset,
1062 { "Timezone Offset",
1063 "sdp.timezone.offset",FT_STRING, BASE_NONE, NULL, 0x0,
1064 "Timezone Offset", HFILL }},
1065 { &hf_encryption_key_type,
1067 "sdp.encryption_key.type",FT_STRING, BASE_NONE, NULL, 0x0,
1069 { &hf_encryption_key_data,
1071 "sdp.encryption_key.data",FT_STRING, BASE_NONE, NULL, 0x0,
1073 { &hf_session_attribute_field,
1074 { "Session Attribute Fieldname",
1075 "sdp.session_attr.field",FT_STRING, BASE_NONE, NULL, 0x0,
1076 "Session Attribute Fieldname", HFILL }},
1077 { &hf_session_attribute_value,
1078 { "Session Attribute Value",
1079 "sdp.session_attr.value",FT_STRING, BASE_NONE, NULL, 0x0,
1080 "Session Attribute Value", HFILL }},
1083 "sdp.media.media",FT_STRING, BASE_NONE, NULL, 0x0,
1084 "Media Type", HFILL }},
1087 "sdp.media.port",FT_STRING, BASE_NONE, NULL, 0x0,
1088 "Media Port", HFILL }},
1089 { &hf_media_portcount,
1090 { "Media Port Count",
1091 "sdp.media.portcount",FT_STRING, BASE_NONE, NULL, 0x0,
1092 "Media Port Count", HFILL }},
1095 "sdp.media.proto",FT_STRING, BASE_NONE, NULL, 0x0,
1096 "Media Proto", HFILL }},
1099 "sdp.media.format",FT_STRING, BASE_NONE, NULL, 0x0,
1100 "Media Format", HFILL }},
1101 { &hf_media_attribute_field,
1102 { "Media Attribute Fieldname",
1103 "sdp.media_attribute.field",FT_STRING, BASE_NONE, NULL, 0x0,
1104 "Media Attribute Fieldname", HFILL }},
1105 { &hf_media_attribute_value,
1106 { "Media Attribute Value",
1107 "sdp.media_attribute.value",FT_STRING, BASE_NONE, NULL, 0x0,
1108 "Media Attribute Value", HFILL }},
1111 static gint *ett[] = {
1114 &ett_sdp_connection_info,
1117 &ett_sdp_repeat_time,
1119 &ett_sdp_encryption_key,
1120 &ett_sdp_session_attribute,
1122 &ett_sdp_media_attribute,
1125 proto_sdp = proto_register_protocol("Session Description Protocol",
1127 proto_register_field_array(proto_sdp, hf, array_length(hf));
1128 proto_register_subtree_array(ett, array_length(ett));
1131 * Register the dissector by name, so other dissectors can
1132 * grab it by name rather than just referring to it directly
1133 * (you can't refer to it directly from a plugin dissector
1134 * on Windows without stuffing it into the Big Transfer Vector).
1136 register_dissector("sdp", dissect_sdp, proto_sdp);
1140 proto_reg_handoff_sdp(void)
1142 dissector_handle_t sdp_handle;
1144 rtp_handle = find_dissector("rtp");
1145 rtcp_handle = find_dissector("rtcp");
1147 sdp_handle = find_dissector("sdp");
1148 dissector_add_string("media_type", "application/sdp", sdp_handle);