2 * Copyright (c) 1998 Mark Newton. All rights reserved.
3 * Copyright (c) 1994, 1996 Christos Zoulas. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Christos Zoulas.
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * $FreeBSD: src/sys/svr4/svr4_stream.c,v 1.12.2.2 2000/11/26 04:42:27 dillon Exp $
31 * $DragonFly: src/sys/emulation/svr4/Attic/svr4_stream.c,v 1.19 2006/05/19 07:33:44 dillon Exp $
35 * Pretend that we have streams...
38 * ToDo: The state machine for getmsg needs re-thinking
43 #include <sys/param.h>
44 #include <sys/systm.h>
46 #include <sys/malloc.h>
48 #include <sys/filedesc.h>
49 #include <sys/fcntl.h>
50 #include <sys/filio.h>
51 #include <sys/select.h>
52 #include <sys/socket.h>
53 #include <sys/socketvar.h>
54 #include <sys/socketops.h>
56 #include <netinet/in.h>
58 #include <sys/protosw.h>
59 #include <sys/signal.h>
60 #include <sys/signalvar.h>
62 #include <sys/ktrace.h>
65 #include <sys/file2.h>
67 #include <sys/sysproto.h>
70 #include "svr4_types.h"
71 #include "svr4_util.h"
72 #include "svr4_signal.h"
73 #include "svr4_proto.h"
74 #include "svr4_stropts.h"
75 #include "svr4_timod.h"
76 #include "svr4_sockmod.h"
77 #include "svr4_ioctl.h"
78 #include "svr4_socket.h"
81 static int clean_pipe (const char *);
82 static void getparm (struct file *, struct svr4_si_sockparms *);
84 /* Address Conversions */
85 static void sockaddr_to_netaddr_in (struct svr4_strmcmd *,
86 const struct sockaddr_in *);
87 static void sockaddr_to_netaddr_un (struct svr4_strmcmd *,
88 const struct sockaddr_un *);
89 static void netaddr_to_sockaddr_in (struct sockaddr_in *,
90 const struct svr4_strmcmd *);
91 static void netaddr_to_sockaddr_un (struct sockaddr_un *,
92 const struct svr4_strmcmd *);
95 static int i_nread (struct file *, struct thread *, register_t *, int,
97 static int i_fdinsert (struct file *, struct thread *, register_t *, int,
99 static int i_str (struct file *, struct thread *, register_t *, int,
101 static int i_setsig (struct file *, struct thread *, register_t *, int,
103 static int i_getsig (struct file *, struct thread *, register_t *, int,
105 static int _i_bind_rsvd (struct file *, struct thread *, register_t *, int,
107 static int _i_rele_rsvd (struct file *, struct thread *, register_t *, int,
110 /* i_str sockmod calls */
111 static int sockmod (struct file *, int, struct svr4_strioctl *,
113 static int si_listen (struct file *, int, struct svr4_strioctl *,
115 static int si_ogetudata (struct file *, int, struct svr4_strioctl *,
117 static int si_sockparams (struct file *, int, struct svr4_strioctl *,
119 static int si_shutdown (struct file *, int, struct svr4_strioctl *,
121 static int si_getudata (struct file *, int, struct svr4_strioctl *,
124 /* i_str timod calls */
125 static int timod (struct file *, int, struct svr4_strioctl *,
127 static int ti_getinfo (struct file *, int, struct svr4_strioctl *,
129 static int ti_bind (struct file *, int, struct svr4_strioctl *,
133 static int svr4_sendit (struct thread *td, int s, struct msghdr *mp,
134 int flags, int *retval);
136 static int svr4_recvit (struct thread *td, int s, struct msghdr *mp,
137 caddr_t namelenp, int *retval);
139 /* <sigh> Ok, so we shouldn't use sendit() in uipc_syscalls.c because
140 * it isn't part of a "public" interface; We're supposed to use
141 * pru_sosend instead. Same goes for recvit()/pru_soreceive() for
142 * that matter. Solution: Suck sendit()/recvit() into here where we
143 * can do what we like.
145 * I hate code duplication.
147 * I will take out all the #ifdef COMPAT_OLDSOCK gumph, though.
150 svr4_sendit(struct thread *td, int s, struct msghdr *mp, int flags,
158 struct mbuf *control;
163 struct iovec *ktriov = NULL;
170 error = holdsock(p->p_fd, s, &fp);
173 auio.uio_iov = mp->msg_iov;
174 auio.uio_iovcnt = mp->msg_iovlen;
175 auio.uio_segflg = UIO_USERSPACE;
176 auio.uio_rw = UIO_WRITE;
178 auio.uio_offset = 0; /* XXX */
181 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
182 if ((auio.uio_resid += iov->iov_len) < 0) {
188 error = getsockaddr(&to, mp->msg_name, mp->msg_namelen);
196 if (mp->msg_control) {
197 if (mp->msg_controllen < sizeof(struct cmsghdr)) {
201 control = m_get(MB_WAIT, MT_CONTROL);
202 if (control == NULL) {
206 control->m_len = mp->msg_controllen;
207 error = copyin(mp->msg_control, mtod(control, caddr_t),
217 if (KTRPOINT(p->p_thread, KTR_GENIO)) {
218 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
220 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
221 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
225 len = auio.uio_resid;
226 so = (struct socket *)fp->f_data;
227 error = so_pru_sosend(so, to, &auio, NULL, control, flags, td);
229 if (auio.uio_resid != len && (error == ERESTART ||
230 error == EINTR || error == EWOULDBLOCK))
236 *retval = len - auio.uio_resid;
238 if (ktriov != NULL) {
240 ktruio.uio_iov = ktriov;
241 ktruio.uio_resid = *retval;
242 ktrgenio(p, s, UIO_WRITE, &ktruio, error);
244 FREE(ktriov, M_TEMP);
255 svr4_recvit(struct thread *td, int s, struct msghdr *mp, caddr_t namelenp,
258 struct proc *p = td->td_proc;
264 struct mbuf *m, *control = 0;
267 struct sockaddr *fromsa = 0;
269 struct iovec *ktriov = NULL;
275 error = holdsock(p->p_fd, s, &fp);
278 auio.uio_iov = mp->msg_iov;
279 auio.uio_iovcnt = mp->msg_iovlen;
280 auio.uio_segflg = UIO_USERSPACE;
281 auio.uio_rw = UIO_READ;
283 auio.uio_offset = 0; /* XXX */
286 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
287 if ((auio.uio_resid += iov->iov_len) < 0) {
293 if (KTRPOINT(p->p_thread, KTR_GENIO)) {
294 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
296 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
297 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
301 len = auio.uio_resid;
302 so = (struct socket *)fp->f_data;
303 error = so_pru_soreceive(so, &fromsa, &auio, NULL,
304 mp->msg_control ? &control : NULL, &mp->msg_flags);
306 if (auio.uio_resid != len && (error == ERESTART ||
307 error == EINTR || error == EWOULDBLOCK))
311 if (ktriov != NULL) {
313 ktruio.uio_iov = ktriov;
314 ktruio.uio_resid = len - auio.uio_resid;
315 ktrgenio(p, s, UIO_READ, &ktruio, error);
317 FREE(ktriov, M_TEMP);
322 *retval = len - auio.uio_resid;
324 len = mp->msg_namelen;
325 if (len <= 0 || fromsa == 0)
329 #define MIN(a,b) ((a)>(b)?(b):(a))
331 /* save sa_len before it is destroyed by MSG_COMPAT */
332 len = MIN(len, fromsa->sa_len);
333 error = copyout(fromsa,
334 (caddr_t)mp->msg_name, (unsigned)len);
338 mp->msg_namelen = len;
340 (error = copyout((caddr_t)&len, namelenp, sizeof (int)))) {
344 if (mp->msg_control) {
345 len = mp->msg_controllen;
347 mp->msg_controllen = 0;
348 ctlbuf = (caddr_t) mp->msg_control;
350 while (m && len > 0) {
356 mp->msg_flags |= MSG_CTRUNC;
360 if ((error = copyout((caddr_t)mtod(m, caddr_t),
361 ctlbuf, tocopy)) != 0)
368 mp->msg_controllen = ctlbuf - (caddr_t)mp->msg_control;
372 FREE(fromsa, M_SONAME);
380 static void bufprint (u_char *, size_t);
381 static int show_ioc (const char *, struct svr4_strioctl *);
382 static int show_strbuf (struct svr4_strbuf *);
383 static void show_msg (const char *, int, struct svr4_strbuf *,
384 struct svr4_strbuf *, int);
387 bufprint(u_char *buf, size_t len)
392 for (i = 0; i < len; i++) {
393 uprintf("%x ", buf[i]);
394 if (i && (i % 16) == 0)
400 show_ioc(const char *str, struct svr4_strioctl *ioc)
402 u_char *ptr = (u_char *) malloc(ioc->len, M_TEMP, M_WAITOK);
405 uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ",
406 str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf);
408 if ((error = copyin(ioc->buf, ptr, ioc->len)) != 0) {
409 free((char *) ptr, M_TEMP);
413 bufprint(ptr, ioc->len);
417 free((char *) ptr, M_TEMP);
423 show_strbuf(struct svr4_strbuf *str)
427 int maxlen = str->maxlen;
437 ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK);
439 if ((error = copyin(str->buf, ptr, len)) != 0) {
440 free((char *) ptr, M_TEMP);
445 uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf);
453 free((char *) ptr, M_TEMP);
460 show_msg(const char *str, int fd, struct svr4_strbuf *ctl,
461 struct svr4_strbuf *dat, int flags)
463 struct svr4_strbuf buf;
466 uprintf("%s(%d", str, fd);
468 if ((error = copyin(ctl, &buf, sizeof(buf))) != 0)
476 if ((error = copyin(dat, &buf, sizeof(buf))) != 0)
483 uprintf(", %x);\n", flags);
486 #endif /* DEBUG_SVR4 */
489 * We are faced with an interesting situation. On svr4 unix sockets
490 * are really pipes. But we really have sockets, and we might as
491 * well use them. At the point where svr4 calls TI_BIND, it has
492 * already created a named pipe for the socket using mknod(2).
493 * We need to create a socket with the same name when we bind,
494 * so we need to remove the pipe before, otherwise we'll get address
495 * already in use. So we *carefully* remove the pipe, to avoid
496 * using this as a random file removal tool. We use system calls
497 * to avoid code duplication.
500 clean_pipe(const char *path)
502 struct lstat_args la;
503 struct unlink_args ua;
506 caddr_t sg = stackgap_init();
507 size_t l = strlen(path) + 1;
510 tpath = stackgap_alloc(&sg, l);
511 SCARG(&la, ub) = stackgap_alloc(&sg, sizeof(struct stat));
513 if ((error = copyout(path, tpath, l)) != 0)
516 SCARG(&la, path) = tpath;
518 if ((error = lstat(&la)) != 0)
521 if ((error = copyin(SCARG(&la, ub), &st, sizeof(st))) != 0)
525 * Make sure we are dealing with a mode 0 named pipe.
527 if ((st.st_mode & S_IFMT) != S_IFIFO)
530 if ((st.st_mode & ALLPERMS) != 0)
533 SCARG(&ua, path) = SCARG(&la, path);
535 if ((error = unlink(&ua)) != 0) {
536 DPRINTF(("clean_pipe: unlink failed %d\n", error));
545 sockaddr_to_netaddr_in(struct svr4_strmcmd *sc, const struct sockaddr_in *sain)
547 struct svr4_netaddr_in *na;
548 na = SVR4_ADDROF(sc);
550 na->family = sain->sin_family;
551 na->port = sain->sin_port;
552 na->addr = sain->sin_addr.s_addr;
553 DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port,
559 sockaddr_to_netaddr_un(struct svr4_strmcmd *sc, const struct sockaddr_un *saun)
561 struct svr4_netaddr_un *na;
562 char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 -
566 na = SVR4_ADDROF(sc);
567 na->family = saun->sun_family;
568 for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; )
571 DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path));
576 netaddr_to_sockaddr_in(struct sockaddr_in *sain, const struct svr4_strmcmd *sc)
578 const struct svr4_netaddr_in *na;
581 na = SVR4_C_ADDROF(sc);
582 memset(sain, 0, sizeof(*sain));
583 sain->sin_len = sizeof(*sain);
584 sain->sin_family = na->family;
585 sain->sin_port = na->port;
586 sain->sin_addr.s_addr = na->addr;
587 DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family,
588 sain->sin_port, sain->sin_addr.s_addr));
593 netaddr_to_sockaddr_un(struct sockaddr_un *saun, const struct svr4_strmcmd *sc)
595 const struct svr4_netaddr_un *na;
596 char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1];
599 na = SVR4_C_ADDROF(sc);
600 memset(saun, 0, sizeof(*saun));
601 saun->sun_family = na->family;
602 for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; )
605 saun->sun_len = dst - saun->sun_path;
606 DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family,
612 getparm(struct file *fp, struct svr4_si_sockparms *pa)
614 struct svr4_strm *st = svr4_stream_get(fp);
615 struct socket *so = (struct socket *) fp->f_data;
620 pa->family = st->s_family;
622 switch (so->so_type) {
624 pa->type = SVR4_T_CLTS;
625 pa->protocol = IPPROTO_UDP;
626 DPRINTF(("getparm(dgram)\n"));
630 pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */
631 pa->protocol = IPPROTO_IP;
632 DPRINTF(("getparm(stream)\n"));
636 pa->type = SVR4_T_CLTS;
637 pa->protocol = IPPROTO_RAW;
638 DPRINTF(("getparm(raw)\n"));
644 DPRINTF(("getparm(type %d?)\n", so->so_type));
651 si_ogetudata(struct file *fp, int fd, struct svr4_strioctl *ioc,
655 struct svr4_si_oudata ud;
656 struct svr4_si_sockparms pa;
658 if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) {
659 DPRINTF(("SI_OGETUDATA: Wrong size %d != %d\n",
660 sizeof(ud), ioc->len));
664 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
672 ud.addrsize = sizeof(struct svr4_sockaddr_in);
673 if (pa.type == SVR4_SOCK_STREAM)
686 DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n",
691 /* I have no idea what these should be! */
695 ud.servtype = pa.type;
700 return copyout(&ud, ioc->buf, ioc->len);
705 si_sockparams(struct file *fp, int fd, struct svr4_strioctl *ioc,
708 struct svr4_si_sockparms pa;
711 return copyout(&pa, ioc->buf, sizeof(pa));
716 si_listen(struct file *fp, int fd, struct svr4_strioctl *ioc,
720 struct svr4_strm *st = svr4_stream_get(fp);
721 struct svr4_strmcmd lst;
722 struct listen_args la;
727 if ((error = copyin(ioc->buf, &lst, ioc->len)) != 0)
730 if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) {
731 DPRINTF(("si_listen: bad request %ld\n", lst.cmd));
736 * We are making assumptions again...
739 DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5));
740 SCARG(&la, backlog) = 5;
742 if ((error = listen(&la)) != 0) {
743 DPRINTF(("SI_LISTEN: listen failed %d\n", error));
747 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
748 lst.cmd = SVR4_TI_BIND_REPLY;
750 switch (st->s_family) {
752 /* XXX: Fill the length here */
757 lst.pad[28] = 0x00000000; /* magic again */
758 lst.pad[29] = 0x00000800; /* magic again */
759 lst.pad[30] = 0x80001400; /* magic again */
763 DPRINTF(("SI_LISTEN: Unsupported address family %d\n",
769 if ((error = copyout(&lst, ioc->buf, ioc->len)) != 0)
777 si_getudata(struct file *fp, int fd, struct svr4_strioctl *ioc,
781 struct svr4_si_udata ud;
783 if (sizeof(ud) != ioc->len) {
784 DPRINTF(("SI_GETUDATA: Wrong size %d != %d\n",
785 sizeof(ud), ioc->len));
789 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
792 getparm(fp, &ud.sockparms);
794 switch (ud.sockparms.family) {
796 DPRINTF(("getudata_inet\n"));
799 ud.addrsize = sizeof(struct svr4_sockaddr_in);
800 if (ud.sockparms.type == SVR4_SOCK_STREAM)
808 DPRINTF(("getudata_local\n"));
817 DPRINTF(("SI_GETUDATA: Unsupported address family %d\n",
818 ud.sockparms.family));
823 ud.servtype = ud.sockparms.type;
824 DPRINTF(("ud.servtype = %d\n", ud.servtype));
828 return copyout(&ud, ioc->buf, sizeof(ud));
833 si_shutdown(struct file *fp, int fd, struct svr4_strioctl *ioc,
837 struct shutdown_args ap;
839 if (ioc->len != sizeof(SCARG(&ap, how))) {
840 DPRINTF(("SI_SHUTDOWN: Wrong size %d != %d\n",
841 sizeof(SCARG(&ap, how)), ioc->len));
845 if ((error = copyin(ioc->buf, &SCARG(&ap, how), ioc->len)) != 0)
850 return shutdown(&ap);
855 sockmod(struct file *fp, int fd, struct svr4_strioctl *ioc,
859 case SVR4_SI_OGETUDATA:
860 DPRINTF(("SI_OGETUDATA\n"));
861 return si_ogetudata(fp, fd, ioc, td);
863 case SVR4_SI_SHUTDOWN:
864 DPRINTF(("SI_SHUTDOWN\n"));
865 return si_shutdown(fp, fd, ioc, td);
868 DPRINTF(("SI_LISTEN\n"));
869 return si_listen(fp, fd, ioc, td);
871 case SVR4_SI_SETMYNAME:
872 DPRINTF(("SI_SETMYNAME\n"));
875 case SVR4_SI_SETPEERNAME:
876 DPRINTF(("SI_SETPEERNAME\n"));
879 case SVR4_SI_GETINTRANSIT:
880 DPRINTF(("SI_GETINTRANSIT\n"));
883 case SVR4_SI_TCL_LINK:
884 DPRINTF(("SI_TCL_LINK\n"));
887 case SVR4_SI_TCL_UNLINK:
888 DPRINTF(("SI_TCL_UNLINK\n"));
891 case SVR4_SI_SOCKPARAMS:
892 DPRINTF(("SI_SOCKPARAMS\n"));
893 return si_sockparams(fp, fd, ioc, td);
895 case SVR4_SI_GETUDATA:
896 DPRINTF(("SI_GETUDATA\n"));
897 return si_getudata(fp, fd, ioc, td);
900 DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd));
908 ti_getinfo(struct file *fp, int fd, struct svr4_strioctl *ioc,
912 struct svr4_infocmd info;
914 memset(&info, 0, sizeof(info));
916 if ((error = copyin(ioc->buf, &info, ioc->len)) != 0)
919 if (info.cmd != SVR4_TI_INFO_REQUEST)
922 info.cmd = SVR4_TI_INFO_REPLY;
934 ioc->len = sizeof(info);
935 if ((error = copyout(&info, ioc->buf, ioc->len)) != 0)
943 ti_bind(struct file *fp, int fd, struct svr4_strioctl *ioc,
947 struct svr4_strm *st = svr4_stream_get(fp);
948 struct sockaddr_in sain;
949 struct sockaddr_un saun;
951 void *skp, *sup = NULL;
953 struct svr4_strmcmd bnd;
957 DPRINTF(("ti_bind: bad file descriptor\n"));
961 if ((error = copyin(ioc->buf, &bnd, ioc->len)) != 0)
964 if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) {
965 DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd));
969 switch (st->s_family) {
972 sasize = sizeof(sain);
977 netaddr_to_sockaddr_in(&sain, &bnd);
979 DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n",
980 sain.sin_family, sain.sin_port,
981 sain.sin_addr.s_addr));
986 sasize = sizeof(saun);
990 netaddr_to_sockaddr_un(&saun, &bnd);
992 if (saun.sun_path[0] == '\0')
995 DPRINTF(("TI_BIND: fam %d, path %s\n",
996 saun.sun_family, saun.sun_path));
998 if ((error = clean_pipe(saun.sun_path)) != 0)
1001 bnd.pad[28] = 0x00001000; /* magic again */
1005 DPRINTF(("TI_BIND: Unsupported address family %d\n",
1010 sg = stackgap_init();
1011 sup = stackgap_alloc(&sg, sasize);
1013 if ((error = copyout(skp, sup, sasize)) != 0)
1017 DPRINTF(("TI_BIND: fileno %d\n", fd));
1018 SCARG(&ba, name) = (void *) sup;
1019 SCARG(&ba, namelen) = sasize;
1021 if ((error = bind(&ba)) != 0) {
1022 DPRINTF(("TI_BIND: bind failed %d\n", error));
1028 memset(&bnd, 0, sizeof(bnd));
1029 bnd.len = sasize + 4;
1030 bnd.offs = 0x10; /* XXX */
1033 bnd.cmd = SVR4_TI_BIND_REPLY;
1035 if ((error = copyout(&bnd, ioc->buf, ioc->len)) != 0)
1043 timod(struct file *fp, int fd, struct svr4_strioctl *ioc, struct thread *td)
1046 case SVR4_TI_GETINFO:
1047 DPRINTF(("TI_GETINFO\n"));
1048 return ti_getinfo(fp, fd, ioc, td);
1050 case SVR4_TI_OPTMGMT:
1051 DPRINTF(("TI_OPTMGMT\n"));
1055 DPRINTF(("TI_BIND\n"));
1056 return ti_bind(fp, fd, ioc, td);
1058 case SVR4_TI_UNBIND:
1059 DPRINTF(("TI_UNBIND\n"));
1063 DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd));
1070 svr4_stream_ti_ioctl(struct file *fp, struct thread *td, register_t *retval,
1071 int fd, u_long cmd, caddr_t dat)
1073 struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat;
1074 struct svr4_strm *st = svr4_stream_get(fp);
1077 struct sockaddr_in sain;
1078 struct sockaddr_un saun;
1079 struct svr4_strmcmd sc;
1084 DPRINTF(("svr4_stream_ti_ioctl\n"));
1091 if ((error = copyin(sub, &skb, sizeof(skb))) != 0) {
1092 DPRINTF(("ti_ioctl: error copying in strbuf\n"));
1096 switch (st->s_family) {
1099 sasize = sizeof(sain);
1104 sasize = sizeof(saun);
1108 DPRINTF(("ti_ioctl: Unsupported address family %d\n",
1113 sg = stackgap_init();
1114 sup = stackgap_alloc(&sg, sasize);
1115 lenp = stackgap_alloc(&sg, sizeof(*lenp));
1117 if ((error = copyout(&sasize, lenp, sizeof(*lenp))) != 0) {
1118 DPRINTF(("ti_ioctl: error copying out lenp\n"));
1123 case SVR4_TI_GETMYNAME:
1124 DPRINTF(("TI_GETMYNAME\n"));
1126 struct getsockname_args ap;
1127 SCARG(&ap, fdes) = fd;
1128 SCARG(&ap, asa) = sup;
1129 SCARG(&ap, alen) = lenp;
1130 if ((error = getsockname(&ap)) != 0) {
1131 DPRINTF(("ti_ioctl: getsockname error\n"));
1137 case SVR4_TI_GETPEERNAME:
1138 DPRINTF(("TI_GETPEERNAME\n"));
1140 struct getpeername_args ap;
1141 SCARG(&ap, fdes) = fd;
1142 SCARG(&ap, asa) = sup;
1143 SCARG(&ap, alen) = lenp;
1144 if ((error = getpeername(&ap)) != 0) {
1145 DPRINTF(("ti_ioctl: getpeername error\n"));
1151 case SVR4_TI_SETMYNAME:
1152 DPRINTF(("TI_SETMYNAME\n"));
1155 case SVR4_TI_SETPEERNAME:
1156 DPRINTF(("TI_SETPEERNAME\n"));
1159 DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd));
1163 if ((error = copyin(sup, skp, sasize)) != 0) {
1164 DPRINTF(("ti_ioctl: error copying in socket data\n"));
1168 if ((error = copyin(lenp, &sasize, sizeof(*lenp))) != 0) {
1169 DPRINTF(("ti_ioctl: error copying in socket size\n"));
1173 switch (st->s_family) {
1175 sockaddr_to_netaddr_in(&sc, &sain);
1180 sockaddr_to_netaddr_un(&sc, &saun);
1181 skb.len = sasize + 4;
1189 if ((error = copyout(SVR4_ADDROF(&sc), skb.buf, sasize)) != 0) {
1190 DPRINTF(("ti_ioctl: error copying out socket data\n"));
1195 if ((error = copyout(&skb, sub, sizeof(skb))) != 0) {
1196 DPRINTF(("ti_ioctl: error copying out strbuf\n"));
1207 i_nread(struct file *fp, struct thread *td, register_t *retval,
1208 int fd, u_long cmd, caddr_t dat)
1212 struct ucred *cred = curproc->p_ucred;
1215 * We are supposed to return the message length in nread, and the
1216 * number of messages in retval. We don't have the notion of number
1217 * of stream messages, so we just find out if we have any bytes waiting
1218 * for us, and if we do, then we assume that we have at least one
1219 * message waiting for us.
1221 if ((error = fo_ioctl(fp, FIONREAD, (caddr_t) &nread, cred)) != 0)
1229 return copyout(&nread, dat, sizeof(nread));
1233 i_fdinsert(struct file *fp, struct thread *td, register_t *retval,
1234 int fd, u_long cmd, caddr_t dat)
1237 * Major hack again here. We assume that we are using this to
1238 * implement accept(2). If that is the case, we have already
1239 * called accept, and we have stored the file descriptor in
1240 * afd. We find the file descriptor that the code wants to use
1241 * in fd insert, and then we dup2() our accepted file descriptor
1245 struct svr4_strm *st = svr4_stream_get(fp);
1246 struct svr4_strfdinsert fdi;
1247 struct dup2_args d2p;
1248 struct close_args clp;
1251 DPRINTF(("fdinsert: bad file type\n"));
1255 if (st->s_afd == -1) {
1256 DPRINTF(("fdinsert: accept fd not found\n"));
1260 if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) {
1261 DPRINTF(("fdinsert: copyin failed %d\n", error));
1265 SCARG(&d2p, from) = st->s_afd;
1266 SCARG(&d2p, to) = fdi.fd;
1268 if ((error = dup2(&d2p)) != 0) {
1269 DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n",
1270 st->s_afd, fdi.fd, error));
1274 SCARG(&clp, fd) = st->s_afd;
1276 if ((error = close(&clp)) != 0) {
1277 DPRINTF(("fdinsert: close(%d) failed %d\n",
1290 _i_bind_rsvd(struct file *fp, struct thread *td, register_t *retval,
1291 int fd, u_long cmd, caddr_t dat)
1293 struct mkfifo_args ap;
1296 * This is a supposed to be a kernel and library only ioctl.
1297 * It gets called before ti_bind, when we have a unix
1298 * socket, to physically create the socket transport and
1299 * ``reserve'' it. I don't know how this get reserved inside
1300 * the kernel, but we are going to create it nevertheless.
1302 SCARG(&ap, path) = dat;
1303 SCARG(&ap, mode) = S_IFIFO;
1309 _i_rele_rsvd(struct file *fp, struct thread *td, register_t *retval,
1310 int fd, u_long cmd, caddr_t dat)
1312 struct unlink_args ap;
1315 * This is a supposed to be a kernel and library only ioctl.
1316 * I guess it is supposed to release the socket.
1318 SCARG(&ap, path) = dat;
1324 i_str(struct file *fp, struct thread *td, register_t *retval,
1325 int fd, u_long cmd, caddr_t dat)
1328 struct svr4_strioctl ioc;
1330 if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0)
1334 if ((error = show_ioc(">", &ioc)) != 0)
1336 #endif /* DEBUG_SVR4 */
1338 switch (ioc.cmd & 0xff00) {
1340 if ((error = sockmod(fp, fd, &ioc, td)) != 0)
1345 if ((error = timod(fp, fd, &ioc, td)) != 0)
1350 DPRINTF(("Unimplemented module %c %ld\n",
1351 (char) (cmd >> 8), cmd & 0xff));
1356 if ((error = show_ioc("<", &ioc)) != 0)
1358 #endif /* DEBUG_SVR4 */
1359 return copyout(&ioc, dat, sizeof(ioc));
1363 i_setsig(struct file *fp, struct thread *td, register_t *retval,
1364 int fd, u_long cmd, caddr_t dat)
1367 * This is the best we can do for now; we cannot generate
1368 * signals only for specific events so the signal mask gets
1369 * ignored; we save it just to pass it to a possible I_GETSIG...
1371 * We alse have to fix the O_ASYNC fcntl bit, so the
1372 * process will get SIGPOLLs.
1374 struct proc *p = td->td_proc;
1375 struct fcntl_args fa;
1377 register_t oflags, flags;
1378 struct svr4_strm *st = svr4_stream_get(fp);
1383 DPRINTF(("i_setsig: bad file descriptor\n"));
1386 /* get old status flags */
1387 SCARG(&fa, fd) = fd;
1388 SCARG(&fa, cmd) = F_GETFL;
1389 if ((error = fcntl(&fa)) != 0)
1392 oflags = fa.sysmsg_result;
1394 /* update the flags */
1398 flags = oflags | O_ASYNC;
1399 if ((error = copyin(dat, &mask, sizeof(mask))) != 0) {
1400 DPRINTF(("i_setsig: bad eventmask pointer\n"));
1403 if (mask & SVR4_S_ALLMASK) {
1404 DPRINTF(("i_setsig: bad eventmask data %x\n", mask));
1407 st->s_eventmask = mask;
1410 flags = oflags & ~O_ASYNC;
1411 st->s_eventmask = 0;
1414 /* set the new flags, if changed */
1415 if (flags != oflags) {
1416 SCARG(&fa, cmd) = F_SETFL;
1417 SCARG(&fa, arg) = (long) flags;
1418 if ((error = fcntl(&fa)) != 0)
1420 flags =fa.sysmsg_result;
1423 /* set up SIGIO receiver if needed */
1425 SCARG(&fa, cmd) = F_SETOWN;
1426 SCARG(&fa, arg) = (long) p->p_pid;
1428 *retval = fa.sysmsg_result;
1431 *retval = fa.sysmsg_result;
1436 i_getsig(struct file *fp, struct thread *td, register_t *retval,
1437 int fd, u_long cmd, caddr_t dat)
1442 struct svr4_strm *st = svr4_stream_get(fp);
1445 DPRINTF(("i_getsig: bad file descriptor\n"));
1448 if ((error = copyout(&st->s_eventmask, dat,
1449 sizeof(st->s_eventmask))) != 0) {
1450 DPRINTF(("i_getsig: bad eventmask pointer\n"));
1458 svr4_stream_ioctl(struct file *fp, struct thread *td, register_t *retval,
1459 int fd, u_long cmd, caddr_t dat)
1464 * All the following stuff assumes "sockmod" is pushed...
1468 DPRINTF(("I_NREAD\n"));
1469 return i_nread(fp, td, retval, fd, cmd, dat);
1472 DPRINTF(("I_PUSH %p\n", dat));
1473 #if defined(DEBUG_SVR4)
1474 show_strbuf((void *)dat);
1479 DPRINTF(("I_POP\n"));
1483 DPRINTF(("I_LOOK\n"));
1487 DPRINTF(("I_FLUSH\n"));
1491 DPRINTF(("I_SRDOPT\n"));
1495 DPRINTF(("I_GRDOPT\n"));
1499 DPRINTF(("I_STR\n"));
1500 return i_str(fp, td, retval, fd, cmd, dat);
1503 DPRINTF(("I_SETSIG\n"));
1504 return i_setsig(fp, td, retval, fd, cmd, dat);
1507 DPRINTF(("I_GETSIG\n"));
1508 return i_getsig(fp, td, retval, fd, cmd, dat);
1511 DPRINTF(("I_FIND\n"));
1513 * Here we are not pushing modules really, we just
1514 * pretend all are present
1520 DPRINTF(("I_LINK\n"));
1524 DPRINTF(("I_UNLINK\n"));
1527 case SVR4_I_ERECVFD:
1528 DPRINTF(("I_ERECVFD\n"));
1532 DPRINTF(("I_PEEK\n"));
1535 case SVR4_I_FDINSERT:
1536 DPRINTF(("I_FDINSERT\n"));
1537 return i_fdinsert(fp, td, retval, fd, cmd, dat);
1540 DPRINTF(("I_SENDFD\n"));
1544 DPRINTF(("I_RECVFD\n"));
1548 DPRINTF(("I_SWROPT\n"));
1552 DPRINTF(("I_GWROPT\n"));
1556 DPRINTF(("I_LIST\n"));
1560 DPRINTF(("I_PLINK\n"));
1563 case SVR4_I_PUNLINK:
1564 DPRINTF(("I_PUNLINK\n"));
1568 DPRINTF(("I_SETEV\n"));
1572 DPRINTF(("I_GETEV\n"));
1576 DPRINTF(("I_STREV\n"));
1579 case SVR4_I_UNSTREV:
1580 DPRINTF(("I_UNSTREV\n"));
1583 case SVR4_I_FLUSHBAND:
1584 DPRINTF(("I_FLUSHBAND\n"));
1588 DPRINTF(("I_CKBAND\n"));
1591 case SVR4_I_GETBAND:
1592 DPRINTF(("I_GETBANK\n"));
1596 DPRINTF(("I_ATMARK\n"));
1599 case SVR4_I_SETCLTIME:
1600 DPRINTF(("I_SETCLTIME\n"));
1603 case SVR4_I_GETCLTIME:
1604 DPRINTF(("I_GETCLTIME\n"));
1608 DPRINTF(("I_CANPUT\n"));
1611 case SVR4__I_BIND_RSVD:
1612 DPRINTF(("_I_BIND_RSVD\n"));
1613 return _i_bind_rsvd(fp, td, retval, fd, cmd, dat);
1615 case SVR4__I_RELE_RSVD:
1616 DPRINTF(("_I_RELE_RSVD\n"));
1617 return _i_rele_rsvd(fp, td, retval, fd, cmd, dat);
1620 DPRINTF(("unimpl cmd = %lx\n", cmd));
1630 svr4_sys_putmsg(struct svr4_sys_putmsg_args *uap)
1632 struct thread *td = curthread;
1633 struct proc *p = td->td_proc;
1635 struct svr4_strbuf dat, ctl;
1636 struct svr4_strmcmd sc;
1637 struct sockaddr_in sain;
1638 struct sockaddr_un saun;
1640 int sasize, *retval;
1641 struct svr4_strm *st;
1646 retval = &uap->sysmsg_result;
1648 fp = holdfp(p->p_fd, SCARG(uap, fd), -1);
1652 if (SCARG(uap, ctl) != NULL) {
1653 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) {
1655 uprintf("putmsg: copyin(): %d\n", error);
1663 if (SCARG(uap, dat) != NULL) {
1664 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0) {
1666 uprintf("putmsg: copyin(): %d (2)\n", error);
1675 * Only for sockets for now.
1677 if ((st = svr4_stream_get(fp)) == NULL) {
1678 DPRINTF(("putmsg: bad file type\n"));
1683 if (ctl.len > sizeof(sc)) {
1684 DPRINTF(("putmsg: Bad control size %d != %d\n", ctl.len,
1685 sizeof(struct svr4_strmcmd)));
1690 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
1693 switch (st->s_family) {
1695 if (sc.len != sizeof(sain)) {
1696 if (sc.cmd == SVR4_TI_DATA_REQUEST) {
1697 struct write_args wa;
1699 /* Solaris seems to use sc.cmd = 3 to
1700 * send "expedited" data. telnet uses
1701 * this for options processing, sending EOF,
1702 * etc. I'm sure other things use it too.
1703 * I don't have any documentation
1704 * on it, so I'm making a guess that this
1705 * is how it works. newton@atdot.dotat.org XXX
1707 DPRINTF(("sending expedited data ??\n"));
1708 SCARG(&wa, fd) = SCARG(uap, fd);
1709 SCARG(&wa, buf) = dat.buf;
1710 SCARG(&wa, nbyte) = dat.len;
1711 wa.sysmsg_result = 0;
1714 *retval = wa.sysmsg_result;
1717 DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len));
1721 netaddr_to_sockaddr_in(&sain, &sc);
1723 sasize = sizeof(sain);
1724 error = sain.sin_family != st->s_family; /* XXX error code thrown away??? */
1729 /* We are doing an accept; succeed */
1730 DPRINTF(("putmsg: Do nothing\n"));
1736 /* Maybe we've been given a device/inode pair */
1737 udev_t *dev = SVR4_ADDROF(&sc);
1738 ino_t *ino = (ino_t *) &dev[1];
1739 skp = svr4_find_socket(td, fp, *dev, *ino);
1742 /* I guess we have it by name */
1743 netaddr_to_sockaddr_un(skp, &sc);
1745 sasize = sizeof(saun);
1750 DPRINTF(("putmsg: Unsupported address family %d\n",
1756 sg = stackgap_init();
1757 sup = stackgap_alloc(&sg, sasize);
1759 if ((error = copyout(skp, sup, sasize)) != 0)
1762 switch (st->s_cmd = sc.cmd) {
1763 case SVR4_TI_CONNECT_REQUEST: /* connect */
1765 struct connect_args co;
1767 SCARG(&co, s) = SCARG(uap, fd);
1768 SCARG(&co, name) = (void *) sup;
1769 SCARG(&co, namelen) = (int) sasize;
1770 co.sysmsg_result = 0;
1772 error = connect(&co);
1773 *retval = co.sysmsg_result;
1777 case SVR4_TI_SENDTO_REQUEST: /* sendto */
1782 msg.msg_name = (caddr_t) sup;
1783 msg.msg_namelen = sasize;
1784 msg.msg_iov = &aiov;
1786 msg.msg_control = 0;
1788 aiov.iov_base = dat.buf;
1789 aiov.iov_len = dat.len;
1791 error = so_pru_sosend(so, NULL, uio, NULL, NULL, 0,
1794 error = svr4_sendit(td, SCARG(uap, fd), &msg,
1795 SCARG(uap, flags), retval);
1796 DPRINTF(("sendto_request error: %d\n", error));
1802 DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd));
1812 svr4_sys_getmsg(struct svr4_sys_getmsg_args *uap)
1814 struct thread *td = curthread;
1815 struct proc *p = td->td_proc;
1817 struct getpeername_args ga;
1818 struct accept_args aa;
1819 struct svr4_strbuf dat, ctl;
1820 struct svr4_strmcmd sc;
1824 struct sockaddr_in sain;
1825 struct sockaddr_un saun;
1828 struct svr4_strm *st;
1835 retval = &uap->sysmsg_result;
1836 fp = holdfp(p->p_fd, SCARG(uap, fd), -1);
1840 memset(&sc, 0, sizeof(sc));
1843 show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl),
1844 SCARG(uap, dat), 0);
1845 #endif /* DEBUG_SVR4 */
1847 if (SCARG(uap, ctl) != NULL) {
1848 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0)
1855 if (SCARG(uap, dat) != NULL) {
1856 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0)
1864 * Only for sockets for now.
1866 if ((st = svr4_stream_get(fp)) == NULL) {
1867 DPRINTF(("getmsg: bad file type\n"));
1872 if (ctl.maxlen == -1 || dat.maxlen == -1) {
1873 DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n"));
1878 switch (st->s_family) {
1881 sasize = sizeof(sain);
1886 sasize = sizeof(saun);
1890 DPRINTF(("getmsg: Unsupported address family %d\n",
1896 sg = stackgap_init();
1897 sup = stackgap_alloc(&sg, sasize);
1898 flen = (int *) stackgap_alloc(&sg, sizeof(*flen));
1901 if ((error = copyout(&fl, flen, sizeof(fl))) != 0)
1904 switch (st->s_cmd) {
1905 case SVR4_TI_CONNECT_REQUEST:
1906 DPRINTF(("getmsg: TI_CONNECT_REQUEST\n"));
1908 * We do the connect in one step, so the putmsg should
1909 * have gotten the error.
1911 sc.cmd = SVR4_TI_OK_REPLY;
1920 case SVR4_TI_OK_REPLY:
1921 DPRINTF(("getmsg: TI_OK_REPLY\n"));
1923 * We are immediately after a connect reply, so we send
1924 * a connect verification.
1927 SCARG(&ga, fdes) = SCARG(uap, fd);
1928 SCARG(&ga, asa) = (void *) sup;
1929 SCARG(&ga, alen) = flen;
1931 if ((error = getpeername(&ga)) != 0) {
1932 DPRINTF(("getmsg: getpeername failed %d\n", error));
1936 if ((error = copyin(sup, skp, sasize)) != 0)
1939 sc.cmd = SVR4_TI_CONNECT_REPLY;
1943 sc.pad[2] = 0x04000402;
1945 switch (st->s_family) {
1948 sockaddr_to_netaddr_in(&sc, &sain);
1952 sc.len = sasize + 4;
1953 sockaddr_to_netaddr_un(&sc, &saun);
1967 case SVR4_TI__ACCEPT_OK:
1968 DPRINTF(("getmsg: TI__ACCEPT_OK\n"));
1970 * We do the connect in one step, so the putmsg should
1971 * have gotten the error.
1973 sc.cmd = SVR4_TI_OK_REPLY;
1979 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
1982 case SVR4_TI__ACCEPT_WAIT:
1983 DPRINTF(("getmsg: TI__ACCEPT_WAIT\n"));
1985 * We are after a listen, so we try to accept...
1987 SCARG(&aa, s) = SCARG(uap, fd);
1988 SCARG(&aa, name) = (void *) sup;
1989 SCARG(&aa, anamelen) = flen;
1991 if ((error = accept(&aa)) != 0) {
1992 DPRINTF(("getmsg: accept failed %d\n", error));
1996 st->s_afd = *retval;
1998 DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd));
2000 if ((error = copyin(sup, skp, sasize)) != 0)
2003 sc.cmd = SVR4_TI_ACCEPT_REPLY;
2007 switch (st->s_family) {
2010 sockaddr_to_netaddr_in(&sc, &sain);
2016 sc.pad[1] = 0x00010000;
2017 sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */
2018 sc.pad[3] = 0x00010000;
2020 sc.len = sasize + 4;
2030 st->s_cmd = SVR4_TI__ACCEPT_OK;
2033 case SVR4_TI_SENDTO_REQUEST:
2034 DPRINTF(("getmsg: TI_SENDTO_REQUEST\n"));
2035 if (ctl.maxlen > 36 && ctl.len < 36)
2038 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
2041 switch (st->s_family) {
2043 sockaddr_to_netaddr_in(&sc, &sain);
2047 sockaddr_to_netaddr_un(&sc, &saun);
2055 msg.msg_name = (caddr_t) sup;
2056 msg.msg_namelen = sasize;
2057 msg.msg_iov = &aiov;
2059 msg.msg_control = 0;
2060 aiov.iov_base = dat.buf;
2061 aiov.iov_len = dat.maxlen;
2064 error = svr4_recvit(td, SCARG(uap, fd), &msg, (caddr_t) flen, retval);
2067 DPRINTF(("getmsg: recvit failed %d\n", error));
2071 if ((error = copyin(msg.msg_name, skp, sasize)) != 0)
2074 sc.cmd = SVR4_TI_RECVFROM_IND;
2076 switch (st->s_family) {
2079 sockaddr_to_netaddr_in(&sc, &sain);
2083 sc.len = sasize + 4;
2084 sockaddr_to_netaddr_un(&sc, &saun);
2099 if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) {
2100 struct read_args ra;
2102 /* More weirdness: Again, I can't find documentation
2103 * to back this up, but when a process does a generic
2104 * "getmsg()" call it seems that the command field is
2105 * zero and the length of the data area is zero. I
2106 * think processes expect getmsg() to fill in dat.len
2107 * after reading at most dat.maxlen octets from the
2108 * stream. Since we're using sockets I can let
2109 * read() look after it and frob return values
2110 * appropriately (or inappropriately :-)
2111 * -- newton@atdot.dotat.org XXX
2113 SCARG(&ra, fd) = SCARG(uap, fd);
2114 SCARG(&ra, buf) = dat.buf;
2115 SCARG(&ra, nbyte) = dat.maxlen;
2116 if ((error = read(&ra)) != 0) {
2121 st->s_cmd = SVR4_TI_SENDTO_REQUEST;
2124 DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd));
2129 if (SCARG(uap, ctl)) {
2131 if ((error = copyout(&sc, ctl.buf, ctl.len)) != 0)
2134 if ((error = copyout(&ctl, SCARG(uap, ctl), sizeof(ctl))) != 0)
2138 if (SCARG(uap, dat)) {
2139 if ((error = copyout(&dat, SCARG(uap, dat), sizeof(dat))) != 0)
2143 if (SCARG(uap, flags)) { /* XXX: Need translation */
2144 if ((error = copyout(&fl, SCARG(uap, flags), sizeof(fl))) != 0)
2152 show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl),
2153 SCARG(uap, dat), fl);
2154 #endif /* DEBUG_SVR4 */
2161 svr4_sys_send(struct svr4_sys_send_args *uap)
2163 struct osend_args osa;
2166 SCARG(&osa, s) = SCARG(uap, s);
2167 SCARG(&osa, buf) = SCARG(uap, buf);
2168 SCARG(&osa, len) = SCARG(uap, len);
2169 SCARG(&osa, flags) = SCARG(uap, flags);
2170 osa.sysmsg_result = 0;
2171 error = osend(&osa);
2172 uap->sysmsg_result = osa.sysmsg_result;
2177 svr4_sys_recv(struct svr4_sys_recv_args *uap)
2179 struct orecv_args ora;
2182 SCARG(&ora, s) = SCARG(uap, s);
2183 SCARG(&ora, buf) = SCARG(uap, buf);
2184 SCARG(&ora, len) = SCARG(uap, len);
2185 SCARG(&ora, flags) = SCARG(uap, flags);
2186 ora.sysmsg_result = 0;
2187 error = orecv(&ora);
2188 uap->sysmsg_result = ora.sysmsg_result;
2193 * XXX This isn't necessary, but it's handy for inserting debug code into
2194 * sendto(). Let's leave it here for now...
2197 svr4_sys_sendto(struct svr4_sys_sendto_args *uap)
2199 struct sendto_args sa;
2202 SCARG(&sa, s) = SCARG(uap, s);
2203 SCARG(&sa, buf) = SCARG(uap, buf);
2204 SCARG(&sa, len) = SCARG(uap, len);
2205 SCARG(&sa, flags) = SCARG(uap, flags);
2206 SCARG(&sa, to) = (caddr_t)SCARG(uap, to);
2207 SCARG(&sa, tolen) = SCARG(uap, tolen);
2209 DPRINTF(("calling sendto()\n"));
2210 sa.sysmsg_result = 0;
2211 error = sendto(&sa);
2212 uap->sysmsg_result = sa.sysmsg_result;