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.2 2003/06/17 04:28:57 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>
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>
65 #include <sys/sysproto.h>
67 #include <svr4/svr4.h>
68 #include <svr4/svr4_types.h>
69 #include <svr4/svr4_util.h>
70 #include <svr4/svr4_signal.h>
71 #include <svr4/svr4_proto.h>
72 #include <svr4/svr4_stropts.h>
73 #include <svr4/svr4_timod.h>
74 #include <svr4/svr4_sockmod.h>
75 #include <svr4/svr4_ioctl.h>
76 #include <svr4/svr4_socket.h>
79 static int clean_pipe __P((struct proc *, const char *));
80 static void getparm __P((struct file *, struct svr4_si_sockparms *));
82 /* Address Conversions */
83 static void sockaddr_to_netaddr_in __P((struct svr4_strmcmd *,
84 const struct sockaddr_in *));
85 static void sockaddr_to_netaddr_un __P((struct svr4_strmcmd *,
86 const struct sockaddr_un *));
87 static void netaddr_to_sockaddr_in __P((struct sockaddr_in *,
88 const struct svr4_strmcmd *));
89 static void netaddr_to_sockaddr_un __P((struct sockaddr_un *,
90 const struct svr4_strmcmd *));
93 static int i_nread __P((struct file *, struct proc *, register_t *, int,
95 static int i_fdinsert __P((struct file *, struct proc *, register_t *, int,
97 static int i_str __P((struct file *, struct proc *, register_t *, int,
99 static int i_setsig __P((struct file *, struct proc *, register_t *, int,
101 static int i_getsig __P((struct file *, struct proc *, register_t *, int,
103 static int _i_bind_rsvd __P((struct file *, struct proc *, register_t *, int,
105 static int _i_rele_rsvd __P((struct file *, struct proc *, register_t *, int,
108 /* i_str sockmod calls */
109 static int sockmod __P((struct file *, int, struct svr4_strioctl *,
111 static int si_listen __P((struct file *, int, struct svr4_strioctl *,
113 static int si_ogetudata __P((struct file *, int, struct svr4_strioctl *,
115 static int si_sockparams __P((struct file *, int, struct svr4_strioctl *,
117 static int si_shutdown __P((struct file *, int, struct svr4_strioctl *,
119 static int si_getudata __P((struct file *, int, struct svr4_strioctl *,
122 /* i_str timod calls */
123 static int timod __P((struct file *, int, struct svr4_strioctl *,
125 static int ti_getinfo __P((struct file *, int, struct svr4_strioctl *,
127 static int ti_bind __P((struct file *, int, struct svr4_strioctl *,
131 static int svr4_sendit __P((struct proc *p, int s, struct msghdr *mp,
134 static int svr4_recvit __P((struct proc *p, int s, struct msghdr *mp,
137 /* <sigh> Ok, so we shouldn't use sendit() in uipc_syscalls.c because
138 * it isn't part of a "public" interface; We're supposed to use
139 * pru_sosend instead. Same goes for recvit()/pru_soreceive() for
140 * that matter. Solution: Suck sendit()/recvit() into here where we
141 * can do what we like.
143 * I hate code duplication.
145 * I will take out all the #ifdef COMPAT_OLDSOCK gumph, though.
148 svr4_sendit(p, s, mp, flags)
149 register struct proc *p;
151 register struct msghdr *mp;
156 register struct iovec *iov;
158 struct mbuf *control;
163 struct iovec *ktriov = NULL;
167 error = holdsock(p->p_fd, s, &fp);
170 auio.uio_iov = mp->msg_iov;
171 auio.uio_iovcnt = mp->msg_iovlen;
172 auio.uio_segflg = UIO_USERSPACE;
173 auio.uio_rw = UIO_WRITE;
175 auio.uio_offset = 0; /* XXX */
178 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
179 if ((auio.uio_resid += iov->iov_len) < 0) {
185 error = getsockaddr(&to, mp->msg_name, mp->msg_namelen);
193 if (mp->msg_control) {
194 if (mp->msg_controllen < sizeof(struct cmsghdr)) {
198 error = sockargs(&control, mp->msg_control,
199 mp->msg_controllen, MT_CONTROL);
206 if (KTRPOINT(p, KTR_GENIO)) {
207 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
209 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
210 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
214 len = auio.uio_resid;
215 so = (struct socket *)fp->f_data;
216 error = so->so_proto->pr_usrreqs->pru_sosend(so, to, &auio, 0, control,
219 if (auio.uio_resid != len && (error == ERESTART ||
220 error == EINTR || error == EWOULDBLOCK))
226 p->p_retval[0] = len - auio.uio_resid;
228 if (ktriov != NULL) {
230 ktruio.uio_iov = ktriov;
231 ktruio.uio_resid = p->p_retval[0];
232 ktrgenio(p->p_tracep, s, UIO_WRITE, &ktruio, error);
234 FREE(ktriov, M_TEMP);
245 svr4_recvit(p, s, mp, namelenp)
246 register struct proc *p;
248 register struct msghdr *mp;
253 register struct iovec *iov;
256 struct mbuf *m, *control = 0;
259 struct sockaddr *fromsa = 0;
261 struct iovec *ktriov = NULL;
265 error = holdsock(p->p_fd, s, &fp);
268 auio.uio_iov = mp->msg_iov;
269 auio.uio_iovcnt = mp->msg_iovlen;
270 auio.uio_segflg = UIO_USERSPACE;
271 auio.uio_rw = UIO_READ;
273 auio.uio_offset = 0; /* XXX */
276 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
277 if ((auio.uio_resid += iov->iov_len) < 0) {
283 if (KTRPOINT(p, KTR_GENIO)) {
284 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
286 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
287 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
291 len = auio.uio_resid;
292 so = (struct socket *)fp->f_data;
293 error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio,
294 (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
297 if (auio.uio_resid != len && (error == ERESTART ||
298 error == EINTR || error == EWOULDBLOCK))
302 if (ktriov != NULL) {
304 ktruio.uio_iov = ktriov;
305 ktruio.uio_resid = len - auio.uio_resid;
306 ktrgenio(p->p_tracep, s, UIO_READ, &ktruio, error);
308 FREE(ktriov, M_TEMP);
313 p->p_retval[0] = len - auio.uio_resid;
315 len = mp->msg_namelen;
316 if (len <= 0 || fromsa == 0)
320 #define MIN(a,b) ((a)>(b)?(b):(a))
322 /* save sa_len before it is destroyed by MSG_COMPAT */
323 len = MIN(len, fromsa->sa_len);
324 error = copyout(fromsa,
325 (caddr_t)mp->msg_name, (unsigned)len);
329 mp->msg_namelen = len;
331 (error = copyout((caddr_t)&len, namelenp, sizeof (int)))) {
335 if (mp->msg_control) {
336 len = mp->msg_controllen;
338 mp->msg_controllen = 0;
339 ctlbuf = (caddr_t) mp->msg_control;
341 while (m && len > 0) {
347 mp->msg_flags |= MSG_CTRUNC;
351 if ((error = copyout((caddr_t)mtod(m, caddr_t),
352 ctlbuf, tocopy)) != 0)
359 mp->msg_controllen = ctlbuf - (caddr_t)mp->msg_control;
363 FREE(fromsa, M_SONAME);
371 static void bufprint __P((u_char *, size_t));
372 static int show_ioc __P((const char *, struct svr4_strioctl *));
373 static int show_strbuf __P((struct svr4_strbuf *));
374 static void show_msg __P((const char *, int, struct svr4_strbuf *,
375 struct svr4_strbuf *, int));
385 for (i = 0; i < len; i++) {
386 uprintf("%x ", buf[i]);
387 if (i && (i % 16) == 0)
395 struct svr4_strioctl *ioc;
397 u_char *ptr = (u_char *) malloc(ioc->len, M_TEMP, M_WAITOK);
400 uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ",
401 str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf);
403 if ((error = copyin(ioc->buf, ptr, ioc->len)) != 0) {
404 free((char *) ptr, M_TEMP);
408 bufprint(ptr, ioc->len);
412 free((char *) ptr, M_TEMP);
419 struct svr4_strbuf *str;
423 int maxlen = str->maxlen;
433 ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK);
435 if ((error = copyin(str->buf, ptr, len)) != 0) {
436 free((char *) ptr, M_TEMP);
441 uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf);
449 free((char *) ptr, M_TEMP);
456 show_msg(str, fd, ctl, dat, flags)
459 struct svr4_strbuf *ctl;
460 struct svr4_strbuf *dat;
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.
504 struct lstat_args la;
505 struct unlink_args ua;
508 caddr_t sg = stackgap_init();
509 size_t l = strlen(path) + 1;
512 tpath = stackgap_alloc(&sg, l);
513 SCARG(&la, ub) = stackgap_alloc(&sg, sizeof(struct stat));
515 if ((error = copyout(path, tpath, l)) != 0)
518 SCARG(&la, path) = tpath;
520 if ((error = lstat(p, &la)) != 0)
523 if ((error = copyin(SCARG(&la, ub), &st, sizeof(st))) != 0)
527 * Make sure we are dealing with a mode 0 named pipe.
529 if ((st.st_mode & S_IFMT) != S_IFIFO)
532 if ((st.st_mode & ALLPERMS) != 0)
535 SCARG(&ua, path) = SCARG(&la, path);
537 if ((error = unlink(p, &ua)) != 0) {
538 DPRINTF(("clean_pipe: unlink failed %d\n", error));
547 sockaddr_to_netaddr_in(sc, sain)
548 struct svr4_strmcmd *sc;
549 const struct sockaddr_in *sain;
551 struct svr4_netaddr_in *na;
552 na = SVR4_ADDROF(sc);
554 na->family = sain->sin_family;
555 na->port = sain->sin_port;
556 na->addr = sain->sin_addr.s_addr;
557 DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port,
563 sockaddr_to_netaddr_un(sc, saun)
564 struct svr4_strmcmd *sc;
565 const struct sockaddr_un *saun;
567 struct svr4_netaddr_un *na;
568 char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 -
572 na = SVR4_ADDROF(sc);
573 na->family = saun->sun_family;
574 for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; )
577 DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path));
582 netaddr_to_sockaddr_in(sain, sc)
583 struct sockaddr_in *sain;
584 const struct svr4_strmcmd *sc;
586 const struct svr4_netaddr_in *na;
589 na = SVR4_C_ADDROF(sc);
590 memset(sain, 0, sizeof(*sain));
591 sain->sin_len = sizeof(*sain);
592 sain->sin_family = na->family;
593 sain->sin_port = na->port;
594 sain->sin_addr.s_addr = na->addr;
595 DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family,
596 sain->sin_port, sain->sin_addr.s_addr));
601 netaddr_to_sockaddr_un(saun, sc)
602 struct sockaddr_un *saun;
603 const struct svr4_strmcmd *sc;
605 const struct svr4_netaddr_un *na;
606 char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1];
609 na = SVR4_C_ADDROF(sc);
610 memset(saun, 0, sizeof(*saun));
611 saun->sun_family = na->family;
612 for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; )
615 saun->sun_len = dst - saun->sun_path;
616 DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family,
624 struct svr4_si_sockparms *pa;
626 struct svr4_strm *st = svr4_stream_get(fp);
627 struct socket *so = (struct socket *) fp->f_data;
632 pa->family = st->s_family;
634 switch (so->so_type) {
636 pa->type = SVR4_T_CLTS;
637 pa->protocol = IPPROTO_UDP;
638 DPRINTF(("getparm(dgram)\n"));
642 pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */
643 pa->protocol = IPPROTO_IP;
644 DPRINTF(("getparm(stream)\n"));
648 pa->type = SVR4_T_CLTS;
649 pa->protocol = IPPROTO_RAW;
650 DPRINTF(("getparm(raw)\n"));
656 DPRINTF(("getparm(type %d?)\n", so->so_type));
663 si_ogetudata(fp, fd, ioc, p)
666 struct svr4_strioctl *ioc;
670 struct svr4_si_oudata ud;
671 struct svr4_si_sockparms pa;
673 if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) {
674 DPRINTF(("SI_OGETUDATA: Wrong size %d != %d\n",
675 sizeof(ud), ioc->len));
679 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
687 ud.addrsize = sizeof(struct svr4_sockaddr_in);
688 if (pa.type == SVR4_SOCK_STREAM)
701 DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n",
706 /* I have no idea what these should be! */
710 ud.servtype = pa.type;
715 return copyout(&ud, ioc->buf, ioc->len);
720 si_sockparams(fp, fd, ioc, p)
723 struct svr4_strioctl *ioc;
726 struct svr4_si_sockparms pa;
729 return copyout(&pa, ioc->buf, sizeof(pa));
734 si_listen(fp, fd, ioc, p)
737 struct svr4_strioctl *ioc;
741 struct svr4_strm *st = svr4_stream_get(fp);
742 struct svr4_strmcmd lst;
743 struct listen_args la;
748 if ((error = copyin(ioc->buf, &lst, ioc->len)) != 0)
751 if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) {
752 DPRINTF(("si_listen: bad request %ld\n", lst.cmd));
757 * We are making assumptions again...
760 DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5));
761 SCARG(&la, backlog) = 5;
763 if ((error = listen(p, &la)) != 0) {
764 DPRINTF(("SI_LISTEN: listen failed %d\n", error));
768 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
769 lst.cmd = SVR4_TI_BIND_REPLY;
771 switch (st->s_family) {
773 /* XXX: Fill the length here */
778 lst.pad[28] = 0x00000000; /* magic again */
779 lst.pad[29] = 0x00000800; /* magic again */
780 lst.pad[30] = 0x80001400; /* magic again */
784 DPRINTF(("SI_LISTEN: Unsupported address family %d\n",
790 if ((error = copyout(&lst, ioc->buf, ioc->len)) != 0)
798 si_getudata(fp, fd, ioc, p)
801 struct svr4_strioctl *ioc;
805 struct svr4_si_udata ud;
807 if (sizeof(ud) != ioc->len) {
808 DPRINTF(("SI_GETUDATA: Wrong size %d != %d\n",
809 sizeof(ud), ioc->len));
813 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
816 getparm(fp, &ud.sockparms);
818 switch (ud.sockparms.family) {
820 DPRINTF(("getudata_inet\n"));
823 ud.addrsize = sizeof(struct svr4_sockaddr_in);
824 if (ud.sockparms.type == SVR4_SOCK_STREAM)
832 DPRINTF(("getudata_local\n"));
841 DPRINTF(("SI_GETUDATA: Unsupported address family %d\n",
842 ud.sockparms.family));
847 ud.servtype = ud.sockparms.type;
848 DPRINTF(("ud.servtype = %d\n", ud.servtype));
852 return copyout(&ud, ioc->buf, sizeof(ud));
857 si_shutdown(fp, fd, ioc, p)
860 struct svr4_strioctl *ioc;
864 struct shutdown_args ap;
866 if (ioc->len != sizeof(SCARG(&ap, how))) {
867 DPRINTF(("SI_SHUTDOWN: Wrong size %d != %d\n",
868 sizeof(SCARG(&ap, how)), ioc->len));
872 if ((error = copyin(ioc->buf, &SCARG(&ap, how), ioc->len)) != 0)
877 return shutdown(p, &ap);
882 sockmod(fp, fd, ioc, p)
885 struct svr4_strioctl *ioc;
889 case SVR4_SI_OGETUDATA:
890 DPRINTF(("SI_OGETUDATA\n"));
891 return si_ogetudata(fp, fd, ioc, p);
893 case SVR4_SI_SHUTDOWN:
894 DPRINTF(("SI_SHUTDOWN\n"));
895 return si_shutdown(fp, fd, ioc, p);
898 DPRINTF(("SI_LISTEN\n"));
899 return si_listen(fp, fd, ioc, p);
901 case SVR4_SI_SETMYNAME:
902 DPRINTF(("SI_SETMYNAME\n"));
905 case SVR4_SI_SETPEERNAME:
906 DPRINTF(("SI_SETPEERNAME\n"));
909 case SVR4_SI_GETINTRANSIT:
910 DPRINTF(("SI_GETINTRANSIT\n"));
913 case SVR4_SI_TCL_LINK:
914 DPRINTF(("SI_TCL_LINK\n"));
917 case SVR4_SI_TCL_UNLINK:
918 DPRINTF(("SI_TCL_UNLINK\n"));
921 case SVR4_SI_SOCKPARAMS:
922 DPRINTF(("SI_SOCKPARAMS\n"));
923 return si_sockparams(fp, fd, ioc, p);
925 case SVR4_SI_GETUDATA:
926 DPRINTF(("SI_GETUDATA\n"));
927 return si_getudata(fp, fd, ioc, p);
930 DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd));
938 ti_getinfo(fp, fd, ioc, p)
941 struct svr4_strioctl *ioc;
945 struct svr4_infocmd info;
947 memset(&info, 0, sizeof(info));
949 if ((error = copyin(ioc->buf, &info, ioc->len)) != 0)
952 if (info.cmd != SVR4_TI_INFO_REQUEST)
955 info.cmd = SVR4_TI_INFO_REPLY;
967 ioc->len = sizeof(info);
968 if ((error = copyout(&info, ioc->buf, ioc->len)) != 0)
976 ti_bind(fp, fd, ioc, p)
979 struct svr4_strioctl *ioc;
983 struct svr4_strm *st = svr4_stream_get(fp);
984 struct sockaddr_in sain;
985 struct sockaddr_un saun;
987 void *skp, *sup = NULL;
989 struct svr4_strmcmd bnd;
993 DPRINTF(("ti_bind: bad file descriptor\n"));
997 if ((error = copyin(ioc->buf, &bnd, ioc->len)) != 0)
1000 if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) {
1001 DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd));
1005 switch (st->s_family) {
1008 sasize = sizeof(sain);
1013 netaddr_to_sockaddr_in(&sain, &bnd);
1015 DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n",
1016 sain.sin_family, sain.sin_port,
1017 sain.sin_addr.s_addr));
1022 sasize = sizeof(saun);
1026 netaddr_to_sockaddr_un(&saun, &bnd);
1028 if (saun.sun_path[0] == '\0')
1031 DPRINTF(("TI_BIND: fam %d, path %s\n",
1032 saun.sun_family, saun.sun_path));
1034 if ((error = clean_pipe(p, saun.sun_path)) != 0)
1037 bnd.pad[28] = 0x00001000; /* magic again */
1041 DPRINTF(("TI_BIND: Unsupported address family %d\n",
1046 sg = stackgap_init();
1047 sup = stackgap_alloc(&sg, sasize);
1049 if ((error = copyout(skp, sup, sasize)) != 0)
1053 DPRINTF(("TI_BIND: fileno %d\n", fd));
1054 SCARG(&ba, name) = (void *) sup;
1055 SCARG(&ba, namelen) = sasize;
1057 if ((error = bind(p, &ba)) != 0) {
1058 DPRINTF(("TI_BIND: bind failed %d\n", error));
1064 memset(&bnd, 0, sizeof(bnd));
1065 bnd.len = sasize + 4;
1066 bnd.offs = 0x10; /* XXX */
1069 bnd.cmd = SVR4_TI_BIND_REPLY;
1071 if ((error = copyout(&bnd, ioc->buf, ioc->len)) != 0)
1079 timod(fp, fd, ioc, p)
1082 struct svr4_strioctl *ioc;
1086 case SVR4_TI_GETINFO:
1087 DPRINTF(("TI_GETINFO\n"));
1088 return ti_getinfo(fp, fd, ioc, p);
1090 case SVR4_TI_OPTMGMT:
1091 DPRINTF(("TI_OPTMGMT\n"));
1095 DPRINTF(("TI_BIND\n"));
1096 return ti_bind(fp, fd, ioc, p);
1098 case SVR4_TI_UNBIND:
1099 DPRINTF(("TI_UNBIND\n"));
1103 DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd));
1110 svr4_stream_ti_ioctl(fp, p, retval, fd, cmd, dat)
1118 struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat;
1119 struct svr4_strm *st = svr4_stream_get(fp);
1122 struct sockaddr_in sain;
1123 struct sockaddr_un saun;
1124 struct svr4_strmcmd sc;
1129 DPRINTF(("svr4_stream_ti_ioctl\n"));
1136 if ((error = copyin(sub, &skb, sizeof(skb))) != 0) {
1137 DPRINTF(("ti_ioctl: error copying in strbuf\n"));
1141 switch (st->s_family) {
1144 sasize = sizeof(sain);
1149 sasize = sizeof(saun);
1153 DPRINTF(("ti_ioctl: Unsupported address family %d\n",
1158 sg = stackgap_init();
1159 sup = stackgap_alloc(&sg, sasize);
1160 lenp = stackgap_alloc(&sg, sizeof(*lenp));
1162 if ((error = copyout(&sasize, lenp, sizeof(*lenp))) != 0) {
1163 DPRINTF(("ti_ioctl: error copying out lenp\n"));
1168 case SVR4_TI_GETMYNAME:
1169 DPRINTF(("TI_GETMYNAME\n"));
1171 struct getsockname_args ap;
1172 SCARG(&ap, fdes) = fd;
1173 SCARG(&ap, asa) = sup;
1174 SCARG(&ap, alen) = lenp;
1175 if ((error = getsockname(p, &ap)) != 0) {
1176 DPRINTF(("ti_ioctl: getsockname error\n"));
1182 case SVR4_TI_GETPEERNAME:
1183 DPRINTF(("TI_GETPEERNAME\n"));
1185 struct getpeername_args ap;
1186 SCARG(&ap, fdes) = fd;
1187 SCARG(&ap, asa) = sup;
1188 SCARG(&ap, alen) = lenp;
1189 if ((error = getpeername(p, &ap)) != 0) {
1190 DPRINTF(("ti_ioctl: getpeername error\n"));
1196 case SVR4_TI_SETMYNAME:
1197 DPRINTF(("TI_SETMYNAME\n"));
1200 case SVR4_TI_SETPEERNAME:
1201 DPRINTF(("TI_SETPEERNAME\n"));
1204 DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd));
1208 if ((error = copyin(sup, skp, sasize)) != 0) {
1209 DPRINTF(("ti_ioctl: error copying in socket data\n"));
1213 if ((error = copyin(lenp, &sasize, sizeof(*lenp))) != 0) {
1214 DPRINTF(("ti_ioctl: error copying in socket size\n"));
1218 switch (st->s_family) {
1220 sockaddr_to_netaddr_in(&sc, &sain);
1225 sockaddr_to_netaddr_un(&sc, &saun);
1226 skb.len = sasize + 4;
1234 if ((error = copyout(SVR4_ADDROF(&sc), skb.buf, sasize)) != 0) {
1235 DPRINTF(("ti_ioctl: error copying out socket data\n"));
1240 if ((error = copyout(&skb, sub, sizeof(skb))) != 0) {
1241 DPRINTF(("ti_ioctl: error copying out strbuf\n"));
1252 i_nread(fp, p, retval, fd, cmd, dat)
1264 * We are supposed to return the message length in nread, and the
1265 * number of messages in retval. We don't have the notion of number
1266 * of stream messages, so we just find out if we have any bytes waiting
1267 * for us, and if we do, then we assume that we have at least one
1268 * message waiting for us.
1270 if ((error = fo_ioctl(fp, FIONREAD, (caddr_t) &nread, p)) != 0)
1278 return copyout(&nread, dat, sizeof(nread));
1282 i_fdinsert(fp, p, retval, fd, cmd, dat)
1291 * Major hack again here. We assume that we are using this to
1292 * implement accept(2). If that is the case, we have already
1293 * called accept, and we have stored the file descriptor in
1294 * afd. We find the file descriptor that the code wants to use
1295 * in fd insert, and then we dup2() our accepted file descriptor
1299 struct svr4_strm *st = svr4_stream_get(fp);
1300 struct svr4_strfdinsert fdi;
1301 struct dup2_args d2p;
1302 struct close_args clp;
1305 DPRINTF(("fdinsert: bad file type\n"));
1309 if (st->s_afd == -1) {
1310 DPRINTF(("fdinsert: accept fd not found\n"));
1314 if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) {
1315 DPRINTF(("fdinsert: copyin failed %d\n", error));
1319 SCARG(&d2p, from) = st->s_afd;
1320 SCARG(&d2p, to) = fdi.fd;
1322 if ((error = dup2(p, &d2p)) != 0) {
1323 DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n",
1324 st->s_afd, fdi.fd, error));
1328 SCARG(&clp, fd) = st->s_afd;
1330 if ((error = close(p, &clp)) != 0) {
1331 DPRINTF(("fdinsert: close(%d) failed %d\n",
1344 _i_bind_rsvd(fp, p, retval, fd, cmd, dat)
1352 struct mkfifo_args ap;
1355 * This is a supposed to be a kernel and library only ioctl.
1356 * It gets called before ti_bind, when we have a unix
1357 * socket, to physically create the socket transport and
1358 * ``reserve'' it. I don't know how this get reserved inside
1359 * the kernel, but we are going to create it nevertheless.
1361 SCARG(&ap, path) = dat;
1362 SCARG(&ap, mode) = S_IFIFO;
1364 return mkfifo(p, &ap);
1368 _i_rele_rsvd(fp, p, retval, fd, cmd, dat)
1376 struct unlink_args ap;
1379 * This is a supposed to be a kernel and library only ioctl.
1380 * I guess it is supposed to release the socket.
1382 SCARG(&ap, path) = dat;
1384 return unlink(p, &ap);
1388 i_str(fp, p, retval, fd, cmd, dat)
1397 struct svr4_strioctl ioc;
1399 if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0)
1403 if ((error = show_ioc(">", &ioc)) != 0)
1405 #endif /* DEBUG_SVR4 */
1407 switch (ioc.cmd & 0xff00) {
1409 if ((error = sockmod(fp, fd, &ioc, p)) != 0)
1414 if ((error = timod(fp, fd, &ioc, p)) != 0)
1419 DPRINTF(("Unimplemented module %c %ld\n",
1420 (char) (cmd >> 8), cmd & 0xff));
1425 if ((error = show_ioc("<", &ioc)) != 0)
1427 #endif /* DEBUG_SVR4 */
1428 return copyout(&ioc, dat, sizeof(ioc));
1432 i_setsig(fp, p, retval, fd, cmd, dat)
1441 * This is the best we can do for now; we cannot generate
1442 * signals only for specific events so the signal mask gets
1443 * ignored; we save it just to pass it to a possible I_GETSIG...
1445 * We alse have to fix the O_ASYNC fcntl bit, so the
1446 * process will get SIGPOLLs.
1448 struct fcntl_args fa;
1450 register_t oflags, flags;
1451 struct svr4_strm *st = svr4_stream_get(fp);
1454 DPRINTF(("i_setsig: bad file descriptor\n"));
1457 /* get old status flags */
1458 SCARG(&fa, fd) = fd;
1459 SCARG(&fa, cmd) = F_GETFL;
1460 if ((error = fcntl(p, &fa)) != 0)
1463 oflags = p->p_retval[0];
1465 /* update the flags */
1469 flags = oflags | O_ASYNC;
1470 if ((error = copyin(dat, &mask, sizeof(mask))) != 0) {
1471 DPRINTF(("i_setsig: bad eventmask pointer\n"));
1474 if (mask & SVR4_S_ALLMASK) {
1475 DPRINTF(("i_setsig: bad eventmask data %x\n", mask));
1478 st->s_eventmask = mask;
1481 flags = oflags & ~O_ASYNC;
1482 st->s_eventmask = 0;
1485 /* set the new flags, if changed */
1486 if (flags != oflags) {
1487 SCARG(&fa, cmd) = F_SETFL;
1488 SCARG(&fa, arg) = (long) flags;
1489 if ((error = fcntl(p, &fa)) != 0)
1491 flags = p->p_retval[0];
1494 /* set up SIGIO receiver if needed */
1496 SCARG(&fa, cmd) = F_SETOWN;
1497 SCARG(&fa, arg) = (long) p->p_pid;
1498 return fcntl(p, &fa);
1504 i_getsig(fp, p, retval, fd, cmd, dat)
1515 struct svr4_strm *st = svr4_stream_get(fp);
1518 DPRINTF(("i_getsig: bad file descriptor\n"));
1521 if ((error = copyout(&st->s_eventmask, dat,
1522 sizeof(st->s_eventmask))) != 0) {
1523 DPRINTF(("i_getsig: bad eventmask pointer\n"));
1531 svr4_stream_ioctl(fp, p, retval, fd, cmd, dat)
1542 * All the following stuff assumes "sockmod" is pushed...
1546 DPRINTF(("I_NREAD\n"));
1547 return i_nread(fp, p, retval, fd, cmd, dat);
1550 DPRINTF(("I_PUSH %x\n", dat));
1551 #if defined(DEBUG_SVR4)
1557 DPRINTF(("I_POP\n"));
1561 DPRINTF(("I_LOOK\n"));
1565 DPRINTF(("I_FLUSH\n"));
1569 DPRINTF(("I_SRDOPT\n"));
1573 DPRINTF(("I_GRDOPT\n"));
1577 DPRINTF(("I_STR\n"));
1578 return i_str(fp, p, retval, fd, cmd, dat);
1581 DPRINTF(("I_SETSIG\n"));
1582 return i_setsig(fp, p, retval, fd, cmd, dat);
1585 DPRINTF(("I_GETSIG\n"));
1586 return i_getsig(fp, p, retval, fd, cmd, dat);
1589 DPRINTF(("I_FIND\n"));
1591 * Here we are not pushing modules really, we just
1592 * pretend all are present
1598 DPRINTF(("I_LINK\n"));
1602 DPRINTF(("I_UNLINK\n"));
1605 case SVR4_I_ERECVFD:
1606 DPRINTF(("I_ERECVFD\n"));
1610 DPRINTF(("I_PEEK\n"));
1613 case SVR4_I_FDINSERT:
1614 DPRINTF(("I_FDINSERT\n"));
1615 return i_fdinsert(fp, p, retval, fd, cmd, dat);
1618 DPRINTF(("I_SENDFD\n"));
1622 DPRINTF(("I_RECVFD\n"));
1626 DPRINTF(("I_SWROPT\n"));
1630 DPRINTF(("I_GWROPT\n"));
1634 DPRINTF(("I_LIST\n"));
1638 DPRINTF(("I_PLINK\n"));
1641 case SVR4_I_PUNLINK:
1642 DPRINTF(("I_PUNLINK\n"));
1646 DPRINTF(("I_SETEV\n"));
1650 DPRINTF(("I_GETEV\n"));
1654 DPRINTF(("I_STREV\n"));
1657 case SVR4_I_UNSTREV:
1658 DPRINTF(("I_UNSTREV\n"));
1661 case SVR4_I_FLUSHBAND:
1662 DPRINTF(("I_FLUSHBAND\n"));
1666 DPRINTF(("I_CKBAND\n"));
1669 case SVR4_I_GETBAND:
1670 DPRINTF(("I_GETBANK\n"));
1674 DPRINTF(("I_ATMARK\n"));
1677 case SVR4_I_SETCLTIME:
1678 DPRINTF(("I_SETCLTIME\n"));
1681 case SVR4_I_GETCLTIME:
1682 DPRINTF(("I_GETCLTIME\n"));
1686 DPRINTF(("I_CANPUT\n"));
1689 case SVR4__I_BIND_RSVD:
1690 DPRINTF(("_I_BIND_RSVD\n"));
1691 return _i_bind_rsvd(fp, p, retval, fd, cmd, dat);
1693 case SVR4__I_RELE_RSVD:
1694 DPRINTF(("_I_RELE_RSVD\n"));
1695 return _i_rele_rsvd(fp, p, retval, fd, cmd, dat);
1698 DPRINTF(("unimpl cmd = %lx\n", cmd));
1708 svr4_sys_putmsg(p, uap)
1709 register struct proc *p;
1710 struct svr4_sys_putmsg_args *uap;
1712 struct filedesc *fdp = p->p_fd;
1714 struct svr4_strbuf dat, ctl;
1715 struct svr4_strmcmd sc;
1716 struct sockaddr_in sain;
1717 struct sockaddr_un saun;
1719 int sasize, *retval;
1720 struct svr4_strm *st;
1724 retval = p->p_retval;
1725 fp = fdp->fd_ofiles[SCARG(uap, fd)];
1727 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) {
1729 uprintf("putmsg: bad fp\n");
1735 show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl),
1736 SCARG(uap, dat), SCARG(uap, flags));
1737 #endif /* DEBUG_SVR4 */
1739 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) {
1741 uprintf("putmsg: bad fp(2)\n");
1746 if (SCARG(uap, ctl) != NULL) {
1747 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) {
1749 uprintf("putmsg: copyin(): %d\n", error);
1757 if (SCARG(uap, dat) != NULL) {
1758 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0) {
1760 uprintf("putmsg: copyin(): %d (2)\n", error);
1769 * Only for sockets for now.
1771 if ((st = svr4_stream_get(fp)) == NULL) {
1772 DPRINTF(("putmsg: bad file type\n"));
1776 if (ctl.len > sizeof(sc)) {
1777 DPRINTF(("putmsg: Bad control size %d != %d\n", ctl.len,
1778 sizeof(struct svr4_strmcmd)));
1782 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
1785 switch (st->s_family) {
1787 if (sc.len != sizeof(sain)) {
1788 if (sc.cmd == SVR4_TI_DATA_REQUEST) {
1789 struct write_args wa;
1791 /* Solaris seems to use sc.cmd = 3 to
1792 * send "expedited" data. telnet uses
1793 * this for options processing, sending EOF,
1794 * etc. I'm sure other things use it too.
1795 * I don't have any documentation
1796 * on it, so I'm making a guess that this
1797 * is how it works. newton@atdot.dotat.org XXX
1799 DPRINTF(("sending expedited data ??\n"));
1800 SCARG(&wa, fd) = SCARG(uap, fd);
1801 SCARG(&wa, buf) = dat.buf;
1802 SCARG(&wa, nbyte) = dat.len;
1803 return write(p, &wa);
1805 DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len));
1808 netaddr_to_sockaddr_in(&sain, &sc);
1810 sasize = sizeof(sain);
1811 error = sain.sin_family != st->s_family;
1816 /* We are doing an accept; succeed */
1817 DPRINTF(("putmsg: Do nothing\n"));
1822 /* Maybe we've been given a device/inode pair */
1823 udev_t *dev = SVR4_ADDROF(&sc);
1824 ino_t *ino = (ino_t *) &dev[1];
1825 skp = svr4_find_socket(p, fp, *dev, *ino);
1828 /* I guess we have it by name */
1829 netaddr_to_sockaddr_un(skp, &sc);
1831 sasize = sizeof(saun);
1836 DPRINTF(("putmsg: Unsupported address family %d\n",
1841 sg = stackgap_init();
1842 sup = stackgap_alloc(&sg, sasize);
1844 if ((error = copyout(skp, sup, sasize)) != 0)
1847 switch (st->s_cmd = sc.cmd) {
1848 case SVR4_TI_CONNECT_REQUEST: /* connect */
1850 struct connect_args co;
1852 SCARG(&co, s) = SCARG(uap, fd);
1853 SCARG(&co, name) = (void *) sup;
1854 SCARG(&co, namelen) = (int) sasize;
1856 return connect(p, &co);
1859 case SVR4_TI_SENDTO_REQUEST: /* sendto */
1864 msg.msg_name = (caddr_t) sup;
1865 msg.msg_namelen = sasize;
1866 msg.msg_iov = &aiov;
1868 msg.msg_control = 0;
1870 aiov.iov_base = dat.buf;
1871 aiov.iov_len = dat.len;
1873 error = so->so_proto->pr_usrreqs->pru_sosend(so, 0,
1874 uio, 0, 0, 0, uio->uio_procp);
1876 error = svr4_sendit(p, SCARG(uap, fd), &msg,
1878 DPRINTF(("sendto_request error: %d\n", error));
1884 DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd));
1890 svr4_sys_getmsg(p, uap)
1891 register struct proc *p;
1892 struct svr4_sys_getmsg_args *uap;
1894 struct filedesc *fdp = p->p_fd;
1896 struct getpeername_args ga;
1897 struct accept_args aa;
1898 struct svr4_strbuf dat, ctl;
1899 struct svr4_strmcmd sc;
1903 struct sockaddr_in sain;
1904 struct sockaddr_un saun;
1907 struct svr4_strm *st;
1912 retval = p->p_retval;
1913 fp = fdp->fd_ofiles[SCARG(uap, fd)];
1915 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL))
1918 memset(&sc, 0, sizeof(sc));
1921 show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl),
1922 SCARG(uap, dat), 0);
1923 #endif /* DEBUG_SVR4 */
1925 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL))
1928 if (SCARG(uap, ctl) != NULL) {
1929 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0)
1937 if (SCARG(uap, dat) != NULL) {
1938 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0)
1947 * Only for sockets for now.
1949 if ((st = svr4_stream_get(fp)) == NULL) {
1950 DPRINTF(("getmsg: bad file type\n"));
1954 if (ctl.maxlen == -1 || dat.maxlen == -1) {
1955 DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n"));
1959 switch (st->s_family) {
1962 sasize = sizeof(sain);
1967 sasize = sizeof(saun);
1971 DPRINTF(("getmsg: Unsupported address family %d\n",
1976 sg = stackgap_init();
1977 sup = stackgap_alloc(&sg, sasize);
1978 flen = (int *) stackgap_alloc(&sg, sizeof(*flen));
1981 if ((error = copyout(&fl, flen, sizeof(fl))) != 0)
1984 switch (st->s_cmd) {
1985 case SVR4_TI_CONNECT_REQUEST:
1986 DPRINTF(("getmsg: TI_CONNECT_REQUEST\n"));
1988 * We do the connect in one step, so the putmsg should
1989 * have gotten the error.
1991 sc.cmd = SVR4_TI_OK_REPLY;
2000 case SVR4_TI_OK_REPLY:
2001 DPRINTF(("getmsg: TI_OK_REPLY\n"));
2003 * We are immediately after a connect reply, so we send
2004 * a connect verification.
2007 SCARG(&ga, fdes) = SCARG(uap, fd);
2008 SCARG(&ga, asa) = (void *) sup;
2009 SCARG(&ga, alen) = flen;
2011 if ((error = getpeername(p, &ga)) != 0) {
2012 DPRINTF(("getmsg: getpeername failed %d\n", error));
2016 if ((error = copyin(sup, skp, sasize)) != 0)
2019 sc.cmd = SVR4_TI_CONNECT_REPLY;
2023 sc.pad[2] = 0x04000402;
2025 switch (st->s_family) {
2028 sockaddr_to_netaddr_in(&sc, &sain);
2032 sc.len = sasize + 4;
2033 sockaddr_to_netaddr_un(&sc, &saun);
2046 case SVR4_TI__ACCEPT_OK:
2047 DPRINTF(("getmsg: TI__ACCEPT_OK\n"));
2049 * We do the connect in one step, so the putmsg should
2050 * have gotten the error.
2052 sc.cmd = SVR4_TI_OK_REPLY;
2058 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
2061 case SVR4_TI__ACCEPT_WAIT:
2062 DPRINTF(("getmsg: TI__ACCEPT_WAIT\n"));
2064 * We are after a listen, so we try to accept...
2066 SCARG(&aa, s) = SCARG(uap, fd);
2067 SCARG(&aa, name) = (void *) sup;
2068 SCARG(&aa, anamelen) = flen;
2070 if ((error = accept(p, &aa)) != 0) {
2071 DPRINTF(("getmsg: accept failed %d\n", error));
2075 st->s_afd = *retval;
2077 DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd));
2079 if ((error = copyin(sup, skp, sasize)) != 0)
2082 sc.cmd = SVR4_TI_ACCEPT_REPLY;
2086 switch (st->s_family) {
2089 sockaddr_to_netaddr_in(&sc, &sain);
2095 sc.pad[1] = 0x00010000;
2096 sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */
2097 sc.pad[3] = 0x00010000;
2099 sc.len = sasize + 4;
2108 st->s_cmd = SVR4_TI__ACCEPT_OK;
2111 case SVR4_TI_SENDTO_REQUEST:
2112 DPRINTF(("getmsg: TI_SENDTO_REQUEST\n"));
2113 if (ctl.maxlen > 36 && ctl.len < 36)
2116 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
2119 switch (st->s_family) {
2121 sockaddr_to_netaddr_in(&sc, &sain);
2125 sockaddr_to_netaddr_un(&sc, &saun);
2132 msg.msg_name = (caddr_t) sup;
2133 msg.msg_namelen = sasize;
2134 msg.msg_iov = &aiov;
2136 msg.msg_control = 0;
2137 aiov.iov_base = dat.buf;
2138 aiov.iov_len = dat.maxlen;
2141 error = svr4_recvit(p, SCARG(uap, fd), &msg, (caddr_t) flen);
2144 DPRINTF(("getmsg: recvit failed %d\n", error));
2148 if ((error = copyin(msg.msg_name, skp, sasize)) != 0)
2151 sc.cmd = SVR4_TI_RECVFROM_IND;
2153 switch (st->s_family) {
2156 sockaddr_to_netaddr_in(&sc, &sain);
2160 sc.len = sasize + 4;
2161 sockaddr_to_netaddr_un(&sc, &saun);
2175 if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) {
2176 struct read_args ra;
2178 /* More wierdness: Again, I can't find documentation
2179 * to back this up, but when a process does a generic
2180 * "getmsg()" call it seems that the command field is
2181 * zero and the length of the data area is zero. I
2182 * think processes expect getmsg() to fill in dat.len
2183 * after reading at most dat.maxlen octets from the
2184 * stream. Since we're using sockets I can let
2185 * read() look after it and frob return values
2186 * appropriately (or inappropriately :-)
2187 * -- newton@atdot.dotat.org XXX
2189 SCARG(&ra, fd) = SCARG(uap, fd);
2190 SCARG(&ra, buf) = dat.buf;
2191 SCARG(&ra, nbyte) = dat.maxlen;
2192 if ((error = read(p, &ra)) != 0) {
2197 st->s_cmd = SVR4_TI_SENDTO_REQUEST;
2200 DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd));
2204 if (SCARG(uap, ctl)) {
2206 if ((error = copyout(&sc, ctl.buf, ctl.len)) != 0)
2209 if ((error = copyout(&ctl, SCARG(uap, ctl), sizeof(ctl))) != 0)
2213 if (SCARG(uap, dat)) {
2214 if ((error = copyout(&dat, SCARG(uap, dat), sizeof(dat))) != 0)
2218 if (SCARG(uap, flags)) { /* XXX: Need translation */
2219 if ((error = copyout(&fl, SCARG(uap, flags), sizeof(fl))) != 0)
2226 show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl),
2227 SCARG(uap, dat), fl);
2228 #endif /* DEBUG_SVR4 */
2232 int svr4_sys_send(p, uap)
2234 struct svr4_sys_send_args *uap;
2236 struct osend_args osa;
2237 SCARG(&osa, s) = SCARG(uap, s);
2238 SCARG(&osa, buf) = SCARG(uap, buf);
2239 SCARG(&osa, len) = SCARG(uap, len);
2240 SCARG(&osa, flags) = SCARG(uap, flags);
2241 return osend(p, &osa);
2244 int svr4_sys_recv(p, uap)
2246 struct svr4_sys_recv_args *uap;
2248 struct orecv_args ora;
2249 SCARG(&ora, s) = SCARG(uap, s);
2250 SCARG(&ora, buf) = SCARG(uap, buf);
2251 SCARG(&ora, len) = SCARG(uap, len);
2252 SCARG(&ora, flags) = SCARG(uap, flags);
2253 return orecv(p, &ora);
2257 * XXX This isn't necessary, but it's handy for inserting debug code into
2258 * sendto(). Let's leave it here for now...
2261 svr4_sys_sendto(p, uap)
2263 struct svr4_sys_sendto_args *uap;
2265 struct sendto_args sa;
2267 SCARG(&sa, s) = SCARG(uap, s);
2268 SCARG(&sa, buf) = SCARG(uap, buf);
2269 SCARG(&sa, len) = SCARG(uap, len);
2270 SCARG(&sa, flags) = SCARG(uap, flags);
2271 SCARG(&sa, to) = SCARG(uap, to);
2272 SCARG(&sa, tolen) = SCARG(uap, tolen);
2274 DPRINTF(("calling sendto()\n"));
2275 return sendto(p, &sa);