[asterisk-commits] dvossel: branch dvossel/gtalk_fixup r291793 - in /team/dvossel/gtalk_fixup: c...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Oct 14 14:13:36 CDT 2010


Author: dvossel
Date: Thu Oct 14 14:13:33 2010
New Revision: 291793

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=291793
Log:
revise how we find our ip for local candidates

Modified:
    team/dvossel/gtalk_fixup/channels/chan_gtalk.c
    team/dvossel/gtalk_fixup/main/acl.c

Modified: team/dvossel/gtalk_fixup/channels/chan_gtalk.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/gtalk_fixup/channels/chan_gtalk.c?view=diff&rev=291793&r1=291792&r2=291793
==============================================================================
--- team/dvossel/gtalk_fixup/channels/chan_gtalk.c (original)
+++ team/dvossel/gtalk_fixup/channels/chan_gtalk.c Thu Oct 14 14:13:33 2010
@@ -810,6 +810,34 @@
 	return 1;
 }
 
+static int gtalk_get_local_ip(struct ast_sockaddr *ourip)
+{
+	struct ast_sockaddr root;
+	struct ast_sockaddr bindaddr_tmp;
+	struct ast_sockaddr *addrs;
+	int addrs_cnt;
+
+	/* If bind address is not 0.0.0.0, then bindaddr is our local ip. */
+	ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
+	if (!ast_sockaddr_is_any(&bindaddr_tmp)) {
+		ast_sockaddr_copy(ourip, &bindaddr_tmp);
+		return 0;
+	}
+
+	/* If no bind address was provided, lets see what ip we would use to connect to google.com and use that.
+	 * If you can't resolve google.com from your network, then this module is useless for you anyway. */
+	if ((addrs_cnt = ast_sockaddr_resolve(&addrs, "google.com", PARSE_PORT_FORBID, AF_INET)) > 0) {
+		ast_sockaddr_copy(&root, &addrs[0]);
+		ast_free(addrs);
+		if (!ast_ouraddrfor(&root, ourip)) {
+			return 0;
+		}
+	}
+
+	/* As a last resort, use this function to find our local address. */
+	return ast_find_ourip(ourip, &bindaddr_tmp, AF_INET);
+}
+
 static int gtalk_create_candidates(struct gtalk *client, struct gtalk_pvt *p, char *sid, char *from, char *to)
 {
 	struct gtalk_candidate *tmp;
@@ -817,7 +845,6 @@
 	struct gtalk_candidate *ours1 = NULL, *ours2 = NULL;
 	struct sockaddr_in sin = { 0, };
 	struct ast_sockaddr sin_tmp;
-	struct ast_sockaddr bindaddr_tmp;
 	struct ast_sockaddr us;
 	iks *iq, *gtalk, *candidate, *transport;
 	char user[17], pass[17], preference[5], port[7];
@@ -858,8 +885,9 @@
 
 	ast_rtp_instance_get_local_address(p->rtp, &sin_tmp);
 	ast_sockaddr_to_sin(&sin_tmp, &sin);
-	ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
-	ast_find_ourip(&us, &bindaddr_tmp, AF_INET);
+
+	gtalk_get_local_ip(&us);
+
 	if (!strcmp(ast_sockaddr_stringify_addr(&us), "127.0.0.1")) {
 		ast_log(LOG_WARNING, "Found a loopback IP on the system, check your network configuration or set the bindaddr attribute.");
 	}
@@ -2217,7 +2245,7 @@
 	}
 
 	ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
-	if (ast_find_ourip(&ourip_tmp, &bindaddr_tmp, AF_INET)) {
+	if (gtalk_get_local_ip(&ourip_tmp)) {
 		ast_log(LOG_WARNING, "Unable to get own IP address, Gtalk disabled\n");
 		return 0;
 	}

Modified: team/dvossel/gtalk_fixup/main/acl.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/gtalk_fixup/main/acl.c?view=diff&rev=291793&r1=291792&r2=291793
==============================================================================
--- team/dvossel/gtalk_fixup/main/acl.c (original)
+++ team/dvossel/gtalk_fixup/main/acl.c Thu Oct 14 14:13:33 2010
@@ -731,14 +731,6 @@
 		ast_debug(3, "Attached to given IP address\n");
 		return 0;
 	}
-
-	ast_debug(3, "Trying to check A.ROOT-SERVERS.NET and get our IP address for that connection\n");
-	/* A.ROOT-SERVERS.NET. */
-	if (!resolve_first(&root, "A.ROOT-SERVERS.NET", PARSE_PORT_FORBID, 0) &&
-	    !ast_ouraddrfor(&root, ourip)) {
-		return 0;
-	}
-
 	/* try to use our hostname */
 	if (gethostname(ourhost, sizeof(ourhost) - 1)) {
 		ast_log(LOG_WARNING, "Unable to get hostname\n");
@@ -747,7 +739,12 @@
 			return 0;
 		}
 	}
-
+	ast_debug(3, "Trying to check A.ROOT-SERVERS.NET and get our IP address for that connection\n");
+	/* A.ROOT-SERVERS.NET. */
+	if (!resolve_first(&root, "A.ROOT-SERVERS.NET", PARSE_PORT_FORBID, 0) &&
+	    !ast_ouraddrfor(&root, ourip)) {
+		return 0;
+	}
 	return get_local_address(ourip);
 }
 




More information about the asterisk-commits mailing list