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.10 2003/10/08 01:30:32 daver 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>
55 #include <netinet/in.h>
57 #include <sys/protosw.h>
58 #include <sys/signal.h>
59 #include <sys/signalvar.h>
61 #include <sys/ktrace.h>
64 #include <sys/file2.h>
66 #include <sys/sysproto.h>
69 #include "svr4_types.h"
70 #include "svr4_util.h"
71 #include "svr4_signal.h"
72 #include "svr4_proto.h"
73 #include "svr4_stropts.h"
74 #include "svr4_timod.h"
75 #include "svr4_sockmod.h"
76 #include "svr4_ioctl.h"
77 #include "svr4_socket.h"
80 static int clean_pipe (const char *);
81 static void getparm (struct file *, struct svr4_si_sockparms *);
83 /* Address Conversions */
84 static void sockaddr_to_netaddr_in (struct svr4_strmcmd *,
85 const struct sockaddr_in *);
86 static void sockaddr_to_netaddr_un (struct svr4_strmcmd *,
87 const struct sockaddr_un *);
88 static void netaddr_to_sockaddr_in (struct sockaddr_in *,
89 const struct svr4_strmcmd *);
90 static void netaddr_to_sockaddr_un (struct sockaddr_un *,
91 const struct svr4_strmcmd *);
94 static int i_nread (struct file *, struct thread *, register_t *, int,
96 static int i_fdinsert (struct file *, struct thread *, register_t *, int,
98 static int i_str (struct file *, struct thread *, register_t *, int,
100 static int i_setsig (struct file *, struct thread *, register_t *, int,
102 static int i_getsig (struct file *, struct thread *, register_t *, int,
104 static int _i_bind_rsvd (struct file *, struct thread *, register_t *, int,
106 static int _i_rele_rsvd (struct file *, struct thread *, register_t *, int,
109 /* i_str sockmod calls */
110 static int sockmod (struct file *, int, struct svr4_strioctl *,
112 static int si_listen (struct file *, int, struct svr4_strioctl *,
114 static int si_ogetudata (struct file *, int, struct svr4_strioctl *,
116 static int si_sockparams (struct file *, int, struct svr4_strioctl *,
118 static int si_shutdown (struct file *, int, struct svr4_strioctl *,
120 static int si_getudata (struct file *, int, struct svr4_strioctl *,
123 /* i_str timod calls */
124 static int timod (struct file *, int, struct svr4_strioctl *,
126 static int ti_getinfo (struct file *, int, struct svr4_strioctl *,
128 static int ti_bind (struct file *, int, struct svr4_strioctl *,
132 static int svr4_sendit (struct thread *td, int s, struct msghdr *mp,
133 int flags, int *retval);
135 static int svr4_recvit (struct thread *td, int s, struct msghdr *mp,
136 caddr_t namelenp, int *retval);
138 /* <sigh> Ok, so we shouldn't use sendit() in uipc_syscalls.c because
139 * it isn't part of a "public" interface; We're supposed to use
140 * pru_sosend instead. Same goes for recvit()/pru_soreceive() for
141 * that matter. Solution: Suck sendit()/recvit() into here where we
142 * can do what we like.
144 * I hate code duplication.
146 * I will take out all the #ifdef COMPAT_OLDSOCK gumph, though.
149 svr4_sendit(td, s, mp, flags, retval)
161 struct mbuf *control;
166 struct iovec *ktriov = NULL;
173 error = holdsock(p->p_fd, s, &fp);
176 auio.uio_iov = mp->msg_iov;
177 auio.uio_iovcnt = mp->msg_iovlen;
178 auio.uio_segflg = UIO_USERSPACE;
179 auio.uio_rw = UIO_WRITE;
181 auio.uio_offset = 0; /* XXX */
184 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
185 if ((auio.uio_resid += iov->iov_len) < 0) {
191 error = getsockaddr(&to, mp->msg_name, mp->msg_namelen);
199 if (mp->msg_control) {
200 if (mp->msg_controllen < sizeof(struct cmsghdr)) {
204 control = m_get(M_WAIT, MT_CONTROL);
205 if (control == NULL) {
209 control->m_len = mp->msg_controllen;
210 error = copyin(mp->msg_control, mtod(control, caddr_t),
220 if (KTRPOINT(p->p_thread, KTR_GENIO)) {
221 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
223 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
224 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
228 len = auio.uio_resid;
229 so = (struct socket *)fp->f_data;
230 error = so->so_proto->pr_usrreqs->pru_sosend
231 (so, to, &auio, 0, control, flags, td);
233 if (auio.uio_resid != len && (error == ERESTART ||
234 error == EINTR || error == EWOULDBLOCK))
240 *retval = len - auio.uio_resid;
242 if (ktriov != NULL) {
244 ktruio.uio_iov = ktriov;
245 ktruio.uio_resid = *retval;
246 ktrgenio(p->p_tracep, s, UIO_WRITE, &ktruio, error);
248 FREE(ktriov, M_TEMP);
259 svr4_recvit(td, s, mp, namelenp, retval)
266 struct proc *p = td->td_proc;
272 struct mbuf *m, *control = 0;
275 struct sockaddr *fromsa = 0;
277 struct iovec *ktriov = NULL;
283 error = holdsock(p->p_fd, s, &fp);
286 auio.uio_iov = mp->msg_iov;
287 auio.uio_iovcnt = mp->msg_iovlen;
288 auio.uio_segflg = UIO_USERSPACE;
289 auio.uio_rw = UIO_READ;
291 auio.uio_offset = 0; /* XXX */
294 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
295 if ((auio.uio_resid += iov->iov_len) < 0) {
301 if (KTRPOINT(p->p_thread, KTR_GENIO)) {
302 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
304 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
305 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
309 len = auio.uio_resid;
310 so = (struct socket *)fp->f_data;
311 error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio,
312 (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
315 if (auio.uio_resid != len && (error == ERESTART ||
316 error == EINTR || error == EWOULDBLOCK))
320 if (ktriov != NULL) {
322 ktruio.uio_iov = ktriov;
323 ktruio.uio_resid = len - auio.uio_resid;
324 ktrgenio(p->p_tracep, s, UIO_READ, &ktruio, error);
326 FREE(ktriov, M_TEMP);
331 *retval = len - auio.uio_resid;
333 len = mp->msg_namelen;
334 if (len <= 0 || fromsa == 0)
338 #define MIN(a,b) ((a)>(b)?(b):(a))
340 /* save sa_len before it is destroyed by MSG_COMPAT */
341 len = MIN(len, fromsa->sa_len);
342 error = copyout(fromsa,
343 (caddr_t)mp->msg_name, (unsigned)len);
347 mp->msg_namelen = len;
349 (error = copyout((caddr_t)&len, namelenp, sizeof (int)))) {
353 if (mp->msg_control) {
354 len = mp->msg_controllen;
356 mp->msg_controllen = 0;
357 ctlbuf = (caddr_t) mp->msg_control;
359 while (m && len > 0) {
365 mp->msg_flags |= MSG_CTRUNC;
369 if ((error = copyout((caddr_t)mtod(m, caddr_t),
370 ctlbuf, tocopy)) != 0)
377 mp->msg_controllen = ctlbuf - (caddr_t)mp->msg_control;
381 FREE(fromsa, M_SONAME);
389 static void bufprint (u_char *, size_t);
390 static int show_ioc (const char *, struct svr4_strioctl *);
391 static int show_strbuf (struct svr4_strbuf *);
392 static void show_msg (const char *, int, struct svr4_strbuf *,
393 struct svr4_strbuf *, int);
403 for (i = 0; i < len; i++) {
404 uprintf("%x ", buf[i]);
405 if (i && (i % 16) == 0)
413 struct svr4_strioctl *ioc;
415 u_char *ptr = (u_char *) malloc(ioc->len, M_TEMP, M_WAITOK);
418 uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ",
419 str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf);
421 if ((error = copyin(ioc->buf, ptr, ioc->len)) != 0) {
422 free((char *) ptr, M_TEMP);
426 bufprint(ptr, ioc->len);
430 free((char *) ptr, M_TEMP);
437 struct svr4_strbuf *str;
441 int maxlen = str->maxlen;
451 ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK);
453 if ((error = copyin(str->buf, ptr, len)) != 0) {
454 free((char *) ptr, M_TEMP);
459 uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf);
467 free((char *) ptr, M_TEMP);
474 show_msg(str, fd, ctl, dat, flags)
477 struct svr4_strbuf *ctl;
478 struct svr4_strbuf *dat;
481 struct svr4_strbuf buf;
484 uprintf("%s(%d", str, fd);
486 if ((error = copyin(ctl, &buf, sizeof(buf))) != 0)
494 if ((error = copyin(dat, &buf, sizeof(buf))) != 0)
501 uprintf(", %x);\n", flags);
504 #endif /* DEBUG_SVR4 */
507 * We are faced with an interesting situation. On svr4 unix sockets
508 * are really pipes. But we really have sockets, and we might as
509 * well use them. At the point where svr4 calls TI_BIND, it has
510 * already created a named pipe for the socket using mknod(2).
511 * We need to create a socket with the same name when we bind,
512 * so we need to remove the pipe before, otherwise we'll get address
513 * already in use. So we *carefully* remove the pipe, to avoid
514 * using this as a random file removal tool. We use system calls
515 * to avoid code duplication.
518 clean_pipe(const char *path)
520 struct lstat_args la;
521 struct unlink_args ua;
524 caddr_t sg = stackgap_init();
525 size_t l = strlen(path) + 1;
528 tpath = stackgap_alloc(&sg, l);
529 SCARG(&la, ub) = stackgap_alloc(&sg, sizeof(struct stat));
531 if ((error = copyout(path, tpath, l)) != 0)
534 SCARG(&la, path) = tpath;
536 if ((error = lstat(&la)) != 0)
539 if ((error = copyin(SCARG(&la, ub), &st, sizeof(st))) != 0)
543 * Make sure we are dealing with a mode 0 named pipe.
545 if ((st.st_mode & S_IFMT) != S_IFIFO)
548 if ((st.st_mode & ALLPERMS) != 0)
551 SCARG(&ua, path) = SCARG(&la, path);
553 if ((error = unlink(&ua)) != 0) {
554 DPRINTF(("clean_pipe: unlink failed %d\n", error));
563 sockaddr_to_netaddr_in(sc, sain)
564 struct svr4_strmcmd *sc;
565 const struct sockaddr_in *sain;
567 struct svr4_netaddr_in *na;
568 na = SVR4_ADDROF(sc);
570 na->family = sain->sin_family;
571 na->port = sain->sin_port;
572 na->addr = sain->sin_addr.s_addr;
573 DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port,
579 sockaddr_to_netaddr_un(sc, saun)
580 struct svr4_strmcmd *sc;
581 const struct sockaddr_un *saun;
583 struct svr4_netaddr_un *na;
584 char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 -
588 na = SVR4_ADDROF(sc);
589 na->family = saun->sun_family;
590 for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; )
593 DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path));
598 netaddr_to_sockaddr_in(sain, sc)
599 struct sockaddr_in *sain;
600 const struct svr4_strmcmd *sc;
602 const struct svr4_netaddr_in *na;
605 na = SVR4_C_ADDROF(sc);
606 memset(sain, 0, sizeof(*sain));
607 sain->sin_len = sizeof(*sain);
608 sain->sin_family = na->family;
609 sain->sin_port = na->port;
610 sain->sin_addr.s_addr = na->addr;
611 DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family,
612 sain->sin_port, sain->sin_addr.s_addr));
617 netaddr_to_sockaddr_un(saun, sc)
618 struct sockaddr_un *saun;
619 const struct svr4_strmcmd *sc;
621 const struct svr4_netaddr_un *na;
622 char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1];
625 na = SVR4_C_ADDROF(sc);
626 memset(saun, 0, sizeof(*saun));
627 saun->sun_family = na->family;
628 for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; )
631 saun->sun_len = dst - saun->sun_path;
632 DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family,
640 struct svr4_si_sockparms *pa;
642 struct svr4_strm *st = svr4_stream_get(fp);
643 struct socket *so = (struct socket *) fp->f_data;
648 pa->family = st->s_family;
650 switch (so->so_type) {
652 pa->type = SVR4_T_CLTS;
653 pa->protocol = IPPROTO_UDP;
654 DPRINTF(("getparm(dgram)\n"));
658 pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */
659 pa->protocol = IPPROTO_IP;
660 DPRINTF(("getparm(stream)\n"));
664 pa->type = SVR4_T_CLTS;
665 pa->protocol = IPPROTO_RAW;
666 DPRINTF(("getparm(raw)\n"));
672 DPRINTF(("getparm(type %d?)\n", so->so_type));
679 si_ogetudata(fp, fd, ioc, td)
682 struct svr4_strioctl *ioc;
686 struct svr4_si_oudata ud;
687 struct svr4_si_sockparms pa;
689 if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) {
690 DPRINTF(("SI_OGETUDATA: Wrong size %d != %d\n",
691 sizeof(ud), ioc->len));
695 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
703 ud.addrsize = sizeof(struct svr4_sockaddr_in);
704 if (pa.type == SVR4_SOCK_STREAM)
717 DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n",
722 /* I have no idea what these should be! */
726 ud.servtype = pa.type;
731 return copyout(&ud, ioc->buf, ioc->len);
736 si_sockparams(fp, fd, ioc, td)
739 struct svr4_strioctl *ioc;
742 struct svr4_si_sockparms pa;
745 return copyout(&pa, ioc->buf, sizeof(pa));
750 si_listen(fp, fd, ioc, td)
753 struct svr4_strioctl *ioc;
757 struct svr4_strm *st = svr4_stream_get(fp);
758 struct svr4_strmcmd lst;
759 struct listen_args la;
764 if ((error = copyin(ioc->buf, &lst, ioc->len)) != 0)
767 if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) {
768 DPRINTF(("si_listen: bad request %ld\n", lst.cmd));
773 * We are making assumptions again...
776 DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5));
777 SCARG(&la, backlog) = 5;
779 if ((error = listen(&la)) != 0) {
780 DPRINTF(("SI_LISTEN: listen failed %d\n", error));
784 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
785 lst.cmd = SVR4_TI_BIND_REPLY;
787 switch (st->s_family) {
789 /* XXX: Fill the length here */
794 lst.pad[28] = 0x00000000; /* magic again */
795 lst.pad[29] = 0x00000800; /* magic again */
796 lst.pad[30] = 0x80001400; /* magic again */
800 DPRINTF(("SI_LISTEN: Unsupported address family %d\n",
806 if ((error = copyout(&lst, ioc->buf, ioc->len)) != 0)
814 si_getudata(fp, fd, ioc, td)
817 struct svr4_strioctl *ioc;
821 struct svr4_si_udata ud;
823 if (sizeof(ud) != ioc->len) {
824 DPRINTF(("SI_GETUDATA: Wrong size %d != %d\n",
825 sizeof(ud), ioc->len));
829 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
832 getparm(fp, &ud.sockparms);
834 switch (ud.sockparms.family) {
836 DPRINTF(("getudata_inet\n"));
839 ud.addrsize = sizeof(struct svr4_sockaddr_in);
840 if (ud.sockparms.type == SVR4_SOCK_STREAM)
848 DPRINTF(("getudata_local\n"));
857 DPRINTF(("SI_GETUDATA: Unsupported address family %d\n",
858 ud.sockparms.family));
863 ud.servtype = ud.sockparms.type;
864 DPRINTF(("ud.servtype = %d\n", ud.servtype));
868 return copyout(&ud, ioc->buf, sizeof(ud));
873 si_shutdown(fp, fd, ioc, td)
876 struct svr4_strioctl *ioc;
880 struct shutdown_args ap;
882 if (ioc->len != sizeof(SCARG(&ap, how))) {
883 DPRINTF(("SI_SHUTDOWN: Wrong size %d != %d\n",
884 sizeof(SCARG(&ap, how)), ioc->len));
888 if ((error = copyin(ioc->buf, &SCARG(&ap, how), ioc->len)) != 0)
893 return shutdown(&ap);
898 sockmod(fp, fd, ioc, td)
901 struct svr4_strioctl *ioc;
905 case SVR4_SI_OGETUDATA:
906 DPRINTF(("SI_OGETUDATA\n"));
907 return si_ogetudata(fp, fd, ioc, td);
909 case SVR4_SI_SHUTDOWN:
910 DPRINTF(("SI_SHUTDOWN\n"));
911 return si_shutdown(fp, fd, ioc, td);
914 DPRINTF(("SI_LISTEN\n"));
915 return si_listen(fp, fd, ioc, td);
917 case SVR4_SI_SETMYNAME:
918 DPRINTF(("SI_SETMYNAME\n"));
921 case SVR4_SI_SETPEERNAME:
922 DPRINTF(("SI_SETPEERNAME\n"));
925 case SVR4_SI_GETINTRANSIT:
926 DPRINTF(("SI_GETINTRANSIT\n"));
929 case SVR4_SI_TCL_LINK:
930 DPRINTF(("SI_TCL_LINK\n"));
933 case SVR4_SI_TCL_UNLINK:
934 DPRINTF(("SI_TCL_UNLINK\n"));
937 case SVR4_SI_SOCKPARAMS:
938 DPRINTF(("SI_SOCKPARAMS\n"));
939 return si_sockparams(fp, fd, ioc, td);
941 case SVR4_SI_GETUDATA:
942 DPRINTF(("SI_GETUDATA\n"));
943 return si_getudata(fp, fd, ioc, td);
946 DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd));
954 ti_getinfo(fp, fd, ioc, td)
957 struct svr4_strioctl *ioc;
961 struct svr4_infocmd info;
963 memset(&info, 0, sizeof(info));
965 if ((error = copyin(ioc->buf, &info, ioc->len)) != 0)
968 if (info.cmd != SVR4_TI_INFO_REQUEST)
971 info.cmd = SVR4_TI_INFO_REPLY;
983 ioc->len = sizeof(info);
984 if ((error = copyout(&info, ioc->buf, ioc->len)) != 0)
992 ti_bind(fp, fd, ioc, td)
995 struct svr4_strioctl *ioc;
999 struct svr4_strm *st = svr4_stream_get(fp);
1000 struct sockaddr_in sain;
1001 struct sockaddr_un saun;
1003 void *skp, *sup = NULL;
1005 struct svr4_strmcmd bnd;
1006 struct bind_args ba;
1009 DPRINTF(("ti_bind: bad file descriptor\n"));
1013 if ((error = copyin(ioc->buf, &bnd, ioc->len)) != 0)
1016 if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) {
1017 DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd));
1021 switch (st->s_family) {
1024 sasize = sizeof(sain);
1029 netaddr_to_sockaddr_in(&sain, &bnd);
1031 DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n",
1032 sain.sin_family, sain.sin_port,
1033 sain.sin_addr.s_addr));
1038 sasize = sizeof(saun);
1042 netaddr_to_sockaddr_un(&saun, &bnd);
1044 if (saun.sun_path[0] == '\0')
1047 DPRINTF(("TI_BIND: fam %d, path %s\n",
1048 saun.sun_family, saun.sun_path));
1050 if ((error = clean_pipe(saun.sun_path)) != 0)
1053 bnd.pad[28] = 0x00001000; /* magic again */
1057 DPRINTF(("TI_BIND: Unsupported address family %d\n",
1062 sg = stackgap_init();
1063 sup = stackgap_alloc(&sg, sasize);
1065 if ((error = copyout(skp, sup, sasize)) != 0)
1069 DPRINTF(("TI_BIND: fileno %d\n", fd));
1070 SCARG(&ba, name) = (void *) sup;
1071 SCARG(&ba, namelen) = sasize;
1073 if ((error = bind(&ba)) != 0) {
1074 DPRINTF(("TI_BIND: bind failed %d\n", error));
1080 memset(&bnd, 0, sizeof(bnd));
1081 bnd.len = sasize + 4;
1082 bnd.offs = 0x10; /* XXX */
1085 bnd.cmd = SVR4_TI_BIND_REPLY;
1087 if ((error = copyout(&bnd, ioc->buf, ioc->len)) != 0)
1095 timod(fp, fd, ioc, td)
1098 struct svr4_strioctl *ioc;
1102 case SVR4_TI_GETINFO:
1103 DPRINTF(("TI_GETINFO\n"));
1104 return ti_getinfo(fp, fd, ioc, td);
1106 case SVR4_TI_OPTMGMT:
1107 DPRINTF(("TI_OPTMGMT\n"));
1111 DPRINTF(("TI_BIND\n"));
1112 return ti_bind(fp, fd, ioc, td);
1114 case SVR4_TI_UNBIND:
1115 DPRINTF(("TI_UNBIND\n"));
1119 DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd));
1126 svr4_stream_ti_ioctl(fp, td, retval, fd, cmd, dat)
1134 struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat;
1135 struct svr4_strm *st = svr4_stream_get(fp);
1138 struct sockaddr_in sain;
1139 struct sockaddr_un saun;
1140 struct svr4_strmcmd sc;
1145 DPRINTF(("svr4_stream_ti_ioctl\n"));
1152 if ((error = copyin(sub, &skb, sizeof(skb))) != 0) {
1153 DPRINTF(("ti_ioctl: error copying in strbuf\n"));
1157 switch (st->s_family) {
1160 sasize = sizeof(sain);
1165 sasize = sizeof(saun);
1169 DPRINTF(("ti_ioctl: Unsupported address family %d\n",
1174 sg = stackgap_init();
1175 sup = stackgap_alloc(&sg, sasize);
1176 lenp = stackgap_alloc(&sg, sizeof(*lenp));
1178 if ((error = copyout(&sasize, lenp, sizeof(*lenp))) != 0) {
1179 DPRINTF(("ti_ioctl: error copying out lenp\n"));
1184 case SVR4_TI_GETMYNAME:
1185 DPRINTF(("TI_GETMYNAME\n"));
1187 struct getsockname_args ap;
1188 SCARG(&ap, fdes) = fd;
1189 SCARG(&ap, asa) = sup;
1190 SCARG(&ap, alen) = lenp;
1191 if ((error = getsockname(&ap)) != 0) {
1192 DPRINTF(("ti_ioctl: getsockname error\n"));
1198 case SVR4_TI_GETPEERNAME:
1199 DPRINTF(("TI_GETPEERNAME\n"));
1201 struct getpeername_args ap;
1202 SCARG(&ap, fdes) = fd;
1203 SCARG(&ap, asa) = sup;
1204 SCARG(&ap, alen) = lenp;
1205 if ((error = getpeername(&ap)) != 0) {
1206 DPRINTF(("ti_ioctl: getpeername error\n"));
1212 case SVR4_TI_SETMYNAME:
1213 DPRINTF(("TI_SETMYNAME\n"));
1216 case SVR4_TI_SETPEERNAME:
1217 DPRINTF(("TI_SETPEERNAME\n"));
1220 DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd));
1224 if ((error = copyin(sup, skp, sasize)) != 0) {
1225 DPRINTF(("ti_ioctl: error copying in socket data\n"));
1229 if ((error = copyin(lenp, &sasize, sizeof(*lenp))) != 0) {
1230 DPRINTF(("ti_ioctl: error copying in socket size\n"));
1234 switch (st->s_family) {
1236 sockaddr_to_netaddr_in(&sc, &sain);
1241 sockaddr_to_netaddr_un(&sc, &saun);
1242 skb.len = sasize + 4;
1250 if ((error = copyout(SVR4_ADDROF(&sc), skb.buf, sasize)) != 0) {
1251 DPRINTF(("ti_ioctl: error copying out socket data\n"));
1256 if ((error = copyout(&skb, sub, sizeof(skb))) != 0) {
1257 DPRINTF(("ti_ioctl: error copying out strbuf\n"));
1268 i_nread(fp, td, retval, fd, cmd, dat)
1280 * We are supposed to return the message length in nread, and the
1281 * number of messages in retval. We don't have the notion of number
1282 * of stream messages, so we just find out if we have any bytes waiting
1283 * for us, and if we do, then we assume that we have at least one
1284 * message waiting for us.
1286 if ((error = fo_ioctl(fp, FIONREAD, (caddr_t) &nread, td)) != 0)
1294 return copyout(&nread, dat, sizeof(nread));
1298 i_fdinsert(fp, td, retval, fd, cmd, dat)
1307 * Major hack again here. We assume that we are using this to
1308 * implement accept(2). If that is the case, we have already
1309 * called accept, and we have stored the file descriptor in
1310 * afd. We find the file descriptor that the code wants to use
1311 * in fd insert, and then we dup2() our accepted file descriptor
1315 struct svr4_strm *st = svr4_stream_get(fp);
1316 struct svr4_strfdinsert fdi;
1317 struct dup2_args d2p;
1318 struct close_args clp;
1321 DPRINTF(("fdinsert: bad file type\n"));
1325 if (st->s_afd == -1) {
1326 DPRINTF(("fdinsert: accept fd not found\n"));
1330 if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) {
1331 DPRINTF(("fdinsert: copyin failed %d\n", error));
1335 SCARG(&d2p, from) = st->s_afd;
1336 SCARG(&d2p, to) = fdi.fd;
1338 if ((error = dup2(&d2p)) != 0) {
1339 DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n",
1340 st->s_afd, fdi.fd, error));
1344 SCARG(&clp, fd) = st->s_afd;
1346 if ((error = close(&clp)) != 0) {
1347 DPRINTF(("fdinsert: close(%d) failed %d\n",
1360 _i_bind_rsvd(fp, td, retval, fd, cmd, dat)
1368 struct mkfifo_args ap;
1371 * This is a supposed to be a kernel and library only ioctl.
1372 * It gets called before ti_bind, when we have a unix
1373 * socket, to physically create the socket transport and
1374 * ``reserve'' it. I don't know how this get reserved inside
1375 * the kernel, but we are going to create it nevertheless.
1377 SCARG(&ap, path) = dat;
1378 SCARG(&ap, mode) = S_IFIFO;
1384 _i_rele_rsvd(fp, td, retval, fd, cmd, dat)
1392 struct unlink_args ap;
1395 * This is a supposed to be a kernel and library only ioctl.
1396 * I guess it is supposed to release the socket.
1398 SCARG(&ap, path) = dat;
1404 i_str(fp, td, retval, fd, cmd, dat)
1413 struct svr4_strioctl ioc;
1415 if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0)
1419 if ((error = show_ioc(">", &ioc)) != 0)
1421 #endif /* DEBUG_SVR4 */
1423 switch (ioc.cmd & 0xff00) {
1425 if ((error = sockmod(fp, fd, &ioc, td)) != 0)
1430 if ((error = timod(fp, fd, &ioc, td)) != 0)
1435 DPRINTF(("Unimplemented module %c %ld\n",
1436 (char) (cmd >> 8), cmd & 0xff));
1441 if ((error = show_ioc("<", &ioc)) != 0)
1443 #endif /* DEBUG_SVR4 */
1444 return copyout(&ioc, dat, sizeof(ioc));
1448 i_setsig(fp, td, retval, fd, cmd, dat)
1457 * This is the best we can do for now; we cannot generate
1458 * signals only for specific events so the signal mask gets
1459 * ignored; we save it just to pass it to a possible I_GETSIG...
1461 * We alse have to fix the O_ASYNC fcntl bit, so the
1462 * process will get SIGPOLLs.
1464 struct proc *p = td->td_proc;
1465 struct fcntl_args fa;
1467 register_t oflags, flags;
1468 struct svr4_strm *st = svr4_stream_get(fp);
1473 DPRINTF(("i_setsig: bad file descriptor\n"));
1476 /* get old status flags */
1477 SCARG(&fa, fd) = fd;
1478 SCARG(&fa, cmd) = F_GETFL;
1479 if ((error = fcntl(&fa)) != 0)
1482 oflags = fa.sysmsg_result;
1484 /* update the flags */
1488 flags = oflags | O_ASYNC;
1489 if ((error = copyin(dat, &mask, sizeof(mask))) != 0) {
1490 DPRINTF(("i_setsig: bad eventmask pointer\n"));
1493 if (mask & SVR4_S_ALLMASK) {
1494 DPRINTF(("i_setsig: bad eventmask data %x\n", mask));
1497 st->s_eventmask = mask;
1500 flags = oflags & ~O_ASYNC;
1501 st->s_eventmask = 0;
1504 /* set the new flags, if changed */
1505 if (flags != oflags) {
1506 SCARG(&fa, cmd) = F_SETFL;
1507 SCARG(&fa, arg) = (long) flags;
1508 if ((error = fcntl(&fa)) != 0)
1510 flags =fa.sysmsg_result;
1513 /* set up SIGIO receiver if needed */
1515 SCARG(&fa, cmd) = F_SETOWN;
1516 SCARG(&fa, arg) = (long) p->p_pid;
1518 *retval = fa.sysmsg_result;
1521 *retval = fa.sysmsg_result;
1526 i_getsig(fp, td, retval, fd, cmd, dat)
1537 struct svr4_strm *st = svr4_stream_get(fp);
1540 DPRINTF(("i_getsig: bad file descriptor\n"));
1543 if ((error = copyout(&st->s_eventmask, dat,
1544 sizeof(st->s_eventmask))) != 0) {
1545 DPRINTF(("i_getsig: bad eventmask pointer\n"));
1553 svr4_stream_ioctl(fp, td, retval, fd, cmd, dat)
1564 * All the following stuff assumes "sockmod" is pushed...
1568 DPRINTF(("I_NREAD\n"));
1569 return i_nread(fp, td, retval, fd, cmd, dat);
1572 DPRINTF(("I_PUSH %p\n", dat));
1573 #if defined(DEBUG_SVR4)
1574 show_strbuf((void *)dat);
1579 DPRINTF(("I_POP\n"));
1583 DPRINTF(("I_LOOK\n"));
1587 DPRINTF(("I_FLUSH\n"));
1591 DPRINTF(("I_SRDOPT\n"));
1595 DPRINTF(("I_GRDOPT\n"));
1599 DPRINTF(("I_STR\n"));
1600 return i_str(fp, td, retval, fd, cmd, dat);
1603 DPRINTF(("I_SETSIG\n"));
1604 return i_setsig(fp, td, retval, fd, cmd, dat);
1607 DPRINTF(("I_GETSIG\n"));
1608 return i_getsig(fp, td, retval, fd, cmd, dat);
1611 DPRINTF(("I_FIND\n"));
1613 * Here we are not pushing modules really, we just
1614 * pretend all are present
1620 DPRINTF(("I_LINK\n"));
1624 DPRINTF(("I_UNLINK\n"));
1627 case SVR4_I_ERECVFD:
1628 DPRINTF(("I_ERECVFD\n"));
1632 DPRINTF(("I_PEEK\n"));
1635 case SVR4_I_FDINSERT:
1636 DPRINTF(("I_FDINSERT\n"));
1637 return i_fdinsert(fp, td, retval, fd, cmd, dat);
1640 DPRINTF(("I_SENDFD\n"));
1644 DPRINTF(("I_RECVFD\n"));
1648 DPRINTF(("I_SWROPT\n"));
1652 DPRINTF(("I_GWROPT\n"));
1656 DPRINTF(("I_LIST\n"));
1660 DPRINTF(("I_PLINK\n"));
1663 case SVR4_I_PUNLINK:
1664 DPRINTF(("I_PUNLINK\n"));
1668 DPRINTF(("I_SETEV\n"));
1672 DPRINTF(("I_GETEV\n"));
1676 DPRINTF(("I_STREV\n"));
1679 case SVR4_I_UNSTREV:
1680 DPRINTF(("I_UNSTREV\n"));
1683 case SVR4_I_FLUSHBAND:
1684 DPRINTF(("I_FLUSHBAND\n"));
1688 DPRINTF(("I_CKBAND\n"));
1691 case SVR4_I_GETBAND:
1692 DPRINTF(("I_GETBANK\n"));
1696 DPRINTF(("I_ATMARK\n"));
1699 case SVR4_I_SETCLTIME:
1700 DPRINTF(("I_SETCLTIME\n"));
1703 case SVR4_I_GETCLTIME:
1704 DPRINTF(("I_GETCLTIME\n"));
1708 DPRINTF(("I_CANPUT\n"));
1711 case SVR4__I_BIND_RSVD:
1712 DPRINTF(("_I_BIND_RSVD\n"));
1713 return _i_bind_rsvd(fp, td, retval, fd, cmd, dat);
1715 case SVR4__I_RELE_RSVD:
1716 DPRINTF(("_I_RELE_RSVD\n"));
1717 return _i_rele_rsvd(fp, td, retval, fd, cmd, dat);
1720 DPRINTF(("unimpl cmd = %lx\n", cmd));
1730 svr4_sys_putmsg(struct svr4_sys_putmsg_args *uap)
1732 struct thread *td = curthread;
1733 struct proc *p = td->td_proc;
1734 struct filedesc *fdp;
1736 struct svr4_strbuf dat, ctl;
1737 struct svr4_strmcmd sc;
1738 struct sockaddr_in sain;
1739 struct sockaddr_un saun;
1741 int sasize, *retval;
1742 struct svr4_strm *st;
1748 retval = &uap->sysmsg_result;
1749 fp = fdp->fd_ofiles[SCARG(uap, fd)];
1751 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) {
1753 uprintf("putmsg: bad fp\n");
1759 show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl),
1760 SCARG(uap, dat), SCARG(uap, flags));
1761 #endif /* DEBUG_SVR4 */
1763 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) {
1765 uprintf("putmsg: bad fp(2)\n");
1770 if (SCARG(uap, ctl) != NULL) {
1771 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) {
1773 uprintf("putmsg: copyin(): %d\n", error);
1781 if (SCARG(uap, dat) != NULL) {
1782 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0) {
1784 uprintf("putmsg: copyin(): %d (2)\n", error);
1793 * Only for sockets for now.
1795 if ((st = svr4_stream_get(fp)) == NULL) {
1796 DPRINTF(("putmsg: bad file type\n"));
1800 if (ctl.len > sizeof(sc)) {
1801 DPRINTF(("putmsg: Bad control size %d != %d\n", ctl.len,
1802 sizeof(struct svr4_strmcmd)));
1806 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
1809 switch (st->s_family) {
1811 if (sc.len != sizeof(sain)) {
1812 if (sc.cmd == SVR4_TI_DATA_REQUEST) {
1813 struct write_args wa;
1815 /* Solaris seems to use sc.cmd = 3 to
1816 * send "expedited" data. telnet uses
1817 * this for options processing, sending EOF,
1818 * etc. I'm sure other things use it too.
1819 * I don't have any documentation
1820 * on it, so I'm making a guess that this
1821 * is how it works. newton@atdot.dotat.org XXX
1823 DPRINTF(("sending expedited data ??\n"));
1824 SCARG(&wa, fd) = SCARG(uap, fd);
1825 SCARG(&wa, buf) = dat.buf;
1826 SCARG(&wa, nbyte) = dat.len;
1827 wa.sysmsg_result = 0;
1830 *retval = wa.sysmsg_result;
1833 DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len));
1836 netaddr_to_sockaddr_in(&sain, &sc);
1838 sasize = sizeof(sain);
1839 error = sain.sin_family != st->s_family;
1844 /* We are doing an accept; succeed */
1845 DPRINTF(("putmsg: Do nothing\n"));
1850 /* Maybe we've been given a device/inode pair */
1851 udev_t *dev = SVR4_ADDROF(&sc);
1852 ino_t *ino = (ino_t *) &dev[1];
1853 skp = svr4_find_socket(td, fp, *dev, *ino);
1856 /* I guess we have it by name */
1857 netaddr_to_sockaddr_un(skp, &sc);
1859 sasize = sizeof(saun);
1864 DPRINTF(("putmsg: Unsupported address family %d\n",
1869 sg = stackgap_init();
1870 sup = stackgap_alloc(&sg, sasize);
1872 if ((error = copyout(skp, sup, sasize)) != 0)
1875 switch (st->s_cmd = sc.cmd) {
1876 case SVR4_TI_CONNECT_REQUEST: /* connect */
1878 struct connect_args co;
1880 SCARG(&co, s) = SCARG(uap, fd);
1881 SCARG(&co, name) = (void *) sup;
1882 SCARG(&co, namelen) = (int) sasize;
1883 co.sysmsg_result = 0;
1885 error = connect(&co);
1886 *retval = co.sysmsg_result;
1890 case SVR4_TI_SENDTO_REQUEST: /* sendto */
1895 msg.msg_name = (caddr_t) sup;
1896 msg.msg_namelen = sasize;
1897 msg.msg_iov = &aiov;
1899 msg.msg_control = 0;
1901 aiov.iov_base = dat.buf;
1902 aiov.iov_len = dat.len;
1904 error = so->so_proto->pr_usrreqs->pru_sosend
1905 (so, 0, uio, 0, 0, 0, uio->uio_td);
1907 error = svr4_sendit(td, SCARG(uap, fd), &msg,
1908 SCARG(uap, flags), retval);
1909 DPRINTF(("sendto_request error: %d\n", error));
1915 DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd));
1921 svr4_sys_getmsg(struct svr4_sys_getmsg_args *uap)
1923 struct thread *td = curthread;
1924 struct proc *p = td->td_proc;
1925 struct filedesc *fdp;
1927 struct getpeername_args ga;
1928 struct accept_args aa;
1929 struct svr4_strbuf dat, ctl;
1930 struct svr4_strmcmd sc;
1934 struct sockaddr_in sain;
1935 struct sockaddr_un saun;
1938 struct svr4_strm *st;
1945 retval = &uap->sysmsg_result;
1946 fp = fdp->fd_ofiles[SCARG(uap, fd)];
1948 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL))
1951 memset(&sc, 0, sizeof(sc));
1954 show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl),
1955 SCARG(uap, dat), 0);
1956 #endif /* DEBUG_SVR4 */
1958 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL))
1961 if (SCARG(uap, ctl) != NULL) {
1962 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0)
1970 if (SCARG(uap, dat) != NULL) {
1971 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0)
1980 * Only for sockets for now.
1982 if ((st = svr4_stream_get(fp)) == NULL) {
1983 DPRINTF(("getmsg: bad file type\n"));
1987 if (ctl.maxlen == -1 || dat.maxlen == -1) {
1988 DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n"));
1992 switch (st->s_family) {
1995 sasize = sizeof(sain);
2000 sasize = sizeof(saun);
2004 DPRINTF(("getmsg: Unsupported address family %d\n",
2009 sg = stackgap_init();
2010 sup = stackgap_alloc(&sg, sasize);
2011 flen = (int *) stackgap_alloc(&sg, sizeof(*flen));
2014 if ((error = copyout(&fl, flen, sizeof(fl))) != 0)
2017 switch (st->s_cmd) {
2018 case SVR4_TI_CONNECT_REQUEST:
2019 DPRINTF(("getmsg: TI_CONNECT_REQUEST\n"));
2021 * We do the connect in one step, so the putmsg should
2022 * have gotten the error.
2024 sc.cmd = SVR4_TI_OK_REPLY;
2033 case SVR4_TI_OK_REPLY:
2034 DPRINTF(("getmsg: TI_OK_REPLY\n"));
2036 * We are immediately after a connect reply, so we send
2037 * a connect verification.
2040 SCARG(&ga, fdes) = SCARG(uap, fd);
2041 SCARG(&ga, asa) = (void *) sup;
2042 SCARG(&ga, alen) = flen;
2044 if ((error = getpeername(&ga)) != 0) {
2045 DPRINTF(("getmsg: getpeername failed %d\n", error));
2049 if ((error = copyin(sup, skp, sasize)) != 0)
2052 sc.cmd = SVR4_TI_CONNECT_REPLY;
2056 sc.pad[2] = 0x04000402;
2058 switch (st->s_family) {
2061 sockaddr_to_netaddr_in(&sc, &sain);
2065 sc.len = sasize + 4;
2066 sockaddr_to_netaddr_un(&sc, &saun);
2079 case SVR4_TI__ACCEPT_OK:
2080 DPRINTF(("getmsg: TI__ACCEPT_OK\n"));
2082 * We do the connect in one step, so the putmsg should
2083 * have gotten the error.
2085 sc.cmd = SVR4_TI_OK_REPLY;
2091 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
2094 case SVR4_TI__ACCEPT_WAIT:
2095 DPRINTF(("getmsg: TI__ACCEPT_WAIT\n"));
2097 * We are after a listen, so we try to accept...
2099 SCARG(&aa, s) = SCARG(uap, fd);
2100 SCARG(&aa, name) = (void *) sup;
2101 SCARG(&aa, anamelen) = flen;
2103 if ((error = accept(&aa)) != 0) {
2104 DPRINTF(("getmsg: accept failed %d\n", error));
2108 st->s_afd = *retval;
2110 DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd));
2112 if ((error = copyin(sup, skp, sasize)) != 0)
2115 sc.cmd = SVR4_TI_ACCEPT_REPLY;
2119 switch (st->s_family) {
2122 sockaddr_to_netaddr_in(&sc, &sain);
2128 sc.pad[1] = 0x00010000;
2129 sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */
2130 sc.pad[3] = 0x00010000;
2132 sc.len = sasize + 4;
2141 st->s_cmd = SVR4_TI__ACCEPT_OK;
2144 case SVR4_TI_SENDTO_REQUEST:
2145 DPRINTF(("getmsg: TI_SENDTO_REQUEST\n"));
2146 if (ctl.maxlen > 36 && ctl.len < 36)
2149 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
2152 switch (st->s_family) {
2154 sockaddr_to_netaddr_in(&sc, &sain);
2158 sockaddr_to_netaddr_un(&sc, &saun);
2165 msg.msg_name = (caddr_t) sup;
2166 msg.msg_namelen = sasize;
2167 msg.msg_iov = &aiov;
2169 msg.msg_control = 0;
2170 aiov.iov_base = dat.buf;
2171 aiov.iov_len = dat.maxlen;
2174 error = svr4_recvit(td, SCARG(uap, fd), &msg, (caddr_t) flen, retval);
2177 DPRINTF(("getmsg: recvit failed %d\n", error));
2181 if ((error = copyin(msg.msg_name, skp, sasize)) != 0)
2184 sc.cmd = SVR4_TI_RECVFROM_IND;
2186 switch (st->s_family) {
2189 sockaddr_to_netaddr_in(&sc, &sain);
2193 sc.len = sasize + 4;
2194 sockaddr_to_netaddr_un(&sc, &saun);
2208 if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) {
2209 struct read_args ra;
2211 /* More wierdness: Again, I can't find documentation
2212 * to back this up, but when a process does a generic
2213 * "getmsg()" call it seems that the command field is
2214 * zero and the length of the data area is zero. I
2215 * think processes expect getmsg() to fill in dat.len
2216 * after reading at most dat.maxlen octets from the
2217 * stream. Since we're using sockets I can let
2218 * read() look after it and frob return values
2219 * appropriately (or inappropriately :-)
2220 * -- newton@atdot.dotat.org XXX
2222 SCARG(&ra, fd) = SCARG(uap, fd);
2223 SCARG(&ra, buf) = dat.buf;
2224 SCARG(&ra, nbyte) = dat.maxlen;
2225 if ((error = read(&ra)) != 0) {
2230 st->s_cmd = SVR4_TI_SENDTO_REQUEST;
2233 DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd));
2237 if (SCARG(uap, ctl)) {
2239 if ((error = copyout(&sc, ctl.buf, ctl.len)) != 0)
2242 if ((error = copyout(&ctl, SCARG(uap, ctl), sizeof(ctl))) != 0)
2246 if (SCARG(uap, dat)) {
2247 if ((error = copyout(&dat, SCARG(uap, dat), sizeof(dat))) != 0)
2251 if (SCARG(uap, flags)) { /* XXX: Need translation */
2252 if ((error = copyout(&fl, SCARG(uap, flags), sizeof(fl))) != 0)
2259 show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl),
2260 SCARG(uap, dat), fl);
2261 #endif /* DEBUG_SVR4 */
2265 int svr4_sys_send(struct svr4_sys_send_args *uap)
2267 struct osend_args osa;
2270 SCARG(&osa, s) = SCARG(uap, s);
2271 SCARG(&osa, buf) = SCARG(uap, buf);
2272 SCARG(&osa, len) = SCARG(uap, len);
2273 SCARG(&osa, flags) = SCARG(uap, flags);
2274 osa.sysmsg_result = 0;
2275 error = osend(&osa);
2276 uap->sysmsg_result = osa.sysmsg_result;
2280 int svr4_sys_recv(struct svr4_sys_recv_args *uap)
2282 struct orecv_args ora;
2285 SCARG(&ora, s) = SCARG(uap, s);
2286 SCARG(&ora, buf) = SCARG(uap, buf);
2287 SCARG(&ora, len) = SCARG(uap, len);
2288 SCARG(&ora, flags) = SCARG(uap, flags);
2289 ora.sysmsg_result = 0;
2290 error = orecv(&ora);
2291 uap->sysmsg_result = ora.sysmsg_result;
2296 * XXX This isn't necessary, but it's handy for inserting debug code into
2297 * sendto(). Let's leave it here for now...
2300 svr4_sys_sendto(struct svr4_sys_sendto_args *uap)
2302 struct sendto_args sa;
2305 SCARG(&sa, s) = SCARG(uap, s);
2306 SCARG(&sa, buf) = SCARG(uap, buf);
2307 SCARG(&sa, len) = SCARG(uap, len);
2308 SCARG(&sa, flags) = SCARG(uap, flags);
2309 SCARG(&sa, to) = (caddr_t)SCARG(uap, to);
2310 SCARG(&sa, tolen) = SCARG(uap, tolen);
2312 DPRINTF(("calling sendto()\n"));
2313 sa.sysmsg_result = 0;
2314 error = sendto(&sa);
2315 uap->sysmsg_result = sa.sysmsg_result;