diff options
Diffstat (limited to 'source4/libcli')
-rw-r--r-- | source4/libcli/nbt/libnbt.h | 8 | ||||
-rw-r--r-- | source4/libcli/nbt/namequery.c | 4 | ||||
-rw-r--r-- | source4/libcli/nbt/nbtsocket.c | 23 |
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; +} + |