[asterisk-commits] simon.perreault: branch group/v6-new r273893 - /team/group/v6-new/main/acl.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jul 5 09:08:09 CDT 2010
Author: simon.perreault
Date: Mon Jul 5 09:08:06 2010
New Revision: 273893
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=273893
Log:
Factored common code into resolve_first()
Modified:
team/group/v6-new/main/acl.c
Modified: team/group/v6-new/main/acl.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/main/acl.c?view=diff&rev=273893&r1=273892&r2=273893
==============================================================================
--- team/group/v6-new/main/acl.c (original)
+++ team/group/v6-new/main/acl.c Mon Jul 5 09:08:06 2010
@@ -374,12 +374,30 @@
return res;
}
+static int resolve_first(struct ast_sockaddr *addr, const char *name, int flag,
+ int family)
+{
+ struct ast_sockaddr *addrs;
+ int addrs_cnt;
+
+ addrs_cnt = ast_sockaddr_resolve(&addrs, name, flag, family);
+ if (addrs_cnt > 0) {
+ if (addrs_cnt > 1)
+ ast_log(LOG_DEBUG, "Multiple addresses. Using the first only\n");
+ ast_sockaddr_copy(addr, &addrs[0]);
+ ast_free(addrs);
+ } else {
+ ast_log(LOG_WARNING, "Unable to lookup '%s'\n", name);
+ return -1;
+ }
+
+ return 0;
+}
+
int ast_get_ip_or_srv(struct ast_sockaddr *addr, const char *value, const char *service)
{
char srv[256];
char host[256];
- struct ast_sockaddr *addrs;
- int addrs_cnt;
int srv_ret = 0;
int tportno;
@@ -389,16 +407,8 @@
value = host;
}
- addrs_cnt = ast_sockaddr_resolve(&addrs, value, PARSE_PORT_FORBID, addr->ss.ss_family);
- if (addrs_cnt > 0) {
- if (addrs_cnt > 1)
- ast_log(LOG_WARNING, "Multiple addresses. Using the first only\n");
- ast_sockaddr_copy(addr, &addrs[0]);
- ast_free(addrs);
- } else {
- ast_log(LOG_WARNING, "Unable to lookup '%s'\n", value);
+ if (resolve_first(addr, value, PARSE_PORT_FORBID, addr->ss.ss_family) != 0)
return -1;
- }
if (srv_ret > 0)
ast_sockaddr_set_port(addr, tportno);
@@ -526,8 +536,7 @@
int ast_find_ourip(struct ast_sockaddr *ourip, const struct ast_sockaddr *bindaddr)
{
char ourhost[MAXHOSTNAMELEN] = "";
- struct ast_sockaddr *addrs;
- int addrs_cnt;
+ struct ast_sockaddr root;
/* just use the bind address if it is nonzero */
if (!ast_sockaddr_is_any(bindaddr)) {
@@ -539,29 +548,15 @@
if (gethostname(ourhost, sizeof(ourhost) - 1)) {
ast_log(LOG_WARNING, "Unable to get hostname\n");
} else {
- addrs_cnt = ast_sockaddr_resolve(&addrs, ourhost,
- PARSE_PORT_FORBID, 0);
- if (addrs_cnt > 0) {
- if (addrs_cnt > 1)
- ast_log(LOG_WARNING, "Multiple addresses. Using the first only\n");
- ast_sockaddr_copy(ourip, &addrs[0]);
- ast_free(addrs);
- ast_debug(3, "Found one IP address based on local hostname %s.\n", ourhost);
+ if (resolve_first(ourip, ourhost, PARSE_PORT_FORBID, 0) == 0) {
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. */
- addrs_cnt = ast_sockaddr_resolve(&addrs, "A.ROOT-SERVERS.NET",
- PARSE_PORT_FORBID, 0);
- if (addrs_cnt > 0) {
- if (addrs_cnt > 1)
- ast_log(LOG_WARNING, "Multiple addresses. Using the first only\n");
- if(!ast_ouraddrfor(&addrs[0], ourip)) {
- ast_free(addrs);
- return 0;
- }
- ast_free(addrs);
+ 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