1 /* $NetBSD: ypset.c,v 1.15 2003/12/10 12:06:26 agc Exp $ */
4 * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
31 __RCSID("$NetBSD: ypset.c,v 1.15 2003/12/10 12:06:26 agc Exp $");
34 #include <sys/param.h>
35 #include <sys/types.h>
36 #include <sys/socket.h>
46 #include <rpcsvc/yp_prot.h>
47 #include <rpcsvc/ypclnt.h>
48 #include <arpa/inet.h>
50 int main
__P((int, char *[]));
51 static void usage
__P((void));
52 static void gethostaddr
__P((const char *, struct in_addr
*));
53 static int bind_tohost
__P((struct sockaddr_in
*, char *, char *));
60 struct sockaddr_in sin
;
64 yp_get_default_domain(&domainname
);
66 (void) memset(&sin
, 0, sizeof sin
);
67 sin
.sin_family
= AF_INET
;
68 sin
.sin_addr
.s_addr
= htonl(INADDR_LOOPBACK
);
70 while ((c
= getopt(argc
, argv
, "h:d:")) != -1) {
77 gethostaddr(optarg
, &sin
.sin_addr
);
85 if (domainname
== NULL
)
86 errx(1, "YP domain name not set");
94 return bind_tohost(&sin
, domainname
, argv
[0]) != 0;
104 if (inet_aton(host
, ia
) != 0)
107 hp
= gethostbyname(host
);
109 errx(1, "Cannot get host address for %s: %s", host
,
111 (void) memcpy(ia
, hp
->h_addr
, sizeof(*ia
));
115 bind_tohost(sin
, dom
, server
)
116 struct sockaddr_in
*sin
;
119 struct ypbind_setdom ypsd
;
125 port
= htons(getrpcport(server
, YPPROG
, YPPROC_NULL
, IPPROTO_UDP
));
127 errx(1, "%s not running ypserv.", server
);
129 (void) memset(&ypsd
, 0, sizeof ypsd
);
131 gethostaddr(server
, &ypsd
.ypsetdom_addr
);
133 (void) strlcpy(ypsd
.ypsetdom_domain
, dom
, sizeof ypsd
.ypsetdom_domain
);
134 ypsd
.ypsetdom_port
= port
;
135 ypsd
.ypsetdom_vers
= YPVERS
;
141 client
= clntudp_create(sin
, YPBINDPROG
, YPBINDVERS
, tv
, &sock
);
142 if (client
== NULL
) {
143 warnx("Can't yp_bind: Reason: %s", yperr_string(YPERR_YPBIND
));
146 client
->cl_auth
= authunix_create_default();
148 r
= clnt_call(client
, YPBINDPROC_SETDOM
,
149 xdr_ypbind_setdom
, &ypsd
, xdr_void
, NULL
, tv
);
151 warnx("Cannot ypset for domain %s on host %s: %s.",
152 dom
, server
, clnt_sperrno(r
));
153 clnt_destroy(client
);
156 clnt_destroy(client
);
163 (void) fprintf(stderr
, "usage: %s [-h host ] [-d domain] server\n",