diff options
Diffstat (limited to 'source/utils/nmblookup.c')
-rw-r--r-- | source/utils/nmblookup.c | 93 |
1 files changed, 45 insertions, 48 deletions
diff --git a/source/utils/nmblookup.c b/source/utils/nmblookup.c index 8e4f5aab037..4fffed74fd9 100644 --- a/source/utils/nmblookup.c +++ b/source/utils/nmblookup.c @@ -1,5 +1,6 @@ /* - Unix SMB/CIFS implementation. + Unix SMB/Netbios implementation. + Version 1.9. NBT client - used to lookup netbios names Copyright (C) Andrew Tridgell 1994-1998 @@ -60,23 +61,23 @@ usage on the program ****************************************************************************/ static void usage(void) { - d_printf("Usage: nmblookup [-M] [-B bcast address] [-d debuglevel] name\n"); - 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"); - d_printf("\t-S lookup node status as well\n"); - d_printf("\t-T translate IP addresses into names\n"); - d_printf("\t-r Use root port 137 (Win95 only replies to this)\n"); - d_printf("\t-A Do a node status on <name> as an IP Address\n"); - d_printf("\t-i NetBIOS scope Use the given NetBIOS scope for name queries\n"); - d_printf("\t-s smb.conf file Use the given path to the smb.conf file\n"); - d_printf("\t-h Print this help message.\n"); - d_printf("\n If you specify -M and name is \"-\", nmblookup looks up __MSBROWSE__<01>\n"); - d_printf("\n"); + printf("Usage: nmblookup [-M] [-B bcast address] [-d debuglevel] name\n"); + printf("Version %s\n",VERSION); + printf("\t-d debuglevel set the debuglevel\n"); + printf("\t-B broadcast address the address to use for broadcasts\n"); + printf("\t-f lists flags returned from a name query\n"); + printf("\t-U unicast address the address to use for unicast\n"); + printf("\t-M searches for a master browser\n"); + printf("\t-R set recursion desired in packet\n"); + printf("\t-S lookup node status as well\n"); + printf("\t-T translate IP addresses into names\n"); + printf("\t-r Use root port 137 (Win95 only replies to this)\n"); + printf("\t-A Do a node status on <name> as an IP Address\n"); + printf("\t-i NetBIOS scope Use the given NetBIOS scope for name queries\n"); + printf("\t-s smb.conf file Use the given path to the smb.conf file\n"); + printf("\t-h Print this help message.\n"); + printf("\n If you specify -M and name is \"-\", nmblookup looks up __MSBROWSE__<01>\n"); + printf("\n"); } /**************************************************************************** @@ -128,7 +129,7 @@ static void do_node_status(int fd, char *name, int type, struct in_addr ip) struct node_status *status; fstring cleanname; - d_printf("Looking up status of %s\n",inet_ntoa(ip)); + printf("Looking up status of %s\n",inet_ntoa(ip)); make_nmb_name(&nname, name, type); status = node_status_query(fd,&nname,ip, &count); if (status) { @@ -137,13 +138,13 @@ static void do_node_status(int fd, char *name, int type, struct in_addr ip) for (j=0;cleanname[j];j++) { if (!isprint((int)cleanname[j])) cleanname[j] = '.'; } - d_printf("\t%-15s <%02x> - %s\n", + printf("\t%-15s <%02x> - %s\n", cleanname,status[i].type, node_status_flags(status[i].flags)); } SAFE_FREE(status); } - d_printf("\n"); + printf("\n"); } @@ -152,42 +153,42 @@ send out one query ****************************************************************************/ static BOOL query_one(char *lookup, unsigned int lookup_type) { - int j, count, flags = 0; + int j, count, flags; struct in_addr *ip_list=NULL; if (got_bcast) { - d_printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr)); + 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, &flags, NULL); + bcast_addr,&count, &flags); } else { struct in_addr *bcast; for (j=iface_count() - 1; !ip_list && j >= 0; j--) { bcast = iface_n_bcast(j); - d_printf("querying %s on %s\n", + printf("querying %s on %s\n", lookup, inet_ntoa(*bcast)); ip_list = name_query(ServerFD,lookup,lookup_type, use_bcast, use_bcast?True:recursion_desired, - *bcast,&count, &flags, NULL); + *bcast,&count, &flags); } } - if (!ip_list) return False; - if (give_flags) - d_printf("Flags: %s\n", query_flags(flags)); + printf("Flags: %s\n", query_flags(flags)); + + if (!ip_list) return False; for (j=0;j<count;j++) { if (translate_addresses) { struct hostent *host = gethostbyaddr((char *)&ip_list[j], sizeof(ip_list[j]), AF_INET); if (host) { - d_printf("%s, ", host -> h_name); + printf("%s, ", host -> h_name); } } - d_printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type); + printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type); } /* We can only do find_status if the ip address returned @@ -215,8 +216,8 @@ int main(int argc,char *argv[]) extern char *optarg; BOOL find_master=False; int i; + static pstring servicesf = CONFIGFILE; BOOL lookup_by_ip = False; - int commandline_debuglevel = -2; DEBUGLEVEL = 1; /* Prevent smb.conf setting from overridding */ @@ -224,8 +225,12 @@ int main(int argc,char *argv[]) *lookup = 0; + TimeInit(); + setup_logging(argv[0],True); + charset_initialise(); + while ((opt = getopt(argc, argv, "d:fB:U:i:s:SMrhART")) != EOF) switch (opt) { @@ -262,10 +267,10 @@ int main(int argc,char *argv[]) recursion_desired = True; break; case 'd': - commandline_debuglevel = DEBUGLEVEL = atoi(optarg); + DEBUGLEVEL = atoi(optarg); break; case 's': - pstrcpy(dyn_CONFIGFILE, optarg); + pstrcpy(servicesf, optarg); break; case 'r': RootPort = True; @@ -287,18 +292,10 @@ int main(int argc,char *argv[]) exit(1); } - if (!lp_load(dyn_CONFIGFILE,True,False,False)) { - fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); + if (!lp_load(servicesf,True,False,False)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); } - /* - * Ensure we reset DEBUGLEVEL if someone specified it - * on the command line. - */ - - if(commandline_debuglevel != -2) - DEBUGLEVEL = commandline_debuglevel; - load_interfaces(); if (!open_sockets()) return(1); @@ -326,17 +323,17 @@ int main(int argc,char *argv[]) } } - p = strchr_m(lookup,'#'); + p = strchr(lookup,'#'); if (p) { *p = '\0'; sscanf(++p,"%x",&lookup_type); } if (!query_one(lookup, lookup_type)) { - d_printf( "name_query failed to find name %s", lookup ); + printf( "name_query failed to find name %s", lookup ); if( 0 != lookup_type ) - d_printf( "#%02x", lookup_type ); - d_printf( "\n" ); + printf( "#%02x", lookup_type ); + printf( "\n" ); } } |