[asterisk-commits] file: branch file/netsock2 r97576 - in /team/file/netsock2: channels/ include...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 9 12:49:52 CST 2008


Author: file
Date: Wed Jan  9 12:49:51 2008
New Revision: 97576

URL: http://svn.digium.com/view/asterisk?view=rev&rev=97576
Log:
Add SRV support to ast_netsock2_dns_lookup.

Modified:
    team/file/netsock2/channels/chan_iax2.c
    team/file/netsock2/include/asterisk/netsock2.h
    team/file/netsock2/main/netsock2.c

Modified: team/file/netsock2/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/file/netsock2/channels/chan_iax2.c?view=diff&rev=97576&r1=97575&r2=97576
==============================================================================
--- team/file/netsock2/channels/chan_iax2.c (original)
+++ team/file/netsock2/channels/chan_iax2.c Wed Jan  9 12:49:51 2008
@@ -3126,7 +3126,7 @@
 
 	if (!(peer = find_peer(peername, 1))) {
 		cai->found = 0;
-		if (ast_netsock2_dns_lookup(sin, peername, AST_NETSOCK2_NETWORK_LAYER_IPV4)) {
+		if (ast_netsock2_dns_lookup(sin, peername, NULL, AST_NETSOCK2_NETWORK_LAYER_IPV4)) {
 			ast_log(LOG_WARNING, "No such host: %s\n", peername);
 			return -1;
 		}
@@ -9800,7 +9800,7 @@
 						ast_sched_del(sched, peer->expire);
 					peer->expire = -1;
 					ast_clear_flag(peer, IAX_DYNAMIC);
-					if (ast_netsock2_dns_lookup(&peer->addr, v->value, AST_NETSOCK2_NETWORK_LAYER_IPV4))
+					if (ast_netsock2_dns_lookup(&peer->addr, v->value, NULL, AST_NETSOCK2_NETWORK_LAYER_IPV4))
 						return peer_unref(peer);
 					ast_netsock2_sa_set_port(&peer->addr, IAX_DEFAULT_PORTNO);
 				}

Modified: team/file/netsock2/include/asterisk/netsock2.h
URL: http://svn.digium.com/view/asterisk/team/file/netsock2/include/asterisk/netsock2.h?view=diff&rev=97576&r1=97575&r2=97576
==============================================================================
--- team/file/netsock2/include/asterisk/netsock2.h (original)
+++ team/file/netsock2/include/asterisk/netsock2.h Wed Jan  9 12:49:51 2008
@@ -231,10 +231,11 @@
 /*! \brief Perform a synchronous DNS lookup
  * \param addr Address structure to put results into
  * \param host Hostname to lookup
+ * \param service Service for SRV record lookup
  * \param network_layer Preferred network layer
  * \return Returns 0 on success,-1 on failure
  */
-int ast_netsock2_dns_lookup(struct ast_netsock2_addr *addr, const char *host, enum ast_netsock2_network_layer network_layer);
+int ast_netsock2_dns_lookup(struct ast_netsock2_addr *addr, const char *host, const char *service, enum ast_netsock2_network_layer network_layer);
 
 /*! \brief Set the address and port on an ast_netsock2_addr structure
  * \param addr Address structure

Modified: team/file/netsock2/main/netsock2.c
URL: http://svn.digium.com/view/asterisk/team/file/netsock2/main/netsock2.c?view=diff&rev=97576&r1=97575&r2=97576
==============================================================================
--- team/file/netsock2/main/netsock2.c (original)
+++ team/file/netsock2/main/netsock2.c Wed Jan  9 12:49:51 2008
@@ -32,6 +32,7 @@
 #include "asterisk/netsock2.h"
 #include "asterisk/utils.h"
 #include "asterisk/threadstorage.h"
+#include "asterisk/srv.h"
 
 #include <fcntl.h>
 #include <signal.h>
@@ -812,15 +813,18 @@
 /*! \brief Perform a synchronous DNS lookup
  * \param addr Address structure to put results into
  * \param host Hostname to lookup
+ * \param service Service for SRV record lookup
  * \param network_layer Preferred network layer
  * \return Returns 0 on success,-1 on failure
  */
-int ast_netsock2_dns_lookup(struct ast_netsock2_addr *addr, const char *host, enum ast_netsock2_network_layer network_layer)
+int ast_netsock2_dns_lookup(struct ast_netsock2_addr *addr, const char *host, const char *service, enum ast_netsock2_network_layer network_layer)
 {
 	struct addrinfo hints = {
 		.ai_family = AF_UNSPEC,
 	};
 	struct addrinfo *res_addrinfo = NULL;
+	char real_host[NI_MAXHOST] = "";
+	int portno = 0;
 
 	/* If the network layer was given as an argument to the host change it */
 	if (!strncmp(host, "ipv4:", 5)) {
@@ -834,8 +838,18 @@
 	/* Now based on the given network layer change our hint so we only get the one we want */
 	hints.ai_family = (network_layer == AST_NETSOCK2_NETWORK_LAYER_IPV6 ? AF_INET6 : AF_INET);
 
+	/* If a service has been provided try to get the SRV record */
+	if (!ast_strlen_zero(service)) {
+		char srv[NI_MAXHOST];
+		/* Create a full string to pass to ast_get_srv so we can retrieve the record */
+		snprintf(srv, sizeof(srv), "%s.%s", service, host);
+		ast_get_srv(NULL, real_host, sizeof(real_host), &portno, srv);
+	} else {
+		ast_copy_string(real_host, host, sizeof(real_host));
+	}
+
 	/* Attempt to look up the given hostname */
-	if (getaddrinfo(host, NULL, &hints, &res_addrinfo))
+	if (getaddrinfo(real_host, NULL, &hints, &res_addrinfo))
 		return -1;
 
 	/* If it was found just copy over the information */
@@ -844,6 +858,10 @@
 
 	/* Yay all done, free it and move on */
 	freeaddrinfo(res_addrinfo);
+
+	/* If we ended up with a port due to an SRV lookup set it on the address structure */
+	if (portno)
+		ast_netsock2_sa_set_port(addr, portno);
 
 	return 0;
 }




More information about the asterisk-commits mailing list