uipc_syscalls.c (1817) | uipc_syscalls.c (3308) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94 | 1/* 2 * Copyright (c) 1982, 1986, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94 |
34 * $Id$ | 34 * $Id: uipc_syscalls.c,v 1.3 1994/08/02 07:43:10 davidg Exp $ |
35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/filedesc.h> 40#include <sys/proc.h> 41#include <sys/file.h> 42#include <sys/buf.h> 43#include <sys/malloc.h> 44#include <sys/mbuf.h> 45#include <sys/protosw.h> | 35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/filedesc.h> 40#include <sys/proc.h> 41#include <sys/file.h> 42#include <sys/buf.h> 43#include <sys/malloc.h> 44#include <sys/mbuf.h> 45#include <sys/protosw.h> |
46#include <sys/stat.h> |
|
46#include <sys/socket.h> 47#include <sys/socketvar.h> | 47#include <sys/socket.h> 48#include <sys/socketvar.h> |
49#include <sys/signalvar.h> |
|
48#ifdef KTRACE 49#include <sys/ktrace.h> 50#endif 51 52/* 53 * System call interface to the socket abstraction. 54 */ 55#if defined(COMPAT_43) || defined(COMPAT_SUNOS) --- 13 unchanged lines hidden (view full) --- 69 register struct socket_args *uap; 70 int *retval; 71{ 72 struct filedesc *fdp = p->p_fd; 73 struct socket *so; 74 struct file *fp; 75 int fd, error; 76 | 50#ifdef KTRACE 51#include <sys/ktrace.h> 52#endif 53 54/* 55 * System call interface to the socket abstraction. 56 */ 57#if defined(COMPAT_43) || defined(COMPAT_SUNOS) --- 13 unchanged lines hidden (view full) --- 71 register struct socket_args *uap; 72 int *retval; 73{ 74 struct filedesc *fdp = p->p_fd; 75 struct socket *so; 76 struct file *fp; 77 int fd, error; 78 |
77 if (error = falloc(p, &fp, &fd)) | 79 error = falloc(p, &fp, &fd); 80 if (error) |
78 return (error); 79 fp->f_flag = FREAD|FWRITE; 80 fp->f_type = DTYPE_SOCKET; 81 fp->f_ops = &socketops; | 81 return (error); 82 fp->f_flag = FREAD|FWRITE; 83 fp->f_type = DTYPE_SOCKET; 84 fp->f_ops = &socketops; |
82 if (error = socreate(uap->domain, &so, uap->type, uap->protocol)) { | 85 error = socreate(uap->domain, &so, uap->type, uap->protocol); 86 if (error) { |
83 fdp->fd_ofiles[fd] = 0; 84 ffree(fp); 85 } else { 86 fp->f_data = (caddr_t)so; 87 *retval = fd; 88 } 89 return (error); 90} --- 9 unchanged lines hidden (view full) --- 100 struct proc *p; 101 register struct bind_args *uap; 102 int *retval; 103{ 104 struct file *fp; 105 struct mbuf *nam; 106 int error; 107 | 87 fdp->fd_ofiles[fd] = 0; 88 ffree(fp); 89 } else { 90 fp->f_data = (caddr_t)so; 91 *retval = fd; 92 } 93 return (error); 94} --- 9 unchanged lines hidden (view full) --- 104 struct proc *p; 105 register struct bind_args *uap; 106 int *retval; 107{ 108 struct file *fp; 109 struct mbuf *nam; 110 int error; 111 |
108 if (error = getsock(p->p_fd, uap->s, &fp)) | 112 error = getsock(p->p_fd, uap->s, &fp); 113 if (error) |
109 return (error); | 114 return (error); |
110 if (error = sockargs(&nam, uap->name, uap->namelen, MT_SONAME)) | 115 error = sockargs(&nam, uap->name, uap->namelen, MT_SONAME); 116 if (error) |
111 return (error); 112 error = sobind((struct socket *)fp->f_data, nam); 113 m_freem(nam); 114 return (error); 115} 116 117struct listen_args { 118 int s; --- 4 unchanged lines hidden (view full) --- 123listen(p, uap, retval) 124 struct proc *p; 125 register struct listen_args *uap; 126 int *retval; 127{ 128 struct file *fp; 129 int error; 130 | 117 return (error); 118 error = sobind((struct socket *)fp->f_data, nam); 119 m_freem(nam); 120 return (error); 121} 122 123struct listen_args { 124 int s; --- 4 unchanged lines hidden (view full) --- 129listen(p, uap, retval) 130 struct proc *p; 131 register struct listen_args *uap; 132 int *retval; 133{ 134 struct file *fp; 135 int error; 136 |
131 if (error = getsock(p->p_fd, uap->s, &fp)) | 137 error = getsock(p->p_fd, uap->s, &fp); 138 if (error) |
132 return (error); 133 return (solisten((struct socket *)fp->f_data, uap->backlog)); 134} 135 136struct accept_args { 137 int s; 138 caddr_t name; 139 int *anamelen; 140#ifdef COMPAT_OLDSOCK 141 int compat_43; /* pseudo */ 142#endif 143}; 144 | 139 return (error); 140 return (solisten((struct socket *)fp->f_data, uap->backlog)); 141} 142 143struct accept_args { 144 int s; 145 caddr_t name; 146 int *anamelen; 147#ifdef COMPAT_OLDSOCK 148 int compat_43; /* pseudo */ 149#endif 150}; 151 |
145#ifdef COMPAT_OLDSOCK 146int 147accept(p, uap, retval) 148 struct proc *p; 149 struct accept_args *uap; 150 int *retval; 151{ | 152#ifndef COMPAT_OLDSOCK 153# define accept1 accept 154#endif /* COMPAT_OLDSOCK*/ |
152 | 155 |
153 uap->compat_43 = 0; 154 return (accept1(p, uap, retval)); 155} 156 | |
157int | 156int |
158oaccept(p, uap, retval) 159 struct proc *p; 160 struct accept_args *uap; 161 int *retval; 162{ 163 164 uap->compat_43 = 1; 165 return (accept1(p, uap, retval)); 166} 167#else /* COMPAT_OLDSOCK */ 168 169#define accept1 accept 170#endif 171 172int | |
173accept1(p, uap, retval) 174 struct proc *p; 175 register struct accept_args *uap; 176 int *retval; 177{ 178 struct file *fp; 179 struct mbuf *nam; 180 int namelen, error, s; 181 register struct socket *so; 182 | 157accept1(p, uap, retval) 158 struct proc *p; 159 register struct accept_args *uap; 160 int *retval; 161{ 162 struct file *fp; 163 struct mbuf *nam; 164 int namelen, error, s; 165 register struct socket *so; 166 |
183 if (uap->name && (error = copyin((caddr_t)uap->anamelen, 184 (caddr_t)&namelen, sizeof (namelen)))) | 167 if (uap->name) { 168 error = copyin((caddr_t)uap->anamelen, (caddr_t)&namelen, 169 sizeof (namelen)); 170 if(error) 171 return (error); 172 } 173 error = getsock(p->p_fd, uap->s, &fp); 174 if (error) |
185 return (error); | 175 return (error); |
186 if (error = getsock(p->p_fd, uap->s, &fp)) 187 return (error); | |
188 s = splnet(); 189 so = (struct socket *)fp->f_data; 190 if ((so->so_options & SO_ACCEPTCONN) == 0) { 191 splx(s); 192 return (EINVAL); 193 } 194 if ((so->so_state & SS_NBIO) && so->so_qlen == 0) { 195 splx(s); 196 return (EWOULDBLOCK); 197 } 198 while (so->so_qlen == 0 && so->so_error == 0) { 199 if (so->so_state & SS_CANTRCVMORE) { 200 so->so_error = ECONNABORTED; 201 break; 202 } | 176 s = splnet(); 177 so = (struct socket *)fp->f_data; 178 if ((so->so_options & SO_ACCEPTCONN) == 0) { 179 splx(s); 180 return (EINVAL); 181 } 182 if ((so->so_state & SS_NBIO) && so->so_qlen == 0) { 183 splx(s); 184 return (EWOULDBLOCK); 185 } 186 while (so->so_qlen == 0 && so->so_error == 0) { 187 if (so->so_state & SS_CANTRCVMORE) { 188 so->so_error = ECONNABORTED; 189 break; 190 } |
203 if (error = tsleep((caddr_t)&so->so_timeo, PSOCK | PCATCH, 204 netcon, 0)) { | 191 error = tsleep((caddr_t)&so->so_timeo, PSOCK | PCATCH, 192 netcon, 0); 193 if (error) { |
205 splx(s); 206 return (error); 207 } 208 } 209 if (so->so_error) { 210 error = so->so_error; 211 so->so_error = 0; 212 splx(s); 213 return (error); 214 } | 194 splx(s); 195 return (error); 196 } 197 } 198 if (so->so_error) { 199 error = so->so_error; 200 so->so_error = 0; 201 splx(s); 202 return (error); 203 } |
215 if (error = falloc(p, &fp, retval)) { | 204 error = falloc(p, &fp, retval); 205 if (error) { |
216 splx(s); 217 return (error); 218 } 219 { struct socket *aso = so->so_q; 220 if (soqremque(aso, 1) == 0) 221 panic("accept"); 222 so = aso; 223 } --- 7 unchanged lines hidden (view full) --- 231#ifdef COMPAT_OLDSOCK 232 if (uap->compat_43) 233 mtod(nam, struct osockaddr *)->sa_family = 234 mtod(nam, struct sockaddr *)->sa_family; 235#endif 236 if (namelen > nam->m_len) 237 namelen = nam->m_len; 238 /* SHOULD COPY OUT A CHAIN HERE */ | 206 splx(s); 207 return (error); 208 } 209 { struct socket *aso = so->so_q; 210 if (soqremque(aso, 1) == 0) 211 panic("accept"); 212 so = aso; 213 } --- 7 unchanged lines hidden (view full) --- 221#ifdef COMPAT_OLDSOCK 222 if (uap->compat_43) 223 mtod(nam, struct osockaddr *)->sa_family = 224 mtod(nam, struct sockaddr *)->sa_family; 225#endif 226 if (namelen > nam->m_len) 227 namelen = nam->m_len; 228 /* SHOULD COPY OUT A CHAIN HERE */ |
239 if ((error = copyout(mtod(nam, caddr_t), (caddr_t)uap->name, 240 (u_int)namelen)) == 0) | 229 error = copyout(mtod(nam, caddr_t), (caddr_t)uap->name, 230 (u_int)namelen); 231 if (!error) |
241 error = copyout((caddr_t)&namelen, 242 (caddr_t)uap->anamelen, sizeof (*uap->anamelen)); 243 } 244 m_freem(nam); 245 splx(s); 246 return (error); 247} 248 | 232 error = copyout((caddr_t)&namelen, 233 (caddr_t)uap->anamelen, sizeof (*uap->anamelen)); 234 } 235 m_freem(nam); 236 splx(s); 237 return (error); 238} 239 |
240#ifdef COMPAT_OLDSOCK 241int 242accept(p, uap, retval) 243 struct proc *p; 244 struct accept_args *uap; 245 int *retval; 246{ 247 248 uap->compat_43 = 0; 249 return (accept1(p, uap, retval)); 250} 251 252int 253oaccept(p, uap, retval) 254 struct proc *p; 255 struct accept_args *uap; 256 int *retval; 257{ 258 259 uap->compat_43 = 1; 260 return (accept1(p, uap, retval)); 261} 262#endif /* COMPAT_OLDSOCK */ 263 |
|
249struct connect_args { 250 int s; 251 caddr_t name; 252 int namelen; 253}; 254/* ARGSUSED */ 255int 256connect(p, uap, retval) 257 struct proc *p; 258 register struct connect_args *uap; 259 int *retval; 260{ 261 struct file *fp; 262 register struct socket *so; 263 struct mbuf *nam; 264 int error, s; 265 | 264struct connect_args { 265 int s; 266 caddr_t name; 267 int namelen; 268}; 269/* ARGSUSED */ 270int 271connect(p, uap, retval) 272 struct proc *p; 273 register struct connect_args *uap; 274 int *retval; 275{ 276 struct file *fp; 277 register struct socket *so; 278 struct mbuf *nam; 279 int error, s; 280 |
266 if (error = getsock(p->p_fd, uap->s, &fp)) | 281 error = getsock(p->p_fd, uap->s, &fp); 282 if (error) |
267 return (error); 268 so = (struct socket *)fp->f_data; 269 if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) 270 return (EALREADY); | 283 return (error); 284 so = (struct socket *)fp->f_data; 285 if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) 286 return (EALREADY); |
271 if (error = sockargs(&nam, uap->name, uap->namelen, MT_SONAME)) | 287 error = sockargs(&nam, uap->name, uap->namelen, MT_SONAME); 288 if (error) |
272 return (error); 273 error = soconnect(so, nam); 274 if (error) 275 goto bad; 276 if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) { 277 m_freem(nam); 278 return (EINPROGRESS); 279 } 280 s = splnet(); | 289 return (error); 290 error = soconnect(so, nam); 291 if (error) 292 goto bad; 293 if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) { 294 m_freem(nam); 295 return (EINPROGRESS); 296 } 297 s = splnet(); |
281 while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) 282 if (error = tsleep((caddr_t)&so->so_timeo, PSOCK | PCATCH, 283 netcon, 0)) | 298 while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) { 299 error = tsleep((caddr_t)&so->so_timeo, PSOCK | PCATCH, 300 netcon, 0); 301 if (error) |
284 break; | 302 break; |
303 } |
|
285 if (error == 0) { 286 error = so->so_error; 287 so->so_error = 0; 288 } 289 splx(s); 290bad: 291 so->so_state &= ~SS_ISCONNECTING; 292 m_freem(nam); --- 14 unchanged lines hidden (view full) --- 307 register struct socketpair_args *uap; 308 int retval[]; 309{ 310 register struct filedesc *fdp = p->p_fd; 311 struct file *fp1, *fp2; 312 struct socket *so1, *so2; 313 int fd, error, sv[2]; 314 | 304 if (error == 0) { 305 error = so->so_error; 306 so->so_error = 0; 307 } 308 splx(s); 309bad: 310 so->so_state &= ~SS_ISCONNECTING; 311 m_freem(nam); --- 14 unchanged lines hidden (view full) --- 326 register struct socketpair_args *uap; 327 int retval[]; 328{ 329 register struct filedesc *fdp = p->p_fd; 330 struct file *fp1, *fp2; 331 struct socket *so1, *so2; 332 int fd, error, sv[2]; 333 |
315 if (error = socreate(uap->domain, &so1, uap->type, uap->protocol)) | 334 error = socreate(uap->domain, &so1, uap->type, uap->protocol); 335 if (error) |
316 return (error); | 336 return (error); |
317 if (error = socreate(uap->domain, &so2, uap->type, uap->protocol)) | 337 error = socreate(uap->domain, &so2, uap->type, uap->protocol); 338 if (error) |
318 goto free1; | 339 goto free1; |
319 if (error = falloc(p, &fp1, &fd)) | 340 error = falloc(p, &fp1, &fd); 341 if (error) |
320 goto free2; 321 sv[0] = fd; 322 fp1->f_flag = FREAD|FWRITE; 323 fp1->f_type = DTYPE_SOCKET; 324 fp1->f_ops = &socketops; 325 fp1->f_data = (caddr_t)so1; | 342 goto free2; 343 sv[0] = fd; 344 fp1->f_flag = FREAD|FWRITE; 345 fp1->f_type = DTYPE_SOCKET; 346 fp1->f_ops = &socketops; 347 fp1->f_data = (caddr_t)so1; |
326 if (error = falloc(p, &fp2, &fd)) | 348 error = falloc(p, &fp2, &fd); 349 if (error) |
327 goto free3; 328 fp2->f_flag = FREAD|FWRITE; 329 fp2->f_type = DTYPE_SOCKET; 330 fp2->f_ops = &socketops; 331 fp2->f_data = (caddr_t)so2; 332 sv[1] = fd; | 350 goto free3; 351 fp2->f_flag = FREAD|FWRITE; 352 fp2->f_type = DTYPE_SOCKET; 353 fp2->f_ops = &socketops; 354 fp2->f_data = (caddr_t)so2; 355 sv[1] = fd; |
333 if (error = soconnect2(so1, so2)) | 356 error = soconnect2(so1, so2); 357 if (error) |
334 goto free4; 335 if (uap->type == SOCK_DGRAM) { 336 /* 337 * Datagram socket connection is asymmetric. 338 */ | 358 goto free4; 359 if (uap->type == SOCK_DGRAM) { 360 /* 361 * Datagram socket connection is asymmetric. 362 */ |
339 if (error = soconnect2(so2, so1)) | 363 error = soconnect2(so2, so1); 364 if (error) |
340 goto free4; 341 } 342 error = copyout((caddr_t)sv, (caddr_t)uap->rsv, 2 * sizeof (int)); 343 retval[0] = sv[0]; /* XXX ??? */ 344 retval[1] = sv[1]; /* XXX ??? */ 345 return (error); 346free4: 347 ffree(fp2); 348 fdp->fd_ofiles[sv[1]] = 0; 349free3: 350 ffree(fp1); 351 fdp->fd_ofiles[sv[0]] = 0; 352free2: 353 (void)soclose(so2); 354free1: 355 (void)soclose(so1); 356 return (error); 357} 358 | 365 goto free4; 366 } 367 error = copyout((caddr_t)sv, (caddr_t)uap->rsv, 2 * sizeof (int)); 368 retval[0] = sv[0]; /* XXX ??? */ 369 retval[1] = sv[1]; /* XXX ??? */ 370 return (error); 371free4: 372 ffree(fp2); 373 fdp->fd_ofiles[sv[1]] = 0; 374free3: 375 ffree(fp1); 376 fdp->fd_ofiles[sv[0]] = 0; 377free2: 378 (void)soclose(so2); 379free1: 380 (void)soclose(so1); 381 return (error); 382} 383 |
384int 385sendit(p, s, mp, flags, retsize) 386 register struct proc *p; 387 int s; 388 register struct msghdr *mp; 389 int flags, *retsize; 390{ 391 struct file *fp; 392 struct uio auio; 393 register struct iovec *iov; 394 register int i; 395 struct mbuf *to, *control; 396 int len, error; 397#ifdef KTRACE 398 struct iovec *ktriov = NULL; 399#endif 400 401 error = getsock(p->p_fd, s, &fp); 402 if (error) 403 return (error); 404 auio.uio_iov = mp->msg_iov; 405 auio.uio_iovcnt = mp->msg_iovlen; 406 auio.uio_segflg = UIO_USERSPACE; 407 auio.uio_rw = UIO_WRITE; 408 auio.uio_procp = p; 409 auio.uio_offset = 0; /* XXX */ 410 auio.uio_resid = 0; 411 iov = mp->msg_iov; 412 for (i = 0; i < mp->msg_iovlen; i++, iov++) { 413 if ((auio.uio_resid += iov->iov_len) < 0) 414 return (EINVAL); 415 } 416 if (mp->msg_name) { 417 error = sockargs(&to, mp->msg_name, mp->msg_namelen, MT_SONAME); 418 if (error) 419 return (error); 420 } else 421 to = 0; 422 if (mp->msg_control) { 423 if (mp->msg_controllen < sizeof(struct cmsghdr) 424#ifdef COMPAT_OLDSOCK 425 && mp->msg_flags != MSG_COMPAT 426#endif 427 ) { 428 error = EINVAL; 429 goto bad; 430 } 431 error = sockargs(&control, mp->msg_control, 432 mp->msg_controllen, MT_CONTROL); 433 if (error) 434 goto bad; 435#ifdef COMPAT_OLDSOCK 436 if (mp->msg_flags == MSG_COMPAT) { 437 register struct cmsghdr *cm; 438 439 M_PREPEND(control, sizeof(*cm), M_WAIT); 440 if (control == 0) { 441 error = ENOBUFS; 442 goto bad; 443 } else { 444 cm = mtod(control, struct cmsghdr *); 445 cm->cmsg_len = control->m_len; 446 cm->cmsg_level = SOL_SOCKET; 447 cm->cmsg_type = SCM_RIGHTS; 448 } 449 } 450#endif 451 } else 452 control = 0; 453#ifdef KTRACE 454 if (KTRPOINT(p, KTR_GENIO)) { 455 int iovlen = auio.uio_iovcnt * sizeof (struct iovec); 456 457 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK); 458 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen); 459 } 460#endif 461 len = auio.uio_resid; 462 error = sosend((struct socket *)fp->f_data, to, &auio, 463 (struct mbuf *)0, control, flags); 464 if (error) { 465 if (auio.uio_resid != len && (error == ERESTART || 466 error == EINTR || error == EWOULDBLOCK)) 467 error = 0; 468 if (error == EPIPE) 469 psignal(p, SIGPIPE); 470 } 471 if (error == 0) 472 *retsize = len - auio.uio_resid; 473#ifdef KTRACE 474 if (ktriov != NULL) { 475 if (error == 0) 476 ktrgenio(p->p_tracep, s, UIO_WRITE, 477 ktriov, *retsize, error); 478 FREE(ktriov, M_TEMP); 479 } 480#endif 481bad: 482 if (to) 483 m_freem(to); 484 return (error); 485} 486 |
|
359struct sendto_args { 360 int s; 361 caddr_t buf; 362 size_t len; 363 int flags; 364 caddr_t to; 365 int tolen; 366}; --- 41 unchanged lines hidden (view full) --- 408 msg.msg_iovlen = 1; 409 aiov.iov_base = uap->buf; 410 aiov.iov_len = uap->len; 411 msg.msg_control = 0; 412 msg.msg_flags = 0; 413 return (sendit(p, uap->s, &msg, uap->flags, retval)); 414} 415 | 487struct sendto_args { 488 int s; 489 caddr_t buf; 490 size_t len; 491 int flags; 492 caddr_t to; 493 int tolen; 494}; --- 41 unchanged lines hidden (view full) --- 536 msg.msg_iovlen = 1; 537 aiov.iov_base = uap->buf; 538 aiov.iov_len = uap->len; 539 msg.msg_control = 0; 540 msg.msg_flags = 0; 541 return (sendit(p, uap->s, &msg, uap->flags, retval)); 542} 543 |
416#define MSG_COMPAT 0x8000 | |
417struct osendmsg_args { 418 int s; 419 caddr_t msg; 420 int flags; 421}; 422int 423osendmsg(p, uap, retval) 424 struct proc *p; 425 register struct osendmsg_args *uap; 426 int *retval; 427{ 428 struct msghdr msg; 429 struct iovec aiov[UIO_SMALLIOV], *iov; 430 int error; 431 | 544struct osendmsg_args { 545 int s; 546 caddr_t msg; 547 int flags; 548}; 549int 550osendmsg(p, uap, retval) 551 struct proc *p; 552 register struct osendmsg_args *uap; 553 int *retval; 554{ 555 struct msghdr msg; 556 struct iovec aiov[UIO_SMALLIOV], *iov; 557 int error; 558 |
432 if (error = copyin(uap->msg, (caddr_t)&msg, sizeof (struct omsghdr))) | 559 error = copyin(uap->msg, (caddr_t)&msg, sizeof (struct omsghdr)); 560 if (error) |
433 return (error); 434 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) { 435 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) 436 return (EMSGSIZE); 437 MALLOC(iov, struct iovec *, 438 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV, 439 M_WAITOK); 440 } else 441 iov = aiov; | 561 return (error); 562 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) { 563 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) 564 return (EMSGSIZE); 565 MALLOC(iov, struct iovec *, 566 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV, 567 M_WAITOK); 568 } else 569 iov = aiov; |
442 if (error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov, 443 (unsigned)(msg.msg_iovlen * sizeof (struct iovec)))) | 570 error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov, 571 (unsigned)(msg.msg_iovlen * sizeof (struct iovec))); 572 if (error) |
444 goto done; 445 msg.msg_flags = MSG_COMPAT; 446 msg.msg_iov = iov; 447 error = sendit(p, uap->s, &msg, uap->flags, retval); 448done: 449 if (iov != aiov) 450 FREE(iov, M_IOV); 451 return (error); --- 10 unchanged lines hidden (view full) --- 462 struct proc *p; 463 register struct sendmsg_args *uap; 464 int *retval; 465{ 466 struct msghdr msg; 467 struct iovec aiov[UIO_SMALLIOV], *iov; 468 int error; 469 | 573 goto done; 574 msg.msg_flags = MSG_COMPAT; 575 msg.msg_iov = iov; 576 error = sendit(p, uap->s, &msg, uap->flags, retval); 577done: 578 if (iov != aiov) 579 FREE(iov, M_IOV); 580 return (error); --- 10 unchanged lines hidden (view full) --- 591 struct proc *p; 592 register struct sendmsg_args *uap; 593 int *retval; 594{ 595 struct msghdr msg; 596 struct iovec aiov[UIO_SMALLIOV], *iov; 597 int error; 598 |
470 if (error = copyin(uap->msg, (caddr_t)&msg, sizeof (msg))) | 599 error = copyin(uap->msg, (caddr_t)&msg, sizeof (msg)); 600 if (error) |
471 return (error); 472 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) { 473 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) 474 return (EMSGSIZE); 475 MALLOC(iov, struct iovec *, 476 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV, 477 M_WAITOK); 478 } else --- 8 unchanged lines hidden (view full) --- 487#endif 488 error = sendit(p, uap->s, &msg, uap->flags, retval); 489done: 490 if (iov != aiov) 491 FREE(iov, M_IOV); 492 return (error); 493} 494 | 601 return (error); 602 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) { 603 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) 604 return (EMSGSIZE); 605 MALLOC(iov, struct iovec *, 606 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV, 607 M_WAITOK); 608 } else --- 8 unchanged lines hidden (view full) --- 617#endif 618 error = sendit(p, uap->s, &msg, uap->flags, retval); 619done: 620 if (iov != aiov) 621 FREE(iov, M_IOV); 622 return (error); 623} 624 |
625struct recvfrom_args { 626 int s; 627 caddr_t buf; 628 size_t len; 629 int flags; 630 caddr_t from; 631 int *fromlenaddr; 632}; 633 |
|
495int | 634int |
496sendit(p, s, mp, flags, retsize) | 635recvit(p, s, mp, namelenp, retsize) |
497 register struct proc *p; 498 int s; 499 register struct msghdr *mp; | 636 register struct proc *p; 637 int s; 638 register struct msghdr *mp; |
500 int flags, *retsize; | 639 caddr_t namelenp; 640 int *retsize; |
501{ 502 struct file *fp; 503 struct uio auio; 504 register struct iovec *iov; 505 register int i; | 641{ 642 struct file *fp; 643 struct uio auio; 644 register struct iovec *iov; 645 register int i; |
506 struct mbuf *to, *control; | |
507 int len, error; | 646 int len, error; |
647 struct mbuf *from = 0, *control = 0; |
|
508#ifdef KTRACE 509 struct iovec *ktriov = NULL; 510#endif 511 | 648#ifdef KTRACE 649 struct iovec *ktriov = NULL; 650#endif 651 |
512 if (error = getsock(p->p_fd, s, &fp)) | 652 error = getsock(p->p_fd, s, &fp); 653 if (error) |
513 return (error); 514 auio.uio_iov = mp->msg_iov; 515 auio.uio_iovcnt = mp->msg_iovlen; 516 auio.uio_segflg = UIO_USERSPACE; | 654 return (error); 655 auio.uio_iov = mp->msg_iov; 656 auio.uio_iovcnt = mp->msg_iovlen; 657 auio.uio_segflg = UIO_USERSPACE; |
517 auio.uio_rw = UIO_WRITE; | 658 auio.uio_rw = UIO_READ; |
518 auio.uio_procp = p; 519 auio.uio_offset = 0; /* XXX */ 520 auio.uio_resid = 0; 521 iov = mp->msg_iov; 522 for (i = 0; i < mp->msg_iovlen; i++, iov++) { 523 if ((auio.uio_resid += iov->iov_len) < 0) 524 return (EINVAL); 525 } | 659 auio.uio_procp = p; 660 auio.uio_offset = 0; /* XXX */ 661 auio.uio_resid = 0; 662 iov = mp->msg_iov; 663 for (i = 0; i < mp->msg_iovlen; i++, iov++) { 664 if ((auio.uio_resid += iov->iov_len) < 0) 665 return (EINVAL); 666 } |
526 if (mp->msg_name) { 527 if (error = sockargs(&to, mp->msg_name, mp->msg_namelen, 528 MT_SONAME)) 529 return (error); 530 } else 531 to = 0; 532 if (mp->msg_control) { 533 if (mp->msg_controllen < sizeof(struct cmsghdr) 534#ifdef COMPAT_OLDSOCK 535 && mp->msg_flags != MSG_COMPAT 536#endif 537 ) { 538 error = EINVAL; 539 goto bad; 540 } 541 if (error = sockargs(&control, mp->msg_control, 542 mp->msg_controllen, MT_CONTROL)) 543 goto bad; 544#ifdef COMPAT_OLDSOCK 545 if (mp->msg_flags == MSG_COMPAT) { 546 register struct cmsghdr *cm; 547 548 M_PREPEND(control, sizeof(*cm), M_WAIT); 549 if (control == 0) { 550 error = ENOBUFS; 551 goto bad; 552 } else { 553 cm = mtod(control, struct cmsghdr *); 554 cm->cmsg_len = control->m_len; 555 cm->cmsg_level = SOL_SOCKET; 556 cm->cmsg_type = SCM_RIGHTS; 557 } 558 } 559#endif 560 } else 561 control = 0; | |
562#ifdef KTRACE 563 if (KTRPOINT(p, KTR_GENIO)) { 564 int iovlen = auio.uio_iovcnt * sizeof (struct iovec); 565 566 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK); 567 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen); 568 } 569#endif 570 len = auio.uio_resid; | 667#ifdef KTRACE 668 if (KTRPOINT(p, KTR_GENIO)) { 669 int iovlen = auio.uio_iovcnt * sizeof (struct iovec); 670 671 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK); 672 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen); 673 } 674#endif 675 len = auio.uio_resid; |
571 if (error = sosend((struct socket *)fp->f_data, to, &auio, 572 (struct mbuf *)0, control, flags)) { | 676 error = soreceive((struct socket *)fp->f_data, &from, &auio, 677 (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0, 678 &mp->msg_flags); 679 if (error) { |
573 if (auio.uio_resid != len && (error == ERESTART || 574 error == EINTR || error == EWOULDBLOCK)) 575 error = 0; | 680 if (auio.uio_resid != len && (error == ERESTART || 681 error == EINTR || error == EWOULDBLOCK)) 682 error = 0; |
576 if (error == EPIPE) 577 psignal(p, SIGPIPE); | |
578 } | 683 } |
579 if (error == 0) 580 *retsize = len - auio.uio_resid; | |
581#ifdef KTRACE 582 if (ktriov != NULL) { 583 if (error == 0) | 684#ifdef KTRACE 685 if (ktriov != NULL) { 686 if (error == 0) |
584 ktrgenio(p->p_tracep, s, UIO_WRITE, 585 ktriov, *retsize, error); | 687 ktrgenio(p->p_tracep, s, UIO_READ, 688 ktriov, len - auio.uio_resid, error); |
586 FREE(ktriov, M_TEMP); 587 } 588#endif | 689 FREE(ktriov, M_TEMP); 690 } 691#endif |
589bad: 590 if (to) 591 m_freem(to); | 692 if (error) 693 goto out; 694 *retsize = len - auio.uio_resid; 695 if (mp->msg_name) { 696 len = mp->msg_namelen; 697 if (len <= 0 || from == 0) 698 len = 0; 699 else { 700#ifdef COMPAT_OLDSOCK 701 if (mp->msg_flags & MSG_COMPAT) 702 mtod(from, struct osockaddr *)->sa_family = 703 mtod(from, struct sockaddr *)->sa_family; 704#endif 705 if (len > from->m_len) 706 len = from->m_len; 707 /* else if len < from->m_len ??? */ 708 error = copyout(mtod(from, caddr_t), 709 (caddr_t)mp->msg_name, (unsigned)len); 710 if (error) 711 goto out; 712 } 713 mp->msg_namelen = len; 714 if (namelenp && 715 (error = copyout((caddr_t)&len, namelenp, sizeof (int)))) { 716#ifdef COMPAT_OLDSOCK 717 if (mp->msg_flags & MSG_COMPAT) 718 error = 0; /* old recvfrom didn't check */ 719 else 720#endif 721 goto out; 722 } 723 } 724 if (mp->msg_control) { 725#ifdef COMPAT_OLDSOCK 726 /* 727 * We assume that old recvmsg calls won't receive access 728 * rights and other control info, esp. as control info 729 * is always optional and those options didn't exist in 4.3. 730 * If we receive rights, trim the cmsghdr; anything else 731 * is tossed. 732 */ 733 if (control && mp->msg_flags & MSG_COMPAT) { 734 if (mtod(control, struct cmsghdr *)->cmsg_level != 735 SOL_SOCKET || 736 mtod(control, struct cmsghdr *)->cmsg_type != 737 SCM_RIGHTS) { 738 mp->msg_controllen = 0; 739 goto out; 740 } 741 control->m_len -= sizeof (struct cmsghdr); 742 control->m_data += sizeof (struct cmsghdr); 743 } 744#endif 745 len = mp->msg_controllen; 746 if (len <= 0 || control == 0) 747 len = 0; 748 else { 749 if (len >= control->m_len) 750 len = control->m_len; 751 else 752 mp->msg_flags |= MSG_CTRUNC; 753 error = copyout((caddr_t)mtod(control, caddr_t), 754 (caddr_t)mp->msg_control, (unsigned)len); 755 } 756 mp->msg_controllen = len; 757 } 758out: 759 if (from) 760 m_freem(from); 761 if (control) 762 m_freem(control); |
592 return (error); 593} 594 | 763 return (error); 764} 765 |
595struct recvfrom_args { | 766struct shutdown_args { |
596 int s; | 767 int s; |
597 caddr_t buf; 598 size_t len; 599 int flags; 600 caddr_t from; 601 int *fromlenaddr; | 768 int how; |
602}; 603 | 769}; 770 |
604#ifdef COMPAT_OLDSOCK | |
605int | 771int |
606orecvfrom(p, uap, retval) 607 struct proc *p; 608 struct recvfrom_args *uap; 609 int *retval; 610{ 611 612 uap->flags |= MSG_COMPAT; 613 return (recvfrom(p, uap, retval)); 614} 615#endif 616 617int | |
618recvfrom(p, uap, retval) 619 struct proc *p; 620 register struct recvfrom_args *uap; 621 int *retval; 622{ 623 struct msghdr msg; 624 struct iovec aiov; 625 int error; 626 627 if (uap->fromlenaddr) { | 772recvfrom(p, uap, retval) 773 struct proc *p; 774 register struct recvfrom_args *uap; 775 int *retval; 776{ 777 struct msghdr msg; 778 struct iovec aiov; 779 int error; 780 781 if (uap->fromlenaddr) { |
628 if (error = copyin((caddr_t)uap->fromlenaddr, 629 (caddr_t)&msg.msg_namelen, sizeof (msg.msg_namelen))) | 782 error = copyin((caddr_t)uap->fromlenaddr, 783 (caddr_t)&msg.msg_namelen, sizeof (msg.msg_namelen)); 784 if (error) |
630 return (error); 631 } else 632 msg.msg_namelen = 0; 633 msg.msg_name = uap->from; 634 msg.msg_iov = &aiov; 635 msg.msg_iovlen = 1; 636 aiov.iov_base = uap->buf; 637 aiov.iov_len = uap->len; 638 msg.msg_control = 0; 639 msg.msg_flags = uap->flags; 640 return (recvit(p, uap->s, &msg, (caddr_t)uap->fromlenaddr, retval)); 641} 642 643#ifdef COMPAT_OLDSOCK | 785 return (error); 786 } else 787 msg.msg_namelen = 0; 788 msg.msg_name = uap->from; 789 msg.msg_iov = &aiov; 790 msg.msg_iovlen = 1; 791 aiov.iov_base = uap->buf; 792 aiov.iov_len = uap->len; 793 msg.msg_control = 0; 794 msg.msg_flags = uap->flags; 795 return (recvit(p, uap->s, &msg, (caddr_t)uap->fromlenaddr, retval)); 796} 797 798#ifdef COMPAT_OLDSOCK |
799int 800orecvfrom(p, uap, retval) 801 struct proc *p; 802 struct recvfrom_args *uap; 803 int *retval; 804{ 805 806 uap->flags |= MSG_COMPAT; 807 return (recvfrom(p, uap, retval)); 808} 809#endif 810 811 812#ifdef COMPAT_OLDSOCK |
|
644struct orecv_args { 645 int s; 646 caddr_t buf; 647 int len; 648 int flags; 649}; 650int 651orecv(p, uap, retval) --- 30 unchanged lines hidden (view full) --- 682 struct proc *p; 683 register struct orecvmsg_args *uap; 684 int *retval; 685{ 686 struct msghdr msg; 687 struct iovec aiov[UIO_SMALLIOV], *iov; 688 int error; 689 | 813struct orecv_args { 814 int s; 815 caddr_t buf; 816 int len; 817 int flags; 818}; 819int 820orecv(p, uap, retval) --- 30 unchanged lines hidden (view full) --- 851 struct proc *p; 852 register struct orecvmsg_args *uap; 853 int *retval; 854{ 855 struct msghdr msg; 856 struct iovec aiov[UIO_SMALLIOV], *iov; 857 int error; 858 |
690 if (error = copyin((caddr_t)uap->msg, (caddr_t)&msg, 691 sizeof (struct omsghdr))) | 859 error = copyin((caddr_t)uap->msg, (caddr_t)&msg, 860 sizeof (struct omsghdr)); 861 if (error) |
692 return (error); 693 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) { 694 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) 695 return (EMSGSIZE); 696 MALLOC(iov, struct iovec *, 697 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV, 698 M_WAITOK); 699 } else 700 iov = aiov; 701 msg.msg_flags = uap->flags | MSG_COMPAT; | 862 return (error); 863 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) { 864 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) 865 return (EMSGSIZE); 866 MALLOC(iov, struct iovec *, 867 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV, 868 M_WAITOK); 869 } else 870 iov = aiov; 871 msg.msg_flags = uap->flags | MSG_COMPAT; |
702 if (error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov, 703 (unsigned)(msg.msg_iovlen * sizeof (struct iovec)))) | 872 error = copyin((caddr_t)msg.msg_iov, (caddr_t)iov, 873 (unsigned)(msg.msg_iovlen * sizeof (struct iovec))); 874 if (error) |
704 goto done; 705 msg.msg_iov = iov; 706 error = recvit(p, uap->s, &msg, (caddr_t)&uap->msg->msg_namelen, retval); 707 708 if (msg.msg_controllen && error == 0) 709 error = copyout((caddr_t)&msg.msg_controllen, 710 (caddr_t)&uap->msg->msg_accrightslen, sizeof (int)); 711done: --- 13 unchanged lines hidden (view full) --- 725 struct proc *p; 726 register struct recvmsg_args *uap; 727 int *retval; 728{ 729 struct msghdr msg; 730 struct iovec aiov[UIO_SMALLIOV], *uiov, *iov; 731 register int error; 732 | 875 goto done; 876 msg.msg_iov = iov; 877 error = recvit(p, uap->s, &msg, (caddr_t)&uap->msg->msg_namelen, retval); 878 879 if (msg.msg_controllen && error == 0) 880 error = copyout((caddr_t)&msg.msg_controllen, 881 (caddr_t)&uap->msg->msg_accrightslen, sizeof (int)); 882done: --- 13 unchanged lines hidden (view full) --- 896 struct proc *p; 897 register struct recvmsg_args *uap; 898 int *retval; 899{ 900 struct msghdr msg; 901 struct iovec aiov[UIO_SMALLIOV], *uiov, *iov; 902 register int error; 903 |
733 if (error = copyin((caddr_t)uap->msg, (caddr_t)&msg, sizeof (msg))) | 904 error = copyin((caddr_t)uap->msg, (caddr_t)&msg, sizeof (msg)); 905 if (error) |
734 return (error); 735 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) { 736 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) 737 return (EMSGSIZE); 738 MALLOC(iov, struct iovec *, 739 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV, 740 M_WAITOK); 741 } else 742 iov = aiov; 743#ifdef COMPAT_OLDSOCK 744 msg.msg_flags = uap->flags &~ MSG_COMPAT; 745#else 746 msg.msg_flags = uap->flags; 747#endif 748 uiov = msg.msg_iov; 749 msg.msg_iov = iov; | 906 return (error); 907 if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) { 908 if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) 909 return (EMSGSIZE); 910 MALLOC(iov, struct iovec *, 911 sizeof(struct iovec) * (u_int)msg.msg_iovlen, M_IOV, 912 M_WAITOK); 913 } else 914 iov = aiov; 915#ifdef COMPAT_OLDSOCK 916 msg.msg_flags = uap->flags &~ MSG_COMPAT; 917#else 918 msg.msg_flags = uap->flags; 919#endif 920 uiov = msg.msg_iov; 921 msg.msg_iov = iov; |
750 if (error = copyin((caddr_t)uiov, (caddr_t)iov, 751 (unsigned)(msg.msg_iovlen * sizeof (struct iovec)))) | 922 error = copyin((caddr_t)uiov, (caddr_t)iov, 923 (unsigned)(msg.msg_iovlen * sizeof (struct iovec))); 924 if (error) |
752 goto done; | 925 goto done; |
753 if ((error = recvit(p, uap->s, &msg, (caddr_t)0, retval)) == 0) { | 926 error = recvit(p, uap->s, &msg, (caddr_t)0, retval); 927 if (!error) { |
754 msg.msg_iov = uiov; 755 error = copyout((caddr_t)&msg, (caddr_t)uap->msg, sizeof(msg)); 756 } 757done: 758 if (iov != aiov) 759 FREE(iov, M_IOV); 760 return (error); 761} | 928 msg.msg_iov = uiov; 929 error = copyout((caddr_t)&msg, (caddr_t)uap->msg, sizeof(msg)); 930 } 931done: 932 if (iov != aiov) 933 FREE(iov, M_IOV); 934 return (error); 935} |
762 763int 764recvit(p, s, mp, namelenp, retsize) 765 register struct proc *p; 766 int s; 767 register struct msghdr *mp; 768 caddr_t namelenp; 769 int *retsize; 770{ 771 struct file *fp; 772 struct uio auio; 773 register struct iovec *iov; 774 register int i; 775 int len, error; 776 struct mbuf *from = 0, *control = 0; 777#ifdef KTRACE 778 struct iovec *ktriov = NULL; 779#endif 780 781 if (error = getsock(p->p_fd, s, &fp)) 782 return (error); 783 auio.uio_iov = mp->msg_iov; 784 auio.uio_iovcnt = mp->msg_iovlen; 785 auio.uio_segflg = UIO_USERSPACE; 786 auio.uio_rw = UIO_READ; 787 auio.uio_procp = p; 788 auio.uio_offset = 0; /* XXX */ 789 auio.uio_resid = 0; 790 iov = mp->msg_iov; 791 for (i = 0; i < mp->msg_iovlen; i++, iov++) { 792 if ((auio.uio_resid += iov->iov_len) < 0) 793 return (EINVAL); 794 } 795#ifdef KTRACE 796 if (KTRPOINT(p, KTR_GENIO)) { 797 int iovlen = auio.uio_iovcnt * sizeof (struct iovec); 798 799 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK); 800 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen); 801 } 802#endif 803 len = auio.uio_resid; 804 if (error = soreceive((struct socket *)fp->f_data, &from, &auio, 805 (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0, 806 &mp->msg_flags)) { 807 if (auio.uio_resid != len && (error == ERESTART || 808 error == EINTR || error == EWOULDBLOCK)) 809 error = 0; 810 } 811#ifdef KTRACE 812 if (ktriov != NULL) { 813 if (error == 0) 814 ktrgenio(p->p_tracep, s, UIO_READ, 815 ktriov, len - auio.uio_resid, error); 816 FREE(ktriov, M_TEMP); 817 } 818#endif 819 if (error) 820 goto out; 821 *retsize = len - auio.uio_resid; 822 if (mp->msg_name) { 823 len = mp->msg_namelen; 824 if (len <= 0 || from == 0) 825 len = 0; 826 else { 827#ifdef COMPAT_OLDSOCK 828 if (mp->msg_flags & MSG_COMPAT) 829 mtod(from, struct osockaddr *)->sa_family = 830 mtod(from, struct sockaddr *)->sa_family; 831#endif 832 if (len > from->m_len) 833 len = from->m_len; 834 /* else if len < from->m_len ??? */ 835 if (error = copyout(mtod(from, caddr_t), 836 (caddr_t)mp->msg_name, (unsigned)len)) 837 goto out; 838 } 839 mp->msg_namelen = len; 840 if (namelenp && 841 (error = copyout((caddr_t)&len, namelenp, sizeof (int)))) { 842#ifdef COMPAT_OLDSOCK 843 if (mp->msg_flags & MSG_COMPAT) 844 error = 0; /* old recvfrom didn't check */ 845 else 846#endif 847 goto out; 848 } 849 } 850 if (mp->msg_control) { 851#ifdef COMPAT_OLDSOCK 852 /* 853 * We assume that old recvmsg calls won't receive access 854 * rights and other control info, esp. as control info 855 * is always optional and those options didn't exist in 4.3. 856 * If we receive rights, trim the cmsghdr; anything else 857 * is tossed. 858 */ 859 if (control && mp->msg_flags & MSG_COMPAT) { 860 if (mtod(control, struct cmsghdr *)->cmsg_level != 861 SOL_SOCKET || 862 mtod(control, struct cmsghdr *)->cmsg_type != 863 SCM_RIGHTS) { 864 mp->msg_controllen = 0; 865 goto out; 866 } 867 control->m_len -= sizeof (struct cmsghdr); 868 control->m_data += sizeof (struct cmsghdr); 869 } 870#endif 871 len = mp->msg_controllen; 872 if (len <= 0 || control == 0) 873 len = 0; 874 else { 875 if (len >= control->m_len) 876 len = control->m_len; 877 else 878 mp->msg_flags |= MSG_CTRUNC; 879 error = copyout((caddr_t)mtod(control, caddr_t), 880 (caddr_t)mp->msg_control, (unsigned)len); 881 } 882 mp->msg_controllen = len; 883 } 884out: 885 if (from) 886 m_freem(from); 887 if (control) 888 m_freem(control); 889 return (error); 890} 891 892struct shutdown_args { 893 int s; 894 int how; 895}; | |
896/* ARGSUSED */ 897int 898shutdown(p, uap, retval) 899 struct proc *p; 900 register struct shutdown_args *uap; 901 int *retval; 902{ 903 struct file *fp; 904 int error; 905 | 936/* ARGSUSED */ 937int 938shutdown(p, uap, retval) 939 struct proc *p; 940 register struct shutdown_args *uap; 941 int *retval; 942{ 943 struct file *fp; 944 int error; 945 |
906 if (error = getsock(p->p_fd, uap->s, &fp)) | 946 error = getsock(p->p_fd, uap->s, &fp); 947 if (error) |
907 return (error); 908 return (soshutdown((struct socket *)fp->f_data, uap->how)); 909} 910 911struct setsockopt_args { 912 int s; 913 int level; 914 int name; --- 6 unchanged lines hidden (view full) --- 921 struct proc *p; 922 register struct setsockopt_args *uap; 923 int *retval; 924{ 925 struct file *fp; 926 struct mbuf *m = NULL; 927 int error; 928 | 948 return (error); 949 return (soshutdown((struct socket *)fp->f_data, uap->how)); 950} 951 952struct setsockopt_args { 953 int s; 954 int level; 955 int name; --- 6 unchanged lines hidden (view full) --- 962 struct proc *p; 963 register struct setsockopt_args *uap; 964 int *retval; 965{ 966 struct file *fp; 967 struct mbuf *m = NULL; 968 int error; 969 |
929 if (error = getsock(p->p_fd, uap->s, &fp)) | 970 error = getsock(p->p_fd, uap->s, &fp); 971 if (error) |
930 return (error); 931 if (uap->valsize > MLEN) 932 return (EINVAL); 933 if (uap->val) { 934 m = m_get(M_WAIT, MT_SOOPTS); 935 if (m == NULL) 936 return (ENOBUFS); | 972 return (error); 973 if (uap->valsize > MLEN) 974 return (EINVAL); 975 if (uap->val) { 976 m = m_get(M_WAIT, MT_SOOPTS); 977 if (m == NULL) 978 return (ENOBUFS); |
937 if (error = copyin(uap->val, mtod(m, caddr_t), 938 (u_int)uap->valsize)) { | 979 error = copyin(uap->val, mtod(m, caddr_t), (u_int)uap->valsize); 980 if (error) { |
939 (void) m_free(m); 940 return (error); 941 } 942 m->m_len = uap->valsize; 943 } 944 return (sosetopt((struct socket *)fp->f_data, uap->level, 945 uap->name, m)); 946} --- 11 unchanged lines hidden (view full) --- 958 struct proc *p; 959 register struct getsockopt_args *uap; 960 int *retval; 961{ 962 struct file *fp; 963 struct mbuf *m = NULL; 964 int valsize, error; 965 | 981 (void) m_free(m); 982 return (error); 983 } 984 m->m_len = uap->valsize; 985 } 986 return (sosetopt((struct socket *)fp->f_data, uap->level, 987 uap->name, m)); 988} --- 11 unchanged lines hidden (view full) --- 1000 struct proc *p; 1001 register struct getsockopt_args *uap; 1002 int *retval; 1003{ 1004 struct file *fp; 1005 struct mbuf *m = NULL; 1006 int valsize, error; 1007 |
966 if (error = getsock(p->p_fd, uap->s, &fp)) | 1008 error = getsock(p->p_fd, uap->s, &fp); 1009 if (error) |
967 return (error); 968 if (uap->val) { | 1010 return (error); 1011 if (uap->val) { |
969 if (error = copyin((caddr_t)uap->avalsize, (caddr_t)&valsize, 970 sizeof (valsize))) | 1012 error = copyin((caddr_t)uap->avalsize, (caddr_t)&valsize, 1013 sizeof (valsize)); 1014 if (error) |
971 return (error); 972 } else 973 valsize = 0; 974 if ((error = sogetopt((struct socket *)fp->f_data, uap->level, 975 uap->name, &m)) == 0 && uap->val && valsize && m != NULL) { 976 if (valsize > m->m_len) 977 valsize = m->m_len; 978 error = copyout(mtod(m, caddr_t), uap->val, (u_int)valsize); --- 16 unchanged lines hidden (view full) --- 995 struct pipe_args *uap; 996 int retval[]; 997{ 998 register struct filedesc *fdp = p->p_fd; 999 struct file *rf, *wf; 1000 struct socket *rso, *wso; 1001 int fd, error; 1002 | 1015 return (error); 1016 } else 1017 valsize = 0; 1018 if ((error = sogetopt((struct socket *)fp->f_data, uap->level, 1019 uap->name, &m)) == 0 && uap->val && valsize && m != NULL) { 1020 if (valsize > m->m_len) 1021 valsize = m->m_len; 1022 error = copyout(mtod(m, caddr_t), uap->val, (u_int)valsize); --- 16 unchanged lines hidden (view full) --- 1039 struct pipe_args *uap; 1040 int retval[]; 1041{ 1042 register struct filedesc *fdp = p->p_fd; 1043 struct file *rf, *wf; 1044 struct socket *rso, *wso; 1045 int fd, error; 1046 |
1003 if (error = socreate(AF_UNIX, &rso, SOCK_STREAM, 0)) | 1047 error = socreate(AF_UNIX, &rso, SOCK_STREAM, 0); 1048 if (error) |
1004 return (error); | 1049 return (error); |
1005 if (error = socreate(AF_UNIX, &wso, SOCK_STREAM, 0)) | 1050 error = socreate(AF_UNIX, &wso, SOCK_STREAM, 0); 1051 if (error) |
1006 goto free1; | 1052 goto free1; |
1007 if (error = falloc(p, &rf, &fd)) | 1053 error = falloc(p, &rf, &fd); 1054 if (error) |
1008 goto free2; 1009 retval[0] = fd; 1010 rf->f_flag = FREAD; 1011 rf->f_type = DTYPE_SOCKET; 1012 rf->f_ops = &socketops; 1013 rf->f_data = (caddr_t)rso; | 1055 goto free2; 1056 retval[0] = fd; 1057 rf->f_flag = FREAD; 1058 rf->f_type = DTYPE_SOCKET; 1059 rf->f_ops = &socketops; 1060 rf->f_data = (caddr_t)rso; |
1014 if (error = falloc(p, &wf, &fd)) | 1061 error = falloc(p, &wf, &fd); 1062 if (error) |
1015 goto free3; 1016 wf->f_flag = FWRITE; 1017 wf->f_type = DTYPE_SOCKET; 1018 wf->f_ops = &socketops; 1019 wf->f_data = (caddr_t)wso; 1020 retval[1] = fd; | 1063 goto free3; 1064 wf->f_flag = FWRITE; 1065 wf->f_type = DTYPE_SOCKET; 1066 wf->f_ops = &socketops; 1067 wf->f_data = (caddr_t)wso; 1068 retval[1] = fd; |
1021 if (error = unp_connect2(wso, rso)) | 1069 error = unp_connect2(wso, rso); 1070 if (error) |
1022 goto free4; 1023 return (0); 1024free4: 1025 ffree(wf); 1026 fdp->fd_ofiles[retval[1]] = 0; 1027free3: 1028 ffree(rf); 1029 fdp->fd_ofiles[retval[0]] = 0; --- 10 unchanged lines hidden (view full) --- 1040struct getsockname_args { 1041 int fdes; 1042 caddr_t asa; 1043 int *alen; 1044#ifdef COMPAT_OLDSOCK 1045 int compat_43; /* pseudo */ 1046#endif 1047}; | 1071 goto free4; 1072 return (0); 1073free4: 1074 ffree(wf); 1075 fdp->fd_ofiles[retval[1]] = 0; 1076free3: 1077 ffree(rf); 1078 fdp->fd_ofiles[retval[0]] = 0; --- 10 unchanged lines hidden (view full) --- 1089struct getsockname_args { 1090 int fdes; 1091 caddr_t asa; 1092 int *alen; 1093#ifdef COMPAT_OLDSOCK 1094 int compat_43; /* pseudo */ 1095#endif 1096}; |
1048#ifdef COMPAT_OLDSOCK 1049int 1050getsockname(p, uap, retval) 1051 struct proc *p; 1052 struct getsockname_args *uap; 1053 int *retval; 1054{ | |
1055 | 1097 |
1056 uap->compat_43 = 0; 1057 return (getsockname1(p, uap, retval)); 1058} 1059 1060int 1061ogetsockname(p, uap, retval) 1062 struct proc *p; 1063 struct getsockname_args *uap; 1064 int *retval; 1065{ 1066 1067 uap->compat_43 = 1; 1068 return (getsockname1(p, uap, retval)); 1069} 1070#else /* COMPAT_OLDSOCK */ 1071 | 1098#ifndef COMPAT_OLDSOCK |
1072#define getsockname1 getsockname 1073#endif 1074 1075/* ARGSUSED */ 1076int 1077getsockname1(p, uap, retval) 1078 struct proc *p; 1079 register struct getsockname_args *uap; 1080 int *retval; 1081{ 1082 struct file *fp; 1083 register struct socket *so; 1084 struct mbuf *m; 1085 int len, error; 1086 | 1099#define getsockname1 getsockname 1100#endif 1101 1102/* ARGSUSED */ 1103int 1104getsockname1(p, uap, retval) 1105 struct proc *p; 1106 register struct getsockname_args *uap; 1107 int *retval; 1108{ 1109 struct file *fp; 1110 register struct socket *so; 1111 struct mbuf *m; 1112 int len, error; 1113 |
1087 if (error = getsock(p->p_fd, uap->fdes, &fp)) | 1114 error = getsock(p->p_fd, uap->fdes, &fp); 1115 if (error) |
1088 return (error); | 1116 return (error); |
1089 if (error = copyin((caddr_t)uap->alen, (caddr_t)&len, sizeof (len))) | 1117 error = copyin((caddr_t)uap->alen, (caddr_t)&len, sizeof (len)); 1118 if (error) |
1090 return (error); 1091 so = (struct socket *)fp->f_data; 1092 m = m_getclr(M_WAIT, MT_SONAME); 1093 if (m == NULL) 1094 return (ENOBUFS); | 1119 return (error); 1120 so = (struct socket *)fp->f_data; 1121 m = m_getclr(M_WAIT, MT_SONAME); 1122 if (m == NULL) 1123 return (ENOBUFS); |
1095 if (error = (*so->so_proto->pr_usrreq)(so, PRU_SOCKADDR, 0, m, 0)) | 1124 error = (*so->so_proto->pr_usrreq)(so, PRU_SOCKADDR, 0, m, 0); 1125 if (error) |
1096 goto bad; 1097 if (len > m->m_len) 1098 len = m->m_len; 1099#ifdef COMPAT_OLDSOCK 1100 if (uap->compat_43) 1101 mtod(m, struct osockaddr *)->sa_family = 1102 mtod(m, struct sockaddr *)->sa_family; 1103#endif 1104 error = copyout(mtod(m, caddr_t), (caddr_t)uap->asa, (u_int)len); 1105 if (error == 0) 1106 error = copyout((caddr_t)&len, (caddr_t)uap->alen, 1107 sizeof (len)); 1108bad: 1109 m_freem(m); 1110 return (error); 1111} 1112 | 1126 goto bad; 1127 if (len > m->m_len) 1128 len = m->m_len; 1129#ifdef COMPAT_OLDSOCK 1130 if (uap->compat_43) 1131 mtod(m, struct osockaddr *)->sa_family = 1132 mtod(m, struct sockaddr *)->sa_family; 1133#endif 1134 error = copyout(mtod(m, caddr_t), (caddr_t)uap->asa, (u_int)len); 1135 if (error == 0) 1136 error = copyout((caddr_t)&len, (caddr_t)uap->alen, 1137 sizeof (len)); 1138bad: 1139 m_freem(m); 1140 return (error); 1141} 1142 |
1113/* 1114 * Get name of peer for connected socket. 1115 */ 1116struct getpeername_args { 1117 int fdes; 1118 caddr_t asa; 1119 int *alen; | |
1120#ifdef COMPAT_OLDSOCK | 1143#ifdef COMPAT_OLDSOCK |
1121 int compat_43; /* pseudo */ 1122#endif 1123}; 1124 1125#ifdef COMPAT_OLDSOCK | |
1126int | 1144int |
1127getpeername(p, uap, retval) | 1145getsockname(p, uap, retval) |
1128 struct proc *p; | 1146 struct proc *p; |
1129 struct getpeername_args *uap; | 1147 struct getsockname_args *uap; |
1130 int *retval; 1131{ 1132 1133 uap->compat_43 = 0; | 1148 int *retval; 1149{ 1150 1151 uap->compat_43 = 0; |
1134 return (getpeername1(p, uap, retval)); | 1152 return (getsockname1(p, uap, retval)); |
1135} 1136 1137int | 1153} 1154 1155int |
1138ogetpeername(p, uap, retval) | 1156ogetsockname(p, uap, retval) |
1139 struct proc *p; | 1157 struct proc *p; |
1140 struct getpeername_args *uap; | 1158 struct getsockname_args *uap; |
1141 int *retval; 1142{ 1143 1144 uap->compat_43 = 1; | 1159 int *retval; 1160{ 1161 1162 uap->compat_43 = 1; |
1145 return (getpeername1(p, uap, retval)); | 1163 return (getsockname1(p, uap, retval)); |
1146} | 1164} |
1147#else /* COMPAT_OLDSOCK */ | 1165#endif /* COMPAT_OLDSOCK */ |
1148 | 1166 |
1167/* 1168 * Get name of peer for connected socket. 1169 */ 1170struct getpeername_args { 1171 int fdes; 1172 caddr_t asa; 1173 int *alen; 1174#ifdef COMPAT_OLDSOCK 1175 int compat_43; /* pseudo */ 1176#endif 1177}; 1178 1179 1180#ifndef COMPAT_OLDSOCK |
|
1149#define getpeername1 getpeername 1150#endif 1151 1152/* ARGSUSED */ 1153int 1154getpeername1(p, uap, retval) 1155 struct proc *p; 1156 register struct getpeername_args *uap; 1157 int *retval; 1158{ 1159 struct file *fp; 1160 register struct socket *so; 1161 struct mbuf *m; 1162 int len, error; 1163 | 1181#define getpeername1 getpeername 1182#endif 1183 1184/* ARGSUSED */ 1185int 1186getpeername1(p, uap, retval) 1187 struct proc *p; 1188 register struct getpeername_args *uap; 1189 int *retval; 1190{ 1191 struct file *fp; 1192 register struct socket *so; 1193 struct mbuf *m; 1194 int len, error; 1195 |
1164 if (error = getsock(p->p_fd, uap->fdes, &fp)) | 1196 error = getsock(p->p_fd, uap->fdes, &fp); 1197 if (error) |
1165 return (error); 1166 so = (struct socket *)fp->f_data; 1167 if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) 1168 return (ENOTCONN); | 1198 return (error); 1199 so = (struct socket *)fp->f_data; 1200 if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) 1201 return (ENOTCONN); |
1169 if (error = copyin((caddr_t)uap->alen, (caddr_t)&len, sizeof (len))) | 1202 error = copyin((caddr_t)uap->alen, (caddr_t)&len, sizeof (len)); 1203 if (error) |
1170 return (error); 1171 m = m_getclr(M_WAIT, MT_SONAME); 1172 if (m == NULL) 1173 return (ENOBUFS); | 1204 return (error); 1205 m = m_getclr(M_WAIT, MT_SONAME); 1206 if (m == NULL) 1207 return (ENOBUFS); |
1174 if (error = (*so->so_proto->pr_usrreq)(so, PRU_PEERADDR, 0, m, 0)) | 1208 error = (*so->so_proto->pr_usrreq)(so, PRU_PEERADDR, 0, m, 0); 1209 if (error) |
1175 goto bad; 1176 if (len > m->m_len) 1177 len = m->m_len; 1178#ifdef COMPAT_OLDSOCK 1179 if (uap->compat_43) 1180 mtod(m, struct osockaddr *)->sa_family = 1181 mtod(m, struct sockaddr *)->sa_family; 1182#endif | 1210 goto bad; 1211 if (len > m->m_len) 1212 len = m->m_len; 1213#ifdef COMPAT_OLDSOCK 1214 if (uap->compat_43) 1215 mtod(m, struct osockaddr *)->sa_family = 1216 mtod(m, struct sockaddr *)->sa_family; 1217#endif |
1183 if (error = copyout(mtod(m, caddr_t), (caddr_t)uap->asa, (u_int)len)) | 1218 error = copyout(mtod(m, caddr_t), (caddr_t)uap->asa, (u_int)len); 1219 if (error) |
1184 goto bad; 1185 error = copyout((caddr_t)&len, (caddr_t)uap->alen, sizeof (len)); 1186bad: 1187 m_freem(m); 1188 return (error); 1189} 1190 | 1220 goto bad; 1221 error = copyout((caddr_t)&len, (caddr_t)uap->alen, sizeof (len)); 1222bad: 1223 m_freem(m); 1224 return (error); 1225} 1226 |
1227#ifdef COMPAT_OLDSOCK |
|
1191int | 1228int |
1229getpeername(p, uap, retval) 1230 struct proc *p; 1231 struct getpeername_args *uap; 1232 int *retval; 1233{ 1234 1235 uap->compat_43 = 0; 1236 return (getpeername1(p, uap, retval)); 1237} 1238 1239int 1240ogetpeername(p, uap, retval) 1241 struct proc *p; 1242 struct getpeername_args *uap; 1243 int *retval; 1244{ 1245 1246 uap->compat_43 = 1; 1247 return (getpeername1(p, uap, retval)); 1248} 1249#endif /* COMPAT_OLDSOCK */ 1250int |
|
1192sockargs(mp, buf, buflen, type) 1193 struct mbuf **mp; 1194 caddr_t buf; 1195 int buflen, type; 1196{ 1197 register struct sockaddr *sa; 1198 register struct mbuf *m; 1199 int error; --- 47 unchanged lines hidden --- | 1251sockargs(mp, buf, buflen, type) 1252 struct mbuf **mp; 1253 caddr_t buf; 1254 int buflen, type; 1255{ 1256 register struct sockaddr *sa; 1257 register struct mbuf *m; 1258 int error; --- 47 unchanged lines hidden --- |