libutil: add O_NOCTTY back to old pty open code
[minix.git] / lib / libc / rpc / pmap_rmt.c
blobf7e43ccf098425154d5dbb7ce7a63fe970428b31
1 /* $NetBSD: pmap_rmt.c,v 1.30 2010/03/23 20:28:59 drochner Exp $ */
3 /*
4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 * unrestricted use provided that this legend is included on all tape
6 * media and as a part of the software program in whole or part. Users
7 * may copy or modify Sun RPC without charge, but are not authorized
8 * to license or distribute it to anyone else except as part of a product or
9 * program developed by the user.
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
15 * Sun RPC is provided with no support and without any obligation on the
16 * part of Sun Microsystems, Inc. to assist in its use, correction,
17 * modification or enhancement.
19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 * OR ANY PART THEREOF.
23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 * or profits or other special, indirect and consequential damages, even if
25 * Sun has been advised of the possibility of such damages.
27 * Sun Microsystems, Inc.
28 * 2550 Garcia Avenue
29 * Mountain View, California 94043
32 #include <sys/cdefs.h>
33 #if defined(LIBC_SCCS) && !defined(lint)
34 #if 0
35 static char *sccsid = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
36 static char *sccsid = "@(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC";
37 #else
38 __RCSID("$NetBSD: pmap_rmt.c,v 1.30 2010/03/23 20:28:59 drochner Exp $");
39 #endif
40 #endif
43 * pmap_rmt.c
44 * Client interface to pmap rpc service.
45 * remote call and broadcast service
47 * Copyright (C) 1984, Sun Microsystems, Inc.
50 #include "namespace.h"
52 #include <sys/types.h>
53 #include <sys/ioctl.h>
54 #include <sys/poll.h>
55 #include <sys/socket.h>
57 #include <net/if.h>
58 #include <netinet/in.h>
59 #include <arpa/inet.h>
61 #include <assert.h>
62 #include <err.h>
63 #include <errno.h>
64 #include <stdio.h>
65 #include <string.h>
66 #include <unistd.h>
68 #include <rpc/rpc.h>
69 #include <rpc/pmap_prot.h>
70 #include <rpc/pmap_clnt.h>
71 #include <rpc/pmap_rmt.h>
73 #ifdef __weak_alias
74 __weak_alias(xdr_rmtcall_args,_xdr_rmtcall_args)
75 __weak_alias(xdr_rmtcallres,_xdr_rmtcallres)
76 #endif
78 static const struct timeval timeout = { 3, 0 };
81 * pmapper remote-call-service interface.
82 * This routine is used to call the pmapper remote call service
83 * which will look up a service program in the port maps, and then
84 * remotely call that routine with the given parameters. This allows
85 * programs to do a lookup and call in one step.
87 enum clnt_stat
88 pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout,
89 port_ptr)
90 struct sockaddr_in *addr;
91 u_long prog, vers, proc;
92 xdrproc_t xdrargs, xdrres;
93 caddr_t argsp, resp;
94 struct timeval tout;
95 u_long *port_ptr;
97 int sock = -1;
98 CLIENT *client;
99 struct rmtcallargs a;
100 struct rmtcallres r;
101 enum clnt_stat stat;
103 _DIAGASSERT(addr != NULL);
104 _DIAGASSERT(port_ptr != NULL);
106 addr->sin_port = htons(PMAPPORT);
107 client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock);
108 if (client != NULL) {
109 a.prog = prog;
110 a.vers = vers;
111 a.proc = proc;
112 a.args_ptr = argsp;
113 a.xdr_args = xdrargs;
114 r.port_ptr = port_ptr;
115 r.results_ptr = resp;
116 r.xdr_results = xdrres;
117 stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT,
118 (xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres,
119 &r, tout);
120 CLNT_DESTROY(client);
121 } else {
122 stat = RPC_FAILED;
124 addr->sin_port = 0;
125 return (stat);
130 * XDR remote call arguments
131 * written for XDR_ENCODE direction only
133 bool_t
134 xdr_rmtcall_args(xdrs, cap)
135 XDR *xdrs;
136 struct rmtcallargs *cap;
138 u_int lenposition, argposition, position;
140 _DIAGASSERT(xdrs != NULL);
141 _DIAGASSERT(cap != NULL);
143 if (xdr_u_long(xdrs, &(cap->prog)) &&
144 xdr_u_long(xdrs, &(cap->vers)) &&
145 xdr_u_long(xdrs, &(cap->proc))) {
146 lenposition = XDR_GETPOS(xdrs);
147 if (! xdr_u_long(xdrs, &(cap->arglen)))
148 return (FALSE);
149 argposition = XDR_GETPOS(xdrs);
150 if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
151 return (FALSE);
152 position = XDR_GETPOS(xdrs);
153 cap->arglen = (u_long)position - (u_long)argposition;
154 XDR_SETPOS(xdrs, lenposition);
155 if (! xdr_u_long(xdrs, &(cap->arglen)))
156 return (FALSE);
157 XDR_SETPOS(xdrs, position);
158 return (TRUE);
160 return (FALSE);
164 * XDR remote call results
165 * written for XDR_DECODE direction only
167 bool_t
168 xdr_rmtcallres(xdrs, crp)
169 XDR *xdrs;
170 struct rmtcallres *crp;
172 caddr_t port_ptr;
174 _DIAGASSERT(xdrs != NULL);
175 _DIAGASSERT(crp != NULL);
177 port_ptr = (caddr_t)(void *)crp->port_ptr;
178 if (xdr_reference(xdrs, &port_ptr, sizeof (u_long),
179 (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
180 crp->port_ptr = (u_long *)(void *)port_ptr;
181 return ((*(crp->xdr_results))(xdrs, crp->results_ptr));
183 return (FALSE);