Index: main/acl.c =================================================================== --- main/acl.c (revision 98980) +++ main/acl.c (working copy) @@ -329,6 +329,7 @@ struct ast_hostent ahp; struct hostent *hp; struct in_addr saddr; + int i, j; /* just use the bind address if it is nonzero */ if (ntohl(bindaddr.sin_addr.s_addr)) { @@ -348,9 +349,39 @@ } } ast_debug(3, "Trying to check A.ROOT-SERVERS.NET and get our IP address for that connection\n"); - /* A.ROOT-SERVERS.NET. */ + /* A.ROOT-SERVERS.NET. - This will succeed 99.999% of the time */ if (inet_aton("198.41.0.4", &saddr) && !ast_ouraddrfor(&saddr, ourip)) return 0; + /* Works on *BSD to find local link address */ + if (inet_aton("0.0.0.1", &saddr) && !ast_ouraddrfor(&saddr, ourip)) + return 0; + /* Not really a network, but could be */ + if (inet_aton("169.254.0.1", &saddr) && !ast_ouraddrfor(&saddr, ourip)) + return 0; + /* Test network */ + if (inet_aton("192.0.2.1", &saddr) && !ast_ouraddrfor(&saddr, ourip)) + return 0; + /* Search bogons */ + for (i = 0; i < 256; i++) { + snprintf(ourhost, sizeof(ourhost), "192.168.%d.1", i); + if (inet_aton(ourhost, &saddr) && !ast_ouraddrfor(&saddr, ourip)) + return 0; + } + for (i = 16; i < 32; i++) { + for (j = 0; j < 256; j++) { + snprintf(ourhost, sizeof(ourhost), "172.%d.%d.1", i, j); + if (inet_aton(ourhost, &saddr) && !ast_ouraddrfor(&saddr, ourip)) + return 0; + } + } + for (i = 0; i < 256; i++) { + for (j = 0; j < 256; j++) { + snprintf(ourhost, sizeof(ourhost), "10.%d.%d.1", i, j); + if (inet_aton(ourhost, &saddr) && !ast_ouraddrfor(&saddr, ourip)) + return 0; + } + } + ast_debug(3, "Failed to find any IP address for us\n"); return -1; }