summaryrefslogtreecommitdiff
path: root/source4/libcli/nbt/nbtsocket.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/libcli/nbt/nbtsocket.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/libcli/nbt/nbtsocket.c')
-rw-r--r--source4/libcli/nbt/nbtsocket.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/source4/libcli/nbt/nbtsocket.c b/source4/libcli/nbt/nbtsocket.c
index 1eea77d356..f1964b7158 100644
--- a/source4/libcli/nbt/nbtsocket.c
+++ b/source4/libcli/nbt/nbtsocket.c
@@ -51,7 +51,8 @@ static int nbt_name_request_destructor(void *ptr)
if (req->nbtsock->send_queue == NULL) {
req->nbtsock->fde->flags &= ~EVENT_FD_WRITE;
}
- if (req->nbtsock->num_pending == 0) {
+ if (req->nbtsock->num_pending == 0 &&
+ req->nbtsock->incoming.handler == NULL) {
req->nbtsock->fde->flags &= ~EVENT_FD_READ;
}
return 0;
@@ -170,6 +171,9 @@ static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
}
if (!(packet->operation & NBT_FLAG_REPLY)) {
+ if (nbtsock->incoming.handler) {
+ nbtsock->incoming.handler(nbtsock, packet, src_addr, src_port);
+ }
talloc_free(tmp_ctx);
return;
}
@@ -375,3 +379,20 @@ NTSTATUS nbt_name_request_recv(struct nbt_name_request *req)
}
return req->status;
}
+
+
+/*
+ setup a handler for incoming requests
+*/
+NTSTATUS nbt_set_incoming_handler(struct nbt_name_socket *nbtsock,
+ void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
+ const char *, int ),
+ void *private)
+{
+ nbtsock->incoming.handler = handler;
+ nbtsock->incoming.private = private;
+ nbtsock->fde->flags |= EVENT_FD_READ;
+ socket_set_option(nbtsock->sock, "SO_BROADCAST", "1");
+ return NT_STATUS_OK;
+}
+