nmblookup PATCH: script-parsable output format

Derrell.Lipman at UnwiredUniverse.com Derrell.Lipman at UnwiredUniverse.com
Tue May 7 17:15:39 GMT 2002


The following patch adds the '-x' option to nmblookup, to display the output
in a format which is easily parsable by scripts.  The usage() function has
been expanded to describe the output format.

*NOTE*: There are four status flags (h, m, p, b) which are currently
undocumented (they say "<what is this?>").  If someone could tell me what they
are, I can fix the usage() documentation.  (Or Simo could just fix that as he
incorporates this patch.)

I've tried to keep formatting consistent with surrounding code, but there are
multiple formats used in this one file, making it a bit more difficult to know
what the "standard" format is.

This patch is against HEAD.

Use of this patch should allow findsmb to be modified such that it can detect
host names which have leading and trailing spaces.  (I use TAB as a separator
in this output format; I'm assuming that TAB is not a possible/valid character
in a host name.  If that turns out to be a false assumption, the separator
character can be changed.)

Cheers,

Derrell
----------------------------------------------------------------------

RCS file: /cvsroot/samba/source/utils/nmblookup.c,v
retrieving revision 1.50
diff -r1.50 nmblookup.c
36a37,38
> static BOOL line_field_output = False;
> 
74a77,103
>   d_printf("\n");
>   d_printf("\t-x                    Generate script-parsable output format.\n\n");
>   d_printf("\t                        Each relevant line begins a '+'.\n");
>   d_printf("\t                        The next character indicates a Node\n");
>   d_printf("\t                        (N) or an IP Address (I) message.\n");
>   d_printf("\t                        The next two characters are hex\n");
>   d_printf("\t                        digits representing the node type.\n\n");
>   d_printf("\t                        Node lines then have 9 characters\n");
>   d_printf("\t                        indicating status flags.  If the \n");
>   d_printf("\t                        flag is enabled, the letter is\n");
>   d_printf("\t                        displayed; otherwise, a dot (.) is\n");
>   d_printf("\t                        shown.  Status flags are:\n\n");
>   d_printf("\t                          g: Group\n");
>   d_printf("\t                          h: <what is this?>\n");
>   d_printf("\t                          m: <what is this?>\n");
>   d_printf("\t                          p: <what is this?>\n");
>   d_printf("\t                          b: <what is this?>\n");
>   d_printf("\t                          d: Deregistering\n");
>   d_printf("\t                          c: Conflict\n");
>   d_printf("\t                          a: Active\n");
>   d_printf("\t                          r: peRmanent\n\n");
>   d_printf("\t                        A tab then separates the status\n");
>   d_printf("\t                        flags from the node name.\n\n");
>   d_printf("\t                        IP Address lines have the name\n");
>   d_printf("\t                        immediately following the type\n");
>   d_printf("\t                        digits.  A tab character separates\n");
>   d_printf("\t                        the name from the IP Address.\n\n");
86c115
< 	fstrcpy(ret,"");
---
>         fstrcpy(ret,"");
88,96c117,137
< 	fstrcat(ret, (flags & 0x80) ? "<GROUP> " : "        ");
< 	if ((flags & 0x60) == 0x00) fstrcat(ret,"B ");
< 	if ((flags & 0x60) == 0x20) fstrcat(ret,"P ");
< 	if ((flags & 0x60) == 0x40) fstrcat(ret,"M ");
< 	if ((flags & 0x60) == 0x60) fstrcat(ret,"H ");
< 	if (flags & 0x10) fstrcat(ret,"<DEREGISTERING> ");
< 	if (flags & 0x08) fstrcat(ret,"<CONFLICT> ");
< 	if (flags & 0x04) fstrcat(ret,"<ACTIVE> ");
< 	if (flags & 0x02) fstrcat(ret,"<PERMANENT> ");
---
>         if (line_field_output) {
>                 fstrcat(ret,(flags & 0x80) ? "g" : ".");
>                 fstrcat(ret,((flags & 0x60) == 0x60) ? "h" : ".");
>                 fstrcat(ret,((flags & 0x60) == 0x40) ? "m" : ".");
>                 fstrcat(ret,((flags & 0x60) == 0x20) ? "p" : ".");
>                 fstrcat(ret,((flags & 0x60) == 0x00) ? "b" : ".");
>                 fstrcat(ret,(flags & 0x10) ? "d" : ".");
>                 fstrcat(ret,(flags & 0x08) ? "c" : ".");
>                 fstrcat(ret,(flags & 0x04) ? "a" : ".");
>                 fstrcat(ret,(flags & 0x02) ? "r" : ".");
>         } else {
>                 fstrcat(ret, (flags & 0x80) ? "<GROUP> " : "        ");
>                 if ((flags & 0x60) == 0x00) fstrcat(ret,"B ");
>                 if ((flags & 0x60) == 0x20) fstrcat(ret,"P ");
>                 if ((flags & 0x60) == 0x40) fstrcat(ret,"M ");
>                 if ((flags & 0x60) == 0x60) fstrcat(ret,"H ");
>                 if (flags & 0x10) fstrcat(ret,"<DEREGISTERING> ");
>                 if (flags & 0x08) fstrcat(ret,"<CONFLICT> ");
>                 if (flags & 0x04) fstrcat(ret,"<ACTIVE> ");
>                 if (flags & 0x02) fstrcat(ret,"<PERMANENT> ");
>         }
111c152,153
< 	d_printf("Looking up status of %s\n",inet_ntoa(ip));
---
>         if (! line_field_output)
>                 d_printf("Looking up status of %s\n",inet_ntoa(ip));
120,122c162,170
< 			d_printf("\t%-15s <%02x> - %s\n",
< 			       cleanname,status[i].type,
< 			       node_status_flags(status[i].flags));
---
>                         if (line_field_output)
>                                 d_printf("+N%02X%s\t%s\n",
>                                          status[i].type,
>                                          node_status_flags(status[i].flags),
>                                          cleanname);
>                         else
>                                 d_printf("\t%-15s <%02x> - %s\n",
>                                          cleanname,status[i].type,
>                                          node_status_flags(status[i].flags));
126c174,175
< 	d_printf("\n");
---
>         if (! line_field_output)
>                 d_printf("\n");
139c188,189
< 		d_printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr));
---
>                 if (! line_field_output)
>                         d_printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr));
149,150c199,201
< 			d_printf("querying %s on %s\n", 
< 			       lookup, inet_ntoa(*bcast));
---
>                         if (! line_field_output)
>         			d_printf("querying %s on %s\n", 
>                                          lookup, inet_ntoa(*bcast));
160a212,213
>                 if (line_field_output)
>                         d_printf("+I%02X%s\t", lookup_type, lookup);
164c217,220
< 				d_printf("%s, ", host -> h_name);
---
>                                 if (line_field_output)
>                                         d_printf("%s", host -> h_name);
>                                 else
>                                         d_printf("%s, ", host -> h_name);
165a222,223
>                         if (line_field_output)
>                                 d_printf(":");
167c225,228
< 		d_printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type);
---
>                 if (line_field_output)
>                         d_printf("%s\n", inet_ntoa(ip_list[j]));
>                 else
>                         d_printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type);
206c267
<   while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhART")) != EOF)
---
>   while ((opt = getopt(argc, argv, "d:B:U:i:s:SMrhARTx")) != EOF)
253a315,317
>       case 'x':
>         line_field_output = True;
>         break;
310c374,376
< 	d_printf( "name_query failed to find name %s", lookup );
---
>         if (line_field_output)
>           d_printf("+E\t");
> 	d_printf( "name_query failed to find name %s ", lookup );




More information about the samba-technical mailing list