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 struct in_addr bcast_ip;
34 extern pstring myhostname;
36 static BOOL got_bcast = False;
37 struct in_addr ipzero;
41 /****************************************************************************
42 open the socket communication
43 **************************************************************************/
44 static BOOL open_sockets(void)
49 if ((hp = Get_Hostbyname(myhostname)) == 0)
51 DEBUG(0,( "Get_Hostbyname: Unknown host. %s\n",myhostname));
55 ServerFD = open_socket_in(SOCK_DGRAM, 0,3);
60 set_socket_options(ServerFD,"SO_BROADCAST");
62 DEBUG(3, ("Socket opened.\n"));
67 /****************************************************************************
68 initialise connect, service and file structs
69 ****************************************************************************/
70 static BOOL init_structs(void )
74 if (!get_myname(myhostname,&myip))
77 /* Read the broadcast address from the interface */
79 struct in_addr ip0,ip2;
84 get_broadcast(&ip0,&bcast_ip,&ip2);
86 DEBUG(2,("Using broadcast %s\n",inet_ntoa(bcast_ip)));
93 /****************************************************************************
95 ****************************************************************************/
96 static void usage(void)
98 printf("Usage: nmblookup [-M] [-B bcast address] [-d debuglevel] name\n");
99 printf("Version %s\n",VERSION);
100 printf("\t-d debuglevel set the debuglevel\n");
101 printf("\t-B broadcast address the address to use for broadcasts\n");
102 printf("\t-M searches for a master browser\n");
103 printf("\t-S lookup node status as well\n");
108 /****************************************************************************
110 ****************************************************************************/
111 int main(int argc,char *argv[])
114 unsigned int lookup_type = 0x20;
118 BOOL find_master=False;
119 BOOL find_status=False;
127 ipzero = *interpret_addr2("0.0.0.0");
129 setup_logging(argv[0],True);
131 charset_initialise();
133 while ((opt = getopt(argc, argv, "p:d:B:i:SMh")) != EOF)
138 unsigned long a = interpret_addr(optarg);
139 putip((char *)&bcast_ip,(char *)&a);
144 strcpy(scope,optarg);
154 DEBUGLEVEL = atoi(optarg);
171 if (!open_sockets()) return(1);
173 DEBUG(1,("Sending queries to %s\n",inet_ntoa(bcast_ip)));
176 for (i=optind;i<argc;i++)
183 strcpy(lookup,argv[i]);
186 if (*lookup == '-') {
187 strcpy(lookup,"\01\02__MSBROWSE__\02");
194 p = strchr(lookup,'#');
198 sscanf(p+1,"%x",&lookup_type);
203 if (name_query(ServerFD,lookup,lookup_type,bcast,True,
206 printf("%s %s\n",inet_ntoa(ip),lookup);
209 printf("Looking up status of %s\n",inet_ntoa(ip));
210 name_status(ServerFD,lookup,lookup_type,True,ip,NULL,NULL,NULL);
214 printf("couldn't find name %s\n",lookup);