Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into 4-0-local
[samba.git] / source4 / nbt_server / nodestatus.c
index 36c37073741659af92783c27e91c324a6b93c222..a7bf67ad511b6fcc7e4985d825cb51ff4de90278 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 "dlinklist.h"
+#include "lib/util/dlinklist.h"
 #include "system/network.h"
 #include "nbt_server/nbt_server.h"
+#include "lib/socket/socket.h"
+#include "librpc/gen_ndr/ndr_nbt.h"
 
 /*
   send a name status reply
 */
-static void nbt_node_status_reply(struct nbt_name_socket *nbtsock, 
-                                 struct nbt_name_packet *request_packet, 
-                                 const char *src_address, int src_port,
-                                 struct nbt_name *name, 
-                                 struct nbt_interface *iface)
+static void nbtd_node_status_reply(struct nbt_name_socket *nbtsock, 
+                                  struct nbt_name_packet *request_packet, 
+                                  struct socket_address *src,
+                                  struct nbt_name *name, 
+                                  struct nbtd_interface *iface)
 {
        struct nbt_name_packet *packet;
        uint32_t name_count;
-       struct nbt_iface_name *iname;
+       struct nbtd_iface_name *iname;
+       struct nbtd_server *nbtsrv = iface->nbtsrv;
        
        /* work out how many names to send */
        name_count = 0;
@@ -82,10 +84,11 @@ static void nbt_node_status_reply(struct nbt_name_socket *nbtsock,
           it could lead to giving attackers too much information */
        ZERO_STRUCT(packet->answers[0].rdata.status.statistics);
 
-       DEBUG(7,("Sending node status reply for %s<%02x> to %s:%d\n", 
-                name->name, name->type, src_address, src_port));
+       DEBUG(7,("Sending node status reply for %s to %s:%d\n", 
+                nbt_name_string(packet, name), src->addr, src->port));
        
-       nbt_name_reply_send(nbtsock, src_address, src_port, packet);
+       nbtsrv->stats.total_sent++;
+       nbt_name_reply_send(nbtsock, src, packet);
 
 failed:
        talloc_free(packet);
@@ -95,28 +98,29 @@ failed:
 /*
   answer a node status query
 */
-void nbt_query_status(struct nbt_name_socket *nbtsock, 
-                     struct nbt_name_packet *packet, 
-                     const char *src_address, int src_port)
+void nbtd_query_status(struct nbt_name_socket *nbtsock, 
+                      struct nbt_name_packet *packet, 
+                      struct socket_address *src)
 {
        struct nbt_name *name;
-       struct nbt_iface_name *iname;
-       struct nbt_interface *iface = talloc_get_type(nbtsock->incoming.private, 
-                                                     struct nbt_interface);
+       struct nbtd_iface_name *iname;
+       struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private, 
+                                                      struct nbtd_interface);
 
-       NBT_ASSERT_PACKET(packet, src_address, packet->qdcount == 1);
-       NBT_ASSERT_PACKET(packet, src_address, packet->questions[0].question_type == NBT_QTYPE_STATUS);
-       NBT_ASSERT_PACKET(packet, src_address, packet->questions[0].question_class == NBT_QCLASS_IP);
+       NBTD_ASSERT_PACKET(packet, src, packet->qdcount == 1);
+       NBTD_ASSERT_PACKET(packet, src, packet->questions[0].question_type == NBT_QTYPE_STATUS);
+       NBTD_ASSERT_PACKET(packet, src, packet->questions[0].question_class == NBT_QCLASS_IP);
 
        /* see if we have the requested name on this interface */
        name = &packet->questions[0].name;
 
-       iname = nbt_find_iname(iface, name, NBT_NM_ACTIVE);
+       iname = nbtd_find_iname(iface, name, NBT_NM_ACTIVE);
        if (iname == NULL) {
-               DEBUG(7,("Node status query for %s<%02x> from %s - not found on %s\n",
-                        name->name, name->type, src_address, iface->ip_address));
+               DEBUG(7,("Node status query for %s from %s - not found on %s\n",
+                        nbt_name_string(packet, name), src->addr, iface->ip_address));
                return;
        }
 
-       nbt_node_status_reply(nbtsock, packet, src_address, src_port, &iname->name, iface);
+       nbtd_node_status_reply(nbtsock, packet, src, 
+                              &iname->name, iface);
 }