2 Unix SMB/CIFS implementation.
4 broadcast name resolution module
6 Copyright (C) Andrew Tridgell 2005
7 Copyright (C) Jelmer Vernooij 2007
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "libcli/resolve/resolve.h"
25 #include "system/network.h"
26 #include "lib/socket/netif.h"
27 #include "param/param.h"
29 struct resolve_bcast_data {
30 struct interface *ifaces;
36 broadcast name resolution method - async send
38 struct composite_context *resolve_name_bcast_send(TALLOC_CTX *mem_ctx,
39 struct event_context *event_ctx,
41 struct nbt_name *name)
44 const char **address_list;
45 struct composite_context *c;
47 struct resolve_bcast_data *data = talloc_get_type(userdata, struct resolve_bcast_data);
49 num_interfaces = iface_count(data->ifaces);
51 address_list = talloc_array(mem_ctx, const char *, num_interfaces+1);
52 if (address_list == NULL) return NULL;
54 for (i=0;i<num_interfaces;i++) {
55 const char *bcast = iface_n_bcast(data->ifaces, i);
56 if (bcast == NULL) continue;
57 address_list[count] = talloc_strdup(address_list, bcast);
58 if (address_list[count] == NULL) {
59 talloc_free(address_list);
64 address_list[count] = NULL;
66 c = resolve_name_nbtlist_send(mem_ctx, event_ctx, name, address_list, data->ifaces, data->nbt_port, data->nbt_timeout, true, false);
67 talloc_free(address_list);
73 broadcast name resolution method - recv side
75 NTSTATUS resolve_name_bcast_recv(struct composite_context *c,
76 TALLOC_CTX *mem_ctx, const char **reply_addr)
78 return resolve_name_nbtlist_recv(c, mem_ctx, reply_addr);
82 broadcast name resolution method - sync call
84 NTSTATUS resolve_name_bcast(struct nbt_name *name,
86 struct interface *ifaces,
89 const char **reply_addr)
91 struct resolve_bcast_data *data = talloc(mem_ctx, struct resolve_bcast_data);
92 struct composite_context *c;
93 data->ifaces = talloc_reference(data, ifaces);
94 data->nbt_port = nbt_port;
95 data->nbt_timeout = nbt_timeout;
97 c = resolve_name_bcast_send(mem_ctx, NULL, data, name);
98 return resolve_name_bcast_recv(c, mem_ctx, reply_addr);
101 bool resolve_context_add_bcast_method(struct resolve_context *ctx, struct interface *ifaces, uint16_t nbt_port, int nbt_timeout)
103 struct resolve_bcast_data *data = talloc(ctx, struct resolve_bcast_data);
104 data->ifaces = ifaces;
105 data->nbt_port = nbt_port;
106 data->nbt_timeout = nbt_timeout;
107 return resolve_context_add_method(ctx, resolve_name_bcast_send, resolve_name_bcast_recv, data);
110 bool resolve_context_add_bcast_method_lp(struct resolve_context *ctx, struct loadparm_context *lp_ctx)
112 struct interface *ifaces;
113 load_interfaces(ctx, lp_interfaces(lp_ctx), &ifaces);
114 return resolve_context_add_bcast_method(ctx, ifaces, lp_nbt_port(lp_ctx), lp_parm_int(lp_ctx, NULL, "nbt", "timeout", 1));