]>
git.saurik.com Git - apple/network_cmds.git/blob - yppoll.tproj/yppoll.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
27 * Copyright (c) 1992, 1993 John Brezak
28 * All rights reserved.
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by Theo de Raadt and
42 * 4. The name of the author may not be used to endorse or promote
43 * products derived from this software without specific prior written
46 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
47 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
48 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
50 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 static char rcsid
[] = "$Id: yppoll.c,v 1.1.1.1 1999/05/02 03:59:03 wsanchez Exp $";
63 #include <sys/param.h>
64 #include <sys/types.h>
65 #include <sys/socket.h>
71 #include <netinet/in.h>
72 #include <arpa/inet.h>
76 #include <rpcsvc/yp_prot.h>
77 #include <rpcsvc/ypclnt.h>
82 fprintf(stderr
, "Usage:\n");
83 fprintf(stderr
, "\typpoll [-h host] [-d domainname] mapname\n");
88 get_remote_info(indomain
, inmap
, server
, outorder
, outname
)
95 struct ypresp_order ypro
;
96 struct ypresp_master yprm
;
97 struct ypreq_nokey yprnk
;
100 struct sockaddr_in rsrv_sin
;
105 bzero((char *)&rsrv_sin
, sizeof rsrv_sin
);
106 rsrv_sin
.sin_len
= sizeof rsrv_sin
;
107 rsrv_sin
.sin_family
= AF_INET
;
108 rsrv_sock
= RPC_ANYSOCK
;
110 h
= gethostbyname(server
);
112 if (inet_aton(server
, &rsrv_sin
.sin_addr
) == 0) {
113 fprintf(stderr
, "unknown host %s\n", server
);
117 rsrv_sin
.sin_addr
.s_addr
= *(u_long
*)h
->h_addr
;
123 client
= clntudp_create(&rsrv_sin
, YPPROG
, YPVERS
, tv
, &rsrv_sock
);
124 if (client
== NULL
) {
125 fprintf(stderr
, "clntudp_create: no contact with host %s.\n",
130 yprnk
.domain
= indomain
;
133 bzero((char *)(char *)&ypro
, sizeof ypro
);
135 r
= clnt_call(client
, YPPROC_ORDER
, xdr_ypreq_nokey
, &yprnk
,
136 xdr_ypresp_order
, &ypro
, tv
);
137 if (r
!= RPC_SUCCESS
)
138 clnt_perror(client
, "yp_order: clnt_call");
140 *outorder
= ypro
.ordernum
;
141 xdr_free(xdr_ypresp_order
, (char *)&ypro
);
143 r
= ypprot_err(ypro
.status
);
144 if (r
== RPC_SUCCESS
) {
145 bzero((char *)&yprm
, sizeof yprm
);
147 r
= clnt_call(client
, YPPROC_MASTER
, xdr_ypreq_nokey
,
148 &yprnk
, xdr_ypresp_master
, &yprm
, tv
);
149 if (r
!= RPC_SUCCESS
)
150 clnt_perror(client
, "yp_master: clnt_call");
151 r
= ypprot_err(yprm
.status
);
153 *outname
= (char *)strdup(yprm
.master
);
154 xdr_free(xdr_ypresp_master
, (char *)&yprm
);
156 clnt_destroy(client
);
166 char *hostname
= NULL
;
167 char *inmap
, *master
;
173 yp_get_default_domain(&domainname
);
175 while ((c
=getopt(argc
, argv
, "h:d:?")) != -1)
188 if (optind
+ 1 != argc
)
190 inmap
= argv
[optind
];
192 if (hostname
!= NULL
) {
193 r
= get_remote_info(domainname
, inmap
, hostname
,
196 r
= yp_order(domainname
, inmap
, &order
);
198 r
= yp_master(domainname
, inmap
, &master
);
202 fprintf(stderr
, "No such map %s. Reason: %s\n",
203 inmap
, yperr_string(r
));
207 printf("Map %s has order number %d. %s", inmap
, order
,
208 ctime((time_t *)&order
));
209 printf("The master server is %s.\n", master
);