[asterisk-commits] blanchet: branch blanchet/v6 r60191 - /team/blanchet/v6/main/acl.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Apr 4 13:15:13 MST 2007


Author: blanchet
Date: Wed Apr  4 15:15:12 2007
New Revision: 60191

URL: http://svn.digium.com/view/asterisk?view=rev&rev=60191
Log:
initial cut for IP version independent api. not complete.
defined: ast_viha (ast_ha)
changed ast_get_ip_or_srv to use generic sockaddr
changed ast_get_ip to correctly use ast_get_ip_or_srv.

Modified:
    team/blanchet/v6/main/acl.c

Modified: team/blanchet/v6/main/acl.c
URL: http://svn.digium.com/view/asterisk/team/blanchet/v6/main/acl.c?view=diff&rev=60191&r1=60190&r2=60191
==============================================================================
--- team/blanchet/v6/main/acl.c (original)
+++ team/blanchet/v6/main/acl.c Wed Apr  4 15:15:12 2007
@@ -69,6 +69,7 @@
 #include "asterisk/utils.h"
 #include "asterisk/lock.h"
 #include "asterisk/srv.h"
+#include "asterisk/netsock.h"
 
 struct ast_ha {
 	/* Host access rule */
@@ -76,6 +77,14 @@
 	struct in_addr netmask;
 	int sense;
 	struct ast_ha *next;
+};
+
+struct ast_viha {
+	struct sockaddr_storage netaddr;
+	struct sockaddr_storage netmask;
+	int prefixlen;
+	int sense;
+	struct ast_viha *next;
 };
 
 /* Default IP - if not otherwise set, don't breathe garbage */
@@ -222,29 +231,25 @@
 	return res;
 }
 
-int ast_get_ip_or_srv(struct sockaddr_in *sin, const char *value, const char *service)
-{
-	struct hostent *hp;
-	struct ast_hostent ahp;
+int ast_get_ip_or_srv(struct sockaddr *sa, socklen_t *salen, const char *value, const char *service)
+{
 	char srv[256];
-	char host[256];
-	int tportno = ntohs(sin->sin_port);
-	if (inet_aton(value, &sin->sin_addr))
+	char host[NI_MAXHOST];
+	int tportno = ast_vinetsock_sa_getport(sa, *salen);
+	if (ast_vinetsock_sa_fromstr(value, NULL, sa, salen, AF_UNSPEC, 0))
 		return 0;
 	if (service) {
 		snprintf(srv, sizeof(srv), "%s.%s", service, value);
 		if (ast_get_srv(NULL, host, sizeof(host), &tportno, srv) > 0) {
-			sin->sin_port = htons(tportno);
 			value = host;
 		}
 	}
-	hp = ast_gethostbyname(value, &ahp);
-	if (hp) {
-		memcpy(&sin->sin_addr, hp->h_addr, sizeof(sin->sin_addr));
-	} else {
+
+	if (ast_vinetsock_sa_fromstr(value, NULL, sa, salen, AF_UNSPEC, 0)) {
 		ast_log(LOG_WARNING, "Unable to lookup '%s'\n", value);
 		return -1;
 	}
+	ast_vinetsock_sa_setport(sa, tportno);
 	return 0;
 }
 
@@ -341,7 +346,8 @@
 
 int ast_get_ip(struct sockaddr_in *sin, const char *value)
 {
-	return ast_get_ip_or_srv(sin, value, NULL);
+	socklen_t sinlen = sizeof(struct sockaddr_in);
+	return ast_get_ip_or_srv((struct sockaddr*)sin, &sinlen, value, NULL);
 }
 
 /* iface is the interface (e.g. eth0); address is the return value */



More information about the asterisk-commits mailing list