updated the 3.0 branch from the head branch - ready for alpha18
[samba.git] / source3 / utils / nmblookup.c
index 9549d16d044096d502264a683141873b03221d2f..8e4f5aab0372e936d4d136c7b7d7652f1277c79d 100644 (file)
@@ -25,6 +25,7 @@
 
 extern BOOL AllowDebugChange;
 
+static BOOL give_flags = False;
 static BOOL use_bcast = True;
 static BOOL got_bcast = False;
 static struct in_addr bcast_addr;
@@ -63,6 +64,7 @@ static void usage(void)
   d_printf("Version %s\n",VERSION);
   d_printf("\t-d debuglevel         set the debuglevel\n");
   d_printf("\t-B broadcast address  the address to use for broadcasts\n");
+  d_printf("\t-f                    list the NMB flags returned\n");
   d_printf("\t-U unicast   address  the address to use for unicast\n");
   d_printf("\t-M                    searches for a master browser\n");
   d_printf("\t-R                    set recursion desired in packet\n");
@@ -98,6 +100,24 @@ static char *node_status_flags(unsigned char flags)
        return ret;
 }
 
+/****************************************************************************
+turn the NMB Query flags into a string
+****************************************************************************/
+static char *query_flags(int flags)
+{
+       static fstring ret1;
+       fstrcpy(ret1, "");
+
+       if (flags & NM_FLAGS_RS) fstrcat(ret1, "Response ");
+       if (flags & NM_FLAGS_AA) fstrcat(ret1, "Authoritative ");
+       if (flags & NM_FLAGS_TC) fstrcat(ret1, "Truncated ");
+       if (flags & NM_FLAGS_RD) fstrcat(ret1, "Recursion_Desired ");
+       if (flags & NM_FLAGS_RA) fstrcat(ret1, "Recursion_Available ");
+       if (flags & NM_FLAGS_B)  fstrcat(ret1, "Broadcast ");
+
+       return ret1;
+}
+
 /****************************************************************************
 do a node status query
 ****************************************************************************/
@@ -132,14 +152,14 @@ send out one query
 ****************************************************************************/
 static BOOL query_one(char *lookup, unsigned int lookup_type)
 {
-       int j, count;
+       int j, count, flags = 0;
        struct in_addr *ip_list=NULL;
 
        if (got_bcast) {
                d_printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr));
                ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast,
                                     use_bcast?True:recursion_desired,
-                                    bcast_addr,&count);
+                                    bcast_addr,&count, &flags, NULL);
        } else {
                struct in_addr *bcast;
                for (j=iface_count() - 1;
@@ -151,12 +171,15 @@ static BOOL query_one(char *lookup, unsigned int lookup_type)
                        ip_list = name_query(ServerFD,lookup,lookup_type,
                                             use_bcast,
                                             use_bcast?True:recursion_desired,
-                                            *bcast,&count);
+                                            *bcast,&count, &flags, NULL);
                }
        }
 
        if (!ip_list) return False;
 
+       if (give_flags)
+         d_printf("Flags: %s\n", query_flags(flags));
+
        for (j=0;j<count;j++) {
                if (translate_addresses) {
                        struct hostent *host = gethostbyaddr((char *)&ip_list[j], sizeof(ip_list[j]), AF_INET);
@@ -203,7 +226,7 @@ int main(int argc,char *argv[])
 
   setup_logging(argv[0],True);
 
-  while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhART")) != EOF)
+  while ((opt = getopt(argc, argv, "d:fB:U:i:s:SMrhART")) != EOF)
     switch (opt)
       {
       case 'B':
@@ -211,6 +234,9 @@ int main(int argc,char *argv[])
        got_bcast = True;
        use_bcast = True;
        break;
+      case 'f':
+       give_flags = True;
+       break;
       case 'U':
        bcast_addr = *interpret_addr2(optarg);
        got_bcast = True;