home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / samba-1.9.18p7.tar.gz / samba-1.9.18p7.tar / samba-1.9.18p7 / source / nmbd_nodestatus.c < prev    next >
C/C++ Source or Header  |  1998-01-26  |  4KB  |  100 lines

  1. /* 
  2.    Unix SMB/Netbios implementation.
  3.    Version 1.9.
  4.    NBT netbios routines and daemon - version 2
  5.    Copyright (C) Andrew Tridgell 1994-1998
  6.    Copyright (C) Luke Kenneth Casson Leighton 1994-1998
  7.    Copyright (C) Jeremy Allison 1994-1998
  8.    
  9.    This program is free software; you can redistribute it and/or modify
  10.    it under the terms of the GNU General Public License as published by
  11.    the Free Software Foundation; either version 2 of the License, or
  12.    (at your option) any later version.
  13.    
  14.    This program is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.    GNU General Public License for more details.
  18.    
  19.    You should have received a copy of the GNU General Public License
  20.    along with this program; if not, write to the Free Software
  21.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.    
  23. */
  24.  
  25. #include "includes.h"
  26.  
  27. extern int DEBUGLEVEL;
  28.  
  29. extern pstring scope;
  30.  
  31. /****************************************************************************
  32.  Deal with a successful node status response.
  33. ****************************************************************************/
  34. static void node_status_response(struct subnet_record *subrec,
  35.                        struct response_record *rrec, struct packet_struct *p)
  36. {
  37.   struct nmb_packet *nmb = &p->packet.nmb;
  38.   struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name;
  39.   struct nmb_name *answer_name = &nmb->answers->rr_name;
  40.  
  41.   /* Sanity check. Ensure that the answer name in the incoming packet is the
  42.      same as the requested name in the outgoing packet. */
  43.  
  44.   if(!nmb_name_equal(question_name, answer_name))
  45.   {
  46.     DEBUG(0,("node_status_response: Answer name %s differs from question \
  47. name %s.\n", namestr(answer_name), namestr(question_name)));
  48.     return;
  49.   }
  50.  
  51.   DEBUG(5,("node_status_response: response from name %s on subnet %s.\n",
  52.         namestr(answer_name), subrec->subnet_name));
  53.  
  54.   /* Just send the whole answer resource record for the success function
  55.      to parse. */
  56.   if(rrec->success_fn)
  57.     (*rrec->success_fn)(subrec, rrec->userdata, nmb->answers, p->ip);
  58.  
  59.   /* Ensure we don't retry. */
  60.   remove_response_record(subrec, rrec);
  61. }
  62.  
  63. /****************************************************************************
  64.  Deal with a timeout when requesting a node status.
  65. ****************************************************************************/
  66. static void node_status_timeout_response(struct subnet_record *subrec,
  67.                        struct response_record *rrec)
  68. {
  69.   struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb;
  70.   struct nmb_name *question_name = &sent_nmb->question.question_name;
  71.  
  72.   DEBUG(5,("node_status_timeout_response: failed to get node status from name %s on subnet %s\n",
  73.            namestr(question_name), subrec->subnet_name));
  74.  
  75.   if( rrec->fail_fn)
  76.     (*rrec->fail_fn)(subrec, rrec);
  77.  
  78.   /* Ensure we don't retry. */
  79.   remove_response_record(subrec, rrec);
  80. }
  81.  
  82. /****************************************************************************
  83.  Try and do a node status to a name - given the name & IP address.
  84. ****************************************************************************/
  85.  
  86. BOOL node_status(struct subnet_record *subrec, struct nmb_name *nmbname,
  87.                  struct in_addr send_ip, node_status_success_function success_fn, 
  88.                  node_status_fail_function fail_fn, struct userdata_struct *userdata)
  89. {
  90.   if(queue_node_status( subrec, 
  91.               node_status_response, node_status_timeout_response,
  92.               success_fn, fail_fn, userdata, nmbname, send_ip)==NULL)
  93.   {
  94.     DEBUG(0,("node_status: Failed to send packet trying to get node status for \
  95. name %s, IP address %s\n", namestr(nmbname), inet_ntoa(send_ip)));
  96.     return True;
  97.   } 
  98.   return False;
  99. }
  100.