summaryrefslogtreecommitdiff
path: root/source4/nbt_server/interfaces.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-01-30 10:24:36 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:09:23 -0500
commitc7ded5ab0accc54a28df4d43cb923e6c808ff347 (patch)
treeeabb1e05c05f8ce01b0ffbf1fda038a80fc237a0 /source4/nbt_server/interfaces.c
parenta0ab1f7afda62964d480af9dc26e60a38d1350e0 (diff)
downloadsamba-c7ded5ab0accc54a28df4d43cb923e6c808ff347.tar.gz
samba-c7ded5ab0accc54a28df4d43cb923e6c808ff347.tar.bz2
samba-c7ded5ab0accc54a28df4d43cb923e6c808ff347.zip
r5108: the beginnings of a nbtd server for Samba4. Currently just displays
the packets it receives, but it at least shows how the server structure will work. To implement it I extended the libcli/nbt/ library to allow for an incoming packet handler to be registered. That allows the nbt client library to be used for low level processing of the nbtd server packets. Other changes: - made the socket library always set SO_REUSEADDR when binding to an interface, to ensure that restarts of a server don't have to wait for a couple of minutes. - made the nbt port configurable. Defaults to 137, but other ports will be useful for testing. (This used to be commit 2fedca6adfd4df9e85cc86896dfa79630777a917)
Diffstat (limited to 'source4/nbt_server/interfaces.c')
-rw-r--r--source4/nbt_server/interfaces.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/source4/nbt_server/interfaces.c b/source4/nbt_server/interfaces.c
new file mode 100644
index 0000000000..18893e179b
--- /dev/null
+++ b/source4/nbt_server/interfaces.c
@@ -0,0 +1,88 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ NBT interface handling
+
+ Copyright (C) Andrew Tridgell 2005
+
+ 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
+ (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, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "dlinklist.h"
+#include "nbt_server/nbt_server.h"
+#include "smbd/service_task.h"
+#include "libcli/nbt/libnbt.h"
+
+/*
+ start listening on the given address
+*/
+static NTSTATUS nbt_add_socket(struct nbt_server *nbtsrv,
+ const char *address, const char *bcast)
+{
+ struct nbt_interface *iface;
+ NTSTATUS status;
+
+ iface = talloc(nbtsrv, struct nbt_interface);
+ NT_STATUS_HAVE_NO_MEMORY(iface);
+
+ iface->nbtsrv = nbtsrv;
+ iface->bcast_address = talloc_steal(iface, bcast);
+ iface->ip_address = talloc_steal(iface, address);
+
+ iface->nbtsock = nbt_name_socket_init(iface, nbtsrv->task->event_ctx);
+ NT_STATUS_HAVE_NO_MEMORY(iface->ip_address);
+
+ status = socket_listen(iface->nbtsock->sock, address, lp_nbt_port(), 0, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("Failed to bind to %s:%d - %s\n",
+ address, lp_nbt_port(), nt_errstr(status)));
+ talloc_free(iface);
+ return status;
+ }
+
+ DLIST_ADD(nbtsrv->interfaces, iface);
+
+ return NT_STATUS_OK;
+}
+
+
+/*
+ setup our listening sockets on the configured network interfaces
+*/
+NTSTATUS nbt_startup_interfaces(struct nbt_server *nbtsrv)
+{
+ int num_interfaces = iface_count();
+ int i;
+ TALLOC_CTX *tmp_ctx = talloc_new(nbtsrv);
+ NTSTATUS status;
+
+ status = nbt_add_socket(nbtsrv,
+ talloc_strdup(tmp_ctx, "0.0.0.0"),
+ talloc_strdup(tmp_ctx, "255.255.255.255"));
+ NT_STATUS_NOT_OK_RETURN(status);
+
+ for (i=0; i<num_interfaces; i++) {
+ const char *address = talloc_strdup(tmp_ctx, sys_inet_ntoa(*iface_n_ip(i)));
+ const char *bcast = talloc_strdup(tmp_ctx, sys_inet_ntoa(*iface_n_bcast(i)));
+
+ status = nbt_add_socket(nbtsrv, address, bcast);
+ NT_STATUS_NOT_OK_RETURN(status);
+ }
+
+ talloc_free(tmp_ctx);
+
+ return NT_STATUS_OK;
+}