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.5 2003/07/23 02:30:23 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>
64 #include <sys/file2.h>
66 #include <sys/sysproto.h>
68 #include <svr4/svr4.h>
69 #include <svr4/svr4_types.h>
70 #include <svr4/svr4_util.h>
71 #include <svr4/svr4_signal.h>
72 #include <svr4/svr4_proto.h>
73 #include <svr4/svr4_stropts.h>
74 #include <svr4/svr4_timod.h>
75 #include <svr4/svr4_sockmod.h>
76 #include <svr4/svr4_ioctl.h>
77 #include <svr4/svr4_socket.h>
80 static int clean_pipe __P((const char *));
81 static void getparm __P((struct file *, struct svr4_si_sockparms *));
83 /* Address Conversions */
84 static void sockaddr_to_netaddr_in __P((struct svr4_strmcmd *,
85 const struct sockaddr_in *));
86 static void sockaddr_to_netaddr_un __P((struct svr4_strmcmd *,
87 const struct sockaddr_un *));
88 static void netaddr_to_sockaddr_in __P((struct sockaddr_in *,
89 const struct svr4_strmcmd *));
90 static void netaddr_to_sockaddr_un __P((struct sockaddr_un *,
91 const struct svr4_strmcmd *));
94 static int i_nread __P((struct file *, struct thread *, register_t *, int,
96 static int i_fdinsert __P((struct file *, struct thread *, register_t *, int,
98 static int i_str __P((struct file *, struct thread *, register_t *, int,
100 static int i_setsig __P((struct file *, struct thread *, register_t *, int,
102 static int i_getsig __P((struct file *, struct thread *, register_t *, int,
104 static int _i_bind_rsvd __P((struct file *, struct thread *, register_t *, int,
106 static int _i_rele_rsvd __P((struct file *, struct thread *, register_t *, int,
109 /* i_str sockmod calls */
110 static int sockmod __P((struct file *, int, struct svr4_strioctl *,
112 static int si_listen __P((struct file *, int, struct svr4_strioctl *,
114 static int si_ogetudata __P((struct file *, int, struct svr4_strioctl *,
116 static int si_sockparams __P((struct file *, int, struct svr4_strioctl *,
118 static int si_shutdown __P((struct file *, int, struct svr4_strioctl *,
120 static int si_getudata __P((struct file *, int, struct svr4_strioctl *,
123 /* i_str timod calls */
124 static int timod __P((struct file *, int, struct svr4_strioctl *,
126 static int ti_getinfo __P((struct file *, int, struct svr4_strioctl *,
128 static int ti_bind __P((struct file *, int, struct svr4_strioctl *,
132 static int svr4_sendit __P((struct thread *td, int s, struct msghdr *mp,
135 static int svr4_recvit __P((struct thread *td, int s, struct msghdr *mp,
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)
160 struct mbuf *control;
165 struct iovec *ktriov = NULL;
172 error = holdsock(p->p_fd, s, &fp);
175 auio.uio_iov = mp->msg_iov;
176 auio.uio_iovcnt = mp->msg_iovlen;
177 auio.uio_segflg = UIO_USERSPACE;
178 auio.uio_rw = UIO_WRITE;
180 auio.uio_offset = 0; /* XXX */
183 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
184 if ((auio.uio_resid += iov->iov_len) < 0) {
190 error = getsockaddr(&to, mp->msg_name, mp->msg_namelen);
198 if (mp->msg_control) {
199 if (mp->msg_controllen < sizeof(struct cmsghdr)) {
203 error = sockargs(&control, mp->msg_control,
204 mp->msg_controllen, MT_CONTROL);
211 if (KTRPOINT(p->p_thread, KTR_GENIO)) {
212 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
214 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
215 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
219 len = auio.uio_resid;
220 so = (struct socket *)fp->f_data;
221 error = so->so_proto->pr_usrreqs->pru_sosend
222 (so, to, &auio, 0, control, flags, td);
224 if (auio.uio_resid != len && (error == ERESTART ||
225 error == EINTR || error == EWOULDBLOCK))
231 p->p_retval[0] = len - auio.uio_resid;
233 if (ktriov != NULL) {
235 ktruio.uio_iov = ktriov;
236 ktruio.uio_resid = p->p_retval[0];
237 ktrgenio(p->p_tracep, s, UIO_WRITE, &ktruio, error);
239 FREE(ktriov, M_TEMP);
250 svr4_recvit(td, s, mp, namelenp)
256 struct proc *p = td->td_proc;
262 struct mbuf *m, *control = 0;
265 struct sockaddr *fromsa = 0;
267 struct iovec *ktriov = NULL;
273 error = holdsock(p->p_fd, s, &fp);
276 auio.uio_iov = mp->msg_iov;
277 auio.uio_iovcnt = mp->msg_iovlen;
278 auio.uio_segflg = UIO_USERSPACE;
279 auio.uio_rw = UIO_READ;
281 auio.uio_offset = 0; /* XXX */
284 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
285 if ((auio.uio_resid += iov->iov_len) < 0) {
291 if (KTRPOINT(p->p_thread, KTR_GENIO)) {
292 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
294 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
295 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
299 len = auio.uio_resid;
300 so = (struct socket *)fp->f_data;
301 error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio,
302 (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
305 if (auio.uio_resid != len && (error == ERESTART ||
306 error == EINTR || error == EWOULDBLOCK))
310 if (ktriov != NULL) {
312 ktruio.uio_iov = ktriov;
313 ktruio.uio_resid = len - auio.uio_resid;
314 ktrgenio(p->p_tracep, s, UIO_READ, &ktruio, error);
316 FREE(ktriov, M_TEMP);
321 p->p_retval[0] = len - auio.uio_resid;
323 len = mp->msg_namelen;
324 if (len <= 0 || fromsa == 0)
328 #define MIN(a,b) ((a)>(b)?(b):(a))
330 /* save sa_len before it is destroyed by MSG_COMPAT */
331 len = MIN(len, fromsa->sa_len);
332 error = copyout(fromsa,
333 (caddr_t)mp->msg_name, (unsigned)len);
337 mp->msg_namelen = len;
339 (error = copyout((caddr_t)&len, namelenp, sizeof (int)))) {
343 if (mp->msg_control) {
344 len = mp->msg_controllen;
346 mp->msg_controllen = 0;
347 ctlbuf = (caddr_t) mp->msg_control;
349 while (m && len > 0) {
355 mp->msg_flags |= MSG_CTRUNC;
359 if ((error = copyout((caddr_t)mtod(m, caddr_t),
360 ctlbuf, tocopy)) != 0)
367 mp->msg_controllen = ctlbuf - (caddr_t)mp->msg_control;
371 FREE(fromsa, M_SONAME);
379 static void bufprint __P((u_char *, size_t));
380 static int show_ioc __P((const char *, struct svr4_strioctl *));
381 static int show_strbuf __P((struct svr4_strbuf *));
382 static void show_msg __P((const char *, int, struct svr4_strbuf *,
383 struct svr4_strbuf *, int));
393 for (i = 0; i < len; i++) {
394 uprintf("%x ", buf[i]);
395 if (i && (i % 16) == 0)
403 struct svr4_strioctl *ioc;
405 u_char *ptr = (u_char *) malloc(ioc->len, M_TEMP, M_WAITOK);
408 uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ",
409 str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf);
411 if ((error = copyin(ioc->buf, ptr, ioc->len)) != 0) {
412 free((char *) ptr, M_TEMP);
416 bufprint(ptr, ioc->len);
420 free((char *) ptr, M_TEMP);
427 struct svr4_strbuf *str;
431 int maxlen = str->maxlen;
441 ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK);
443 if ((error = copyin(str->buf, ptr, len)) != 0) {
444 free((char *) ptr, M_TEMP);
449 uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf);
457 free((char *) ptr, M_TEMP);
464 show_msg(str, fd, ctl, dat, flags)
467 struct svr4_strbuf *ctl;
468 struct svr4_strbuf *dat;
471 struct svr4_strbuf buf;
474 uprintf("%s(%d", str, fd);
476 if ((error = copyin(ctl, &buf, sizeof(buf))) != 0)
484 if ((error = copyin(dat, &buf, sizeof(buf))) != 0)
491 uprintf(", %x);\n", flags);
494 #endif /* DEBUG_SVR4 */
497 * We are faced with an interesting situation. On svr4 unix sockets
498 * are really pipes. But we really have sockets, and we might as
499 * well use them. At the point where svr4 calls TI_BIND, it has
500 * already created a named pipe for the socket using mknod(2).
501 * We need to create a socket with the same name when we bind,
502 * so we need to remove the pipe before, otherwise we'll get address
503 * already in use. So we *carefully* remove the pipe, to avoid
504 * using this as a random file removal tool. We use system calls
505 * to avoid code duplication.
508 clean_pipe(const char *path)
510 struct lstat_args la;
511 struct unlink_args ua;
514 caddr_t sg = stackgap_init();
515 size_t l = strlen(path) + 1;
518 tpath = stackgap_alloc(&sg, l);
519 SCARG(&la, ub) = stackgap_alloc(&sg, sizeof(struct stat));
521 if ((error = copyout(path, tpath, l)) != 0)
524 SCARG(&la, path) = tpath;
526 if ((error = lstat(&la)) != 0)
529 if ((error = copyin(SCARG(&la, ub), &st, sizeof(st))) != 0)
533 * Make sure we are dealing with a mode 0 named pipe.
535 if ((st.st_mode & S_IFMT) != S_IFIFO)
538 if ((st.st_mode & ALLPERMS) != 0)
541 SCARG(&ua, path) = SCARG(&la, path);
543 if ((error = unlink(&ua)) != 0) {
544 DPRINTF(("clean_pipe: unlink failed %d\n", error));
553 sockaddr_to_netaddr_in(sc, sain)
554 struct svr4_strmcmd *sc;
555 const struct sockaddr_in *sain;
557 struct svr4_netaddr_in *na;
558 na = SVR4_ADDROF(sc);
560 na->family = sain->sin_family;
561 na->port = sain->sin_port;
562 na->addr = sain->sin_addr.s_addr;
563 DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port,
569 sockaddr_to_netaddr_un(sc, saun)
570 struct svr4_strmcmd *sc;
571 const struct sockaddr_un *saun;
573 struct svr4_netaddr_un *na;
574 char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 -
578 na = SVR4_ADDROF(sc);
579 na->family = saun->sun_family;
580 for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; )
583 DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path));
588 netaddr_to_sockaddr_in(sain, sc)
589 struct sockaddr_in *sain;
590 const struct svr4_strmcmd *sc;
592 const struct svr4_netaddr_in *na;
595 na = SVR4_C_ADDROF(sc);
596 memset(sain, 0, sizeof(*sain));
597 sain->sin_len = sizeof(*sain);
598 sain->sin_family = na->family;
599 sain->sin_port = na->port;
600 sain->sin_addr.s_addr = na->addr;
601 DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family,
602 sain->sin_port, sain->sin_addr.s_addr));
607 netaddr_to_sockaddr_un(saun, sc)
608 struct sockaddr_un *saun;
609 const struct svr4_strmcmd *sc;
611 const struct svr4_netaddr_un *na;
612 char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1];
615 na = SVR4_C_ADDROF(sc);
616 memset(saun, 0, sizeof(*saun));
617 saun->sun_family = na->family;
618 for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; )
621 saun->sun_len = dst - saun->sun_path;
622 DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family,
630 struct svr4_si_sockparms *pa;
632 struct svr4_strm *st = svr4_stream_get(fp);
633 struct socket *so = (struct socket *) fp->f_data;
638 pa->family = st->s_family;
640 switch (so->so_type) {
642 pa->type = SVR4_T_CLTS;
643 pa->protocol = IPPROTO_UDP;
644 DPRINTF(("getparm(dgram)\n"));
648 pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */
649 pa->protocol = IPPROTO_IP;
650 DPRINTF(("getparm(stream)\n"));
654 pa->type = SVR4_T_CLTS;
655 pa->protocol = IPPROTO_RAW;
656 DPRINTF(("getparm(raw)\n"));
662 DPRINTF(("getparm(type %d?)\n", so->so_type));
669 si_ogetudata(fp, fd, ioc, td)
672 struct svr4_strioctl *ioc;
676 struct svr4_si_oudata ud;
677 struct svr4_si_sockparms pa;
679 if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) {
680 DPRINTF(("SI_OGETUDATA: Wrong size %d != %d\n",
681 sizeof(ud), ioc->len));
685 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
693 ud.addrsize = sizeof(struct svr4_sockaddr_in);
694 if (pa.type == SVR4_SOCK_STREAM)
707 DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n",
712 /* I have no idea what these should be! */
716 ud.servtype = pa.type;
721 return copyout(&ud, ioc->buf, ioc->len);
726 si_sockparams(fp, fd, ioc, td)
729 struct svr4_strioctl *ioc;
732 struct svr4_si_sockparms pa;
735 return copyout(&pa, ioc->buf, sizeof(pa));
740 si_listen(fp, fd, ioc, td)
743 struct svr4_strioctl *ioc;
747 struct svr4_strm *st = svr4_stream_get(fp);
748 struct svr4_strmcmd lst;
749 struct listen_args la;
754 if ((error = copyin(ioc->buf, &lst, ioc->len)) != 0)
757 if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) {
758 DPRINTF(("si_listen: bad request %ld\n", lst.cmd));
763 * We are making assumptions again...
766 DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5));
767 SCARG(&la, backlog) = 5;
769 if ((error = listen(&la)) != 0) {
770 DPRINTF(("SI_LISTEN: listen failed %d\n", error));
774 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
775 lst.cmd = SVR4_TI_BIND_REPLY;
777 switch (st->s_family) {
779 /* XXX: Fill the length here */
784 lst.pad[28] = 0x00000000; /* magic again */
785 lst.pad[29] = 0x00000800; /* magic again */
786 lst.pad[30] = 0x80001400; /* magic again */
790 DPRINTF(("SI_LISTEN: Unsupported address family %d\n",
796 if ((error = copyout(&lst, ioc->buf, ioc->len)) != 0)
804 si_getudata(fp, fd, ioc, td)
807 struct svr4_strioctl *ioc;
811 struct svr4_si_udata ud;
813 if (sizeof(ud) != ioc->len) {
814 DPRINTF(("SI_GETUDATA: Wrong size %d != %d\n",
815 sizeof(ud), ioc->len));
819 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
822 getparm(fp, &ud.sockparms);
824 switch (ud.sockparms.family) {
826 DPRINTF(("getudata_inet\n"));
829 ud.addrsize = sizeof(struct svr4_sockaddr_in);
830 if (ud.sockparms.type == SVR4_SOCK_STREAM)
838 DPRINTF(("getudata_local\n"));
847 DPRINTF(("SI_GETUDATA: Unsupported address family %d\n",
848 ud.sockparms.family));
853 ud.servtype = ud.sockparms.type;
854 DPRINTF(("ud.servtype = %d\n", ud.servtype));
858 return copyout(&ud, ioc->buf, sizeof(ud));
863 si_shutdown(fp, fd, ioc, td)
866 struct svr4_strioctl *ioc;
870 struct shutdown_args ap;
872 if (ioc->len != sizeof(SCARG(&ap, how))) {
873 DPRINTF(("SI_SHUTDOWN: Wrong size %d != %d\n",
874 sizeof(SCARG(&ap, how)), ioc->len));
878 if ((error = copyin(ioc->buf, &SCARG(&ap, how), ioc->len)) != 0)
883 return shutdown(&ap);
888 sockmod(fp, fd, ioc, td)
891 struct svr4_strioctl *ioc;
895 case SVR4_SI_OGETUDATA:
896 DPRINTF(("SI_OGETUDATA\n"));
897 return si_ogetudata(fp, fd, ioc, td);
899 case SVR4_SI_SHUTDOWN:
900 DPRINTF(("SI_SHUTDOWN\n"));
901 return si_shutdown(fp, fd, ioc, td);
904 DPRINTF(("SI_LISTEN\n"));
905 return si_listen(fp, fd, ioc, td);
907 case SVR4_SI_SETMYNAME:
908 DPRINTF(("SI_SETMYNAME\n"));
911 case SVR4_SI_SETPEERNAME:
912 DPRINTF(("SI_SETPEERNAME\n"));
915 case SVR4_SI_GETINTRANSIT:
916 DPRINTF(("SI_GETINTRANSIT\n"));
919 case SVR4_SI_TCL_LINK:
920 DPRINTF(("SI_TCL_LINK\n"));
923 case SVR4_SI_TCL_UNLINK:
924 DPRINTF(("SI_TCL_UNLINK\n"));
927 case SVR4_SI_SOCKPARAMS:
928 DPRINTF(("SI_SOCKPARAMS\n"));
929 return si_sockparams(fp, fd, ioc, td);
931 case SVR4_SI_GETUDATA:
932 DPRINTF(("SI_GETUDATA\n"));
933 return si_getudata(fp, fd, ioc, td);
936 DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd));
944 ti_getinfo(fp, fd, ioc, td)
947 struct svr4_strioctl *ioc;
951 struct svr4_infocmd info;
953 memset(&info, 0, sizeof(info));
955 if ((error = copyin(ioc->buf, &info, ioc->len)) != 0)
958 if (info.cmd != SVR4_TI_INFO_REQUEST)
961 info.cmd = SVR4_TI_INFO_REPLY;
973 ioc->len = sizeof(info);
974 if ((error = copyout(&info, ioc->buf, ioc->len)) != 0)
982 ti_bind(fp, fd, ioc, td)
985 struct svr4_strioctl *ioc;
989 struct svr4_strm *st = svr4_stream_get(fp);
990 struct sockaddr_in sain;
991 struct sockaddr_un saun;
993 void *skp, *sup = NULL;
995 struct svr4_strmcmd bnd;
999 DPRINTF(("ti_bind: bad file descriptor\n"));
1003 if ((error = copyin(ioc->buf, &bnd, ioc->len)) != 0)
1006 if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) {
1007 DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd));
1011 switch (st->s_family) {
1014 sasize = sizeof(sain);
1019 netaddr_to_sockaddr_in(&sain, &bnd);
1021 DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n",
1022 sain.sin_family, sain.sin_port,
1023 sain.sin_addr.s_addr));
1028 sasize = sizeof(saun);
1032 netaddr_to_sockaddr_un(&saun, &bnd);
1034 if (saun.sun_path[0] == '\0')
1037 DPRINTF(("TI_BIND: fam %d, path %s\n",
1038 saun.sun_family, saun.sun_path));
1040 if ((error = clean_pipe(saun.sun_path)) != 0)
1043 bnd.pad[28] = 0x00001000; /* magic again */
1047 DPRINTF(("TI_BIND: Unsupported address family %d\n",
1052 sg = stackgap_init();
1053 sup = stackgap_alloc(&sg, sasize);
1055 if ((error = copyout(skp, sup, sasize)) != 0)
1059 DPRINTF(("TI_BIND: fileno %d\n", fd));
1060 SCARG(&ba, name) = (void *) sup;
1061 SCARG(&ba, namelen) = sasize;
1063 if ((error = bind(&ba)) != 0) {
1064 DPRINTF(("TI_BIND: bind failed %d\n", error));
1070 memset(&bnd, 0, sizeof(bnd));
1071 bnd.len = sasize + 4;
1072 bnd.offs = 0x10; /* XXX */
1075 bnd.cmd = SVR4_TI_BIND_REPLY;
1077 if ((error = copyout(&bnd, ioc->buf, ioc->len)) != 0)
1085 timod(fp, fd, ioc, td)
1088 struct svr4_strioctl *ioc;
1092 case SVR4_TI_GETINFO:
1093 DPRINTF(("TI_GETINFO\n"));
1094 return ti_getinfo(fp, fd, ioc, td);
1096 case SVR4_TI_OPTMGMT:
1097 DPRINTF(("TI_OPTMGMT\n"));
1101 DPRINTF(("TI_BIND\n"));
1102 return ti_bind(fp, fd, ioc, td);
1104 case SVR4_TI_UNBIND:
1105 DPRINTF(("TI_UNBIND\n"));
1109 DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd));
1116 svr4_stream_ti_ioctl(fp, td, retval, fd, cmd, dat)
1124 struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat;
1125 struct svr4_strm *st = svr4_stream_get(fp);
1128 struct sockaddr_in sain;
1129 struct sockaddr_un saun;
1130 struct svr4_strmcmd sc;
1135 DPRINTF(("svr4_stream_ti_ioctl\n"));
1142 if ((error = copyin(sub, &skb, sizeof(skb))) != 0) {
1143 DPRINTF(("ti_ioctl: error copying in strbuf\n"));
1147 switch (st->s_family) {
1150 sasize = sizeof(sain);
1155 sasize = sizeof(saun);
1159 DPRINTF(("ti_ioctl: Unsupported address family %d\n",
1164 sg = stackgap_init();
1165 sup = stackgap_alloc(&sg, sasize);
1166 lenp = stackgap_alloc(&sg, sizeof(*lenp));
1168 if ((error = copyout(&sasize, lenp, sizeof(*lenp))) != 0) {
1169 DPRINTF(("ti_ioctl: error copying out lenp\n"));
1174 case SVR4_TI_GETMYNAME:
1175 DPRINTF(("TI_GETMYNAME\n"));
1177 struct getsockname_args ap;
1178 SCARG(&ap, fdes) = fd;
1179 SCARG(&ap, asa) = sup;
1180 SCARG(&ap, alen) = lenp;
1181 if ((error = getsockname(&ap)) != 0) {
1182 DPRINTF(("ti_ioctl: getsockname error\n"));
1188 case SVR4_TI_GETPEERNAME:
1189 DPRINTF(("TI_GETPEERNAME\n"));
1191 struct getpeername_args ap;
1192 SCARG(&ap, fdes) = fd;
1193 SCARG(&ap, asa) = sup;
1194 SCARG(&ap, alen) = lenp;
1195 if ((error = getpeername(&ap)) != 0) {
1196 DPRINTF(("ti_ioctl: getpeername error\n"));
1202 case SVR4_TI_SETMYNAME:
1203 DPRINTF(("TI_SETMYNAME\n"));
1206 case SVR4_TI_SETPEERNAME:
1207 DPRINTF(("TI_SETPEERNAME\n"));
1210 DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd));
1214 if ((error = copyin(sup, skp, sasize)) != 0) {
1215 DPRINTF(("ti_ioctl: error copying in socket data\n"));
1219 if ((error = copyin(lenp, &sasize, sizeof(*lenp))) != 0) {
1220 DPRINTF(("ti_ioctl: error copying in socket size\n"));
1224 switch (st->s_family) {
1226 sockaddr_to_netaddr_in(&sc, &sain);
1231 sockaddr_to_netaddr_un(&sc, &saun);
1232 skb.len = sasize + 4;
1240 if ((error = copyout(SVR4_ADDROF(&sc), skb.buf, sasize)) != 0) {
1241 DPRINTF(("ti_ioctl: error copying out socket data\n"));
1246 if ((error = copyout(&skb, sub, sizeof(skb))) != 0) {
1247 DPRINTF(("ti_ioctl: error copying out strbuf\n"));
1258 i_nread(fp, td, retval, fd, cmd, dat)
1270 * We are supposed to return the message length in nread, and the
1271 * number of messages in retval. We don't have the notion of number
1272 * of stream messages, so we just find out if we have any bytes waiting
1273 * for us, and if we do, then we assume that we have at least one
1274 * message waiting for us.
1276 if ((error = fo_ioctl(fp, FIONREAD, (caddr_t) &nread, td)) != 0)
1284 return copyout(&nread, dat, sizeof(nread));
1288 i_fdinsert(fp, td, retval, fd, cmd, dat)
1297 * Major hack again here. We assume that we are using this to
1298 * implement accept(2). If that is the case, we have already
1299 * called accept, and we have stored the file descriptor in
1300 * afd. We find the file descriptor that the code wants to use
1301 * in fd insert, and then we dup2() our accepted file descriptor
1305 struct svr4_strm *st = svr4_stream_get(fp);
1306 struct svr4_strfdinsert fdi;
1307 struct dup2_args d2p;
1308 struct close_args clp;
1311 DPRINTF(("fdinsert: bad file type\n"));
1315 if (st->s_afd == -1) {
1316 DPRINTF(("fdinsert: accept fd not found\n"));
1320 if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) {
1321 DPRINTF(("fdinsert: copyin failed %d\n", error));
1325 SCARG(&d2p, from) = st->s_afd;
1326 SCARG(&d2p, to) = fdi.fd;
1328 if ((error = dup2(&d2p)) != 0) {
1329 DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n",
1330 st->s_afd, fdi.fd, error));
1334 SCARG(&clp, fd) = st->s_afd;
1336 if ((error = close(&clp)) != 0) {
1337 DPRINTF(("fdinsert: close(%d) failed %d\n",
1350 _i_bind_rsvd(fp, td, retval, fd, cmd, dat)
1358 struct mkfifo_args ap;
1361 * This is a supposed to be a kernel and library only ioctl.
1362 * It gets called before ti_bind, when we have a unix
1363 * socket, to physically create the socket transport and
1364 * ``reserve'' it. I don't know how this get reserved inside
1365 * the kernel, but we are going to create it nevertheless.
1367 SCARG(&ap, path) = dat;
1368 SCARG(&ap, mode) = S_IFIFO;
1374 _i_rele_rsvd(fp, td, retval, fd, cmd, dat)
1382 struct unlink_args ap;
1385 * This is a supposed to be a kernel and library only ioctl.
1386 * I guess it is supposed to release the socket.
1388 SCARG(&ap, path) = dat;
1394 i_str(fp, td, retval, fd, cmd, dat)
1403 struct svr4_strioctl ioc;
1405 if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0)
1409 if ((error = show_ioc(">", &ioc)) != 0)
1411 #endif /* DEBUG_SVR4 */
1413 switch (ioc.cmd & 0xff00) {
1415 if ((error = sockmod(fp, fd, &ioc, td)) != 0)
1420 if ((error = timod(fp, fd, &ioc, td)) != 0)
1425 DPRINTF(("Unimplemented module %c %ld\n",
1426 (char) (cmd >> 8), cmd & 0xff));
1431 if ((error = show_ioc("<", &ioc)) != 0)
1433 #endif /* DEBUG_SVR4 */
1434 return copyout(&ioc, dat, sizeof(ioc));
1438 i_setsig(fp, td, retval, fd, cmd, dat)
1447 * This is the best we can do for now; we cannot generate
1448 * signals only for specific events so the signal mask gets
1449 * ignored; we save it just to pass it to a possible I_GETSIG...
1451 * We alse have to fix the O_ASYNC fcntl bit, so the
1452 * process will get SIGPOLLs.
1454 struct proc *p = td->td_proc;
1455 struct fcntl_args fa;
1457 register_t oflags, flags;
1458 struct svr4_strm *st = svr4_stream_get(fp);
1463 DPRINTF(("i_setsig: bad file descriptor\n"));
1466 /* get old status flags */
1467 SCARG(&fa, fd) = fd;
1468 SCARG(&fa, cmd) = F_GETFL;
1469 if ((error = fcntl(&fa)) != 0)
1472 oflags = p->p_retval[0];
1474 /* update the flags */
1478 flags = oflags | O_ASYNC;
1479 if ((error = copyin(dat, &mask, sizeof(mask))) != 0) {
1480 DPRINTF(("i_setsig: bad eventmask pointer\n"));
1483 if (mask & SVR4_S_ALLMASK) {
1484 DPRINTF(("i_setsig: bad eventmask data %x\n", mask));
1487 st->s_eventmask = mask;
1490 flags = oflags & ~O_ASYNC;
1491 st->s_eventmask = 0;
1494 /* set the new flags, if changed */
1495 if (flags != oflags) {
1496 SCARG(&fa, cmd) = F_SETFL;
1497 SCARG(&fa, arg) = (long) flags;
1498 if ((error = fcntl(&fa)) != 0)
1500 flags = p->p_retval[0];
1503 /* set up SIGIO receiver if needed */
1505 SCARG(&fa, cmd) = F_SETOWN;
1506 SCARG(&fa, arg) = (long) p->p_pid;
1513 i_getsig(fp, td, retval, fd, cmd, dat)
1524 struct svr4_strm *st = svr4_stream_get(fp);
1527 DPRINTF(("i_getsig: bad file descriptor\n"));
1530 if ((error = copyout(&st->s_eventmask, dat,
1531 sizeof(st->s_eventmask))) != 0) {
1532 DPRINTF(("i_getsig: bad eventmask pointer\n"));
1540 svr4_stream_ioctl(fp, td, retval, fd, cmd, dat)
1551 * All the following stuff assumes "sockmod" is pushed...
1555 DPRINTF(("I_NREAD\n"));
1556 return i_nread(fp, td, retval, fd, cmd, dat);
1559 DPRINTF(("I_PUSH %p\n", dat));
1560 #if defined(DEBUG_SVR4)
1561 show_strbuf((void *)dat);
1566 DPRINTF(("I_POP\n"));
1570 DPRINTF(("I_LOOK\n"));
1574 DPRINTF(("I_FLUSH\n"));
1578 DPRINTF(("I_SRDOPT\n"));
1582 DPRINTF(("I_GRDOPT\n"));
1586 DPRINTF(("I_STR\n"));
1587 return i_str(fp, td, retval, fd, cmd, dat);
1590 DPRINTF(("I_SETSIG\n"));
1591 return i_setsig(fp, td, retval, fd, cmd, dat);
1594 DPRINTF(("I_GETSIG\n"));
1595 return i_getsig(fp, td, retval, fd, cmd, dat);
1598 DPRINTF(("I_FIND\n"));
1600 * Here we are not pushing modules really, we just
1601 * pretend all are present
1607 DPRINTF(("I_LINK\n"));
1611 DPRINTF(("I_UNLINK\n"));
1614 case SVR4_I_ERECVFD:
1615 DPRINTF(("I_ERECVFD\n"));
1619 DPRINTF(("I_PEEK\n"));
1622 case SVR4_I_FDINSERT:
1623 DPRINTF(("I_FDINSERT\n"));
1624 return i_fdinsert(fp, td, retval, fd, cmd, dat);
1627 DPRINTF(("I_SENDFD\n"));
1631 DPRINTF(("I_RECVFD\n"));
1635 DPRINTF(("I_SWROPT\n"));
1639 DPRINTF(("I_GWROPT\n"));
1643 DPRINTF(("I_LIST\n"));
1647 DPRINTF(("I_PLINK\n"));
1650 case SVR4_I_PUNLINK:
1651 DPRINTF(("I_PUNLINK\n"));
1655 DPRINTF(("I_SETEV\n"));
1659 DPRINTF(("I_GETEV\n"));
1663 DPRINTF(("I_STREV\n"));
1666 case SVR4_I_UNSTREV:
1667 DPRINTF(("I_UNSTREV\n"));
1670 case SVR4_I_FLUSHBAND:
1671 DPRINTF(("I_FLUSHBAND\n"));
1675 DPRINTF(("I_CKBAND\n"));
1678 case SVR4_I_GETBAND:
1679 DPRINTF(("I_GETBANK\n"));
1683 DPRINTF(("I_ATMARK\n"));
1686 case SVR4_I_SETCLTIME:
1687 DPRINTF(("I_SETCLTIME\n"));
1690 case SVR4_I_GETCLTIME:
1691 DPRINTF(("I_GETCLTIME\n"));
1695 DPRINTF(("I_CANPUT\n"));
1698 case SVR4__I_BIND_RSVD:
1699 DPRINTF(("_I_BIND_RSVD\n"));
1700 return _i_bind_rsvd(fp, td, retval, fd, cmd, dat);
1702 case SVR4__I_RELE_RSVD:
1703 DPRINTF(("_I_RELE_RSVD\n"));
1704 return _i_rele_rsvd(fp, td, retval, fd, cmd, dat);
1707 DPRINTF(("unimpl cmd = %lx\n", cmd));
1717 svr4_sys_putmsg(struct svr4_sys_putmsg_args *uap)
1719 struct thread *td = curthread;
1720 struct proc *p = td->td_proc;
1721 struct filedesc *fdp;
1723 struct svr4_strbuf dat, ctl;
1724 struct svr4_strmcmd sc;
1725 struct sockaddr_in sain;
1726 struct sockaddr_un saun;
1728 int sasize, *retval;
1729 struct svr4_strm *st;
1735 retval = p->p_retval;
1736 fp = fdp->fd_ofiles[SCARG(uap, fd)];
1738 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) {
1740 uprintf("putmsg: bad fp\n");
1746 show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl),
1747 SCARG(uap, dat), SCARG(uap, flags));
1748 #endif /* DEBUG_SVR4 */
1750 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) {
1752 uprintf("putmsg: bad fp(2)\n");
1757 if (SCARG(uap, ctl) != NULL) {
1758 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) {
1760 uprintf("putmsg: copyin(): %d\n", error);
1768 if (SCARG(uap, dat) != NULL) {
1769 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0) {
1771 uprintf("putmsg: copyin(): %d (2)\n", error);
1780 * Only for sockets for now.
1782 if ((st = svr4_stream_get(fp)) == NULL) {
1783 DPRINTF(("putmsg: bad file type\n"));
1787 if (ctl.len > sizeof(sc)) {
1788 DPRINTF(("putmsg: Bad control size %d != %d\n", ctl.len,
1789 sizeof(struct svr4_strmcmd)));
1793 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
1796 switch (st->s_family) {
1798 if (sc.len != sizeof(sain)) {
1799 if (sc.cmd == SVR4_TI_DATA_REQUEST) {
1800 struct write_args wa;
1802 /* Solaris seems to use sc.cmd = 3 to
1803 * send "expedited" data. telnet uses
1804 * this for options processing, sending EOF,
1805 * etc. I'm sure other things use it too.
1806 * I don't have any documentation
1807 * on it, so I'm making a guess that this
1808 * is how it works. newton@atdot.dotat.org XXX
1810 DPRINTF(("sending expedited data ??\n"));
1811 SCARG(&wa, fd) = SCARG(uap, fd);
1812 SCARG(&wa, buf) = dat.buf;
1813 SCARG(&wa, nbyte) = dat.len;
1816 DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len));
1819 netaddr_to_sockaddr_in(&sain, &sc);
1821 sasize = sizeof(sain);
1822 error = sain.sin_family != st->s_family;
1827 /* We are doing an accept; succeed */
1828 DPRINTF(("putmsg: Do nothing\n"));
1833 /* Maybe we've been given a device/inode pair */
1834 udev_t *dev = SVR4_ADDROF(&sc);
1835 ino_t *ino = (ino_t *) &dev[1];
1836 skp = svr4_find_socket(td, fp, *dev, *ino);
1839 /* I guess we have it by name */
1840 netaddr_to_sockaddr_un(skp, &sc);
1842 sasize = sizeof(saun);
1847 DPRINTF(("putmsg: Unsupported address family %d\n",
1852 sg = stackgap_init();
1853 sup = stackgap_alloc(&sg, sasize);
1855 if ((error = copyout(skp, sup, sasize)) != 0)
1858 switch (st->s_cmd = sc.cmd) {
1859 case SVR4_TI_CONNECT_REQUEST: /* connect */
1861 struct connect_args co;
1863 SCARG(&co, s) = SCARG(uap, fd);
1864 SCARG(&co, name) = (void *) sup;
1865 SCARG(&co, namelen) = (int) sasize;
1867 return connect(&co);
1870 case SVR4_TI_SENDTO_REQUEST: /* sendto */
1875 msg.msg_name = (caddr_t) sup;
1876 msg.msg_namelen = sasize;
1877 msg.msg_iov = &aiov;
1879 msg.msg_control = 0;
1881 aiov.iov_base = dat.buf;
1882 aiov.iov_len = dat.len;
1884 error = so->so_proto->pr_usrreqs->pru_sosend
1885 (so, 0, uio, 0, 0, 0, uio->uio_td);
1887 error = svr4_sendit(td, SCARG(uap, fd), &msg,
1889 DPRINTF(("sendto_request error: %d\n", error));
1895 DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd));
1901 svr4_sys_getmsg(struct svr4_sys_getmsg_args *uap)
1903 struct thread *td = curthread;
1904 struct proc *p = td->td_proc;
1905 struct filedesc *fdp;
1907 struct getpeername_args ga;
1908 struct accept_args aa;
1909 struct svr4_strbuf dat, ctl;
1910 struct svr4_strmcmd sc;
1914 struct sockaddr_in sain;
1915 struct sockaddr_un saun;
1918 struct svr4_strm *st;
1925 retval = p->p_retval;
1926 fp = fdp->fd_ofiles[SCARG(uap, fd)];
1928 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL))
1931 memset(&sc, 0, sizeof(sc));
1934 show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl),
1935 SCARG(uap, dat), 0);
1936 #endif /* DEBUG_SVR4 */
1938 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL))
1941 if (SCARG(uap, ctl) != NULL) {
1942 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0)
1950 if (SCARG(uap, dat) != NULL) {
1951 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0)
1960 * Only for sockets for now.
1962 if ((st = svr4_stream_get(fp)) == NULL) {
1963 DPRINTF(("getmsg: bad file type\n"));
1967 if (ctl.maxlen == -1 || dat.maxlen == -1) {
1968 DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n"));
1972 switch (st->s_family) {
1975 sasize = sizeof(sain);
1980 sasize = sizeof(saun);
1984 DPRINTF(("getmsg: Unsupported address family %d\n",
1989 sg = stackgap_init();
1990 sup = stackgap_alloc(&sg, sasize);
1991 flen = (int *) stackgap_alloc(&sg, sizeof(*flen));
1994 if ((error = copyout(&fl, flen, sizeof(fl))) != 0)
1997 switch (st->s_cmd) {
1998 case SVR4_TI_CONNECT_REQUEST:
1999 DPRINTF(("getmsg: TI_CONNECT_REQUEST\n"));
2001 * We do the connect in one step, so the putmsg should
2002 * have gotten the error.
2004 sc.cmd = SVR4_TI_OK_REPLY;
2013 case SVR4_TI_OK_REPLY:
2014 DPRINTF(("getmsg: TI_OK_REPLY\n"));
2016 * We are immediately after a connect reply, so we send
2017 * a connect verification.
2020 SCARG(&ga, fdes) = SCARG(uap, fd);
2021 SCARG(&ga, asa) = (void *) sup;
2022 SCARG(&ga, alen) = flen;
2024 if ((error = getpeername(&ga)) != 0) {
2025 DPRINTF(("getmsg: getpeername failed %d\n", error));
2029 if ((error = copyin(sup, skp, sasize)) != 0)
2032 sc.cmd = SVR4_TI_CONNECT_REPLY;
2036 sc.pad[2] = 0x04000402;
2038 switch (st->s_family) {
2041 sockaddr_to_netaddr_in(&sc, &sain);
2045 sc.len = sasize + 4;
2046 sockaddr_to_netaddr_un(&sc, &saun);
2059 case SVR4_TI__ACCEPT_OK:
2060 DPRINTF(("getmsg: TI__ACCEPT_OK\n"));
2062 * We do the connect in one step, so the putmsg should
2063 * have gotten the error.
2065 sc.cmd = SVR4_TI_OK_REPLY;
2071 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
2074 case SVR4_TI__ACCEPT_WAIT:
2075 DPRINTF(("getmsg: TI__ACCEPT_WAIT\n"));
2077 * We are after a listen, so we try to accept...
2079 SCARG(&aa, s) = SCARG(uap, fd);
2080 SCARG(&aa, name) = (void *) sup;
2081 SCARG(&aa, anamelen) = flen;
2083 if ((error = accept(&aa)) != 0) {
2084 DPRINTF(("getmsg: accept failed %d\n", error));
2088 st->s_afd = *retval;
2090 DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd));
2092 if ((error = copyin(sup, skp, sasize)) != 0)
2095 sc.cmd = SVR4_TI_ACCEPT_REPLY;
2099 switch (st->s_family) {
2102 sockaddr_to_netaddr_in(&sc, &sain);
2108 sc.pad[1] = 0x00010000;
2109 sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */
2110 sc.pad[3] = 0x00010000;
2112 sc.len = sasize + 4;
2121 st->s_cmd = SVR4_TI__ACCEPT_OK;
2124 case SVR4_TI_SENDTO_REQUEST:
2125 DPRINTF(("getmsg: TI_SENDTO_REQUEST\n"));
2126 if (ctl.maxlen > 36 && ctl.len < 36)
2129 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
2132 switch (st->s_family) {
2134 sockaddr_to_netaddr_in(&sc, &sain);
2138 sockaddr_to_netaddr_un(&sc, &saun);
2145 msg.msg_name = (caddr_t) sup;
2146 msg.msg_namelen = sasize;
2147 msg.msg_iov = &aiov;
2149 msg.msg_control = 0;
2150 aiov.iov_base = dat.buf;
2151 aiov.iov_len = dat.maxlen;
2154 error = svr4_recvit(td, SCARG(uap, fd), &msg, (caddr_t) flen);
2157 DPRINTF(("getmsg: recvit failed %d\n", error));
2161 if ((error = copyin(msg.msg_name, skp, sasize)) != 0)
2164 sc.cmd = SVR4_TI_RECVFROM_IND;
2166 switch (st->s_family) {
2169 sockaddr_to_netaddr_in(&sc, &sain);
2173 sc.len = sasize + 4;
2174 sockaddr_to_netaddr_un(&sc, &saun);
2188 if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) {
2189 struct read_args ra;
2191 /* More wierdness: Again, I can't find documentation
2192 * to back this up, but when a process does a generic
2193 * "getmsg()" call it seems that the command field is
2194 * zero and the length of the data area is zero. I
2195 * think processes expect getmsg() to fill in dat.len
2196 * after reading at most dat.maxlen octets from the
2197 * stream. Since we're using sockets I can let
2198 * read() look after it and frob return values
2199 * appropriately (or inappropriately :-)
2200 * -- newton@atdot.dotat.org XXX
2202 SCARG(&ra, fd) = SCARG(uap, fd);
2203 SCARG(&ra, buf) = dat.buf;
2204 SCARG(&ra, nbyte) = dat.maxlen;
2205 if ((error = read(&ra)) != 0) {
2210 st->s_cmd = SVR4_TI_SENDTO_REQUEST;
2213 DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd));
2217 if (SCARG(uap, ctl)) {
2219 if ((error = copyout(&sc, ctl.buf, ctl.len)) != 0)
2222 if ((error = copyout(&ctl, SCARG(uap, ctl), sizeof(ctl))) != 0)
2226 if (SCARG(uap, dat)) {
2227 if ((error = copyout(&dat, SCARG(uap, dat), sizeof(dat))) != 0)
2231 if (SCARG(uap, flags)) { /* XXX: Need translation */
2232 if ((error = copyout(&fl, SCARG(uap, flags), sizeof(fl))) != 0)
2239 show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl),
2240 SCARG(uap, dat), fl);
2241 #endif /* DEBUG_SVR4 */
2245 int svr4_sys_send(struct svr4_sys_send_args *uap)
2247 struct osend_args osa;
2248 SCARG(&osa, s) = SCARG(uap, s);
2249 SCARG(&osa, buf) = SCARG(uap, buf);
2250 SCARG(&osa, len) = SCARG(uap, len);
2251 SCARG(&osa, flags) = SCARG(uap, flags);
2255 int svr4_sys_recv(struct svr4_sys_recv_args *uap)
2257 struct orecv_args ora;
2258 SCARG(&ora, s) = SCARG(uap, s);
2259 SCARG(&ora, buf) = SCARG(uap, buf);
2260 SCARG(&ora, len) = SCARG(uap, len);
2261 SCARG(&ora, flags) = SCARG(uap, flags);
2266 * XXX This isn't necessary, but it's handy for inserting debug code into
2267 * sendto(). Let's leave it here for now...
2270 svr4_sys_sendto(struct svr4_sys_sendto_args *uap)
2272 struct sendto_args sa;
2274 SCARG(&sa, s) = SCARG(uap, s);
2275 SCARG(&sa, buf) = SCARG(uap, buf);
2276 SCARG(&sa, len) = SCARG(uap, len);
2277 SCARG(&sa, flags) = SCARG(uap, flags);
2278 SCARG(&sa, to) = (caddr_t)SCARG(uap, to);
2279 SCARG(&sa, tolen) = SCARG(uap, tolen);
2281 DPRINTF(("calling sendto()\n"));