[Asterisk-Dev] Patch for SIP and no callerID

Michael Graff Michael_Graff at isc.org
Tue Apr 29 09:02:18 MST 2003


It seems that our PSTN gateway (a Cisco 2600 with a T1 and a DSP card)
sends us a call for which there is no caller id name or number, Asterisk
"helpfully" puts the IP address there.  This patch fixes that.

The From line in question is like:

        From: "unknown" <sip:1.2.3.4>

and Asterisk would say the number was 1.2.3.4

--Michael

Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.93
diff -u -r1.93 chan_sip.c
--- chan_sip.c	27 Apr 2003 21:34:27 -0000	1.93
+++ chan_sip.c	28 Apr 2003 09:37:59 -0000
@@ -3258,6 +3258,8 @@
 	char *of, from[256] = "", *c;
 	int res = 0;
 	char *t;
+	int hascallerid = 0;
+
 	/* Terminate URI */
 	t = uri;
 	while(*t && (*t > 32) && (*t != ';'))
@@ -3271,11 +3273,22 @@
 	} else
 		of += 4;
 	/* Get just the username part */
-	if ((c = strchr(of, '@')))
+	if ((c = strchr(of, '@'))) {
+		hascallerid = 1;
 		*c = '\0';
+	}
 	if ((c = strchr(of, ':')))
 		*c = '\0';
-	strncpy(p->callerid, of, sizeof(p->callerid) - 1);
+
+	/*
+	 * Caller-ID blocked SIP calls seem to have the format of sip:1.2.3.4 (that is, no @ sign)
+	 * while normal calls are like sip:skan at 1.2.3.4 -- if we did not see an @ sign in the
+	 * From line, don't put anything in the caller-id field, since it will just be gibberish.
+	 */
+	if (hascallerid)
+		strncpy(p->callerid, of, sizeof(p->callerid) - 1);
+	else
+		p->callerid[0] = 0;
 	if (!strlen(of))
 			return 0;
 	ast_pthread_mutex_lock(&userl.lock);



More information about the asterisk-dev mailing list