[asterisk-commits] dvossel: branch dvossel/stun_monitor r281869 - in /team/dvossel/stun_monitor:...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Aug 11 15:23:05 CDT 2010


Author: dvossel
Date: Wed Aug 11 15:23:02 2010
New Revision: 281869

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=281869
Log:
using connect() instead of bind.  no longer need stunbind config option

Modified:
    team/dvossel/stun_monitor/configs/res_stun_monitor.conf.sample
    team/dvossel/stun_monitor/res/res_stun_monitor.c

Modified: team/dvossel/stun_monitor/configs/res_stun_monitor.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/stun_monitor/configs/res_stun_monitor.conf.sample?view=diff&rev=281869&r1=281868&r2=281869
==============================================================================
--- team/dvossel/stun_monitor/configs/res_stun_monitor.conf.sample (original)
+++ team/dvossel/stun_monitor/configs/res_stun_monitor.conf.sample Wed Aug 11 15:23:02 2010
@@ -20,9 +20,3 @@
 ; stunaddr = mystunserver.com ; address of the stun server to query.
 ; stunrefresh = 30     ; number of seconds between stun refreshes. default is 30
 ;
-; ---- STUN Client configuration ---
-;  By default stun queries will be sent from port 3478 when a 'stunadd' is
-;  specified. To bind the stun client to a different address/port use the
-;  'stunbindaddr' option.
-;
-; stunbindaddr = 0.0.0.0:5000 ; bind stun client address.

Modified: team/dvossel/stun_monitor/res/res_stun_monitor.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/stun_monitor/res/res_stun_monitor.c?view=diff&rev=281869&r1=281868&r2=281869
==============================================================================
--- team/dvossel/stun_monitor/res/res_stun_monitor.c (original)
+++ team/dvossel/stun_monitor/res/res_stun_monitor.c Wed Aug 11 15:23:02 2010
@@ -42,7 +42,6 @@
 static struct ast_sched_thread *sched;
 
 static struct {
-	struct ast_sockaddr stunbindaddr; /*!< The stun addres we bind to */
 	struct sockaddr_in stunaddr;      /*!< The stun address we send requests to*/
 	struct sockaddr_in externaladdr;  /*!< current perceived external address. */
 	ast_mutex_t lock;
@@ -57,6 +56,8 @@
 	if (args.stunsock != -1) {
 		close(args.stunsock);
 		args.stunsock = -1;
+		memset(&args.externaladdr, 0, sizeof(args.externaladdr));
+		args.externaladdr_known = 0;
 	}
 }
 
@@ -138,23 +139,22 @@
  */
 static int stun_start_monitor(void)
 {
-	const int reuseFlag = 1;
-
+	struct ast_sockaddr dst;
 	/* clean up any previous open socket */
 	stun_close_sock();
 
+	/* create destination ast_sockaddr */
+	ast_sockaddr_from_sin(&dst, &args.stunaddr);
+
 	/* open new socket binding */
-	if (!ast_sockaddr_port(&args.stunbindaddr)) {
-		ast_sockaddr_set_port(&args.stunbindaddr, STANDARD_STUN_PORT);
-	}
-	args.stunsock = socket(ast_sockaddr_is_ipv6(&args.stunbindaddr) ? AF_INET6 : AF_INET, SOCK_DGRAM, 0);
+	args.stunsock = socket(AF_INET, SOCK_DGRAM, 0);
 	if (args.stunsock < 0) {
 		ast_log(LOG_WARNING, "Unable to create STUN socket: %s\n", strerror(errno));
 		return -1;
 	}
-	setsockopt(args.stunsock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuseFlag, sizeof(reuseFlag));
-	if (ast_bind(args.stunsock, &args.stunbindaddr) < 0) {
-		ast_log(LOG_WARNING, "SIP STUN Failed to bind to %s: %s\n", ast_sockaddr_stringify(&args.stunbindaddr), strerror(errno));
+
+	if (ast_connect(args.stunsock, &dst) != 0) {
+		ast_log(LOG_WARNING, "SIP STUN Failed to connect to %s\n", ast_sockaddr_stringify(&dst));
 		stun_close_sock();
 		return -1;
 	}
@@ -204,7 +204,6 @@
 	/* set defaults */
 	args.monitor_enabled = 0;
 	memset(&args.stunaddr, 0, sizeof(args.stunaddr));
-	ast_sockaddr_parse(&args.stunbindaddr, "0.0.0.0:0", 0);
 	args.refresh = DEFAULT_MONITOR_REFRESH;
 
 	for (v = ast_variable_browse(cfg, "general"); v; v = v->next) {
@@ -215,11 +214,6 @@
 			} else {
 				ast_log(LOG_NOTICE, "STUN monitor enabled: %s\n", v->value);
 				args.monitor_enabled = 1;
-			}
-		} else if (!strcasecmp(v->name, "stunbindaddr")) {
-			if (ast_parse_arg(v->value, PARSE_ADDR, &args.stunbindaddr)) {
-				ast_log(LOG_WARNING, "SIP STUN. invalid address: %s\n", v->value);
-				ast_sockaddr_parse(&args.stunbindaddr, "0.0.0.0:0", 0);
 			}
 		} else if (!strcasecmp(v->name, "stunrefresh")) {
 			if ((sscanf(v->value, "%30u", &args.refresh) != 1) || !args.refresh) {




More information about the asterisk-commits mailing list