Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / contrib / query-loc-0.4.0 / query-loc.c
blob5a1cd77a9fe32c3c4a1176efc1bdb6e1abbbf574
1 /* $NetBSD: query-loc.c,v 1.4 2014/12/10 04:37:56 christos Exp $ */
3 #include "loc.h"
5 /* Id: query-loc.c,v 1.1 2008/02/15 01:47:15 marka Exp */
7 /* Global variables */
8 char *progname;
9 short debug;
11 int
12 main (argc, argv)
13 int argc;
14 char *argv[];
16 extern char *optarg;
17 extern int optind;
19 short verbose = FALSE;
20 char *host;
22 char ch;
24 char *loc = NULL;
25 struct in_addr addr;
26 struct hostent *hp;
28 progname = argv[0];
29 while ((ch = getopt (argc, argv, "vd:")) != EOF)
31 switch (ch)
33 case 'v':
34 verbose = TRUE;
35 break;
36 case 'd':
37 debug = atoi (optarg);
38 if (debug <= 0)
40 (void) fprintf (stderr,
41 "%s: illegal debug value.\n", progname);
42 exit (2);
44 break;
45 default:
46 usage ();
49 argc -= optind;
50 argv += optind;
51 if (argc != 1)
53 usage ();
55 if (verbose || debug)
57 printf ("\nThis is %s, version %s.\n\n", progname, VERSION);
59 host = argv[0];
60 (void) res_init ();
62 if ((addr.s_addr = inet_addr (host)) == INADDR_NONE)
64 if (debug >= 1)
65 printf ("%s is a name\n", host);
66 loc = getlocbyname (host, FALSE);
68 else
70 if (debug >= 1)
71 printf ("%s is an IP address ", host);
72 hp = (struct hostent *) gethostbyaddr
73 ((char *) &addr, sizeof (addr), AF_INET);
74 if (hp)
76 if (debug >= 1)
77 printf ("and %s is its official name\n",
78 hp->h_name);
79 loc = getlocbyname (hp->h_name, FALSE);
81 else
83 if (debug >= 1)
84 printf ("which has no name\n");
85 loc = getlocbyaddr (addr, NULL);
88 if (loc == NULL)
90 printf ("No LOCation found for %s\n", host);
91 exit (1);
93 else
95 if (verbose || debug)
96 printf ("LOCation for %s is ", host);
97 printf ("%s\n", loc);
98 exit (0);