2 Unix SMB/CIFS implementation.
4 a raw async NBT library
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "librpc/gen_ndr/nbt.h"
26 #include "librpc/ndr/libndr.h"
28 possible states for pending requests
30 enum nbt_request_state
{NBT_REQUEST_SEND
,
39 struct nbt_name_request
{
40 struct nbt_name_request
*next
, *prev
;
42 enum nbt_request_state state
;
46 /* the socket this was on */
47 struct nbt_name_socket
*nbtsock
;
49 /* where to send the request */
50 struct socket_address
*dest
;
52 /* timeout between retries */
55 /* how many retries to send on timeout */
58 /* whether we have received a WACK */
61 /* the timeout event */
62 struct tevent_timer
*te
;
64 /* the name transaction id */
70 /* the encoded request */
73 /* shall we allow multiple replies? */
74 bool allow_multiple_replies
;
76 unsigned int num_replies
;
77 struct nbt_name_reply
{
78 struct nbt_name_packet
*packet
;
79 struct socket_address
*dest
;
82 /* information on what to do on completion */
84 void (*fn
)(struct nbt_name_request
*);
92 context structure for operations on name queries
94 struct nbt_name_socket
{
95 struct socket_context
*sock
;
96 struct tevent_context
*event_ctx
;
98 /* a queue of requests pending to be sent */
99 struct nbt_name_request
*send_queue
;
102 struct tevent_fd
*fde
;
104 /* mapping from name_trn_id to pending event */
105 struct idr_context
*idr
;
107 /* how many requests are waiting for a reply */
108 uint16_t num_pending
;
110 /* what to do with incoming request packets */
112 void (*handler
)(struct nbt_name_socket
*, struct nbt_name_packet
*,
113 struct socket_address
*);
117 /* what to do with unexpected replies */
119 void (*handler
)(struct nbt_name_socket
*, struct nbt_name_packet
*,
120 struct socket_address
*);
126 /* a simple name query */
127 struct nbt_name_query
{
129 struct nbt_name name
;
130 const char *dest_addr
;
134 int timeout
; /* in seconds */
138 const char *reply_from
;
139 struct nbt_name name
;
141 const char **reply_addrs
;
145 /* a simple name status query */
146 struct nbt_name_status
{
148 struct nbt_name name
;
149 const char *dest_addr
;
151 int timeout
; /* in seconds */
155 const char *reply_from
;
156 struct nbt_name name
;
157 struct nbt_rdata_status status
;
161 /* a name registration request */
162 struct nbt_name_register
{
164 struct nbt_name name
;
165 const char *dest_addr
;
169 bool register_demand
;
173 int timeout
; /* in seconds */
177 const char *reply_from
;
178 struct nbt_name name
;
179 const char *reply_addr
;
184 /* a send 3 times then demand name broadcast name registration */
185 struct nbt_name_register_bcast
{
187 struct nbt_name name
;
188 const char *dest_addr
;
197 /* wins name register with multiple wins servers to try and multiple
198 addresses to register */
199 struct nbt_name_register_wins
{
201 struct nbt_name name
;
202 const char **wins_servers
;
204 const char **addresses
;
209 const char *wins_server
;
216 /* a name refresh request */
217 struct nbt_name_refresh
{
219 struct nbt_name name
;
220 const char *dest_addr
;
226 int timeout
; /* in seconds */
230 const char *reply_from
;
231 struct nbt_name name
;
232 const char *reply_addr
;
237 /* wins name refresh with multiple wins servers to try and multiple
238 addresses to register */
239 struct nbt_name_refresh_wins
{
241 struct nbt_name name
;
242 const char **wins_servers
;
244 const char **addresses
;
249 const char *wins_server
;
255 /* a name release request */
256 struct nbt_name_release
{
258 struct nbt_name name
;
259 const char *dest_addr
;
264 int timeout
; /* in seconds */
268 const char *reply_from
;
269 struct nbt_name name
;
270 const char *reply_addr
;
275 struct nbt_name_socket
*nbt_name_socket_init(TALLOC_CTX
*mem_ctx
,
276 struct tevent_context
*event_ctx
);
277 void nbt_name_socket_handle_response_packet(struct nbt_name_request
*req
,
278 struct nbt_name_packet
*packet
,
279 struct socket_address
*src
);
280 struct nbt_name_request
*nbt_name_query_send(struct nbt_name_socket
*nbtsock
,
281 struct nbt_name_query
*io
);
282 NTSTATUS
nbt_name_query_recv(struct nbt_name_request
*req
,
283 TALLOC_CTX
*mem_ctx
, struct nbt_name_query
*io
);
284 NTSTATUS
nbt_name_query(struct nbt_name_socket
*nbtsock
,
285 TALLOC_CTX
*mem_ctx
, struct nbt_name_query
*io
);
286 struct nbt_name_request
*nbt_name_status_send(struct nbt_name_socket
*nbtsock
,
287 struct nbt_name_status
*io
);
288 NTSTATUS
nbt_name_status_recv(struct nbt_name_request
*req
,
289 TALLOC_CTX
*mem_ctx
, struct nbt_name_status
*io
);
290 NTSTATUS
nbt_name_status(struct nbt_name_socket
*nbtsock
,
291 TALLOC_CTX
*mem_ctx
, struct nbt_name_status
*io
);
293 NTSTATUS
nbt_name_dup(TALLOC_CTX
*mem_ctx
, struct nbt_name
*name
, struct nbt_name
*newname
);
294 NTSTATUS
nbt_name_to_blob(TALLOC_CTX
*mem_ctx
, DATA_BLOB
*blob
, struct nbt_name
*name
);
295 NTSTATUS
nbt_name_from_blob(TALLOC_CTX
*mem_ctx
, const DATA_BLOB
*blob
, struct nbt_name
*name
);
296 void nbt_choose_called_name(TALLOC_CTX
*mem_ctx
, struct nbt_name
*n
, const char *name
, int type
);
297 char *nbt_name_string(TALLOC_CTX
*mem_ctx
, const struct nbt_name
*name
);
298 NTSTATUS
nbt_name_register(struct nbt_name_socket
*nbtsock
,
299 TALLOC_CTX
*mem_ctx
, struct nbt_name_register
*io
);
300 NTSTATUS
nbt_name_refresh(struct nbt_name_socket
*nbtsock
,
301 TALLOC_CTX
*mem_ctx
, struct nbt_name_refresh
*io
);
302 NTSTATUS
nbt_name_release(struct nbt_name_socket
*nbtsock
,
303 TALLOC_CTX
*mem_ctx
, struct nbt_name_release
*io
);
304 NTSTATUS
nbt_name_register_wins(struct nbt_name_socket
*nbtsock
,
306 struct nbt_name_register_wins
*io
);
307 NTSTATUS
nbt_name_refresh_wins(struct nbt_name_socket
*nbtsock
,
309 struct nbt_name_refresh_wins
*io
);
310 NTSTATUS
nbt_name_register_recv(struct nbt_name_request
*req
,
311 TALLOC_CTX
*mem_ctx
, struct nbt_name_register
*io
);
312 struct nbt_name_request
*nbt_name_register_send(struct nbt_name_socket
*nbtsock
,
313 struct nbt_name_register
*io
);
314 NTSTATUS
nbt_name_release_recv(struct nbt_name_request
*req
,
315 TALLOC_CTX
*mem_ctx
, struct nbt_name_release
*io
);
317 struct nbt_name_request
*nbt_name_release_send(struct nbt_name_socket
*nbtsock
,
318 struct nbt_name_release
*io
);
320 NTSTATUS
nbt_name_refresh_recv(struct nbt_name_request
*req
,
321 TALLOC_CTX
*mem_ctx
, struct nbt_name_refresh
*io
);
323 NTSTATUS
nbt_set_incoming_handler(struct nbt_name_socket
*nbtsock
,
324 void (*handler
)(struct nbt_name_socket
*, struct nbt_name_packet
*,
325 struct socket_address
*),
327 NTSTATUS
nbt_set_unexpected_handler(struct nbt_name_socket
*nbtsock
,
328 void (*handler
)(struct nbt_name_socket
*, struct nbt_name_packet
*,
329 struct socket_address
*),
331 NTSTATUS
nbt_name_reply_send(struct nbt_name_socket
*nbtsock
,
332 struct socket_address
*dest
,
333 struct nbt_name_packet
*request
);
336 NDR_SCALAR_PROTO(wrepl_nbt_name
, const struct nbt_name
*)
337 NDR_BUFFER_PROTO(nbt_name
, struct nbt_name
)
338 NTSTATUS
nbt_rcode_to_ntstatus(uint8_t rcode
);
340 struct tevent_context
;
342 struct tevent_req
*nbt_name_register_bcast_send(TALLOC_CTX
*mem_ctx
,
343 struct tevent_context
*ev
,
344 struct nbt_name_socket
*nbtsock
,
345 struct nbt_name_register_bcast
*io
);
346 NTSTATUS
nbt_name_register_bcast_recv(struct tevent_req
*req
);
347 struct tevent_req
*nbt_name_register_wins_send(TALLOC_CTX
*mem_ctx
,
348 struct tevent_context
*ev
,
349 struct nbt_name_socket
*nbtsock
,
350 struct nbt_name_register_wins
*io
);
351 NTSTATUS
nbt_name_register_wins_recv(struct tevent_req
*req
,
353 struct nbt_name_register_wins
*io
);
354 struct tevent_req
*nbt_name_refresh_wins_send(TALLOC_CTX
*mem_ctx
,
355 struct tevent_context
*ev
,
356 struct nbt_name_socket
*nbtsock
,
357 struct nbt_name_refresh_wins
*io
);
358 NTSTATUS
nbt_name_refresh_wins_recv(struct tevent_req
*req
,
360 struct nbt_name_refresh_wins
*io
);
362 XFILE
*startlmhosts(const char *fname
);
363 bool getlmhostsent(TALLOC_CTX
*ctx
, XFILE
*fp
, char **pp_name
, int *name_type
,
364 struct sockaddr_storage
*pss
);
365 void endlmhosts(XFILE
*fp
);
367 NTSTATUS
resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file
,
368 const char *name
, int name_type
,
370 struct sockaddr_storage
**return_iplist
,
373 NTSTATUS
resolve_dns_hosts_file_as_sockaddr(const char *dns_hosts_file
,
374 const char *name
, bool srv_lookup
,
376 struct sockaddr_storage
**return_iplist
,
379 #endif /* __LIBNBT_H__ */