Home | History | Annotate | Line # | Download | only in common
uipc_syscalls_43.c revision 1.14.2.2
      1  1.14.2.2   thorpej /*	$NetBSD: uipc_syscalls_43.c,v 1.14.2.2 2002/01/10 19:51:01 thorpej 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.14.2.2   thorpej 
     38  1.14.2.2   thorpej #include <sys/cdefs.h>
     39  1.14.2.2   thorpej __KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_43.c,v 1.14.2.2 2002/01/10 19:51:01 thorpej Exp $");
     40       1.1  christos 
     41       1.1  christos #include <sys/param.h>
     42       1.1  christos #include <sys/systm.h>
     43       1.1  christos #include <sys/filedesc.h>
     44       1.1  christos #include <sys/kernel.h>
     45       1.1  christos #include <sys/proc.h>
     46       1.1  christos #include <sys/file.h>
     47       1.1  christos #include <sys/socket.h>
     48       1.1  christos #include <sys/socketvar.h>
     49       1.1  christos #include <sys/stat.h>
     50       1.1  christos #include <sys/ioctl.h>
     51       1.1  christos #include <sys/fcntl.h>
     52       1.1  christos #include <sys/malloc.h>
     53       1.1  christos #include <sys/syslog.h>
     54       1.1  christos #include <sys/unistd.h>
     55       1.1  christos #include <sys/resourcevar.h>
     56  1.14.2.1     lukem #include <sys/mbuf.h>		/* for MLEN */
     57       1.1  christos 
     58       1.1  christos #include <sys/mount.h>
     59       1.1  christos #include <sys/syscallargs.h>
     60       1.1  christos 
     61  1.14.2.1     lukem #include <compat/common/compat_util.h>
     62  1.14.2.1     lukem 
     63  1.14.2.1     lukem #include <uvm/uvm_extern.h>
     64  1.14.2.1     lukem 
     65  1.14.2.1     lukem /*
     66  1.14.2.1     lukem  * Following 4.3 syscalls were not versioned, even through they should
     67  1.14.2.1     lukem  * have been:
     68  1.14.2.1     lukem  * connect(2), bind(2), sendto(2)
     69  1.14.2.1     lukem  */
     70  1.14.2.1     lukem 
     71  1.14.2.1     lukem static int compat_43_sa_put(caddr_t);
     72  1.14.2.1     lukem 
     73       1.1  christos int
     74       1.3   mycroft compat_43_sys_accept(p, v, retval)
     75       1.1  christos 	struct proc *p;
     76       1.2   thorpej 	void *v;
     77       1.2   thorpej 	register_t *retval;
     78       1.2   thorpej {
     79  1.14.2.1     lukem 	struct compat_43_sys_accept_args /* {
     80       1.1  christos 		syscallarg(int) s;
     81       1.1  christos 		syscallarg(caddr_t) name;
     82       1.1  christos 		syscallarg(int *) anamelen;
     83       1.2   thorpej 	} */ *uap = v;
     84       1.1  christos 	int error;
     85       1.1  christos 
     86  1.14.2.1     lukem 	if ((error = sys_accept(p, v, retval)) != 0)
     87       1.1  christos 		return error;
     88       1.1  christos 
     89  1.14.2.1     lukem 	if (SCARG(uap, name)
     90  1.14.2.1     lukem 	    && (error = compat_43_sa_put(SCARG(uap, name))))
     91  1.14.2.1     lukem 		return (error);
     92       1.1  christos 
     93       1.1  christos 	return 0;
     94       1.1  christos }
     95       1.1  christos 
     96       1.1  christos int
     97       1.3   mycroft compat_43_sys_getpeername(p, v, retval)
     98       1.1  christos 	struct proc *p;
     99       1.2   thorpej 	void *v;
    100       1.2   thorpej 	register_t *retval;
    101       1.2   thorpej {
    102  1.14.2.1     lukem 	struct compat_43_sys_getpeername_args /* {
    103       1.1  christos 		syscallarg(int) fdes;
    104       1.1  christos 		syscallarg(caddr_t) asa;
    105       1.1  christos 		syscallarg(int *) alen;
    106       1.2   thorpej 	} */ *uap = v;
    107       1.1  christos 
    108       1.1  christos 	int error;
    109       1.1  christos 
    110  1.14.2.1     lukem 	if ((error = sys_getpeername(p, v, retval)) != 0)
    111       1.1  christos 		return error;
    112       1.1  christos 
    113  1.14.2.1     lukem 	if ((error = compat_43_sa_put(SCARG(uap, asa))))
    114  1.14.2.1     lukem 		return (error);
    115       1.1  christos 
    116       1.1  christos 	return 0;
    117       1.1  christos }
    118       1.1  christos 
    119       1.1  christos int
    120       1.3   mycroft compat_43_sys_getsockname(p, v, retval)
    121       1.1  christos 	struct proc *p;
    122       1.2   thorpej 	void *v;
    123       1.2   thorpej 	register_t *retval;
    124       1.2   thorpej {
    125  1.14.2.1     lukem 	struct compat_43_sys_getsockname_args /* {
    126       1.1  christos 		syscallarg(int) fdes;
    127       1.1  christos 		syscallarg(caddr_t) asa;
    128       1.1  christos 		syscallarg(int *) alen;
    129       1.2   thorpej 	} */ *uap = v;
    130       1.1  christos 	int error;
    131       1.1  christos 
    132  1.14.2.1     lukem 	if ((error = sys_getsockname(p, v, retval)) != 0)
    133       1.1  christos 		return error;
    134       1.1  christos 
    135  1.14.2.1     lukem 	if ((error = compat_43_sa_put(SCARG(uap, asa))))
    136  1.14.2.1     lukem 		return (error);
    137       1.1  christos 
    138       1.1  christos 	return 0;
    139       1.1  christos }
    140       1.1  christos 
    141       1.1  christos int
    142       1.3   mycroft compat_43_sys_recv(p, v, retval)
    143       1.1  christos 	struct proc *p;
    144       1.2   thorpej 	void *v;
    145       1.2   thorpej 	register_t *retval;
    146       1.2   thorpej {
    147      1.11  augustss 	struct compat_43_sys_recv_args /* {
    148       1.1  christos 		syscallarg(int) s;
    149       1.1  christos 		syscallarg(caddr_t) buf;
    150       1.1  christos 		syscallarg(int) len;
    151       1.1  christos 		syscallarg(int) flags;
    152       1.2   thorpej 	} */ *uap = v;
    153      1.14  jdolecek 	struct sys_recvfrom_args bra;
    154      1.14  jdolecek 
    155      1.14  jdolecek 	SCARG(&bra, s) = SCARG(uap, s);
    156      1.14  jdolecek 	SCARG(&bra, buf) = SCARG(uap, buf);
    157      1.14  jdolecek 	SCARG(&bra, len) = (size_t) SCARG(uap, len);
    158      1.14  jdolecek 	SCARG(&bra, flags) = SCARG(uap, flags);
    159      1.14  jdolecek 	SCARG(&bra, from) = NULL;
    160      1.14  jdolecek 	SCARG(&bra, fromlenaddr) = NULL;
    161       1.1  christos 
    162      1.14  jdolecek 	return (sys_recvfrom(p, &bra, retval));
    163       1.1  christos }
    164       1.1  christos 
    165       1.1  christos int
    166       1.3   mycroft compat_43_sys_recvfrom(p, v, retval)
    167       1.1  christos 	struct proc *p;
    168       1.2   thorpej 	void *v;
    169       1.2   thorpej 	register_t *retval;
    170       1.2   thorpej {
    171  1.14.2.1     lukem 	struct compat_43_sys_recvfrom_args /* {
    172       1.1  christos 		syscallarg(int) s;
    173       1.1  christos 		syscallarg(caddr_t) buf;
    174       1.1  christos 		syscallarg(size_t) len;
    175       1.1  christos 		syscallarg(int) flags;
    176       1.1  christos 		syscallarg(caddr_t) from;
    177       1.1  christos 		syscallarg(int *) fromlenaddr;
    178       1.2   thorpej 	} */ *uap = v;
    179  1.14.2.1     lukem 	int error;
    180       1.1  christos 
    181  1.14.2.1     lukem 	if ((error = sys_recvfrom(p, v, retval)))
    182  1.14.2.1     lukem 		return (error);
    183  1.14.2.1     lukem 
    184  1.14.2.1     lukem 	if (SCARG(uap, from) && (error = compat_43_sa_put(SCARG(uap, from))))
    185  1.14.2.1     lukem 		return (error);
    186  1.14.2.1     lukem 
    187  1.14.2.1     lukem 	return (0);
    188       1.1  christos }
    189       1.1  christos 
    190       1.1  christos /*
    191  1.14.2.1     lukem  * Old recvmsg. Arrange necessary structures, calls generic code and
    192  1.14.2.1     lukem  * adjusts results accordingly.
    193       1.1  christos  */
    194       1.1  christos int
    195       1.3   mycroft compat_43_sys_recvmsg(p, v, retval)
    196       1.1  christos 	struct proc *p;
    197       1.2   thorpej 	void *v;
    198       1.2   thorpej 	register_t *retval;
    199       1.2   thorpej {
    200      1.11  augustss 	struct compat_43_sys_recvmsg_args /* {
    201       1.1  christos 		syscallarg(int) s;
    202       1.1  christos 		syscallarg(struct omsghdr *) msg;
    203       1.1  christos 		syscallarg(int) flags;
    204       1.2   thorpej 	} */ *uap = v;
    205  1.14.2.1     lukem 	struct omsghdr omsg;
    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.14.2.1     lukem 	error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&omsg,
    211       1.5  christos 	    sizeof (struct omsghdr));
    212       1.5  christos 	if (error)
    213       1.1  christos 		return (error);
    214  1.14.2.1     lukem 	if ((u_int)omsg.msg_iovlen > UIO_SMALLIOV) {
    215  1.14.2.1     lukem 		if ((u_int)omsg.msg_iovlen > IOV_MAX)
    216       1.1  christos 			return (EMSGSIZE);
    217  1.14.2.1     lukem 		iov = malloc(sizeof(struct iovec) * omsg.msg_iovlen,
    218  1.14.2.1     lukem 		    M_IOV, M_WAITOK);
    219       1.1  christos 	} else
    220       1.1  christos 		iov = aiov;
    221  1.14.2.1     lukem 
    222  1.14.2.1     lukem 	error = copyin((caddr_t)omsg.msg_iov, (caddr_t)iov,
    223  1.14.2.1     lukem 	    (unsigned)(omsg.msg_iovlen * sizeof (struct iovec)));
    224       1.5  christos 	if (error)
    225       1.1  christos 		goto done;
    226  1.14.2.1     lukem 
    227  1.14.2.1     lukem 	msg.msg_name	= omsg.msg_name;
    228  1.14.2.1     lukem 	msg.msg_namelen = omsg.msg_namelen;
    229  1.14.2.1     lukem 	msg.msg_iovlen	= omsg.msg_iovlen;
    230  1.14.2.1     lukem 	msg.msg_iov	= iov;
    231  1.14.2.1     lukem 	msg.msg_flags	= SCARG(uap, flags);
    232  1.14.2.1     lukem 
    233  1.14.2.1     lukem 	/*
    234  1.14.2.1     lukem 	 * If caller passes accrights, arrange things for generic code to
    235  1.14.2.1     lukem 	 * DTRT.
    236  1.14.2.1     lukem 	 */
    237  1.14.2.1     lukem 	if (omsg.msg_accrights && omsg.msg_accrightslen) {
    238  1.14.2.1     lukem 		caddr_t sg = stackgap_init(p->p_emul);
    239  1.14.2.1     lukem 		struct cmsg *ucmsg;
    240  1.14.2.1     lukem 
    241  1.14.2.1     lukem 		/* it was this way in 4.4BSD */
    242  1.14.2.1     lukem 		if ((u_int) omsg.msg_accrightslen > MLEN)
    243  1.14.2.1     lukem 			return (EINVAL);
    244  1.14.2.1     lukem 
    245  1.14.2.1     lukem 		ucmsg = stackgap_alloc(&sg, CMSG_SPACE(omsg.msg_accrightslen));
    246  1.14.2.1     lukem 		if (ucmsg == NULL)
    247  1.14.2.1     lukem 			return (EMSGSIZE);
    248  1.14.2.1     lukem 
    249  1.14.2.1     lukem 		msg.msg_control = ucmsg;
    250  1.14.2.1     lukem 		msg.msg_controllen = CMSG_SPACE(omsg.msg_accrightslen);
    251  1.14.2.1     lukem 	} else {
    252  1.14.2.1     lukem 		msg.msg_control = NULL;
    253  1.14.2.1     lukem 		msg.msg_controllen = 0;
    254  1.14.2.1     lukem 	}
    255  1.14.2.1     lukem 
    256       1.1  christos 	error = recvit(p, SCARG(uap, s), &msg,
    257      1.13  jdolecek 	    (caddr_t)&SCARG(uap, msg)->msg_namelen, retval);
    258       1.1  christos 
    259  1.14.2.1     lukem 	/*
    260  1.14.2.1     lukem 	 * If there is any control information and it's SCM_RIGHTS,
    261  1.14.2.1     lukem 	 * pass it back to the program.
    262  1.14.2.1     lukem 	 */
    263  1.14.2.1     lukem 	if (!error && omsg.msg_accrights && msg.msg_controllen > 0) {
    264  1.14.2.1     lukem 		struct cmsghdr *cmsg;
    265  1.14.2.1     lukem 
    266  1.14.2.1     lukem 		/* safe - msg.msg_controllen set by kernel */
    267  1.14.2.1     lukem 		cmsg = (struct cmsghdr *) malloc(msg.msg_controllen,
    268  1.14.2.1     lukem 		    M_TEMP, M_WAITOK);
    269  1.14.2.1     lukem 
    270  1.14.2.1     lukem 		error = copyin(msg.msg_control, cmsg, msg.msg_controllen);
    271  1.14.2.1     lukem 		if (error) {
    272  1.14.2.1     lukem 			free(cmsg, M_TEMP);
    273  1.14.2.1     lukem 			return (error);
    274  1.14.2.1     lukem 		}
    275  1.14.2.1     lukem 
    276  1.14.2.1     lukem 		if (cmsg->cmsg_level != SOL_SOCKET
    277  1.14.2.1     lukem 		    || cmsg->cmsg_type != SCM_RIGHTS
    278  1.14.2.1     lukem 		    || copyout(CMSG_DATA(cmsg), omsg.msg_accrights,
    279  1.14.2.1     lukem 			    cmsg->cmsg_len)) {
    280  1.14.2.1     lukem 			omsg.msg_accrightslen = 0;
    281  1.14.2.1     lukem 		}
    282  1.14.2.1     lukem 
    283  1.14.2.1     lukem 		free(cmsg, M_TEMP);
    284  1.14.2.1     lukem 
    285  1.14.2.1     lukem 		if (!error) {
    286  1.14.2.1     lukem 			error = copyout(&cmsg->cmsg_len,
    287  1.14.2.1     lukem 			    &SCARG(uap, msg)->msg_accrightslen, sizeof(int));
    288  1.14.2.1     lukem 		}
    289  1.14.2.1     lukem 	}
    290  1.14.2.1     lukem 
    291  1.14.2.1     lukem 	if (!error && omsg.msg_name) {
    292  1.14.2.1     lukem 		int namelen;
    293  1.14.2.1     lukem 
    294  1.14.2.1     lukem 		if ((error = copyin(&SCARG(uap, msg)->msg_namelen, &namelen, sizeof(int)) == 0)
    295  1.14.2.1     lukem 		    && namelen > 0)
    296  1.14.2.1     lukem 			error = compat_43_sa_put(omsg.msg_name);
    297  1.14.2.1     lukem 	}
    298  1.14.2.1     lukem 
    299       1.1  christos done:
    300       1.1  christos 	if (iov != aiov)
    301  1.14.2.1     lukem 		free(iov, M_IOV);
    302       1.1  christos 	return (error);
    303       1.1  christos }
    304       1.1  christos 
    305       1.1  christos int
    306       1.3   mycroft compat_43_sys_send(p, v, retval)
    307       1.1  christos 	struct proc *p;
    308       1.2   thorpej 	void *v;
    309       1.2   thorpej 	register_t *retval;
    310       1.2   thorpej {
    311      1.11  augustss 	struct compat_43_sys_send_args /* {
    312       1.1  christos 		syscallarg(int) s;
    313       1.1  christos 		syscallarg(caddr_t) buf;
    314       1.1  christos 		syscallarg(int) len;
    315       1.1  christos 		syscallarg(int) flags;
    316       1.2   thorpej 	} */ *uap = v;
    317      1.14  jdolecek 	struct sys_sendto_args bsa;
    318      1.14  jdolecek 
    319      1.14  jdolecek 	SCARG(&bsa, s)		= SCARG(uap, s);
    320      1.14  jdolecek 	SCARG(&bsa, buf)	= SCARG(uap, buf);
    321      1.14  jdolecek 	SCARG(&bsa, len)	= SCARG(uap, len);
    322      1.14  jdolecek 	SCARG(&bsa, flags)	= SCARG(uap, flags);
    323      1.14  jdolecek 	SCARG(&bsa, to)		= NULL;
    324      1.14  jdolecek 	SCARG(&bsa, tolen)	= 0;
    325       1.1  christos 
    326      1.14  jdolecek 	return (sys_sendto(p, &bsa, retval));
    327       1.1  christos }
    328       1.1  christos 
    329  1.14.2.1     lukem /*
    330  1.14.2.1     lukem  * Old sendmsg. Arrange necessary structures, call generic code and
    331  1.14.2.1     lukem  * adjust the results accordingly for old code.
    332  1.14.2.1     lukem  */
    333       1.1  christos int
    334       1.3   mycroft compat_43_sys_sendmsg(p, v, retval)
    335       1.1  christos 	struct proc *p;
    336       1.2   thorpej 	void *v;
    337       1.2   thorpej 	register_t *retval;
    338       1.2   thorpej {
    339      1.11  augustss 	struct compat_43_sys_sendmsg_args /* {
    340       1.1  christos 		syscallarg(int) s;
    341       1.1  christos 		syscallarg(caddr_t) msg;
    342       1.1  christos 		syscallarg(int) flags;
    343       1.2   thorpej 	} */ *uap = v;
    344  1.14.2.1     lukem 	struct omsghdr omsg;
    345       1.1  christos 	struct msghdr msg;
    346       1.1  christos 	struct iovec aiov[UIO_SMALLIOV], *iov;
    347       1.1  christos 	int error;
    348  1.14.2.1     lukem 	caddr_t sg = stackgap_init(p->p_emul);
    349       1.1  christos 
    350  1.14.2.1     lukem 	error = copyin(SCARG(uap, msg), (caddr_t)&omsg,
    351       1.5  christos 	    sizeof (struct omsghdr));
    352       1.5  christos 	if (error)
    353       1.1  christos 		return (error);
    354  1.14.2.1     lukem 	if ((u_int)omsg.msg_iovlen > UIO_SMALLIOV) {
    355  1.14.2.1     lukem 		if ((u_int)omsg.msg_iovlen > IOV_MAX)
    356       1.1  christos 			return (EMSGSIZE);
    357  1.14.2.1     lukem 		iov = malloc(sizeof(struct iovec) * omsg.msg_iovlen,
    358  1.14.2.1     lukem 		    M_IOV, M_WAITOK);
    359       1.1  christos 	} else
    360       1.1  christos 		iov = aiov;
    361  1.14.2.1     lukem 	error = copyin((caddr_t)omsg.msg_iov, (caddr_t)iov,
    362  1.14.2.1     lukem 	    (unsigned)(omsg.msg_iovlen * sizeof (struct iovec)));
    363       1.5  christos 	if (error)
    364       1.1  christos 		goto done;
    365  1.14.2.1     lukem 
    366  1.14.2.1     lukem 	if (omsg.msg_name) {
    367  1.14.2.1     lukem 		struct osockaddr *osa;
    368  1.14.2.1     lukem 		struct sockaddr *sa, *usa;
    369  1.14.2.1     lukem 
    370  1.14.2.1     lukem 		if ((u_int) omsg.msg_namelen > UCHAR_MAX)
    371  1.14.2.1     lukem 			return (EINVAL);
    372  1.14.2.1     lukem 
    373  1.14.2.1     lukem 		osa = malloc(omsg.msg_namelen, M_TEMP, M_WAITOK);
    374  1.14.2.1     lukem 
    375  1.14.2.1     lukem 		if ((error = copyin(omsg.msg_name, osa, omsg.msg_namelen))) {
    376  1.14.2.1     lukem 			free(osa, M_TEMP);
    377  1.14.2.1     lukem 			return (error);
    378  1.14.2.1     lukem 		}
    379  1.14.2.1     lukem 
    380  1.14.2.1     lukem 		sa = (struct sockaddr *) osa;
    381  1.14.2.1     lukem 		sa->sa_family = osa->sa_family;
    382  1.14.2.1     lukem 		sa->sa_len = omsg.msg_namelen;
    383  1.14.2.1     lukem 
    384  1.14.2.1     lukem 		usa = stackgap_alloc(&sg, omsg.msg_namelen);
    385  1.14.2.1     lukem 		if (!usa) {
    386  1.14.2.1     lukem 			free(osa, M_TEMP);
    387  1.14.2.1     lukem 			return (ENOMEM);
    388  1.14.2.1     lukem 		}
    389  1.14.2.1     lukem 
    390  1.14.2.1     lukem 		(void) copyout(sa, usa, omsg.msg_namelen);
    391  1.14.2.1     lukem 		free(osa, M_TEMP);
    392  1.14.2.1     lukem 
    393  1.14.2.1     lukem 		msg.msg_name = usa;
    394  1.14.2.1     lukem 		msg.msg_namelen = omsg.msg_namelen;
    395  1.14.2.1     lukem 	} else {
    396  1.14.2.1     lukem 		msg.msg_name = NULL;
    397  1.14.2.1     lukem 		msg.msg_namelen = 0;
    398  1.14.2.1     lukem 	}
    399  1.14.2.1     lukem 	msg.msg_iovlen	= omsg.msg_iovlen;
    400  1.14.2.1     lukem 	msg.msg_iov	= iov;
    401  1.14.2.1     lukem 	msg.msg_flags	= 0;
    402  1.14.2.1     lukem 
    403  1.14.2.1     lukem 	if (omsg.msg_accrights && omsg.msg_accrightslen != 0) {
    404  1.14.2.1     lukem 		struct cmsghdr *cmsg, *ucmsg;
    405  1.14.2.1     lukem 
    406  1.14.2.1     lukem 		/* it was this way in 4.4BSD */
    407  1.14.2.1     lukem 		if ((u_int) omsg.msg_accrightslen > MLEN)
    408  1.14.2.1     lukem 			return (EINVAL);
    409  1.14.2.1     lukem 
    410  1.14.2.1     lukem 		cmsg = malloc(CMSG_SPACE(omsg.msg_accrightslen), M_TEMP,
    411  1.14.2.1     lukem 		    M_WAITOK);
    412  1.14.2.1     lukem 		cmsg->cmsg_len		= CMSG_SPACE(omsg.msg_accrightslen);
    413  1.14.2.1     lukem 		cmsg->cmsg_level	= SOL_SOCKET;
    414  1.14.2.1     lukem 		cmsg->cmsg_type 	= SCM_RIGHTS;
    415  1.14.2.1     lukem 
    416  1.14.2.1     lukem 		error = copyin(omsg.msg_accrights, CMSG_DATA(cmsg),
    417  1.14.2.1     lukem 		    omsg.msg_accrightslen);
    418  1.14.2.1     lukem 		if (error) {
    419  1.14.2.1     lukem 			free(cmsg, M_TEMP);
    420  1.14.2.1     lukem 			return (error);
    421  1.14.2.1     lukem 		}
    422  1.14.2.1     lukem 
    423  1.14.2.1     lukem 		ucmsg = stackgap_alloc(&sg, CMSG_SPACE(omsg.msg_accrightslen));
    424  1.14.2.1     lukem 		if (!ucmsg) {
    425  1.14.2.1     lukem 			free(cmsg, M_TEMP);
    426  1.14.2.1     lukem 			return (EMSGSIZE);
    427  1.14.2.1     lukem 		}
    428  1.14.2.1     lukem 
    429  1.14.2.1     lukem 		(void) copyout(cmsg, ucmsg, CMSG_SPACE(omsg.msg_accrightslen));
    430  1.14.2.1     lukem 		free(cmsg, M_TEMP);
    431  1.14.2.1     lukem 
    432  1.14.2.1     lukem 		msg.msg_control = ucmsg;
    433  1.14.2.1     lukem 		msg.msg_controllen = CMSG_SPACE(omsg.msg_accrightslen);
    434  1.14.2.1     lukem 	} else {
    435  1.14.2.1     lukem 		msg.msg_control = NULL;
    436  1.14.2.1     lukem 		msg.msg_controllen = 0;
    437  1.14.2.1     lukem 	}
    438  1.14.2.1     lukem 
    439      1.13  jdolecek 	error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
    440       1.1  christos done:
    441       1.1  christos 	if (iov != aiov)
    442       1.1  christos 		FREE(iov, M_IOV);
    443       1.1  christos 	return (error);
    444  1.14.2.1     lukem }
    445  1.14.2.1     lukem 
    446  1.14.2.1     lukem static int
    447  1.14.2.1     lukem compat_43_sa_put(from)
    448  1.14.2.1     lukem 	caddr_t from;
    449  1.14.2.1     lukem {
    450  1.14.2.1     lukem 	struct osockaddr *osa = (struct osockaddr *) from;
    451  1.14.2.1     lukem 	struct sockaddr sa;
    452  1.14.2.1     lukem 	struct osockaddr *kosa;
    453  1.14.2.1     lukem 	int error, len;
    454  1.14.2.1     lukem 
    455  1.14.2.1     lukem 	/*
    456  1.14.2.1     lukem 	 * Only read/write the sockaddr family and length, the rest is
    457  1.14.2.1     lukem 	 * not changed.
    458  1.14.2.1     lukem 	 */
    459  1.14.2.1     lukem 	len = sizeof(sa.sa_len) + sizeof(sa.sa_family);
    460  1.14.2.1     lukem 
    461  1.14.2.1     lukem 	error = copyin((caddr_t) osa, (caddr_t) &sa, len);
    462  1.14.2.1     lukem 	if (error)
    463  1.14.2.1     lukem 		return (error);
    464  1.14.2.1     lukem 
    465  1.14.2.1     lukem 	/* Note: we convert from sockaddr sa_family to osockaddr one here */
    466  1.14.2.1     lukem 	kosa = (struct osockaddr *) &sa;
    467  1.14.2.1     lukem 	kosa->sa_family = sa.sa_family;
    468  1.14.2.1     lukem 	error = copyout(kosa, osa, len);
    469  1.14.2.1     lukem 	if (error)
    470  1.14.2.1     lukem 		return (error);
    471  1.14.2.1     lukem 
    472  1.14.2.1     lukem 	return (0);
    473       1.1  christos }
    474