2 Unix SMB/CIFS implementation.
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "smbd/service_task.h"
26 #include "nbt_server/nbt_server.h"
30 receive an incoming request
32 static void nbt_request_handler(struct nbt_name_socket *nbtsock,
33 struct nbt_name_packet *packet,
34 const char *src_address, int src_port)
36 switch (packet->operation & NBT_OPCODE) {
37 case NBT_OPCODE_QUERY:
38 nbt_request_query(nbtsock, packet, src_address, src_port);
47 static void nbtd_task_init(struct task_server *task)
49 struct nbt_server *nbtsrv;
50 struct nbt_interface *iface;
53 nbtsrv = talloc(task, struct nbt_server);
55 task_terminate(task, "nbtd: out of memory");
60 nbtsrv->interfaces = NULL;
61 nbtsrv->bcast_interface = NULL;
63 /* start listening on the configured network interfaces */
64 status = nbt_startup_interfaces(nbtsrv);
65 if (!NT_STATUS_IS_OK(status)) {
66 task_terminate(task, "nbtd failed to setup interfaces");
70 /* setup the incoming request handler for all our interfaces */
71 for (iface=nbtsrv->interfaces;iface;iface=iface->next) {
72 nbt_set_incoming_handler(iface->nbtsock, nbt_request_handler, iface);
74 nbt_set_incoming_handler(nbtsrv->bcast_interface->nbtsock, nbt_request_handler,
75 nbtsrv->bcast_interface);
77 /* start the process of registering our names on all interfaces */
78 nbt_register_names(nbtsrv);
83 initialise the nbt server
85 static NTSTATUS nbtd_init(struct event_context *event_ctx, const struct model_ops *model_ops)
87 return task_server_startup(event_ctx, model_ops, nbtd_task_init);
92 register ourselves as a available server
94 NTSTATUS server_service_nbtd_init(void)
96 return register_server_service("nbt", nbtd_init);