aboutsummaryrefslogtreecommitdiffstats
path: root/acl.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-02-09 03:22:42 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-02-09 03:22:42 +0000
commit2cd6fff4d0a310389a372ca154f08ee887caa83e (patch)
treee10408b6455f04f154abd2a2d43030d6a922007c /acl.c
parente0e45dd31dac9c54f8680f723ba08d50d181d0a7 (diff)
Handle DNS failures on startup more gracefully (bug #3086)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4989 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'acl.c')
-rwxr-xr-xacl.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/acl.c b/acl.c
index dbc2065dd..7042eeee5 100755
--- a/acl.c
+++ b/acl.c
@@ -384,3 +384,32 @@ struct ast_netsock *ast_netsock_bind(struct ast_netsock_list *list, struct io_co
ast_log(LOG_WARNING, "Out of memory!\n");
return NULL;
}
+
+int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr)
+{
+ char ourhost[256];
+ struct ast_hostent ahp;
+ struct hostent *hp;
+ struct in_addr saddr;
+
+ /* just use the bind address if it is nonzero */
+ if (ntohl(bindaddr.sin_addr.s_addr)) {
+ memcpy(ourip, &bindaddr.sin_addr, sizeof(*ourip));
+ return 0;
+ }
+ /* try to use our hostname */
+ if (gethostname(ourhost, sizeof(ourhost))) {
+ ast_log(LOG_WARNING, "Unable to get hostname\n");
+ } else {
+ hp = ast_gethostbyname(ourhost, &ahp);
+ if (hp) {
+ memcpy(ourip, hp->h_addr, sizeof(*ourip));
+ return 0;
+ }
+ }
+ /* A.ROOT-SERVERS.NET. */
+ if (inet_aton("198.41.0.4", &saddr) && !ast_ouraddrfor(&saddr, ourip))
+ return 0;
+ return -1;
+}
+