uipc_syscalls_43.c revision 1.5 1 1.5 christos /* $NetBSD: uipc_syscalls_43.c,v 1.5 1996/03/14 19:31:50 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 int
58 1.3 mycroft compat_43_sys_accept(p, v, retval)
59 1.1 christos struct proc *p;
60 1.2 thorpej void *v;
61 1.2 thorpej register_t *retval;
62 1.2 thorpej {
63 1.3 mycroft struct sys_accept_args /* {
64 1.1 christos syscallarg(int) s;
65 1.1 christos syscallarg(caddr_t) name;
66 1.1 christos syscallarg(int *) anamelen;
67 1.2 thorpej } */ *uap = v;
68 1.1 christos int error;
69 1.1 christos
70 1.3 mycroft if ((error = sys_accept(p, uap, retval)) != 0)
71 1.1 christos return error;
72 1.1 christos
73 1.1 christos if (SCARG(uap, name)) {
74 1.1 christos struct sockaddr sa;
75 1.1 christos
76 1.1 christos if ((error = copyin(SCARG(uap, name), &sa, sizeof(sa))) != 0)
77 1.1 christos return error;
78 1.1 christos
79 1.1 christos ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
80 1.1 christos
81 1.1 christos if ((error = copyout(&sa, SCARG(uap, name), sizeof(sa))) != 0)
82 1.1 christos return error;
83 1.1 christos }
84 1.1 christos return 0;
85 1.1 christos }
86 1.1 christos
87 1.1 christos
88 1.1 christos int
89 1.3 mycroft compat_43_sys_getpeername(p, v, retval)
90 1.1 christos struct proc *p;
91 1.2 thorpej void *v;
92 1.2 thorpej register_t *retval;
93 1.2 thorpej {
94 1.3 mycroft struct sys_getpeername_args /* {
95 1.1 christos syscallarg(int) fdes;
96 1.1 christos syscallarg(caddr_t) asa;
97 1.1 christos syscallarg(int *) alen;
98 1.2 thorpej } */ *uap = v;
99 1.1 christos struct sockaddr sa;
100 1.1 christos
101 1.1 christos int error;
102 1.1 christos
103 1.3 mycroft if ((error = sys_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.3 mycroft compat_43_sys_getsockname(p, v, retval)
120 1.1 christos struct proc *p;
121 1.2 thorpej void *v;
122 1.2 thorpej register_t *retval;
123 1.2 thorpej {
124 1.3 mycroft struct sys_getsockname_args /* {
125 1.1 christos syscallarg(int) fdes;
126 1.1 christos syscallarg(caddr_t) asa;
127 1.1 christos syscallarg(int *) alen;
128 1.2 thorpej } */ *uap = v;
129 1.1 christos struct sockaddr sa;
130 1.1 christos int error;
131 1.1 christos
132 1.3 mycroft if ((error = sys_getsockname(p, uap, retval)) != 0)
133 1.1 christos return error;
134 1.1 christos
135 1.1 christos if ((error = copyin(SCARG(uap, asa), &sa, sizeof(sa))) != 0)
136 1.1 christos return error;
137 1.1 christos
138 1.1 christos ((struct osockaddr*) &sa)->sa_family = sa.sa_family;
139 1.1 christos
140 1.1 christos if ((error = copyout(&sa, SCARG(uap, asa), sizeof(sa))) != 0)
141 1.1 christos return error;
142 1.1 christos
143 1.1 christos return 0;
144 1.1 christos }
145 1.1 christos
146 1.1 christos
147 1.1 christos int
148 1.3 mycroft compat_43_sys_recv(p, v, retval)
149 1.1 christos struct proc *p;
150 1.2 thorpej void *v;
151 1.2 thorpej register_t *retval;
152 1.2 thorpej {
153 1.3 mycroft register struct compat_43_sys_recv_args /* {
154 1.1 christos syscallarg(int) s;
155 1.1 christos syscallarg(caddr_t) buf;
156 1.1 christos syscallarg(int) len;
157 1.1 christos syscallarg(int) flags;
158 1.2 thorpej } */ *uap = v;
159 1.1 christos struct msghdr msg;
160 1.1 christos struct iovec aiov;
161 1.1 christos
162 1.1 christos msg.msg_name = 0;
163 1.1 christos msg.msg_namelen = 0;
164 1.1 christos msg.msg_iov = &aiov;
165 1.1 christos msg.msg_iovlen = 1;
166 1.1 christos aiov.iov_base = SCARG(uap, buf);
167 1.1 christos aiov.iov_len = SCARG(uap, len);
168 1.1 christos msg.msg_control = 0;
169 1.1 christos msg.msg_flags = SCARG(uap, flags);
170 1.1 christos return (recvit(p, SCARG(uap, s), &msg, (caddr_t)0, retval));
171 1.1 christos }
172 1.1 christos
173 1.1 christos
174 1.4 christos #ifdef MSG_COMPAT
175 1.1 christos int
176 1.3 mycroft compat_43_sys_recvfrom(p, v, retval)
177 1.1 christos struct proc *p;
178 1.2 thorpej void *v;
179 1.2 thorpej register_t *retval;
180 1.2 thorpej {
181 1.3 mycroft struct sys_recvfrom_args /* {
182 1.1 christos syscallarg(int) s;
183 1.1 christos syscallarg(caddr_t) buf;
184 1.1 christos syscallarg(size_t) len;
185 1.1 christos syscallarg(int) flags;
186 1.1 christos syscallarg(caddr_t) from;
187 1.1 christos syscallarg(int *) fromlenaddr;
188 1.2 thorpej } */ *uap = v;
189 1.1 christos
190 1.1 christos SCARG(uap, flags) |= MSG_COMPAT;
191 1.3 mycroft return (sys_recvfrom(p, uap, retval));
192 1.1 christos }
193 1.4 christos #endif
194 1.1 christos
195 1.1 christos
196 1.4 christos #ifdef MSG_COMPAT
197 1.1 christos /*
198 1.1 christos * Old recvmsg. This code takes advantage of the fact that the old msghdr
199 1.1 christos * overlays the new one, missing only the flags, and with the (old) access
200 1.1 christos * rights where the control fields are now.
201 1.1 christos */
202 1.1 christos int
203 1.3 mycroft compat_43_sys_recvmsg(p, v, retval)
204 1.1 christos struct proc *p;
205 1.2 thorpej void *v;
206 1.2 thorpej register_t *retval;
207 1.2 thorpej {
208 1.3 mycroft register struct compat_43_sys_recvmsg_args /* {
209 1.1 christos syscallarg(int) s;
210 1.1 christos syscallarg(struct omsghdr *) msg;
211 1.1 christos syscallarg(int) flags;
212 1.2 thorpej } */ *uap = v;
213 1.1 christos struct msghdr msg;
214 1.1 christos struct iovec aiov[UIO_SMALLIOV], *iov;
215 1.1 christos int error;
216 1.1 christos
217 1.5 christos error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&msg,
218 1.5 christos sizeof (struct omsghdr));
219 1.5 christos if (error)
220 1.1 christos return (error);
221 1.1 christos if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
222 1.1 christos if ((u_int)msg.msg_iovlen >= UIO_MAXIOV)
223 1.1 christos return (EMSGSIZE);
224 1.1 christos MALLOC(iov, struct iovec *,
225 1.1 christos sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
226 1.1 christos M_WAITOK);
227 1.1 christos } else
228 1.1 christos iov = aiov;
229 1.1 christos msg.msg_flags = SCARG(uap, flags) | MSG_COMPAT;
230 1.5 christos error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
231 1.5 christos (unsigned)(msg.msg_iovlen * sizeof (struct iovec)));
232 1.5 christos if (error)
233 1.1 christos goto done;
234 1.1 christos msg.msg_iov = iov;
235 1.1 christos error = recvit(p, SCARG(uap, s), &msg,
236 1.1 christos (caddr_t)&SCARG(uap, msg)->msg_namelen, retval);
237 1.1 christos
238 1.1 christos if (msg.msg_controllen && error == 0)
239 1.1 christos error = copyout((caddr_t)&msg.msg_controllen,
240 1.1 christos (caddr_t)&SCARG(uap, msg)->msg_accrightslen, sizeof (int));
241 1.1 christos done:
242 1.1 christos if (iov != aiov)
243 1.1 christos FREE(iov, M_IOV);
244 1.1 christos return (error);
245 1.1 christos }
246 1.4 christos #endif
247 1.1 christos
248 1.1 christos int
249 1.3 mycroft compat_43_sys_send(p, v, retval)
250 1.1 christos struct proc *p;
251 1.2 thorpej void *v;
252 1.2 thorpej register_t *retval;
253 1.2 thorpej {
254 1.3 mycroft register struct compat_43_sys_send_args /* {
255 1.1 christos syscallarg(int) s;
256 1.1 christos syscallarg(caddr_t) buf;
257 1.1 christos syscallarg(int) len;
258 1.1 christos syscallarg(int) flags;
259 1.2 thorpej } */ *uap = v;
260 1.1 christos struct msghdr msg;
261 1.1 christos struct iovec aiov;
262 1.1 christos
263 1.1 christos msg.msg_name = 0;
264 1.1 christos msg.msg_namelen = 0;
265 1.1 christos msg.msg_iov = &aiov;
266 1.1 christos msg.msg_iovlen = 1;
267 1.1 christos aiov.iov_base = SCARG(uap, buf);
268 1.1 christos aiov.iov_len = SCARG(uap, len);
269 1.1 christos msg.msg_control = 0;
270 1.1 christos msg.msg_flags = 0;
271 1.1 christos return (sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval));
272 1.1 christos }
273 1.1 christos
274 1.4 christos #ifdef MSG_COMPAT
275 1.1 christos int
276 1.3 mycroft compat_43_sys_sendmsg(p, v, retval)
277 1.1 christos struct proc *p;
278 1.2 thorpej void *v;
279 1.2 thorpej register_t *retval;
280 1.2 thorpej {
281 1.3 mycroft register struct compat_43_sys_sendmsg_args /* {
282 1.1 christos syscallarg(int) s;
283 1.1 christos syscallarg(caddr_t) msg;
284 1.1 christos syscallarg(int) flags;
285 1.2 thorpej } */ *uap = v;
286 1.1 christos struct msghdr msg;
287 1.1 christos struct iovec aiov[UIO_SMALLIOV], *iov;
288 1.1 christos int error;
289 1.1 christos
290 1.5 christos error = copyin(SCARG(uap, msg), (caddr_t)&msg,
291 1.5 christos sizeof (struct omsghdr));
292 1.5 christos if (error)
293 1.1 christos return (error);
294 1.1 christos if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) {
295 1.1 christos if ((u_int)msg.msg_iovlen >= UIO_MAXIOV)
296 1.1 christos return (EMSGSIZE);
297 1.1 christos MALLOC(iov, struct iovec *,
298 1.1 christos sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV,
299 1.1 christos M_WAITOK);
300 1.1 christos } else
301 1.1 christos iov = aiov;
302 1.5 christos error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov,
303 1.5 christos (unsigned)(msg.msg_iovlen * sizeof (struct iovec)));
304 1.5 christos if (error)
305 1.1 christos goto done;
306 1.1 christos msg.msg_flags = MSG_COMPAT;
307 1.1 christos msg.msg_iov = iov;
308 1.1 christos error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
309 1.1 christos done:
310 1.1 christos if (iov != aiov)
311 1.1 christos FREE(iov, M_IOV);
312 1.1 christos return (error);
313 1.1 christos }
314 1.4 christos #endif
315