RIP BOOL. Convert BOOL -> bool. I found a few interesting
[nivanova/samba-autobuild/.git] / source3 / utils / nmblookup.c
index 97cea3a7bbf77b5d2f5068c419caa7322b7f83f8..6d17fb7982930b0c2825b42e707dc5623607c800 100644 (file)
@@ -6,7 +6,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
    
    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,
    (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
    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/>.
    
 */
 
    
 */
 
-#define NO_SYSLOG
-
 #include "includes.h"
 
 #include "includes.h"
 
-extern BOOL AllowDebugChange;
+extern bool AllowDebugChange;
 
 
-static BOOL give_flags = False;
-static BOOL use_bcast = True;
-static BOOL got_bcast = False;
+static bool give_flags = False;
+static bool use_bcast = True;
+static bool got_bcast = False;
 static struct in_addr bcast_addr;
 static struct in_addr bcast_addr;
-static BOOL recursion_desired = False;
-static BOOL translate_addresses = False;
+static bool recursion_desired = False;
+static bool translate_addresses = False;
 static int ServerFD= -1;
 static int RootPort = False;
 static int ServerFD= -1;
 static int RootPort = False;
-static BOOL find_status=False;
+static bool find_status=False;
 
 /****************************************************************************
   open the socket communication
   **************************************************************************/
 
 /****************************************************************************
   open the socket communication
   **************************************************************************/
-static BOOL open_sockets(void)
+static bool open_sockets(void)
 {
   ServerFD = open_socket_in( SOCK_DGRAM,
                              (RootPort ? 137 : 0),
 {
   ServerFD = open_socket_in( SOCK_DGRAM,
                              (RootPort ? 137 : 0),
@@ -101,15 +98,16 @@ static void do_node_status(int fd, const char *name, int type, struct in_addr ip
 {
        struct nmb_name nname;
        int count, i, j;
 {
        struct nmb_name nname;
        int count, i, j;
-       struct node_status *status;
+       NODE_STATUS_STRUCT *status;
+       struct node_status_extra extra;
        fstring cleanname;
 
        d_printf("Looking up status of %s\n",inet_ntoa(ip));
        make_nmb_name(&nname, name, type);
        fstring cleanname;
 
        d_printf("Looking up status of %s\n",inet_ntoa(ip));
        make_nmb_name(&nname, name, type);
-       status = node_status_query(fd,&nname,ip, &count);
+       status = node_status_query(fd,&nname,ip, &count, &extra);
        if (status) {
                for (i=0;i<count;i++) {
        if (status) {
                for (i=0;i<count;i++) {
-                       fstrcpy(cleanname, status[i].name);
+                       pull_ascii_fstring(cleanname, status[i].name);
                        for (j=0;cleanname[j];j++) {
                                if (!isprint((int)cleanname[j])) cleanname[j] = '.';
                        }
                        for (j=0;cleanname[j];j++) {
                                if (!isprint((int)cleanname[j])) cleanname[j] = '.';
                        }
@@ -117,16 +115,22 @@ static void do_node_status(int fd, const char *name, int type, struct in_addr ip
                               cleanname,status[i].type,
                               node_status_flags(status[i].flags));
                }
                               cleanname,status[i].type,
                               node_status_flags(status[i].flags));
                }
+               d_printf("\n\tMAC Address = %02X-%02X-%02X-%02X-%02X-%02X\n",
+                               extra.mac_addr[0], extra.mac_addr[1],
+                               extra.mac_addr[2], extra.mac_addr[3],
+                               extra.mac_addr[4], extra.mac_addr[5]);
+               d_printf("\n");
                SAFE_FREE(status);
                SAFE_FREE(status);
+       } else {
+               d_printf("No reply from %s\n\n",inet_ntoa(ip));
        }
        }
-       d_printf("\n");
 }
 
 
 /****************************************************************************
 send out one query
 ****************************************************************************/
 }
 
 
 /****************************************************************************
 send out one query
 ****************************************************************************/
-static BOOL query_one(const char *lookup, unsigned int lookup_type)
+static bool query_one(const char *lookup, unsigned int lookup_type)
 {
        int j, count, flags = 0;
        struct in_addr *ip_list=NULL;
 {
        int j, count, flags = 0;
        struct in_addr *ip_list=NULL;
@@ -137,11 +141,14 @@ static BOOL query_one(const char *lookup, unsigned int lookup_type)
                                     use_bcast?True:recursion_desired,
                                     bcast_addr,&count, &flags, NULL);
        } else {
                                     use_bcast?True:recursion_desired,
                                     bcast_addr,&count, &flags, NULL);
        } else {
-               struct in_addr *bcast;
+               const struct in_addr *bcast;
                for (j=iface_count() - 1;
                     !ip_list && j >= 0;
                     j--) {
                for (j=iface_count() - 1;
                     !ip_list && j >= 0;
                     j--) {
-                       bcast = iface_n_bcast(j);
+                       bcast = iface_n_bcast_v4(j);
+                       if (!bcast) {
+                               continue;
+                       }
                        d_printf("querying %s on %s\n", 
                               lookup, inet_ntoa(*bcast));
                        ip_list = name_query(ServerFD,lookup,lookup_type,
                        d_printf("querying %s on %s\n", 
                               lookup, inet_ntoa(*bcast));
                        ip_list = name_query(ServerFD,lookup,lookup_type,
@@ -164,13 +171,12 @@ static BOOL query_one(const char *lookup, unsigned int lookup_type)
                        }
                }
                d_printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type);
                        }
                }
                d_printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type);
-       }
-
-       /* We can only do find_status if the ip address returned
-          was valid - ie. name_query returned true.
-       */
-       if (find_status) {
-               do_node_status(ServerFD, lookup, lookup_type, ip_list[0]);
+               /* We can only do find_status if the ip address returned
+                  was valid - ie. name_query returned true.
+                */
+               if (find_status) {
+                       do_node_status(ServerFD, lookup, lookup_type, ip_list[j]);
+               }
        }
 
        safe_free(ip_list);
        }
 
        safe_free(ip_list);
@@ -187,15 +193,16 @@ int main(int argc,char *argv[])
   int opt;
   unsigned int lookup_type = 0x0;
   fstring lookup;
   int opt;
   unsigned int lookup_type = 0x0;
   fstring lookup;
-  BOOL find_master=False;
-  BOOL lookup_by_ip = False;
+  static bool find_master=False;
+  static bool lookup_by_ip = False;
   poptContext pc;
   poptContext pc;
+  TALLOC_CTX *frame = talloc_stackframe();
 
   struct poptOption long_options[] = {
          POPT_AUTOHELP
 
   struct poptOption long_options[] = {
          POPT_AUTOHELP
-         { "broadcast", 'b', POPT_ARG_STRING, NULL, 'B', "Specify address to use for broadcasts", "BROADCAST-ADDRESS" },
+         { "broadcast", 'B', POPT_ARG_STRING, NULL, 'B', "Specify address to use for broadcasts", "BROADCAST-ADDRESS" },
          { "flags", 'f', POPT_ARG_VAL, &give_flags, True, "List the NMB flags returned" },
          { "flags", 'f', POPT_ARG_VAL, &give_flags, True, "List the NMB flags returned" },
-         { "unicast", 'U', POPT_ARG_NONE, NULL, 'U', "Specify address to use for unicast" },
+         { "unicast", 'U', POPT_ARG_STRING, NULL, 'U', "Specify address to use for unicast" },
          { "master-browser", 'M', POPT_ARG_VAL, &find_master, True, "Search for a master browser" },
          { "recursion", 'R', POPT_ARG_VAL, &recursion_desired, True, "Set recursion desired in package" },
          { "status", 'S', POPT_ARG_VAL, &find_status, True, "Lookup node status as well" },
          { "master-browser", 'M', POPT_ARG_VAL, &find_master, True, "Search for a master browser" },
          { "recursion", 'R', POPT_ARG_VAL, &recursion_desired, True, "Set recursion desired in package" },
          { "status", 'S', POPT_ARG_VAL, &find_status, True, "Lookup node status as well" },
@@ -203,14 +210,14 @@ int main(int argc,char *argv[])
          { "root-port", 'r', POPT_ARG_VAL, &RootPort, True, "Use root port 137 (Win95 only replies to this)" },
          { "lookup-by-ip", 'A', POPT_ARG_VAL, &lookup_by_ip, True, "Do a node status on <name> as an IP Address" },
          POPT_COMMON_SAMBA
          { "root-port", 'r', POPT_ARG_VAL, &RootPort, True, "Use root port 137 (Win95 only replies to this)" },
          { "lookup-by-ip", 'A', POPT_ARG_VAL, &lookup_by_ip, True, "Do a node status on <name> as an IP Address" },
          POPT_COMMON_SAMBA
-         { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_scope },
-         { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
-         { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
+         POPT_COMMON_CONNECTION
          { 0, 0, 0, 0 }
   };
        
   *lookup = 0;
 
          { 0, 0, 0, 0 }
   };
        
   *lookup = 0;
 
+  load_case_tables();
+
   setup_logging(argv[0],True);
 
   pc = poptGetContext("nmblookup", argc, (const char **)argv, long_options, 
   setup_logging(argv[0],True);
 
   pc = poptGetContext("nmblookup", argc, (const char **)argv, long_options, 
@@ -218,9 +225,8 @@ int main(int argc,char *argv[])
 
   poptSetOtherOptionHelp(pc, "<NODE> ...");
 
 
   poptSetOtherOptionHelp(pc, "<NODE> ...");
 
-  while ((opt = poptGetNextOpt(pc)) != -1)
-         switch (opt)
-         {
+  while ((opt = poptGetNextOpt(pc)) != -1) {
+         switch (opt) {
          case 'B':
                  bcast_addr = *interpret_addr2(poptGetOptArg(pc));
                  got_bcast = True;
          case 'B':
                  bcast_addr = *interpret_addr2(poptGetOptArg(pc));
                  got_bcast = True;
@@ -235,6 +241,7 @@ int main(int argc,char *argv[])
                  translate_addresses = !translate_addresses;
                  break;
          }
                  translate_addresses = !translate_addresses;
                  break;
          }
+  }
 
   poptGetArg(pc); /* Remove argv[0] */
 
 
   poptGetArg(pc); /* Remove argv[0] */
 
@@ -243,7 +250,7 @@ int main(int argc,char *argv[])
          exit(1);
   }
 
          exit(1);
   }
 
-  if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
+  if (!lp_load(dyn_CONFIGFILE,True,False,False,True)) {
          fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
   }
 
          fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
   }
 
@@ -289,6 +296,6 @@ int main(int argc,char *argv[])
   }
 
   poptFreeContext(pc);
   }
 
   poptFreeContext(pc);
-
+  TALLOC_FREE(frame);
   return(0);
 }
   return(0);
 }