r25026: Move param/param.h out of includes.h
[kai/samba-autobuild/.git] / source4 / libcli / nbt / namequery.c
index a9748c7bd25dc1a326a4f271eb1e1045500b71fe..ab26a7b2d2d6afedab9b294da7648fb8c26b4fa2 100644 (file)
@@ -7,7 +7,7 @@
    
    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;
@@ -50,8 +52,11 @@ struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nbtsock,
        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;
 
@@ -63,10 +68,10 @@ 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;
@@ -81,7 +86,7 @@ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
        }
        
        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);
@@ -98,16 +103,17 @@ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
 
        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);
@@ -117,10 +123,10 @@ NTSTATUS nbt_name_query_recv(struct nbt_name_request *req,
        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);
@@ -128,14 +134,15 @@ NTSTATUS nbt_name_query(struct nbt_name_socket *nbtsock,
 }
 
 
-/*
+/**
   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;
@@ -149,8 +156,11 @@ struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *nbtsock,
        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;
 
@@ -162,10 +172,10 @@ 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;
@@ -180,7 +190,7 @@ NTSTATUS nbt_name_status_recv(struct nbt_name_request *req,
        }
        
        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);
@@ -211,10 +221,10 @@ NTSTATUS nbt_name_status_recv(struct nbt_name_request *req,
        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);