sync getopt() args with 2.2
[Samba.git] / source / utils / net_lookup.c
blob21f3eb033de3ffb6203ecd103a5f78c68486fbe0
1 /*
2 Samba Unix/Linux SMB client library
3 Version 3.0
4 net lookup command
5 Copyright (C) 2001 Andrew Tridgell (tridge@samba.org)
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. */
21 #include "includes.h"
22 #include "../utils/net.h"
24 int net_lookup_usage(int argc, const char **argv)
26 d_printf(
27 "net lookup host HOSTNAME <type>\n\tgives IP for a hostname\n\n"\
28 "\n");
29 return -1;
32 /* lookup a hostname giving an IP */
33 static int net_lookup_host(int argc, const char **argv)
35 struct in_addr ip;
36 int name_type = 0x20;
38 if (argc == 0) return net_lookup_usage(argc, argv);
39 if (argc > 1) name_type = strtol(argv[1], NULL, 0);
41 if (!resolve_name(argv[0], &ip, name_type)) {
42 /* we deliberately use DEBUG() here to send it to stderr
43 so scripts aren't mucked up */
44 DEBUG(0,("Didn't find %s#%02x\n", argv[0], name_type));
45 return -1;
48 d_printf("%s\n", inet_ntoa(ip));
49 return 0;
53 /* lookup hosts or IP addresses using internal samba lookup fns */
54 int net_lookup(int argc, const char **argv)
56 struct functable func[] = {
57 {"HOST", net_lookup_host},
58 {NULL, NULL}
61 return net_run_function(argc, argv, func, net_lookup_usage);