yppoll.c revision 48171
1261041Simp/*
2210040Scognet * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
3210040Scognet * Copyright (c) 1992/3 John Brezak
4210040Scognet * All rights reserved.
5210040Scognet *
6210040Scognet * Redistribution and use in source and binary forms, with or without
7210040Scognet * modification, are permitted provided that the following conditions
8210040Scognet * are met:
9210040Scognet * 1. Redistributions of source code must retain the above copyright
10210040Scognet *    notice, this list of conditions and the following disclaimer.
11210040Scognet * 2. Redistributions in binary form must reproduce the above copyright
12210040Scognet *    notice, this list of conditions and the following disclaimer in the
13210040Scognet *    documentation and/or other materials provided with the distribution.
14236988Simp * 3. The name of the author may not be used to endorse or promote
15236988Simp *    products derived from this software without specific prior written
16210040Scognet *    permission.
17210040Scognet *
18210040Scognet * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19210040Scognet * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20265155Simp * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21265155Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22210040Scognet * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23210040Scognet * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24210040Scognet * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25210040Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26210040Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27210040Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28210040Scognet * SUCH DAMAGE.
29210040Scognet */
30263245Simp
31210040Scognet#ifndef lint
32210040Scognetstatic const char rcsid[] =
33210040Scognet	"$Id: yppoll.c,v 1.3 1997/10/27 12:30:30 charnier Exp $";
34263245Simp#endif /* not lint */
35263245Simp
36263245Simp#include <sys/param.h>
37263245Simp#include <sys/types.h>
38263245Simp#include <sys/socket.h>
39263245Simp#include <err.h>
40263245Simp#include <stdio.h>
41263245Simp#include <time.h>
42260887Simp#include <unistd.h>
43260887Simp
44261041Simp#include <rpc/rpc.h>
45263245Simp#include <rpc/xdr.h>
46263245Simp#include <rpcsvc/yp_prot.h>
47263245Simp#include <rpcsvc/ypclnt.h>
48263245Simp
49261041Simpstatic void
50261041Simpusage()
51261041Simp{
52210040Scognet	fprintf(stderr, "usage: yppoll [-h host] [-d domainname] mapname\n");
53261041Simp	exit(1);
54210040Scognet}
55240572Sjmg
56210040Scognetint
57263245Simpmain(argc, argv)
58263245Simpchar **argv;
59263301Simp{
60263245Simp	char *domainname;
61263245Simp        char *hostname = "localhost";
62263245Simp        char *inmap, *master;
63263245Simp        int order;
64263245Simp	int c, r;
65263245Simp
66263245Simp        yp_get_default_domain(&domainname);
67263245Simp
68263245Simp	while( (c=getopt(argc, argv, "h:d:")) != -1)
69263245Simp		switch(c) {
70210040Scognet		case 'd':
71210040Scognet                        domainname = optarg;
72210040Scognet			break;
73210040Scognet                case 'h':
74210040Scognet                        hostname = optarg;
75210040Scognet                        break;
76210040Scognet                case '?':
77210040Scognet                        usage();
78238957Simp                        /*NOTREACHED*/
79210040Scognet		}
80210040Scognet
81210040Scognet	if(optind + 1 != argc )
82210040Scognet		usage();
83263245Simp
84263245Simp	inmap = argv[optind];
85263245Simp
86263245Simp	r = yp_order(domainname, inmap, &order);
87210040Scognet        if (r != 0)
88210040Scognet		errx(1, "no such map %s. Reason: %s", inmap, yperr_string(r));
89210040Scognet        printf("Map %s has order number %d. %s", inmap, order,
90261041Simp			ctime((time_t *)&order));
91210040Scognet	r = yp_master(domainname, inmap, &master);
92210040Scognet        if (r != 0)
93263245Simp		errx(1, "no such map %s. Reason: %s", inmap, yperr_string(r));
94263245Simp        printf("The master server is %s.\n", master);
95263245Simp
96263245Simp        exit(0);
97263245Simp}
98263245Simp