[Asterisk-Dev] Patch: SIP bindaddr not always used

Tilghman Lesher tilghman at mail.jeffandtilghman.com
Tue May 13 13:26:39 MST 2003


On Tuesday 13 May 2003 02:07 pm, matt at overloaded.net wrote:
--- channels/chan_sip.c.default	2003-05-12 18:26:50.000000000 -0400
+++ channels/chan_sip.c	2003-05-12 20:24:26.000000000 -0400
@@ -1276,7 +1276,9 @@
 #endif
 	if (sin) {
 		memcpy(&p->sa, sin, sizeof(p->sa));
-		if (ast_ouraddrfor(&p->sa.sin_addr,&p->ourip))
+		if (&bindaddr)
+			memcpy(&p->ourip, &bindaddr.sin_addr, sizeof(p->ourip));
+		else if (ast_ouraddrfor(&p->sa.sin_addr,&p->ourip))
 			memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
 	} else {
 		memcpy(&p->ourip, &__ourip, sizeof(p->ourip));


There is a slight problem with the patch:  the address of anything is
true in C (because nothing is ever allowed to be located at memory
location 0).  Therefore, the second condition will never be evaluated.

Instead, try:
+		if (bindaddr.sin_addr)

This presumes that nobody will ever have an IPv4 address in the
range 0.0.0.1-0.255.255.255 (fairly reasonable assumption, I think).

-Tilghman




More information about the asterisk-dev mailing list