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
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
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.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "libcli/nbt/libnbt.h"
+#include "lib/socket/socket.h"
+#include "param/param.h"
-/*
+/**
send a nbt name query
*/
-struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock,
+_PUBLIC_ struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock,
struct nbt_name_query *io)
{
struct nbt_name_request *req;
struct nbt_name_packet *packet;
+ struct socket_address *dest;
packet = talloc_zero(nbtsock, struct nbt_name_packet);
if (packet == NULL) return NULL;
packet->questions[0].name = io->in.name;
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, lp_nbt_port(), packet,
+
+ dest = socket_address_from_strings(packet, nbtsock->sock->backend_name,
+ io->in.dest_addr, lp_nbt_port());
+ if (dest == NULL) goto failed;
+ req = nbt_name_request_send(nbtsock, dest, packet,
io->in.timeout, io->in.retries, False);
if (req == NULL) goto failed;
return NULL;
}
-/*
+/**
wait for a name query reply
*/
-NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
+_PUBLIC_ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
TALLOC_CTX *mem_ctx, struct nbt_name_query *io)
{
NTSTATUS status;
}
packet = req->replies[0].packet;
- io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].reply_addr);
+ io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest->addr);
if ((packet->operation & NBT_RCODE) != 0) {
status = nbt_rcode_to_ntstatus(packet->operation & NBT_RCODE);
io->out.name = packet->answers[0].name;
io->out.num_addrs = packet->answers[0].rdata.netbios.length / 6;
- io->out.reply_addrs = talloc_array(mem_ctx, const char *, io->out.num_addrs);
+ io->out.reply_addrs = talloc_array(mem_ctx, const char *, io->out.num_addrs+1);
if (io->out.reply_addrs == NULL) {
talloc_free(req);
return NT_STATUS_NO_MEMORY;
}
for (i=0;i<io->out.num_addrs;i++) {
- io->out.reply_addrs[i] = talloc_steal(mem_ctx,
+ io->out.reply_addrs[i] = talloc_steal(io->out.reply_addrs,
packet->answers[0].rdata.netbios.addresses[i].ipaddr);
}
+ io->out.reply_addrs[i] = NULL;
talloc_steal(mem_ctx, io->out.name.name);
talloc_steal(mem_ctx, io->out.name.scope);
return NT_STATUS_OK;
}
-/*
+/**
wait for a name query reply
*/
-NTSTATUS nbt_name_query(struct nbt_name_socket *nbtsock,
+_PUBLIC_ NTSTATUS nbt_name_query(struct nbt_name_socket *nbtsock,
TALLOC_CTX *mem_ctx, struct nbt_name_query *io)
{
struct nbt_name_request *req = nbt_name_query_send(nbtsock, io);
}
-/*
+/**
send a nbt name status
*/
-struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock,
+_PUBLIC_ struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock,
struct nbt_name_status *io)
{
struct nbt_name_request *req;
struct nbt_name_packet *packet;
+ struct socket_address *dest;
packet = talloc_zero(nbtsock, struct nbt_name_packet);
if (packet == NULL) return NULL;
packet->questions[0].name = io->in.name;
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, lp_nbt_port(), packet,
+
+ dest = socket_address_from_strings(packet, nbtsock->sock->backend_name,
+ io->in.dest_addr, lp_nbt_port());
+ if (dest == NULL) goto failed;
+ req = nbt_name_request_send(nbtsock, dest, packet,
io->in.timeout, io->in.retries, False);
if (req == NULL) goto failed;
return NULL;
}
-/*
+/**
wait for a name status reply
*/
-NTSTATUS nbt_name_status_recv(struct nbt_name_request *req,
+_PUBLIC_ NTSTATUS nbt_name_status_recv(struct nbt_name_request *req,
TALLOC_CTX *mem_ctx, struct nbt_name_status *io)
{
NTSTATUS status;
}
packet = req->replies[0].packet;
- io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].reply_addr);
+ io->out.reply_from = talloc_steal(mem_ctx, req->replies[0].dest->addr);
if ((packet->operation & NBT_RCODE) != 0) {
status = nbt_rcode_to_ntstatus(packet->operation & NBT_RCODE);
return NT_STATUS_OK;
}
-/*
+/**
wait for a name status reply
*/
-NTSTATUS nbt_name_status(struct nbt_name_socket *nbtsock,
+_PUBLIC_ NTSTATUS nbt_name_status(struct nbt_name_socket *nbtsock,
TALLOC_CTX *mem_ctx, struct nbt_name_status *io)
{
struct nbt_name_request *req = nbt_name_status_send(nbtsock, io);