This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.
[tprouty/samba.git] / source / utils / net_lookup.c
1 /* 
2    Samba Unix/Linux SMB client library 
3    net lookup command
4    Copyright (C) 2001 Andrew Tridgell (tridge@samba.org)
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #include "includes.h"
21 #include "../utils/net.h"
22
23 int net_lookup_usage(int argc, const char **argv)
24 {
25         d_printf(
26 "  net lookup host HOSTNAME <type>\n\tgives IP for a hostname\n\n"\
27 "\n");
28         return -1;
29 }
30
31 /* lookup a hostname giving an IP */
32 static int net_lookup_host(int argc, const char **argv)
33 {
34         struct in_addr ip;
35         int name_type = 0x20;
36
37         if (argc == 0) return net_lookup_usage(argc, argv);
38         if (argc > 1) name_type = strtol(argv[1], NULL, 0);
39
40         if (!resolve_name(argv[0], &ip, name_type)) {
41                 /* we deliberately use DEBUG() here to send it to stderr 
42                    so scripts aren't mucked up */
43                 DEBUG(0,("Didn't find %s#%02x\n", argv[0], name_type));
44                 return -1;
45         }
46
47         d_printf("%s\n", inet_ntoa(ip));
48         return 0;
49 }
50
51
52 /* lookup hosts or IP addresses using internal samba lookup fns */
53 int net_lookup(int argc, const char **argv)
54 {
55         struct functable func[] = {
56                 {"HOST", net_lookup_host},
57                 {NULL, NULL}
58         };
59
60         return net_run_function(argc, argv, func, net_lookup_usage);
61 }