1 /* $OpenBSD: yppoll.c,v 1.15 2015/01/16 06:40:22 deraadt Exp $ */
2 /* $NetBSD: yppoll.c,v 1.5 1996/05/13 02:46:36 thorpej Exp $ */
5 * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@openbsd.org>
6 * Copyright (c) 1992, 1993 John Brezak
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote
18 * products derived from this software without specific prior written
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
38 #include <sys/types.h>
39 #include <sys/socket.h>
41 #include <arpa/inet.h>
42 #include <netinet/in.h>
55 #include <rpcsvc/yp_prot.h>
56 #include <rpcsvc/ypclnt.h>
61 fprintf(stderr, "usage: yppoll [-d domain] [-h host] mapname\n");
66 get_remote_info(char *indomain, char *inmap, char *server, int *outorder,
69 struct ypresp_order ypro;
70 struct ypresp_master yprm;
71 struct ypreq_nokey yprnk;
73 struct sockaddr_in rsrv_sin;
79 bzero((char *)&rsrv_sin, sizeof rsrv_sin);
80 rsrv_sin.sin_len = sizeof rsrv_sin;
81 rsrv_sin.sin_family = AF_INET;
82 rsrv_sock = RPC_ANYSOCK;
84 h = gethostbyname(server);
86 if (inet_aton(server, &rsrv_sin.sin_addr) == 0)
87 errx(1, "unknown host %s.", server);
89 rsrv_sin.sin_addr.s_addr = *(u_int32_t *)h->h_addr;
94 client = clntudp_create(&rsrv_sin, YPPROG, YPVERS, tv, &rsrv_sock);
96 errx(1, "clntudp_create: no contact with host %s.", server);
98 yprnk.domain = indomain;
101 bzero((char *)(char *)&ypro, sizeof ypro);
103 r = clnt_call(client, YPPROC_ORDER, (xdrproc_t)xdr_ypreq_nokey, &yprnk,
104 (xdrproc_t)xdr_ypresp_order, &ypro, tv);
105 if (r != RPC_SUCCESS)
106 clnt_perror(client, "yp_order: clnt_call");
108 *outorder = ypro.ordernum;
109 xdr_free((xdrproc_t)xdr_ypresp_order, (char *)&ypro);
111 r = ypprot_err(ypro.status);
112 if (r == RPC_SUCCESS) {
113 bzero((char *)&yprm, sizeof yprm);
115 r = clnt_call(client, YPPROC_MASTER, (xdrproc_t)xdr_ypreq_nokey,
116 &yprnk, (xdrproc_t)xdr_ypresp_master, &yprm, tv);
117 if (r != RPC_SUCCESS)
118 clnt_perror(client, "yp_master: clnt_call");
119 r = ypprot_err(yprm.status);
121 *outname = (char *)strdup(yprm.master);
122 xdr_free((xdrproc_t)xdr_ypresp_master, (char *)&yprm);
124 clnt_destroy(client);
129 main(int argc, char *argv[])
131 char *domainname, *hostname = NULL, *inmap, *master;
135 yp_get_default_domain(&domainname);
137 while ((c = getopt(argc, argv, "h:d:")) != -1)
150 if (optind + 1 != argc)
152 inmap = argv[optind];
154 if (hostname != NULL) {
155 r = get_remote_info(domainname, inmap, hostname,
158 r = yp_order(domainname, inmap, &order);
160 r = yp_master(domainname, inmap, &master);
164 errx(1, "no such map %s: reason: %s",
165 inmap, yperr_string(r));
168 printf("Map %s has order number %lld. %s", inmap,
169 (long long)order, ctime(&torder));
170 printf("The master server is %s.\n", master);