s3-net: move out some prototypes to net_dns.h.
[obnox/samba/samba-obnox.git] / source3 / utils / net_dns.c
index 44a0b46e4eae2871c287764e9799f6e15b16f40f..2948e7cd3c9f71b0534bb39032c33a9f9bb13f1f 100644 (file)
@@ -1,4 +1,3 @@
-
 /* 
    Samba Unix/Linux Dynamic DNS Update
    net ads commands
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  
 */
 
 #include "includes.h"
 #include "utils/net.h"
-#include "dns.h"
+#include "../lib/addns/dns.h"
+#include "utils/net_dns.h"
 
 #if defined(WITH_DNS_UPDATES)
 
-/*
- * Silly prototype to get rid of a warning
- */
-
-DNS_ERROR DoDNSUpdate(char *pszServerName,
-                     const char *pszDomainName, const char *pszHostName,
-                     const struct sockaddr_storage *sslist, size_t num_addrs );
-
 /*********************************************************************
 *********************************************************************/
 
@@ -54,7 +46,7 @@ DNS_ERROR DoDNSUpdate(char *pszServerName,
        if (!(mem_ctx = talloc_init("DoDNSUpdate"))) {
                return ERROR_DNS_NO_MEMORY;
        }
-               
+
        err = dns_open_connection( pszServerName, DNS_TCP, mem_ctx, &conn );
        if (!ERR_DNS_IS_OK(err)) {
                goto error;
@@ -113,10 +105,9 @@ DNS_ERROR DoDNSUpdate(char *pszServerName,
                                                     keyname, &gss_context, 
                                                     DNS_SRV_WIN2000 );
                }
-               
+
                if (!ERR_DNS_IS_OK(err))
                        goto error;
-               
 
                err = dns_sign_update(req, gss_context, keyname,
                                      "gss.microsoft.com", time(NULL), 3600);
@@ -144,14 +135,14 @@ error:
 int get_my_ip_address( struct sockaddr_storage **pp_ss )
 
 {
-       struct iface_struct nics[MAX_INTERFACES];
        int i, n;
        struct sockaddr_storage *list = NULL;
        int count = 0;
 
-       /* find the first non-loopback address from our list of interfaces */
+       /* Honor the configured list of interfaces to register */
 
-       n = get_interfaces(nics, MAX_INTERFACES);
+       load_interfaces();
+       n = iface_count();
 
        if (n <= 0) {
                return -1;
@@ -162,31 +153,28 @@ int get_my_ip_address( struct sockaddr_storage **pp_ss )
        }
 
        for ( i=0; i<n; i++ ) {
-               if (is_loopback_addr(&nics[i].ip)) {
+               const struct sockaddr_storage *nic_sa_storage = NULL;
+
+               if ((nic_sa_storage = iface_n_sockaddr_storage(i)) == NULL)
+                       continue;
+
+               /* Don't register loopback addresses */
+               if (is_loopback_addr((const struct sockaddr *)nic_sa_storage)) {
                        continue;
                }
-#if defined(HAVE_IPV6)
-               if ((nics[i].ip.ss_family == AF_INET)) {
-                       memcpy(&list[count++], &nics[i].ip,
-                              sizeof(struct sockaddr_storage));
-               } else
-#endif
-               if (nics[i].ip.ss_family == AF_INET) {
-                       memcpy(&list[count++], &nics[i].ip,
-                              sizeof(struct sockaddr_storage));
+
+               /* Don't register link-local addresses */
+               if (is_linklocal_addr(nic_sa_storage)) {
+                       continue;
                }
+
+               memcpy(&list[count++], nic_sa_storage, sizeof(struct sockaddr_storage));
        }
        *pp_ss = list;
 
        return count;
 }
 
-/*
- * Silly prototype to get rid of a warning
- */
-
-DNS_ERROR do_gethostbyname(const char *server, const char *host);
-
 DNS_ERROR do_gethostbyname(const char *server, const char *host)
 {
        struct dns_connection *conn;