[asterisk-commits] blanchet: branch blanchet/v6 r60525 -
/team/blanchet/v6/main/acl.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Fri Apr 6 12:08:40 MST 2007
Author: blanchet
Date: Fri Apr 6 14:08:40 2007
New Revision: 60525
URL: http://svn.digium.com/view/asterisk?view=rev&rev=60525
Log:
restored ast_get_ip* routines to their original version. then copied the new IP version independent version to ast_viget_ip* versions, so that other customers of these routines could move whenever ready.
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=60525&r1=60524&r2=60525
==============================================================================
--- team/blanchet/v6/main/acl.c (original)
+++ team/blanchet/v6/main/acl.c Fri Apr 6 14:08:40 2007
@@ -69,7 +69,6 @@
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/srv.h"
-#include "asterisk/netsock.h"
struct ast_ha {
/* Host access rule */
@@ -77,14 +76,6 @@
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 */
@@ -231,25 +222,30 @@
return res;
}
-int ast_get_ip_or_srv(struct sockaddr *sa, socklen_t *salen, const char *value, const char *service)
-{
+
+int ast_get_ip_or_srv(struct sockaddr_in *sin, const char *value, const char *service)
+{
+ struct hostent *hp;
+ struct ast_hostent ahp;
char srv[256];
- char host[NI_MAXHOST];
- int tportno = ast_vinetsock_sa_getport(sa, *salen);
- if (ast_vinetsock_sa_fromstr(value, NULL, sa, salen, AF_UNSPEC, 0))
+ char host[256];
+ int tportno = ntohs(sin->sin_port);
+ if (inet_aton(value, &sin->sin_addr))
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;
}
}
-
- if (ast_vinetsock_sa_fromstr(value, NULL, sa, salen, AF_UNSPEC, 0)) {
+ hp = ast_gethostbyname(value, &ahp);
+ if (hp) {
+ memcpy(&sin->sin_addr, hp->h_addr, sizeof(sin->sin_addr));
+ } else {
ast_log(LOG_WARNING, "Unable to lookup '%s'\n", value);
return -1;
}
- ast_vinetsock_sa_setport(sa, tportno);
return 0;
}
@@ -346,8 +342,7 @@
int ast_get_ip(struct sockaddr_in *sin, const char *value)
{
- socklen_t sinlen = sizeof(struct sockaddr_in);
- return ast_get_ip_or_srv((struct sockaddr*)sin, &sinlen, value, NULL);
+ return ast_get_ip_or_srv(sin, value, NULL);
}
/* iface is the interface (e.g. eth0); address is the return value */
@@ -431,3 +426,50 @@
return -1;
}
+
+
+/* IP version independent (IPv4 and IPv6) version of ACL
+ * using a new namespace to avoid conflict with current code
+ * so any channel and module can transition to IPv6 one at a time.
+ * duplicate code however is not automatically synched with changes above
+ *
+ * \author Marc Blanchet <marc.blanchet at viagenie.ca>
+ * Copyright (C) 2007, Viagenie, Inc.
+ */
+#include "asterisk/netsock.h"
+
+struct ast_viha {
+ struct sockaddr_storage netaddr;
+ struct sockaddr_storage netmask;
+ int prefixlen;
+ int sense;
+ struct ast_viha *next;
+};
+
+int ast_viget_ip_or_srv(struct sockaddr *sa, socklen_t *sa_len, const char *value, const char *service)
+{
+ char srv[256];
+ char host[NI_MAXHOST];
+ int tportno = ast_vinetsock_sa_getport(sa, *sa_len);
+ if (ast_vinetsock_sa_fromstr(value, NULL, sa, sa_len, 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) {
+ value = host;
+ }
+ }
+
+ if (ast_vinetsock_sa_fromstr(value, NULL, sa, sa_len, AF_UNSPEC, 0)) {
+ ast_log(LOG_WARNING, "Unable to lookup '%s'\n", value);
+ return -1;
+ }
+ ast_vinetsock_sa_setport(sa, tportno);
+ return 0;
+}
+
+int ast_viget_ip(struct sockaddr *sa, socklen_t *sa_len, const char *value)
+{
+ return ast_viget_ip_or_srv((struct sockaddr*)sa, sa_len, value, NULL);
+}
+
More information about the asterisk-commits
mailing list