uipc_syscalls_43.c revision 1.1 1 1.1 christos /* $NetBSD: uipc_syscalls_43.c,v 1.1 1995/06/24 20:16:23 christos Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright (c) 1982, 1986, 1989, 1990, 1993
5 1.1 christos * The Regents of the University of California. All rights reserved.
6 1.1 christos *
7 1.1 christos * Redistribution and use in source and binary forms, with or without
8 1.1 christos * modification, are permitted provided that the following conditions
9 1.1 christos * are met:
10 1.1 christos * 1. Redistributions of source code must retain the above copyright
11 1.1 christos * notice, this list of conditions and the following disclaimer.
12 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 christos * notice, this list of conditions and the following disclaimer in the
14 1.1 christos * documentation and/or other materials provided with the distribution.
15 1.1 christos * 3. All advertising materials mentioning features or use of this software
16 1.1 christos * must display the following acknowledgement:
17 1.1 christos * This product includes software developed by the University of
18 1.1 christos * California, Berkeley and its contributors.
19 1.1 christos * 4. Neither the name of the University nor the names of its contributors
20 1.1 christos * may be used to endorse or promote products derived from this software
21 1.1 christos * without specific prior written permission.
22 1.1 christos *
23 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 christos * SUCH DAMAGE.
34 1.1 christos *
35 1.1 christos * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94
36 1.1 christos */
37 1.1 christos
38 1.1 christos #include <sys/param.h>
39 1.1 christos #include <sys/systm.h>
40 1.1 christos #include <sys/filedesc.h>
41 1.1 christos #include <sys/kernel.h>
42 1.1 christos #include <sys/proc.h>
43 1.1 christos #include <sys/file.h>
44 1.1 christos #include <sys/socket.h>
45 1.1 christos #include <sys/socketvar.h>
46 1.1 christos #include <sys/stat.h>
47 1.1 christos #include <sys/ioctl.h>
48 1.1 christos #include <sys/fcntl.h>
49 1.1 christos #include <sys/malloc.h>
50 1.1 christos #include <sys/syslog.h>
51 1.1 christos #include <sys/unistd.h>
52 1.1 christos #include <sys/resourcevar.h>
53 1.1 christos
54 1.1 christos #include <sys/mount.h>
55 1.1 christos #include <sys/syscallargs.h>
56 1.1 christos
57 1.1 christos #define MSG_COMPAT 0x8000 /* XXX */
58 1.1 christos
59 1.1 christos int
60 1.1 christos compat_43_accept(p, uap, retval)
61 1.1 christos struct proc *p;
62 1.1 christos struct accept_args /* {
63 1.1 christos syscallarg(int) s;
64 1.1 christos syscallarg(caddr_t) name;
65 1.1 christos syscallarg(int *) anamelen;
66 1.1 christos } */ *uap;
67 1.1 christos register_t *retval;
68 1.1 christos {
69 1.1 christos int error;
70 1.1 christos
71 1.1 christos if ((error = accept(p, uap, retval)) != 0)
72 1.1 christos return error;
73 1.1 christos
74 1.1 christos if (SCARG(uap, name)) {
75 1.1 christos struct sockaddr sa;
76 1.1 christos
77 1.1 christos if ((error = copyin(SCARG(uap, name), &sa, sizeof(sa))) != 0)
78 1.1 christos return error;
79 1.1 christos
80 1.1 christos ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
81 1.1 christos
82 1.1 christos if ((error = copyout(&sa, SCARG(uap, name), sizeof(sa))) != 0)
83 1.1 christos return error;
84 1.1 christos }
85 1.1 christos return 0;
86 1.1 christos }
87 1.1 christos
88 1.1 christos
89 1.1 christos int
90 1.1 christos compat_43_getpeername(p, uap, retval)
91 1.1 christos struct proc *p;
92 1.1 christos struct getpeername_args /* {
93 1.1 christos syscallarg(int) fdes;
94 1.1 christos syscallarg(caddr_t) asa;
95 1.1 christos syscallarg(int *) alen;
96 1.1 christos } */ *uap;
97 1.1 christos register_t *retval;
98 1.1 christos {
99 1.1 christos struct sockaddr sa;
100 1.1 christos
101 1.1 christos int error;
102 1.1 christos
103 1.1 christos if ((error = getpeername(p, uap, retval)) != 0)
104 1.1 christos return error;
105 1.1 christos
106 1.1 christos if ((error = copyin(SCARG(uap, asa), &sa, sizeof(sa))) != 0)
107 1.1 christos return error;
108 1.1 christos
109 1.1 christos ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
110 1.1 christos
111 1.1 christos if ((error = copyout(&sa, SCARG(uap, asa), sizeof(sa))) != 0)
112 1.1 christos return error;
113 1.1 christos
114 1.1 christos return 0;
115 1.1 christos }
116 1.1 christos
117 1.1 christos
118 1.1 christos int
119 1.1 christos compat_43_getsockname(p, uap, retval)
120 1.1 christos struct proc *p;
121 1.1 christos struct getsockname_args /* {
122 1.1 christos syscallarg(int) fdes;
123 1.1 christos syscallarg(caddr_t) asa;
124 1.1 christos syscallarg(int *) alen;
125 1.1 christos } */ *uap;
126 1.1 christos register_t *retval;
127 1.1 christos {
128 1.1 christos struct sockaddr sa;
129 1.1 christos int error;
130 1.1 christos
131 1.1 christos if ((error = getsockname(p, uap, retval)) != 0)
132 1.1 christos return error;
133 1.1 christos
134 1.1 christos if ((error = copyin(SCARG(uap, asa), &sa, sizeof(sa))) != 0)
135 1.1 christos return error;
136 1.1 christos
137 1.1 christos ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
138 1.1 christos
139 1.1 christos if ((error = copyout(&sa, SCARG(uap, asa), sizeof(sa))) != 0)
140 1.1 christos return error;
141 1.1 christos
142 1.1 christos return 0;
143 1.1 christos }
144 1.1 christos
145 1.1 christos
146 1.1 christos int
147 1.1 christos compat_43_recv(p, uap, retval)
148 1.1 christos struct proc *p;
149 1.1 christos register struct compat_43_recv_args /* {
150 1.1 christos syscallarg(int) s;
151 1.1 christos syscallarg(caddr_t) buf;
152 1.1 christos syscallarg(int) len;
153 1.1 christos syscallarg(int) flags;
154 1.1 christos } */ *uap;
155 1.1 christos register_t *retval;
156 1.1 christos {
157 1.1 christos struct msghdr msg;
158 1.1 christos struct iovec aiov;
159 1.1 christos
160 1.1 christos msg.msg_name = 0;
161 1.1 christos msg.msg_namelen = 0;
162 1.1 christos msg.msg_iov = &aiov;
163 1.1 christos msg.msg_iovlen = 1;
164 1.1 christos aiov.iov_base = SCARG(uap, buf);
165 1.1 christos aiov.iov_len = SCARG(uap, len);
166 1.1 christos msg.msg_control = 0;
167 1.1 christos msg.msg_flags = SCARG(uap, flags);
168 1.1 christos return (recvit(p, SCARG(uap, s), &msg, (caddr_t)0, retval));
169 1.1 christos }
170 1.1 christos
171 1.1 christos
172 1.1 christos int
173 1.1 christos compat_43_recvfrom(p, uap, retval)
174 1.1 christos struct proc *p;
175 1.1 christos struct recvfrom_args /* {
176 1.1 christos syscallarg(int) s;
177 1.1 christos syscallarg(caddr_t) buf;
178 1.1 christos syscallarg(size_t) len;
179 1.1 christos syscallarg(int) flags;
180 1.1 christos syscallarg(caddr_t) from;
181 1.1 christos syscallarg(int *) fromlenaddr;
182 1.1 christos } */ *uap;
183 1.1 christos register_t *retval;
184 1.1 christos {
185 1.1 christos
186 1.1 christos SCARG(uap, flags) |= MSG_COMPAT;
187 1.1 christos return (recvfrom(p, uap, retval));
188 1.1 christos }
189 1.1 christos
190 1.1 christos
191 1.1 christos /*
192 1.1 christos * Old recvmsg. This code takes advantage of the fact that the old msghdr
193 1.1 christos * overlays the new one, missing only the flags, and with the (old) access
194 1.1 christos * rights where the control fields are now.
195 1.1 christos */
196 1.1 christos int
197 1.1 christos compat_43_recvmsg(p, uap, retval)
198 1.1 christos struct proc *p;
199 1.1 christos register struct compat_43_recvmsg_args /* {
200 1.1 christos syscallarg(int) s;
201 1.1 christos syscallarg(struct omsghdr *) msg;
202 1.1 christos syscallarg(int) flags;
203 1.1 christos } */ *uap;
204 1.1 christos register_t *retval;
205 1.1 christos {
206 1.1 christos struct msghdr msg;
207 1.1 christos struct iovec aiov[UIO_SMALLIOV], *iov;
208 1.1 christos int error;
209 1.1 christos
210 1.1 christos if (error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&msg,
211 1.1 christos sizeof (struct omsghdr)))
212 1.1 christos return (error);
213 1.1 christos if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
214 1.1 christos if ((u_int)msg.msg_iovlen >= UIO_MAXIOV)
215 1.1 christos return (EMSGSIZE);
216 1.1 christos MALLOC(iov, struct iovec *,
217 1.1 christos sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
218 1.1 christos M_WAITOK);
219 1.1 christos } else
220 1.1 christos iov = aiov;
221 1.1 christos msg.msg_flags = SCARG(uap, flags) | MSG_COMPAT;
222 1.1 christos if (error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
223 1.1 christos (unsigned)(msg.msg_iovlen * sizeof (struct iovec))))
224 1.1 christos goto done;
225 1.1 christos msg.msg_iov = iov;
226 1.1 christos error = recvit(p, SCARG(uap, s), &msg,
227 1.1 christos (caddr_t)&SCARG(uap, msg)->msg_namelen, retval);
228 1.1 christos
229 1.1 christos if (msg.msg_controllen && error == 0)
230 1.1 christos error = copyout((caddr_t)&msg.msg_controllen,
231 1.1 christos (caddr_t)&SCARG(uap, msg)->msg_accrightslen, sizeof (int));
232 1.1 christos done:
233 1.1 christos if (iov != aiov)
234 1.1 christos FREE(iov, M_IOV);
235 1.1 christos return (error);
236 1.1 christos }
237 1.1 christos
238 1.1 christos int
239 1.1 christos compat_43_send(p, uap, retval)
240 1.1 christos struct proc *p;
241 1.1 christos register struct compat_43_send_args /* {
242 1.1 christos syscallarg(int) s;
243 1.1 christos syscallarg(caddr_t) buf;
244 1.1 christos syscallarg(int) len;
245 1.1 christos syscallarg(int) flags;
246 1.1 christos } */ *uap;
247 1.1 christos register_t *retval;
248 1.1 christos {
249 1.1 christos struct msghdr msg;
250 1.1 christos struct iovec aiov;
251 1.1 christos
252 1.1 christos msg.msg_name = 0;
253 1.1 christos msg.msg_namelen = 0;
254 1.1 christos msg.msg_iov = &aiov;
255 1.1 christos msg.msg_iovlen = 1;
256 1.1 christos aiov.iov_base = SCARG(uap, buf);
257 1.1 christos aiov.iov_len = SCARG(uap, len);
258 1.1 christos msg.msg_control = 0;
259 1.1 christos msg.msg_flags = 0;
260 1.1 christos return (sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval));
261 1.1 christos }
262 1.1 christos
263 1.1 christos int
264 1.1 christos compat_43_sendmsg(p, uap, retval)
265 1.1 christos struct proc *p;
266 1.1 christos register struct compat_43_sendmsg_args /* {
267 1.1 christos syscallarg(int) s;
268 1.1 christos syscallarg(caddr_t) msg;
269 1.1 christos syscallarg(int) flags;
270 1.1 christos } */ *uap;
271 1.1 christos register_t *retval;
272 1.1 christos {
273 1.1 christos struct msghdr msg;
274 1.1 christos struct iovec aiov[UIO_SMALLIOV], *iov;
275 1.1 christos int error;
276 1.1 christos
277 1.1 christos if (error = copyin(SCARG(uap, msg), (caddr_t)&msg,
278 1.1 christos sizeof (struct omsghdr)))
279 1.1 christos return (error);
280 1.1 christos if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
281 1.1 christos if ((u_int)msg.msg_iovlen >= UIO_MAXIOV)
282 1.1 christos return (EMSGSIZE);
283 1.1 christos MALLOC(iov, struct iovec *,
284 1.1 christos sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
285 1.1 christos M_WAITOK);
286 1.1 christos } else
287 1.1 christos iov = aiov;
288 1.1 christos if (error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
289 1.1 christos (unsigned)(msg.msg_iovlen * sizeof (struct iovec))))
290 1.1 christos goto done;
291 1.1 christos msg.msg_flags = MSG_COMPAT;
292 1.1 christos msg.msg_iov = iov;
293 1.1 christos error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
294 1.1 christos done:
295 1.1 christos if (iov != aiov)
296 1.1 christos FREE(iov, M_IOV);
297 1.1 christos return (error);
298 1.1 christos }
299