[asterisk-dev] patch for realtime mode in chan_sip.c

Germán Aracil Boned german at tecnoxarxa.com
Tue Feb 13 03:31:30 MST 2007


Hello

With this patch, you need add in sip_conf table (realtime mode) field 
ipsvr vchar(20).

This save ip address of server where sip peer was registered. you can 
have more of one servers with same database and you can get this field 
for send call to server where sip peer was sip register.

I like this for cluster system, and I think this is a pretty change for 
add to asterisk sources.

bye !

From: Asterisk SVN-branch-1.2-r53658M

+++ chan_sip.c	2007-02-12 23:47:12.000000000 +0100
@@ -28,7 +28,6 @@
   * \todo Better support of forking
   */

-
  #include <stdio.h>
  #include <ctype.h>
  #include <string.h>
@@ -1614,17 +1613,30 @@ static void realtime_update_peer(const c
  	char ipaddr[20];
  	char regseconds[20];
  	time_t nowtime;
-	
+
+	char ipsvr[20];
+	struct in_addr *us;
+	struct in_addr *them;
+	struct sockaddr_in *sockaddr_us;
+	us = malloc(sizeof(struct in_addr));
+	them = malloc(sizeof(struct in_addr));
+	sockaddr_us = malloc(sizeof(struct sockaddr_in));
+
  	time(&nowtime);
  	nowtime += expirey;
  	snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime);	/* 
Expiration time */
  	ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr);
  	snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port));
-	
+
+	memcpy((char *)them, (char*)&sin->sin_addr, sizeof(&sin->sin_addr));
+	ast_ouraddrfor(them, us);
+	memcpy((char *)&sockaddr_us->sin_addr.s_addr, (char*)&us->s_addr, 
sizeof(&us->s_addr));
+	ast_inet_ntoa(ipsvr, sizeof(ipsvr), sockaddr_us->sin_addr);
+
  	if (fullcontact)
-		ast_update_realtime("sippeers", "name", peername, "ipaddr", ipaddr, 
"port", port, "regseconds", regseconds, "username", username, 
"fullcontact", fullcontact, NULL);
+		ast_update_realtime("sippeers", "name", peername, "ipaddr", ipaddr, 
"port", port, "regseconds", regseconds, "username", username, 
"fullcontact", fullcontact, "ipsvr", ipsvr, NULL);
  	else
-		ast_update_realtime("sippeers", "name", peername, "ipaddr", ipaddr, 
"port", port, "regseconds", regseconds, "username", username, NULL);
+		ast_update_realtime("sippeers", "name", peername, "ipaddr", ipaddr, 
"port", port, "regseconds", regseconds, "username", username, "ipsvr", 
ipsvr, NULL);
  }

  /*! \brief  register_peer_exten: Automatically add peer extension to 
dial plan ---*/


More information about the asterisk-dev mailing list