Home | History | Annotate | Line # | Download | only in common
uipc_syscalls_43.c revision 1.22
      1  1.22       agc /*	$NetBSD: uipc_syscalls_43.c,v 1.22 2003/08/07 16:30:36 agc 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.22       agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1  christos  *    may be used to endorse or promote products derived from this software
     17   1.1  christos  *    without specific prior written permission.
     18   1.1  christos  *
     19   1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1  christos  * SUCH DAMAGE.
     30   1.1  christos  *
     31   1.1  christos  *	@(#)uipc_syscalls.c	8.4 (Berkeley) 2/21/94
     32   1.1  christos  */
     33  1.17     lukem 
     34  1.17     lukem #include <sys/cdefs.h>
     35  1.22       agc __KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_43.c,v 1.22 2003/08/07 16:30:36 agc Exp $");
     36   1.1  christos 
     37   1.1  christos #include <sys/param.h>
     38   1.1  christos #include <sys/systm.h>
     39   1.1  christos #include <sys/filedesc.h>
     40   1.1  christos #include <sys/kernel.h>
     41   1.1  christos #include <sys/proc.h>
     42   1.1  christos #include <sys/file.h>
     43   1.1  christos #include <sys/socket.h>
     44   1.1  christos #include <sys/socketvar.h>
     45   1.1  christos #include <sys/stat.h>
     46   1.1  christos #include <sys/ioctl.h>
     47   1.1  christos #include <sys/fcntl.h>
     48   1.1  christos #include <sys/malloc.h>
     49   1.1  christos #include <sys/syslog.h>
     50   1.1  christos #include <sys/unistd.h>
     51   1.1  christos #include <sys/resourcevar.h>
     52  1.15  jdolecek #include <sys/mbuf.h>		/* for MLEN */
     53   1.1  christos 
     54   1.1  christos #include <sys/mount.h>
     55  1.19   thorpej #include <sys/sa.h>
     56   1.1  christos #include <sys/syscallargs.h>
     57   1.1  christos 
     58  1.15  jdolecek #include <compat/common/compat_util.h>
     59  1.15  jdolecek 
     60  1.15  jdolecek #include <uvm/uvm_extern.h>
     61  1.15  jdolecek 
     62  1.15  jdolecek /*
     63  1.15  jdolecek  * Following 4.3 syscalls were not versioned, even through they should
     64  1.15  jdolecek  * have been:
     65  1.15  jdolecek  * connect(2), bind(2), sendto(2)
     66  1.15  jdolecek  */
     67  1.15  jdolecek 
     68  1.15  jdolecek static int compat_43_sa_put(caddr_t);
     69  1.15  jdolecek 
     70   1.1  christos int
     71  1.19   thorpej compat_43_sys_accept(struct lwp *l, void *v, register_t *retval)
     72   1.2   thorpej {
     73  1.15  jdolecek 	struct compat_43_sys_accept_args /* {
     74   1.1  christos 		syscallarg(int) s;
     75   1.1  christos 		syscallarg(caddr_t) name;
     76   1.1  christos 		syscallarg(int *) anamelen;
     77   1.2   thorpej 	} */ *uap = v;
     78   1.1  christos 	int error;
     79   1.1  christos 
     80  1.19   thorpej 	if ((error = sys_accept(l, v, retval)) != 0)
     81   1.1  christos 		return error;
     82   1.1  christos 
     83  1.15  jdolecek 	if (SCARG(uap, name)
     84  1.15  jdolecek 	    && (error = compat_43_sa_put(SCARG(uap, name))))
     85  1.15  jdolecek 		return (error);
     86   1.1  christos 
     87   1.1  christos 	return 0;
     88   1.1  christos }
     89   1.1  christos 
     90   1.1  christos int
     91  1.19   thorpej compat_43_sys_getpeername(struct lwp *l, void *v, register_t *retval)
     92   1.2   thorpej {
     93  1.15  jdolecek 	struct compat_43_sys_getpeername_args /* {
     94   1.1  christos 		syscallarg(int) fdes;
     95   1.1  christos 		syscallarg(caddr_t) asa;
     96   1.1  christos 		syscallarg(int *) alen;
     97   1.2   thorpej 	} */ *uap = v;
     98   1.1  christos 
     99   1.1  christos 	int error;
    100   1.1  christos 
    101  1.19   thorpej 	if ((error = sys_getpeername(l, v, retval)) != 0)
    102   1.1  christos 		return error;
    103   1.1  christos 
    104  1.15  jdolecek 	if ((error = compat_43_sa_put(SCARG(uap, asa))))
    105  1.15  jdolecek 		return (error);
    106   1.1  christos 
    107   1.1  christos 	return 0;
    108   1.1  christos }
    109   1.1  christos 
    110   1.1  christos int
    111  1.19   thorpej compat_43_sys_getsockname(struct lwp *l, void *v, register_t *retval)
    112   1.2   thorpej {
    113  1.15  jdolecek 	struct compat_43_sys_getsockname_args /* {
    114   1.1  christos 		syscallarg(int) fdes;
    115   1.1  christos 		syscallarg(caddr_t) asa;
    116   1.1  christos 		syscallarg(int *) alen;
    117   1.2   thorpej 	} */ *uap = v;
    118   1.1  christos 	int error;
    119   1.1  christos 
    120  1.19   thorpej 	if ((error = sys_getsockname(l, v, retval)) != 0)
    121   1.1  christos 		return error;
    122   1.1  christos 
    123  1.15  jdolecek 	if ((error = compat_43_sa_put(SCARG(uap, asa))))
    124  1.15  jdolecek 		return (error);
    125   1.1  christos 
    126   1.1  christos 	return 0;
    127   1.1  christos }
    128   1.1  christos 
    129   1.1  christos int
    130  1.19   thorpej compat_43_sys_recv(struct lwp *l, void *v, register_t *retval)
    131   1.2   thorpej {
    132  1.11  augustss 	struct compat_43_sys_recv_args /* {
    133   1.1  christos 		syscallarg(int) s;
    134   1.1  christos 		syscallarg(caddr_t) buf;
    135   1.1  christos 		syscallarg(int) len;
    136   1.1  christos 		syscallarg(int) flags;
    137   1.2   thorpej 	} */ *uap = v;
    138  1.14  jdolecek 	struct sys_recvfrom_args bra;
    139  1.14  jdolecek 
    140  1.14  jdolecek 	SCARG(&bra, s) = SCARG(uap, s);
    141  1.14  jdolecek 	SCARG(&bra, buf) = SCARG(uap, buf);
    142  1.14  jdolecek 	SCARG(&bra, len) = (size_t) SCARG(uap, len);
    143  1.14  jdolecek 	SCARG(&bra, flags) = SCARG(uap, flags);
    144  1.14  jdolecek 	SCARG(&bra, from) = NULL;
    145  1.14  jdolecek 	SCARG(&bra, fromlenaddr) = NULL;
    146   1.1  christos 
    147  1.19   thorpej 	return (sys_recvfrom(l, &bra, retval));
    148   1.1  christos }
    149   1.1  christos 
    150   1.1  christos int
    151  1.19   thorpej compat_43_sys_recvfrom(struct lwp *l, void *v, register_t *retval)
    152   1.2   thorpej {
    153  1.15  jdolecek 	struct compat_43_sys_recvfrom_args /* {
    154   1.1  christos 		syscallarg(int) s;
    155   1.1  christos 		syscallarg(caddr_t) buf;
    156   1.1  christos 		syscallarg(size_t) len;
    157   1.1  christos 		syscallarg(int) flags;
    158   1.1  christos 		syscallarg(caddr_t) from;
    159   1.1  christos 		syscallarg(int *) fromlenaddr;
    160   1.2   thorpej 	} */ *uap = v;
    161  1.15  jdolecek 	int error;
    162  1.15  jdolecek 
    163  1.19   thorpej 	if ((error = sys_recvfrom(l, v, retval)))
    164  1.15  jdolecek 		return (error);
    165  1.15  jdolecek 
    166  1.15  jdolecek 	if (SCARG(uap, from) && (error = compat_43_sa_put(SCARG(uap, from))))
    167  1.15  jdolecek 		return (error);
    168   1.1  christos 
    169  1.15  jdolecek 	return (0);
    170   1.1  christos }
    171   1.1  christos 
    172   1.1  christos /*
    173  1.15  jdolecek  * Old recvmsg. Arrange necessary structures, calls generic code and
    174  1.15  jdolecek  * adjusts results accordingly.
    175   1.1  christos  */
    176   1.1  christos int
    177  1.19   thorpej compat_43_sys_recvmsg(struct lwp *l, void *v, register_t *retval)
    178   1.2   thorpej {
    179  1.11  augustss 	struct compat_43_sys_recvmsg_args /* {
    180   1.1  christos 		syscallarg(int) s;
    181   1.1  christos 		syscallarg(struct omsghdr *) msg;
    182   1.1  christos 		syscallarg(int) flags;
    183   1.2   thorpej 	} */ *uap = v;
    184  1.19   thorpej 	struct proc *p = l->l_proc;
    185  1.15  jdolecek 	struct omsghdr omsg;
    186   1.1  christos 	struct msghdr msg;
    187   1.1  christos 	struct iovec aiov[UIO_SMALLIOV], *iov;
    188   1.1  christos 	int error;
    189   1.1  christos 
    190  1.15  jdolecek 	error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&omsg,
    191   1.5  christos 	    sizeof (struct omsghdr));
    192   1.5  christos 	if (error)
    193   1.1  christos 		return (error);
    194  1.15  jdolecek 	if ((u_int)omsg.msg_iovlen > UIO_SMALLIOV) {
    195  1.15  jdolecek 		if ((u_int)omsg.msg_iovlen > IOV_MAX)
    196   1.1  christos 			return (EMSGSIZE);
    197  1.15  jdolecek 		iov = malloc(sizeof(struct iovec) * omsg.msg_iovlen,
    198  1.15  jdolecek 		    M_IOV, M_WAITOK);
    199   1.1  christos 	} else
    200   1.1  christos 		iov = aiov;
    201  1.15  jdolecek 
    202  1.15  jdolecek 	error = copyin((caddr_t)omsg.msg_iov, (caddr_t)iov,
    203  1.15  jdolecek 	    (unsigned)(omsg.msg_iovlen * sizeof (struct iovec)));
    204   1.5  christos 	if (error)
    205   1.1  christos 		goto done;
    206  1.15  jdolecek 
    207  1.15  jdolecek 	msg.msg_name	= omsg.msg_name;
    208  1.15  jdolecek 	msg.msg_namelen = omsg.msg_namelen;
    209  1.15  jdolecek 	msg.msg_iovlen	= omsg.msg_iovlen;
    210  1.15  jdolecek 	msg.msg_iov	= iov;
    211  1.15  jdolecek 	msg.msg_flags	= SCARG(uap, flags);
    212  1.15  jdolecek 
    213  1.15  jdolecek 	/*
    214  1.15  jdolecek 	 * If caller passes accrights, arrange things for generic code to
    215  1.15  jdolecek 	 * DTRT.
    216  1.15  jdolecek 	 */
    217  1.15  jdolecek 	if (omsg.msg_accrights && omsg.msg_accrightslen) {
    218  1.18  christos 		caddr_t sg = stackgap_init(p, 0);
    219  1.15  jdolecek 		struct cmsg *ucmsg;
    220  1.15  jdolecek 
    221  1.15  jdolecek 		/* it was this way in 4.4BSD */
    222  1.15  jdolecek 		if ((u_int) omsg.msg_accrightslen > MLEN)
    223  1.15  jdolecek 			return (EINVAL);
    224  1.15  jdolecek 
    225  1.18  christos 		ucmsg = stackgap_alloc(p, &sg, CMSG_SPACE(omsg.msg_accrightslen));
    226  1.15  jdolecek 		if (ucmsg == NULL)
    227  1.16  jdolecek 			return (EMSGSIZE);
    228  1.15  jdolecek 
    229  1.15  jdolecek 		msg.msg_control = ucmsg;
    230  1.15  jdolecek 		msg.msg_controllen = CMSG_SPACE(omsg.msg_accrightslen);
    231  1.15  jdolecek 	} else {
    232  1.15  jdolecek 		msg.msg_control = NULL;
    233  1.15  jdolecek 		msg.msg_controllen = 0;
    234  1.15  jdolecek 	}
    235  1.15  jdolecek 
    236  1.21      fvdl 	error = recvit(p, SCARG(uap, s), &msg,
    237  1.13  jdolecek 	    (caddr_t)&SCARG(uap, msg)->msg_namelen, retval);
    238   1.1  christos 
    239  1.15  jdolecek 	/*
    240  1.15  jdolecek 	 * If there is any control information and it's SCM_RIGHTS,
    241  1.15  jdolecek 	 * pass it back to the program.
    242  1.15  jdolecek 	 */
    243  1.15  jdolecek 	if (!error && omsg.msg_accrights && msg.msg_controllen > 0) {
    244  1.15  jdolecek 		struct cmsghdr *cmsg;
    245  1.15  jdolecek 
    246  1.16  jdolecek 		/* safe - msg.msg_controllen set by kernel */
    247  1.15  jdolecek 		cmsg = (struct cmsghdr *) malloc(msg.msg_controllen,
    248  1.15  jdolecek 		    M_TEMP, M_WAITOK);
    249  1.15  jdolecek 
    250  1.15  jdolecek 		error = copyin(msg.msg_control, cmsg, msg.msg_controllen);
    251  1.15  jdolecek 		if (error) {
    252  1.15  jdolecek 			free(cmsg, M_TEMP);
    253  1.15  jdolecek 			return (error);
    254  1.15  jdolecek 		}
    255  1.15  jdolecek 
    256  1.15  jdolecek 		if (cmsg->cmsg_level != SOL_SOCKET
    257  1.15  jdolecek 		    || cmsg->cmsg_type != SCM_RIGHTS
    258  1.15  jdolecek 		    || copyout(CMSG_DATA(cmsg), omsg.msg_accrights,
    259  1.15  jdolecek 			    cmsg->cmsg_len)) {
    260  1.15  jdolecek 			omsg.msg_accrightslen = 0;
    261  1.15  jdolecek 		}
    262  1.15  jdolecek 
    263  1.15  jdolecek 		free(cmsg, M_TEMP);
    264  1.15  jdolecek 
    265  1.15  jdolecek 		if (!error) {
    266  1.15  jdolecek 			error = copyout(&cmsg->cmsg_len,
    267  1.15  jdolecek 			    &SCARG(uap, msg)->msg_accrightslen, sizeof(int));
    268  1.15  jdolecek 		}
    269  1.15  jdolecek 	}
    270  1.15  jdolecek 
    271  1.15  jdolecek 	if (!error && omsg.msg_name) {
    272  1.15  jdolecek 		int namelen;
    273  1.15  jdolecek 
    274  1.15  jdolecek 		if ((error = copyin(&SCARG(uap, msg)->msg_namelen, &namelen, sizeof(int)) == 0)
    275  1.15  jdolecek 		    && namelen > 0)
    276  1.15  jdolecek 			error = compat_43_sa_put(omsg.msg_name);
    277  1.15  jdolecek 	}
    278  1.15  jdolecek 
    279   1.1  christos done:
    280   1.1  christos 	if (iov != aiov)
    281  1.15  jdolecek 		free(iov, M_IOV);
    282   1.1  christos 	return (error);
    283   1.1  christos }
    284   1.1  christos 
    285   1.1  christos int
    286  1.19   thorpej compat_43_sys_send(struct lwp *l, void *v, register_t *retval)
    287   1.2   thorpej {
    288  1.11  augustss 	struct compat_43_sys_send_args /* {
    289   1.1  christos 		syscallarg(int) s;
    290   1.1  christos 		syscallarg(caddr_t) buf;
    291   1.1  christos 		syscallarg(int) len;
    292   1.1  christos 		syscallarg(int) flags;
    293   1.2   thorpej 	} */ *uap = v;
    294  1.14  jdolecek 	struct sys_sendto_args bsa;
    295  1.14  jdolecek 
    296  1.14  jdolecek 	SCARG(&bsa, s)		= SCARG(uap, s);
    297  1.14  jdolecek 	SCARG(&bsa, buf)	= SCARG(uap, buf);
    298  1.14  jdolecek 	SCARG(&bsa, len)	= SCARG(uap, len);
    299  1.14  jdolecek 	SCARG(&bsa, flags)	= SCARG(uap, flags);
    300  1.14  jdolecek 	SCARG(&bsa, to)		= NULL;
    301  1.14  jdolecek 	SCARG(&bsa, tolen)	= 0;
    302   1.1  christos 
    303  1.19   thorpej 	return (sys_sendto(l, &bsa, retval));
    304   1.1  christos }
    305   1.1  christos 
    306  1.15  jdolecek /*
    307  1.15  jdolecek  * Old sendmsg. Arrange necessary structures, call generic code and
    308  1.15  jdolecek  * adjust the results accordingly for old code.
    309  1.15  jdolecek  */
    310   1.1  christos int
    311  1.19   thorpej compat_43_sys_sendmsg(struct lwp *l, void *v, register_t *retval)
    312   1.2   thorpej {
    313  1.11  augustss 	struct compat_43_sys_sendmsg_args /* {
    314   1.1  christos 		syscallarg(int) s;
    315   1.1  christos 		syscallarg(caddr_t) msg;
    316   1.1  christos 		syscallarg(int) flags;
    317   1.2   thorpej 	} */ *uap = v;
    318  1.19   thorpej 	struct proc *p = l->l_proc;
    319  1.15  jdolecek 	struct omsghdr omsg;
    320   1.1  christos 	struct msghdr msg;
    321   1.1  christos 	struct iovec aiov[UIO_SMALLIOV], *iov;
    322   1.1  christos 	int error;
    323  1.18  christos 	caddr_t sg = stackgap_init(p, 0);
    324   1.1  christos 
    325  1.15  jdolecek 	error = copyin(SCARG(uap, msg), (caddr_t)&omsg,
    326   1.5  christos 	    sizeof (struct omsghdr));
    327   1.5  christos 	if (error)
    328   1.1  christos 		return (error);
    329  1.15  jdolecek 	if ((u_int)omsg.msg_iovlen > UIO_SMALLIOV) {
    330  1.15  jdolecek 		if ((u_int)omsg.msg_iovlen > IOV_MAX)
    331   1.1  christos 			return (EMSGSIZE);
    332  1.15  jdolecek 		iov = malloc(sizeof(struct iovec) * omsg.msg_iovlen,
    333  1.15  jdolecek 		    M_IOV, M_WAITOK);
    334   1.1  christos 	} else
    335   1.1  christos 		iov = aiov;
    336  1.15  jdolecek 	error = copyin((caddr_t)omsg.msg_iov, (caddr_t)iov,
    337  1.15  jdolecek 	    (unsigned)(omsg.msg_iovlen * sizeof (struct iovec)));
    338   1.5  christos 	if (error)
    339   1.1  christos 		goto done;
    340  1.15  jdolecek 
    341  1.15  jdolecek 	if (omsg.msg_name) {
    342  1.15  jdolecek 		struct osockaddr *osa;
    343  1.15  jdolecek 		struct sockaddr *sa, *usa;
    344  1.15  jdolecek 
    345  1.15  jdolecek 		if ((u_int) omsg.msg_namelen > UCHAR_MAX)
    346  1.15  jdolecek 			return (EINVAL);
    347  1.15  jdolecek 
    348  1.15  jdolecek 		osa = malloc(omsg.msg_namelen, M_TEMP, M_WAITOK);
    349  1.15  jdolecek 
    350  1.15  jdolecek 		if ((error = copyin(omsg.msg_name, osa, omsg.msg_namelen))) {
    351  1.15  jdolecek 			free(osa, M_TEMP);
    352  1.15  jdolecek 			return (error);
    353  1.15  jdolecek 		}
    354  1.15  jdolecek 
    355  1.15  jdolecek 		sa = (struct sockaddr *) osa;
    356  1.15  jdolecek 		sa->sa_family = osa->sa_family;
    357  1.15  jdolecek 		sa->sa_len = omsg.msg_namelen;
    358  1.15  jdolecek 
    359  1.18  christos 		usa = stackgap_alloc(p, &sg, omsg.msg_namelen);
    360  1.15  jdolecek 		if (!usa) {
    361  1.15  jdolecek 			free(osa, M_TEMP);
    362  1.15  jdolecek 			return (ENOMEM);
    363  1.15  jdolecek 		}
    364  1.15  jdolecek 
    365  1.15  jdolecek 		(void) copyout(sa, usa, omsg.msg_namelen);
    366  1.15  jdolecek 		free(osa, M_TEMP);
    367  1.15  jdolecek 
    368  1.15  jdolecek 		msg.msg_name = usa;
    369  1.15  jdolecek 		msg.msg_namelen = omsg.msg_namelen;
    370  1.15  jdolecek 	} else {
    371  1.15  jdolecek 		msg.msg_name = NULL;
    372  1.15  jdolecek 		msg.msg_namelen = 0;
    373  1.15  jdolecek 	}
    374  1.15  jdolecek 	msg.msg_iovlen	= omsg.msg_iovlen;
    375  1.15  jdolecek 	msg.msg_iov	= iov;
    376  1.15  jdolecek 	msg.msg_flags	= 0;
    377  1.15  jdolecek 
    378  1.15  jdolecek 	if (omsg.msg_accrights && omsg.msg_accrightslen != 0) {
    379  1.15  jdolecek 		struct cmsghdr *cmsg, *ucmsg;
    380  1.15  jdolecek 
    381  1.15  jdolecek 		/* it was this way in 4.4BSD */
    382  1.15  jdolecek 		if ((u_int) omsg.msg_accrightslen > MLEN)
    383  1.15  jdolecek 			return (EINVAL);
    384  1.15  jdolecek 
    385  1.15  jdolecek 		cmsg = malloc(CMSG_SPACE(omsg.msg_accrightslen), M_TEMP,
    386  1.15  jdolecek 		    M_WAITOK);
    387  1.15  jdolecek 		cmsg->cmsg_len		= CMSG_SPACE(omsg.msg_accrightslen);
    388  1.15  jdolecek 		cmsg->cmsg_level	= SOL_SOCKET;
    389  1.15  jdolecek 		cmsg->cmsg_type 	= SCM_RIGHTS;
    390  1.15  jdolecek 
    391  1.15  jdolecek 		error = copyin(omsg.msg_accrights, CMSG_DATA(cmsg),
    392  1.15  jdolecek 		    omsg.msg_accrightslen);
    393  1.15  jdolecek 		if (error) {
    394  1.15  jdolecek 			free(cmsg, M_TEMP);
    395  1.15  jdolecek 			return (error);
    396  1.15  jdolecek 		}
    397  1.15  jdolecek 
    398  1.18  christos 		ucmsg = stackgap_alloc(p, &sg, CMSG_SPACE(omsg.msg_accrightslen));
    399  1.15  jdolecek 		if (!ucmsg) {
    400  1.15  jdolecek 			free(cmsg, M_TEMP);
    401  1.16  jdolecek 			return (EMSGSIZE);
    402  1.15  jdolecek 		}
    403  1.15  jdolecek 
    404  1.15  jdolecek 		(void) copyout(cmsg, ucmsg, CMSG_SPACE(omsg.msg_accrightslen));
    405  1.15  jdolecek 		free(cmsg, M_TEMP);
    406  1.15  jdolecek 
    407  1.15  jdolecek 		msg.msg_control = ucmsg;
    408  1.15  jdolecek 		msg.msg_controllen = CMSG_SPACE(omsg.msg_accrightslen);
    409  1.15  jdolecek 	} else {
    410  1.15  jdolecek 		msg.msg_control = NULL;
    411  1.15  jdolecek 		msg.msg_controllen = 0;
    412  1.15  jdolecek 	}
    413  1.15  jdolecek 
    414  1.21      fvdl 	error = sendit(p, SCARG(uap, s), &msg, SCARG(uap, flags), retval);
    415   1.1  christos done:
    416   1.1  christos 	if (iov != aiov)
    417   1.1  christos 		FREE(iov, M_IOV);
    418   1.1  christos 	return (error);
    419  1.15  jdolecek }
    420  1.15  jdolecek 
    421  1.15  jdolecek static int
    422  1.15  jdolecek compat_43_sa_put(from)
    423  1.15  jdolecek 	caddr_t from;
    424  1.15  jdolecek {
    425  1.15  jdolecek 	struct osockaddr *osa = (struct osockaddr *) from;
    426  1.15  jdolecek 	struct sockaddr sa;
    427  1.15  jdolecek 	struct osockaddr *kosa;
    428  1.15  jdolecek 	int error, len;
    429  1.15  jdolecek 
    430  1.15  jdolecek 	/*
    431  1.15  jdolecek 	 * Only read/write the sockaddr family and length, the rest is
    432  1.15  jdolecek 	 * not changed.
    433  1.15  jdolecek 	 */
    434  1.15  jdolecek 	len = sizeof(sa.sa_len) + sizeof(sa.sa_family);
    435  1.15  jdolecek 
    436  1.15  jdolecek 	error = copyin((caddr_t) osa, (caddr_t) &sa, len);
    437  1.15  jdolecek 	if (error)
    438  1.15  jdolecek 		return (error);
    439  1.15  jdolecek 
    440  1.15  jdolecek 	/* Note: we convert from sockaddr sa_family to osockaddr one here */
    441  1.15  jdolecek 	kosa = (struct osockaddr *) &sa;
    442  1.15  jdolecek 	kosa->sa_family = sa.sa_family;
    443  1.15  jdolecek 	error = copyout(kosa, osa, len);
    444  1.15  jdolecek 	if (error)
    445  1.15  jdolecek 		return (error);
    446  1.15  jdolecek 
    447  1.15  jdolecek 	return (0);
    448   1.1  christos }
    449