Add context for libcli_resolve.
[samba-svnmirror.git] / source / libcli / resolve / bcast.c
index c95fe945b1f6493b726cbabcbaf6ca471fcd050b..5a2c49c5ad8846b3af38de1d71f134eff6093528 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   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,
    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, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
+#include "libcli/resolve/resolve.h"
+#include "system/network.h"
+#include "lib/socket/netif.h"
+#include "param/param.h"
 
-/*
+/**
   broadcast name resolution method - async send
  */
-struct composite_context *resolve_name_bcast_send(struct nbt_name *name, 
-                                                struct event_context *event_ctx)
+struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx, 
+                                                 struct event_context *event_ctx,
+                                                 void *userdata,
+                                                 struct nbt_name *name)
 {
-       int num_interfaces = iface_count();
+       int num_interfaces = iface_count(global_loadparm);
        const char **address_list;
        struct composite_context *c;
-       int i;
+       int i, count=0;
 
-       address_list = talloc_array(NULL, const char *, num_interfaces+1);
+       address_list = talloc_array(mem_ctx, const char *, num_interfaces+1);
        if (address_list == NULL) return NULL;
 
        for (i=0;i<num_interfaces;i++) {
-               address_list[i] = talloc_strdup(address_list, iface_n_bcast(i));
-               if (address_list[i] == NULL) {
+               const char *bcast = iface_n_bcast(global_loadparm, i);
+               if (bcast == NULL) continue;
+               address_list[count] = talloc_strdup(address_list, bcast);
+               if (address_list[count] == NULL) {
                        talloc_free(address_list);
                        return NULL;
                }
+               count++;
        }
-       address_list[i] = NULL;
+       address_list[count] = NULL;
 
-       c = resolve_name_nbtlist_send(name, event_ctx, address_list, True, False);
+       c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, true, false);
        talloc_free(address_list);
 
        return c;       
@@ -67,7 +75,12 @@ NTSTATUS resolve_name_bcast(struct nbt_name *name,
                            TALLOC_CTX *mem_ctx,
                            const char **reply_addr)
 {
-       struct composite_context *c = resolve_name_bcast_send(name, NULL);
+       struct composite_context *c = resolve_name_bcast_send(mem_ctx, NULL, NULL, name);
        return resolve_name_bcast_recv(c, mem_ctx, reply_addr);
 }
 
+bool resolve_context_add_bcast_method(struct resolve_context *ctx)
+{
+       return resolve_context_add_method(ctx, resolve_name_bcast_send, resolve_name_bcast_recv,
+                                         NULL);
+}