]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
handle DNS failures on startup more gracefully (bug #3086)
authorRussell Bryant <russell@russellbryant.com>
Mon, 21 Feb 2005 03:57:27 +0000 (03:57 +0000)
committerRussell Bryant <russell@russellbryant.com>
Mon, 21 Feb 2005 03:57:27 +0000 (03:57 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/v1-0@5061 65c4cc65-6c06-0410-ace0-fbb531ad65f3

acl.c
channels/chan_sip.c

diff --git a/acl.c b/acl.c
index 935ec808dab40f55e102286477aac4829fe5560c..5fa8b7c8b57afadd5034a3ff80b8b23d84fc85f5 100755 (executable)
--- a/acl.c
+++ b/acl.c
@@ -378,3 +378,32 @@ int ast_ouraddrfor(struct in_addr *them, struct in_addr *us)
        return 0;
 #endif
 }
+
+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;
+}
+
index 5bb4466f7cee24416153f4fed7af246b9df591e5..6873dce625b8ea8bd20bbdb7c2c2d5865c21cdfc 100755 (executable)
@@ -190,7 +190,6 @@ static int restart_monitor(void);
 static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
 static int noncodeccapability = AST_RTP_DTMF;
 
-static char ourhost[256];
 static struct in_addr __ourip;
 static int ourport;
 
@@ -8603,10 +8602,6 @@ static int reload_config(void)
        global_dtmfmode = SIP_DTMF_RFC2833;
        global_promiscredir = 0;
        
-       if (gethostname(ourhost, sizeof(ourhost))) {
-               ast_log(LOG_WARNING, "Unable to get hostname, SIP disabled\n");
-               return 0;
-       }
        cfg = ast_load(config);
 
        /* We *must* have a config file otherwise stop immediately */
@@ -8827,19 +8822,11 @@ static int reload_config(void)
                cat = ast_category_browse(cfg, cat);
        }
        
-       if (ntohl(bindaddr.sin_addr.s_addr)) {
-               memcpy(&__ourip, &bindaddr.sin_addr, sizeof(__ourip));
-       } else {
-               hp = ast_gethostbyname(ourhost, &ahp);
-               if (!hp) {
-                       ast_log(LOG_WARNING, "Unable to get IP address for %s, SIP disabled\n", ourhost);
-                       if (!__ourip.s_addr) {
-                               ast_destroy(cfg);
-                               return 0;
-                       }
-               } else
-                       memcpy(&__ourip, hp->h_addr, sizeof(__ourip));
-       }
+       if (ast_find_ourip(&__ourip, bindaddr)) {
+               ast_log(LOG_WARNING, "Unable to get own IP address, SIP disabled\n");
+               return 0;
+       }
+
        if (!ntohs(bindaddr.sin_port))
                bindaddr.sin_port = ntohs(DEFAULT_SIP_PORT);
        bindaddr.sin_family = AF_INET;