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