netmap: revamped documentation
[dragonfly.git] / usr.sbin / yppoll / yppoll.c
1 /*
2  * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
3  * Copyright (c) 1992/3 John Brezak
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote
15  *    products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD: src/usr.sbin/yppoll/yppoll.c,v 1.5.2.2 2002/02/15 00:46:59 des Exp $
31  */
32
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <err.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <time.h>
40 #include <unistd.h>
41
42 #include <rpc/rpc.h>
43 #include <rpc/xdr.h>
44 #include <rpcsvc/yp_prot.h>
45 #include <rpcsvc/ypclnt.h>
46
47 static void
48 usage(void)
49 {
50 #if 0
51         fprintf(stderr, "usage: yppoll [-h host] [-d domainname] mapname\n");
52 #else
53         fprintf(stderr, "usage: yppoll [-d domainname] mapname\n");
54 #endif
55         exit(1);
56 }
57
58 int
59 main(int argc, char **argv)
60 {
61         char *domainname;
62 #if 0
63         char *hostname = "localhost";
64 #endif
65         char *inmap, *master;
66         int order;
67         int c, r;
68
69         yp_get_default_domain(&domainname);
70
71         while ((c = getopt(argc, argv, "h:d:")) != -1)
72                 switch (c) {
73                 case 'd':
74                         domainname = optarg;
75                         break;
76                 case 'h':
77 #if 0
78                         hostname = optarg;
79 #else
80                         /* does nothing */
81 #endif
82                         break;
83                 case '?':
84                         usage();
85                         /*NOTREACHED*/
86                 }
87
88         if (optind + 1 != argc)
89                 usage();
90
91         inmap = argv[optind];
92
93         r = yp_order(domainname, inmap, &order);
94         if (r != 0)
95                 errx(1, "no such map %s. Reason: %s", inmap, yperr_string(r));
96         printf("Map %s has order number %d. %s", inmap, order,
97                         ctime((time_t *)&order));
98         r = yp_master(domainname, inmap, &master);
99         if (r != 0)
100                 errx(1, "no such map %s. Reason: %s", inmap, yperr_string(r));
101         printf("The master server is %s.\n", master);
102
103         exit(0);
104 }