2 Unix SMB/Netbios implementation.
4 NBT client - used to lookup netbios names
5 Copyright (C) Andrew Tridgell 1994-1995
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 extern int DEBUGLEVEL
;
33 extern pstring myhostname
;
34 extern struct in_addr ipzero
;
38 /****************************************************************************
39 open the socket communication
40 **************************************************************************/
41 static BOOL
open_sockets(void)
46 if ((hp
= Get_Hostbyname(myhostname
)) == 0)
48 DEBUG(0,( "Get_Hostbyname: Unknown host. %s\n",myhostname
));
52 ServerFD
= open_socket_in(SOCK_DGRAM
, 0,3);
57 set_socket_options(ServerFD
,"SO_BROADCAST");
59 DEBUG(3, ("Socket opened.\n"));
64 /****************************************************************************
65 initialise connect, service and file structs
66 ****************************************************************************/
67 static BOOL
init_structs(void )
69 if (!get_myname(myhostname
,NULL
))
75 /****************************************************************************
77 ****************************************************************************/
78 static void usage(void)
80 printf("Usage: nmblookup [-M] [-B bcast address] [-d debuglevel] name\n");
81 printf("Version %s\n",VERSION
);
82 printf("\t-d debuglevel set the debuglevel\n");
83 printf("\t-B broadcast address the address to use for broadcasts\n");
84 printf("\t-M searches for a master browser\n");
85 printf("\t-S lookup node status as well\n");
90 /****************************************************************************
92 ****************************************************************************/
93 int main(int argc
,char *argv
[])
96 unsigned int lookup_type
= 0x0;
100 BOOL find_master
=False
;
101 BOOL find_status
=False
;
109 setup_logging(argv
[0],True
);
111 charset_initialise();
113 while ((opt
= getopt(argc
, argv
, "p:d:B:i:SMh")) != EOF
)
117 iface_set_default(NULL
,optarg
,NULL
);
120 strcpy(scope
,optarg
);
130 DEBUGLEVEL
= atoi(optarg
);
148 if (!open_sockets()) return(1);
150 DEBUG(1,("Sending queries to %s\n",inet_ntoa(*iface_bcast(ipzero
))));
153 for (i
=optind
;i
<argc
;i
++)
160 strcpy(lookup
,argv
[i
]);
163 if (*lookup
== '-') {
164 strcpy(lookup
,"\01\02__MSBROWSE__\02");
171 p
= strchr(lookup
,'#');
175 sscanf(p
+1,"%x",&lookup_type
);
180 if (name_query(ServerFD
,lookup
,lookup_type
,bcast
,True
,
181 *iface_bcast(ipzero
),&ip
,NULL
))
183 printf("%s %s\n",inet_ntoa(ip
),lookup
);
186 printf("Looking up status of %s\n",inet_ntoa(ip
));
187 name_status(ServerFD
,lookup
,lookup_type
,True
,ip
,NULL
,NULL
,NULL
);
191 printf("couldn't find name %s\n",lookup
);