#include "includes.h"
#include "popt_common.h"
#include "libsmb/nmblib.h"
+#include "libsmb/namequery.h"
static bool give_flags = false;
static bool use_bcast = true;
static bool open_sockets(void)
{
struct sockaddr_storage ss;
- const char *sock_addr = lp_socket_address();
+ const char *sock_addr = lp_nbt_client_socket_address();
if (!interpret_string_addr(&ss, sock_addr,
AI_NUMERICHOST|AI_PASSIVE)) {
Do a node status query.
****************************************************************************/
-static void do_node_status(const char *name,
+static bool do_node_status(const char *name,
int type,
struct sockaddr_storage *pss)
{
extra.mac_addr[4], extra.mac_addr[5]);
d_printf("\n");
TALLOC_FREE(addrs);
+ return true;
} else {
d_printf("No reply from %s\n\n",addr);
+ return false;
}
}
was valid - ie. name_query returned true.
*/
if (find_status) {
- do_node_status(lookup, lookup_type, &ip_list[j]);
+ if (!do_node_status(lookup, lookup_type, &ip_list[j])) {
+ status = NT_STATUS_UNSUCCESSFUL;
+ }
}
}
/****************************************************************************
main program
****************************************************************************/
-int main(int argc,char *argv[])
+int main(int argc, const char *argv[])
{
int opt;
unsigned int lookup_type = 0x0;
fstring lookup;
static bool find_master=False;
static bool lookup_by_ip = False;
- poptContext pc;
+ poptContext pc = NULL;
TALLOC_CTX *frame = talloc_stackframe();
+ int rc = 0;
struct poptOption long_options[] = {
POPT_AUTOHELP
- { "broadcast", 'B', POPT_ARG_STRING, NULL, 'B', "Specify address to use for broadcasts", "BROADCAST-ADDRESS" },
- { "flags", 'f', POPT_ARG_NONE, NULL, 'f', "List the NMB flags returned" },
- { "unicast", 'U', POPT_ARG_STRING, NULL, 'U', "Specify address to use for unicast" },
- { "master-browser", 'M', POPT_ARG_NONE, NULL, 'M', "Search for a master browser" },
- { "recursion", 'R', POPT_ARG_NONE, NULL, 'R', "Set recursion desired in package" },
- { "status", 'S', POPT_ARG_NONE, NULL, 'S', "Lookup node status as well" },
- { "translate", 'T', POPT_ARG_NONE, NULL, 'T', "Translate IP addresses into names" },
- { "root-port", 'r', POPT_ARG_NONE, NULL, 'r', "Use root port 137 (Win95 only replies to this)" },
- { "lookup-by-ip", 'A', POPT_ARG_NONE, NULL, 'A', "Do a node status on <name> as an IP Address" },
+ {
+ .longName = "broadcast",
+ .shortName = 'B',
+ .argInfo = POPT_ARG_STRING,
+ .arg = NULL,
+ .val = 'B',
+ .descrip = "Specify address to use for broadcasts",
+ .argDescrip = "BROADCAST-ADDRESS",
+ },
+ {
+ .longName = "flags",
+ .shortName = 'f',
+ .argInfo = POPT_ARG_NONE,
+ .arg = NULL,
+ .val = 'f',
+ .descrip = "List the NMB flags returned",
+ },
+ {
+ .longName = "unicast",
+ .shortName = 'U',
+ .argInfo = POPT_ARG_STRING,
+ .arg = NULL,
+ .val = 'U',
+ .descrip = "Specify address to use for unicast",
+ },
+ {
+ .longName = "master-browser",
+ .shortName = 'M',
+ .argInfo = POPT_ARG_NONE,
+ .arg = NULL,
+ .val = 'M',
+ .descrip = "Search for a master browser",
+ },
+ {
+ .longName = "recursion",
+ .shortName = 'R',
+ .argInfo = POPT_ARG_NONE,
+ .arg = NULL,
+ .val = 'R',
+ .descrip = "Set recursion desired in package",
+ },
+ {
+ .longName = "status",
+ .shortName = 'S',
+ .argInfo = POPT_ARG_NONE,
+ .arg = NULL,
+ .val = 'S',
+ .descrip = "Lookup node status as well",
+ },
+ {
+ .longName = "translate",
+ .shortName = 'T',
+ .argInfo = POPT_ARG_NONE,
+ .arg = NULL,
+ .val = 'T',
+ .descrip = "Translate IP addresses into names",
+ },
+ {
+ .longName = "root-port",
+ .shortName = 'r',
+ .argInfo = POPT_ARG_NONE,
+ .arg = NULL,
+ .val = 'r',
+ .descrip = "Use root port 137 (Win95 only replies to this)",
+ },
+ {
+ .longName = "lookup-by-ip",
+ .shortName = 'A',
+ .argInfo = POPT_ARG_NONE,
+ .arg = NULL,
+ .val = 'A',
+ .descrip = "Do a node status on <name> as an IP Address",
+ },
POPT_COMMON_SAMBA
POPT_COMMON_CONNECTION
- { 0, 0, 0, 0 }
+ POPT_TABLEEND
};
*lookup = 0;
- load_case_tables();
+ smb_init_locale();
setup_logging(argv[0], DEBUG_STDOUT);
- pc = poptGetContext("nmblookup", argc, (const char **)argv,
+ pc = poptGetContext("nmblookup", argc, argv,
long_options, POPT_CONTEXT_KEEP_FIRST);
poptSetOtherOptionHelp(pc, "<NODE> ...");
if(!poptPeekArg(pc)) {
poptPrintUsage(pc, stderr, 0);
- exit(1);
+ rc = 1;
+ goto out;
}
- if (!lp_load(get_dyn_CONFIGFILE(),True,False,False,True)) {
+ if (!lp_load_global(get_dyn_CONFIGFILE())) {
fprintf(stderr, "Can't load %s - run testparm to debug it\n",
get_dyn_CONFIGFILE());
}
load_interfaces();
if (!open_sockets()) {
- return(1);
+ rc = 1;
+ goto out;
}
while(poptPeekArg(pc)) {
char *p;
struct in_addr ip;
+ size_t nbt_len;
fstrcpy(lookup,poptGetArg(pc));
ip = interpret_addr2(lookup);
in_addr_to_sockaddr_storage(&ss, ip);
fstrcpy(lookup,"*");
- do_node_status(lookup, lookup_type, &ss);
+ if (!do_node_status(lookup, lookup_type, &ss)) {
+ rc = 1;
+ }
continue;
}
sscanf(++p,"%x",&lookup_type);
}
+ nbt_len = strlen(lookup);
+ if (nbt_len > MAX_NETBIOSNAME_LEN - 1) {
+ d_printf("The specified netbios name [%s] is too long!\n",
+ lookup);
+ continue;
+ }
+
+
if (!query_one(lookup, lookup_type)) {
+ rc = 1;
d_printf( "name_query failed to find name %s", lookup );
if( 0 != lookup_type ) {
d_printf( "#%02x", lookup_type );
}
}
+out:
poptFreeContext(pc);
TALLOC_FREE(frame);
- return(0);
+ return rc;
}