summaryrefslogtreecommitdiff
path: root/source4/libcli/nbt
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
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')
-rw-r--r--source4/libcli/nbt/libnbt.h8
-rw-r--r--source4/libcli/nbt/namequery.c4
-rw-r--r--source4/libcli/nbt/nbtsocket.c23
3 files changed, 32 insertions, 3 deletions
diff --git a/source4/libcli/nbt/libnbt.h b/source4/libcli/nbt/libnbt.h
index a7788f791b..82069f0390 100644
--- a/source4/libcli/nbt/libnbt.h
+++ b/source4/libcli/nbt/libnbt.h
@@ -90,6 +90,14 @@ struct nbt_name_socket {
/* how many requests are waiting for a reply */
uint16_t num_pending;
+
+ /* what to do with incoming request packets */
+ struct {
+ void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
+ const char *, int );
+ void *private;
+ } incoming;
+
};
diff --git a/source4/libcli/nbt/namequery.c b/source4/libcli/nbt/namequery.c
index 05d5e55491..6f549e6241 100644
--- a/source4/libcli/nbt/namequery.c
+++ b/source4/libcli/nbt/namequery.c
@@ -52,7 +52,7 @@ struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock,
packet->questions[0].question_type = NBT_QTYPE_NETBIOS;
packet->questions[0].question_class = NBT_QCLASS_IP;
- req = nbt_name_request_send(nbtsock, io->in.dest_addr, NBT_NAME_SERVICE_PORT, packet,
+ req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet,
timeval_current_ofs(io->in.timeout, 0), False);
if (req == NULL) goto failed;
@@ -142,7 +142,7 @@ struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock,
packet->questions[0].question_type = NBT_QTYPE_STATUS;
packet->questions[0].question_class = NBT_QCLASS_IP;
- req = nbt_name_request_send(nbtsock, io->in.dest_addr, NBT_NAME_SERVICE_PORT, packet,
+ req = nbt_name_request_send(nbtsock, io->in.dest_addr, lp_nbt_port(), packet,
timeval_current_ofs(io->in.timeout, 0), False);
if (req == NULL) goto failed;
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;
+}
+