yppoll.c revision 1.3 1 /*
2 * Copyright (c) 1992, 1993 Theo de Raadt <deraadt (at) fsa.ca>
3 * Copyright (c) 1992, 1993 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. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Theo de Raadt and
17 * John Brezak.
18 * 4. The name of the author may not be used to endorse or promote
19 * products derived from this software without specific prior written
20 * permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 #ifndef lint
36 static char rcsid[] = "$Id: yppoll.c,v 1.3 1994/05/25 09:55:41 deraadt Exp $";
37 #endif /* not lint */
38
39 #include <sys/param.h>
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <stdio.h>
43 #include <time.h>
44
45 #include <rpc/rpc.h>
46 #include <rpc/xdr.h>
47 #include <rpcsvc/yp_prot.h>
48 #include <rpcsvc/ypclnt.h>
49
50 usage()
51 {
52 fprintf(stderr, "Usage:\n");
53 fprintf(stderr, "\typpoll [-h host] [-d domainname] mapname\n");
54 exit(1);
55 }
56
57 int
58 main(argc, argv)
59 char **argv;
60 {
61 char *domainname;
62 char *hostname = "localhost";
63 char *inmap, *master;
64 int order;
65 extern char *optarg;
66 extern int optind;
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 hostname = optarg;
78 break;
79 case '?':
80 usage();
81 /*NOTREACHED*/
82 }
83
84 if(optind + 1 != argc )
85 usage();
86
87 inmap = argv[optind];
88
89 r = yp_order(domainname, inmap, &order);
90 if (r != 0) {
91 fprintf(stderr, "No such map %s. Reason: %s\n",
92 inmap, yperr_string(r));
93 exit(1);
94 }
95 printf("Map %s has order number %d. %s", inmap, order, ctime((time_t *)&order));
96 r = yp_master(domainname, inmap, &master);
97 if (r != 0) {
98 fprintf(stderr, "No such map %s. Reason: %s\n",
99 inmap, yperr_string(r));
100 exit(1);
101 }
102 printf("The master server is %s.\n", master);
103
104 exit(0);
105 }
106