Ethereal-dev: [Ethereal-dev] SIP-Patch to consider multiple URI's per Contact header

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Nils Ohlmeier <lists@xxxxxxxxxxxx>
Date: Sun, 7 Nov 2004 03:17:13 +0100
Hi,

please find attached a very basic patch for packet-sip.c which looks if the 
Contact header in the REGISTER reply contains more then one binding.  
Details: up to now each Contact header was counted as one binding. But that 
is not correct, because several Contact headers (as several other SIP headers 
as well) can be written in one line separated by commatas.

Status: works for me and far from being perfect.

Theoretically you would have to implement a complete SIP URI parser to be able 
to count the the number of header fields in a line, but for the purpose of 
just showing the number of bindings it should hopefully be sufficient :)

Greetings
  Nils Ohlmeier
--- ethereal-0.10.7/epan/dissectors/packet-sip.c	2004-10-21 00:34:37.000000000 +0200
+++ ethereal-0.10.7.patched/epan/dissectors/packet-sip.c	2004-11-07 02:32:01.000000000 +0100
@@ -706,6 +706,10 @@
                 gint header_len;
                 gint hf_index;
                 gint value_offset;
+                gint comma_offset;
+                gint comma_next_offset;
+                gint sip_offset;
+                gint con_offset;
                 guchar c;
 		size_t value_len;
                 char *value;
@@ -1073,10 +1077,30 @@
 					break;
 
 				case POS_CONTACT :
-					contacts++;
-					if (strcmp(value, "*") == 0)
-					{
-						contact_is_star = 1;
+					comma_offset = tvb_find_guint8(tvb, value_offset,value_len, ',');
+					if (comma_offset != -1) {
+						con_offset = value_offset + 1;
+						while (comma_offset != -1) {
+							sip_offset = tvb_find_guint8(tvb, con_offset, (comma_offset - con_offset), 's');
+							if (sip_offset != -1 && tvb_get_guint8(tvb, sip_offset+1) == 'i' && tvb_get_guint8(tvb, sip_offset+2) == 'p')
+								contacts++;
+							comma_next_offset = tvb_find_guint8(tvb, comma_offset + 1, value_len - (comma_offset - value_offset), ',');
+							if (comma_next_offset == -1)
+								con_offset = comma_offset + 1;
+							else
+								con_offset = comma_next_offset + 1;
+							comma_offset = comma_next_offset;
+						}
+						sip_offset = tvb_find_guint8(tvb, con_offset, value_len - (con_offset - value_offset), 's');
+						if (sip_offset != -1 && tvb_get_guint8(tvb, sip_offset+1) == 'i' && tvb_get_guint8(tvb, sip_offset+2) == 'p')
+							contacts++;
+					}
+					else {
+						contacts++;
+						if (strcmp(value, "*") == 0)
+						{
+							contact_is_star = 1;
+						}
 					}
 					/* Fall through to default case to add string to tree */