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.14 2005/06/22 01:33:29 dillon Exp $
35 * Pretend that we have streams...
38 * ToDo: The state machine for getmsg needs re-thinking
43 #include <sys/param.h>
44 #include <sys/systm.h>
46 #include <sys/malloc.h>
48 #include <sys/filedesc.h>
49 #include <sys/fcntl.h>
50 #include <sys/filio.h>
51 #include <sys/select.h>
52 #include <sys/socket.h>
53 #include <sys/socketvar.h>
54 #include <sys/socketops.h>
56 #include <netinet/in.h>
58 #include <sys/protosw.h>
59 #include <sys/signal.h>
60 #include <sys/signalvar.h>
62 #include <sys/ktrace.h>
65 #include <sys/file2.h>
67 #include <sys/sysproto.h>
70 #include "svr4_types.h"
71 #include "svr4_util.h"
72 #include "svr4_signal.h"
73 #include "svr4_proto.h"
74 #include "svr4_stropts.h"
75 #include "svr4_timod.h"
76 #include "svr4_sockmod.h"
77 #include "svr4_ioctl.h"
78 #include "svr4_socket.h"
81 static int clean_pipe (const char *);
82 static void getparm (struct file *, struct svr4_si_sockparms *);
84 /* Address Conversions */
85 static void sockaddr_to_netaddr_in (struct svr4_strmcmd *,
86 const struct sockaddr_in *);
87 static void sockaddr_to_netaddr_un (struct svr4_strmcmd *,
88 const struct sockaddr_un *);
89 static void netaddr_to_sockaddr_in (struct sockaddr_in *,
90 const struct svr4_strmcmd *);
91 static void netaddr_to_sockaddr_un (struct sockaddr_un *,
92 const struct svr4_strmcmd *);
95 static int i_nread (struct file *, struct thread *, register_t *, int,
97 static int i_fdinsert (struct file *, struct thread *, register_t *, int,
99 static int i_str (struct file *, struct thread *, register_t *, int,
101 static int i_setsig (struct file *, struct thread *, register_t *, int,
103 static int i_getsig (struct file *, struct thread *, register_t *, int,
105 static int _i_bind_rsvd (struct file *, struct thread *, register_t *, int,
107 static int _i_rele_rsvd (struct file *, struct thread *, register_t *, int,
110 /* i_str sockmod calls */
111 static int sockmod (struct file *, int, struct svr4_strioctl *,
113 static int si_listen (struct file *, int, struct svr4_strioctl *,
115 static int si_ogetudata (struct file *, int, struct svr4_strioctl *,
117 static int si_sockparams (struct file *, int, struct svr4_strioctl *,
119 static int si_shutdown (struct file *, int, struct svr4_strioctl *,
121 static int si_getudata (struct file *, int, struct svr4_strioctl *,
124 /* i_str timod calls */
125 static int timod (struct file *, int, struct svr4_strioctl *,
127 static int ti_getinfo (struct file *, int, struct svr4_strioctl *,
129 static int ti_bind (struct file *, int, struct svr4_strioctl *,
133 static int svr4_sendit (struct thread *td, int s, struct msghdr *mp,
134 int flags, int *retval);
136 static int svr4_recvit (struct thread *td, int s, struct msghdr *mp,
137 caddr_t namelenp, int *retval);
139 /* <sigh> Ok, so we shouldn't use sendit() in uipc_syscalls.c because
140 * it isn't part of a "public" interface; We're supposed to use
141 * pru_sosend instead. Same goes for recvit()/pru_soreceive() for
142 * that matter. Solution: Suck sendit()/recvit() into here where we
143 * can do what we like.
145 * I hate code duplication.
147 * I will take out all the #ifdef COMPAT_OLDSOCK gumph, though.
150 svr4_sendit(td, s, mp, flags, retval)
162 struct mbuf *control;
167 struct iovec *ktriov = NULL;
174 error = holdsock(p->p_fd, s, &fp);
177 auio.uio_iov = mp->msg_iov;
178 auio.uio_iovcnt = mp->msg_iovlen;
179 auio.uio_segflg = UIO_USERSPACE;
180 auio.uio_rw = UIO_WRITE;
182 auio.uio_offset = 0; /* XXX */
185 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
186 if ((auio.uio_resid += iov->iov_len) < 0) {
192 error = getsockaddr(&to, mp->msg_name, mp->msg_namelen);
200 if (mp->msg_control) {
201 if (mp->msg_controllen < sizeof(struct cmsghdr)) {
205 control = m_get(MB_WAIT, MT_CONTROL);
206 if (control == NULL) {
210 control->m_len = mp->msg_controllen;
211 error = copyin(mp->msg_control, mtod(control, caddr_t),
221 if (KTRPOINT(p->p_thread, KTR_GENIO)) {
222 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
224 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
225 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
229 len = auio.uio_resid;
230 so = (struct socket *)fp->f_data;
231 error = so_pru_sosend(so, to, &auio, NULL, 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_pru_soreceive(so, &fromsa, &auio, NULL,
312 mp->msg_control ? &control : NULL, &mp->msg_flags);
314 if (auio.uio_resid != len && (error == ERESTART ||
315 error == EINTR || error == EWOULDBLOCK))
319 if (ktriov != NULL) {
321 ktruio.uio_iov = ktriov;
322 ktruio.uio_resid = len - auio.uio_resid;
323 ktrgenio(p->p_tracep, s, UIO_READ, &ktruio, error);
325 FREE(ktriov, M_TEMP);
330 *retval = len - auio.uio_resid;
332 len = mp->msg_namelen;
333 if (len <= 0 || fromsa == 0)
337 #define MIN(a,b) ((a)>(b)?(b):(a))
339 /* save sa_len before it is destroyed by MSG_COMPAT */
340 len = MIN(len, fromsa->sa_len);
341 error = copyout(fromsa,
342 (caddr_t)mp->msg_name, (unsigned)len);
346 mp->msg_namelen = len;
348 (error = copyout((caddr_t)&len, namelenp, sizeof (int)))) {
352 if (mp->msg_control) {
353 len = mp->msg_controllen;
355 mp->msg_controllen = 0;
356 ctlbuf = (caddr_t) mp->msg_control;
358 while (m && len > 0) {
364 mp->msg_flags |= MSG_CTRUNC;
368 if ((error = copyout((caddr_t)mtod(m, caddr_t),
369 ctlbuf, tocopy)) != 0)
376 mp->msg_controllen = ctlbuf - (caddr_t)mp->msg_control;
380 FREE(fromsa, M_SONAME);
388 static void bufprint (u_char *, size_t);
389 static int show_ioc (const char *, struct svr4_strioctl *);
390 static int show_strbuf (struct svr4_strbuf *);
391 static void show_msg (const char *, int, struct svr4_strbuf *,
392 struct svr4_strbuf *, int);
402 for (i = 0; i < len; i++) {
403 uprintf("%x ", buf[i]);
404 if (i && (i % 16) == 0)
412 struct svr4_strioctl *ioc;
414 u_char *ptr = (u_char *) malloc(ioc->len, M_TEMP, M_WAITOK);
417 uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ",
418 str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf);
420 if ((error = copyin(ioc->buf, ptr, ioc->len)) != 0) {
421 free((char *) ptr, M_TEMP);
425 bufprint(ptr, ioc->len);
429 free((char *) ptr, M_TEMP);
436 struct svr4_strbuf *str;
440 int maxlen = str->maxlen;
450 ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK);
452 if ((error = copyin(str->buf, ptr, len)) != 0) {
453 free((char *) ptr, M_TEMP);
458 uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf);
466 free((char *) ptr, M_TEMP);
473 show_msg(str, fd, ctl, dat, flags)
476 struct svr4_strbuf *ctl;
477 struct svr4_strbuf *dat;
480 struct svr4_strbuf buf;
483 uprintf("%s(%d", str, fd);
485 if ((error = copyin(ctl, &buf, sizeof(buf))) != 0)
493 if ((error = copyin(dat, &buf, sizeof(buf))) != 0)
500 uprintf(", %x);\n", flags);
503 #endif /* DEBUG_SVR4 */
506 * We are faced with an interesting situation. On svr4 unix sockets
507 * are really pipes. But we really have sockets, and we might as
508 * well use them. At the point where svr4 calls TI_BIND, it has
509 * already created a named pipe for the socket using mknod(2).
510 * We need to create a socket with the same name when we bind,
511 * so we need to remove the pipe before, otherwise we'll get address
512 * already in use. So we *carefully* remove the pipe, to avoid
513 * using this as a random file removal tool. We use system calls
514 * to avoid code duplication.
517 clean_pipe(const char *path)
519 struct lstat_args la;
520 struct unlink_args ua;
523 caddr_t sg = stackgap_init();
524 size_t l = strlen(path) + 1;
527 tpath = stackgap_alloc(&sg, l);
528 SCARG(&la, ub) = stackgap_alloc(&sg, sizeof(struct stat));
530 if ((error = copyout(path, tpath, l)) != 0)
533 SCARG(&la, path) = tpath;
535 if ((error = lstat(&la)) != 0)
538 if ((error = copyin(SCARG(&la, ub), &st, sizeof(st))) != 0)
542 * Make sure we are dealing with a mode 0 named pipe.
544 if ((st.st_mode & S_IFMT) != S_IFIFO)
547 if ((st.st_mode & ALLPERMS) != 0)
550 SCARG(&ua, path) = SCARG(&la, path);
552 if ((error = unlink(&ua)) != 0) {
553 DPRINTF(("clean_pipe: unlink failed %d\n", error));
562 sockaddr_to_netaddr_in(sc, sain)
563 struct svr4_strmcmd *sc;
564 const struct sockaddr_in *sain;
566 struct svr4_netaddr_in *na;
567 na = SVR4_ADDROF(sc);
569 na->family = sain->sin_family;
570 na->port = sain->sin_port;
571 na->addr = sain->sin_addr.s_addr;
572 DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port,
578 sockaddr_to_netaddr_un(sc, saun)
579 struct svr4_strmcmd *sc;
580 const struct sockaddr_un *saun;
582 struct svr4_netaddr_un *na;
583 char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 -
587 na = SVR4_ADDROF(sc);
588 na->family = saun->sun_family;
589 for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; )
592 DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path));
597 netaddr_to_sockaddr_in(sain, sc)
598 struct sockaddr_in *sain;
599 const struct svr4_strmcmd *sc;
601 const struct svr4_netaddr_in *na;
604 na = SVR4_C_ADDROF(sc);
605 memset(sain, 0, sizeof(*sain));
606 sain->sin_len = sizeof(*sain);
607 sain->sin_family = na->family;
608 sain->sin_port = na->port;
609 sain->sin_addr.s_addr = na->addr;
610 DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family,
611 sain->sin_port, sain->sin_addr.s_addr));
616 netaddr_to_sockaddr_un(saun, sc)
617 struct sockaddr_un *saun;
618 const struct svr4_strmcmd *sc;
620 const struct svr4_netaddr_un *na;
621 char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1];
624 na = SVR4_C_ADDROF(sc);
625 memset(saun, 0, sizeof(*saun));
626 saun->sun_family = na->family;
627 for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; )
630 saun->sun_len = dst - saun->sun_path;
631 DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family,
639 struct svr4_si_sockparms *pa;
641 struct svr4_strm *st = svr4_stream_get(fp);
642 struct socket *so = (struct socket *) fp->f_data;
647 pa->family = st->s_family;
649 switch (so->so_type) {
651 pa->type = SVR4_T_CLTS;
652 pa->protocol = IPPROTO_UDP;
653 DPRINTF(("getparm(dgram)\n"));
657 pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */
658 pa->protocol = IPPROTO_IP;
659 DPRINTF(("getparm(stream)\n"));
663 pa->type = SVR4_T_CLTS;
664 pa->protocol = IPPROTO_RAW;
665 DPRINTF(("getparm(raw)\n"));
671 DPRINTF(("getparm(type %d?)\n", so->so_type));
678 si_ogetudata(fp, fd, ioc, td)
681 struct svr4_strioctl *ioc;
685 struct svr4_si_oudata ud;
686 struct svr4_si_sockparms pa;
688 if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) {
689 DPRINTF(("SI_OGETUDATA: Wrong size %d != %d\n",
690 sizeof(ud), ioc->len));
694 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
702 ud.addrsize = sizeof(struct svr4_sockaddr_in);
703 if (pa.type == SVR4_SOCK_STREAM)
716 DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n",
721 /* I have no idea what these should be! */
725 ud.servtype = pa.type;
730 return copyout(&ud, ioc->buf, ioc->len);
735 si_sockparams(fp, fd, ioc, td)
738 struct svr4_strioctl *ioc;
741 struct svr4_si_sockparms pa;
744 return copyout(&pa, ioc->buf, sizeof(pa));
749 si_listen(fp, fd, ioc, td)
752 struct svr4_strioctl *ioc;
756 struct svr4_strm *st = svr4_stream_get(fp);
757 struct svr4_strmcmd lst;
758 struct listen_args la;
763 if ((error = copyin(ioc->buf, &lst, ioc->len)) != 0)
766 if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) {
767 DPRINTF(("si_listen: bad request %ld\n", lst.cmd));
772 * We are making assumptions again...
775 DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5));
776 SCARG(&la, backlog) = 5;
778 if ((error = listen(&la)) != 0) {
779 DPRINTF(("SI_LISTEN: listen failed %d\n", error));
783 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
784 lst.cmd = SVR4_TI_BIND_REPLY;
786 switch (st->s_family) {
788 /* XXX: Fill the length here */
793 lst.pad[28] = 0x00000000; /* magic again */
794 lst.pad[29] = 0x00000800; /* magic again */
795 lst.pad[30] = 0x80001400; /* magic again */
799 DPRINTF(("SI_LISTEN: Unsupported address family %d\n",
805 if ((error = copyout(&lst, ioc->buf, ioc->len)) != 0)
813 si_getudata(fp, fd, ioc, td)
816 struct svr4_strioctl *ioc;
820 struct svr4_si_udata ud;
822 if (sizeof(ud) != ioc->len) {
823 DPRINTF(("SI_GETUDATA: Wrong size %d != %d\n",
824 sizeof(ud), ioc->len));
828 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
831 getparm(fp, &ud.sockparms);
833 switch (ud.sockparms.family) {
835 DPRINTF(("getudata_inet\n"));
838 ud.addrsize = sizeof(struct svr4_sockaddr_in);
839 if (ud.sockparms.type == SVR4_SOCK_STREAM)
847 DPRINTF(("getudata_local\n"));
856 DPRINTF(("SI_GETUDATA: Unsupported address family %d\n",
857 ud.sockparms.family));
862 ud.servtype = ud.sockparms.type;
863 DPRINTF(("ud.servtype = %d\n", ud.servtype));
867 return copyout(&ud, ioc->buf, sizeof(ud));
872 si_shutdown(fp, fd, ioc, td)
875 struct svr4_strioctl *ioc;
879 struct shutdown_args ap;
881 if (ioc->len != sizeof(SCARG(&ap, how))) {
882 DPRINTF(("SI_SHUTDOWN: Wrong size %d != %d\n",
883 sizeof(SCARG(&ap, how)), ioc->len));
887 if ((error = copyin(ioc->buf, &SCARG(&ap, how), ioc->len)) != 0)
892 return shutdown(&ap);
897 sockmod(fp, fd, ioc, td)
900 struct svr4_strioctl *ioc;
904 case SVR4_SI_OGETUDATA:
905 DPRINTF(("SI_OGETUDATA\n"));
906 return si_ogetudata(fp, fd, ioc, td);
908 case SVR4_SI_SHUTDOWN:
909 DPRINTF(("SI_SHUTDOWN\n"));
910 return si_shutdown(fp, fd, ioc, td);
913 DPRINTF(("SI_LISTEN\n"));
914 return si_listen(fp, fd, ioc, td);
916 case SVR4_SI_SETMYNAME:
917 DPRINTF(("SI_SETMYNAME\n"));
920 case SVR4_SI_SETPEERNAME:
921 DPRINTF(("SI_SETPEERNAME\n"));
924 case SVR4_SI_GETINTRANSIT:
925 DPRINTF(("SI_GETINTRANSIT\n"));
928 case SVR4_SI_TCL_LINK:
929 DPRINTF(("SI_TCL_LINK\n"));
932 case SVR4_SI_TCL_UNLINK:
933 DPRINTF(("SI_TCL_UNLINK\n"));
936 case SVR4_SI_SOCKPARAMS:
937 DPRINTF(("SI_SOCKPARAMS\n"));
938 return si_sockparams(fp, fd, ioc, td);
940 case SVR4_SI_GETUDATA:
941 DPRINTF(("SI_GETUDATA\n"));
942 return si_getudata(fp, fd, ioc, td);
945 DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd));
953 ti_getinfo(fp, fd, ioc, td)
956 struct svr4_strioctl *ioc;
960 struct svr4_infocmd info;
962 memset(&info, 0, sizeof(info));
964 if ((error = copyin(ioc->buf, &info, ioc->len)) != 0)
967 if (info.cmd != SVR4_TI_INFO_REQUEST)
970 info.cmd = SVR4_TI_INFO_REPLY;
982 ioc->len = sizeof(info);
983 if ((error = copyout(&info, ioc->buf, ioc->len)) != 0)
991 ti_bind(fp, fd, ioc, td)
994 struct svr4_strioctl *ioc;
998 struct svr4_strm *st = svr4_stream_get(fp);
999 struct sockaddr_in sain;
1000 struct sockaddr_un saun;
1002 void *skp, *sup = NULL;
1004 struct svr4_strmcmd bnd;
1005 struct bind_args ba;
1008 DPRINTF(("ti_bind: bad file descriptor\n"));
1012 if ((error = copyin(ioc->buf, &bnd, ioc->len)) != 0)
1015 if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) {
1016 DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd));
1020 switch (st->s_family) {
1023 sasize = sizeof(sain);
1028 netaddr_to_sockaddr_in(&sain, &bnd);
1030 DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n",
1031 sain.sin_family, sain.sin_port,
1032 sain.sin_addr.s_addr));
1037 sasize = sizeof(saun);
1041 netaddr_to_sockaddr_un(&saun, &bnd);
1043 if (saun.sun_path[0] == '\0')
1046 DPRINTF(("TI_BIND: fam %d, path %s\n",
1047 saun.sun_family, saun.sun_path));
1049 if ((error = clean_pipe(saun.sun_path)) != 0)
1052 bnd.pad[28] = 0x00001000; /* magic again */
1056 DPRINTF(("TI_BIND: Unsupported address family %d\n",
1061 sg = stackgap_init();
1062 sup = stackgap_alloc(&sg, sasize);
1064 if ((error = copyout(skp, sup, sasize)) != 0)
1068 DPRINTF(("TI_BIND: fileno %d\n", fd));
1069 SCARG(&ba, name) = (void *) sup;
1070 SCARG(&ba, namelen) = sasize;
1072 if ((error = bind(&ba)) != 0) {
1073 DPRINTF(("TI_BIND: bind failed %d\n", error));
1079 memset(&bnd, 0, sizeof(bnd));
1080 bnd.len = sasize + 4;
1081 bnd.offs = 0x10; /* XXX */
1084 bnd.cmd = SVR4_TI_BIND_REPLY;
1086 if ((error = copyout(&bnd, ioc->buf, ioc->len)) != 0)
1094 timod(fp, fd, ioc, td)
1097 struct svr4_strioctl *ioc;
1101 case SVR4_TI_GETINFO:
1102 DPRINTF(("TI_GETINFO\n"));
1103 return ti_getinfo(fp, fd, ioc, td);
1105 case SVR4_TI_OPTMGMT:
1106 DPRINTF(("TI_OPTMGMT\n"));
1110 DPRINTF(("TI_BIND\n"));
1111 return ti_bind(fp, fd, ioc, td);
1113 case SVR4_TI_UNBIND:
1114 DPRINTF(("TI_UNBIND\n"));
1118 DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd));
1125 svr4_stream_ti_ioctl(fp, td, retval, fd, cmd, dat)
1133 struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat;
1134 struct svr4_strm *st = svr4_stream_get(fp);
1137 struct sockaddr_in sain;
1138 struct sockaddr_un saun;
1139 struct svr4_strmcmd sc;
1144 DPRINTF(("svr4_stream_ti_ioctl\n"));
1151 if ((error = copyin(sub, &skb, sizeof(skb))) != 0) {
1152 DPRINTF(("ti_ioctl: error copying in strbuf\n"));
1156 switch (st->s_family) {
1159 sasize = sizeof(sain);
1164 sasize = sizeof(saun);
1168 DPRINTF(("ti_ioctl: Unsupported address family %d\n",
1173 sg = stackgap_init();
1174 sup = stackgap_alloc(&sg, sasize);
1175 lenp = stackgap_alloc(&sg, sizeof(*lenp));
1177 if ((error = copyout(&sasize, lenp, sizeof(*lenp))) != 0) {
1178 DPRINTF(("ti_ioctl: error copying out lenp\n"));
1183 case SVR4_TI_GETMYNAME:
1184 DPRINTF(("TI_GETMYNAME\n"));
1186 struct getsockname_args ap;
1187 SCARG(&ap, fdes) = fd;
1188 SCARG(&ap, asa) = sup;
1189 SCARG(&ap, alen) = lenp;
1190 if ((error = getsockname(&ap)) != 0) {
1191 DPRINTF(("ti_ioctl: getsockname error\n"));
1197 case SVR4_TI_GETPEERNAME:
1198 DPRINTF(("TI_GETPEERNAME\n"));
1200 struct getpeername_args ap;
1201 SCARG(&ap, fdes) = fd;
1202 SCARG(&ap, asa) = sup;
1203 SCARG(&ap, alen) = lenp;
1204 if ((error = getpeername(&ap)) != 0) {
1205 DPRINTF(("ti_ioctl: getpeername error\n"));
1211 case SVR4_TI_SETMYNAME:
1212 DPRINTF(("TI_SETMYNAME\n"));
1215 case SVR4_TI_SETPEERNAME:
1216 DPRINTF(("TI_SETPEERNAME\n"));
1219 DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd));
1223 if ((error = copyin(sup, skp, sasize)) != 0) {
1224 DPRINTF(("ti_ioctl: error copying in socket data\n"));
1228 if ((error = copyin(lenp, &sasize, sizeof(*lenp))) != 0) {
1229 DPRINTF(("ti_ioctl: error copying in socket size\n"));
1233 switch (st->s_family) {
1235 sockaddr_to_netaddr_in(&sc, &sain);
1240 sockaddr_to_netaddr_un(&sc, &saun);
1241 skb.len = sasize + 4;
1249 if ((error = copyout(SVR4_ADDROF(&sc), skb.buf, sasize)) != 0) {
1250 DPRINTF(("ti_ioctl: error copying out socket data\n"));
1255 if ((error = copyout(&skb, sub, sizeof(skb))) != 0) {
1256 DPRINTF(("ti_ioctl: error copying out strbuf\n"));
1267 i_nread(fp, td, retval, fd, cmd, dat)
1279 * We are supposed to return the message length in nread, and the
1280 * number of messages in retval. We don't have the notion of number
1281 * of stream messages, so we just find out if we have any bytes waiting
1282 * for us, and if we do, then we assume that we have at least one
1283 * message waiting for us.
1285 if ((error = fo_ioctl(fp, FIONREAD, (caddr_t) &nread, td)) != 0)
1293 return copyout(&nread, dat, sizeof(nread));
1297 i_fdinsert(fp, td, retval, fd, cmd, dat)
1306 * Major hack again here. We assume that we are using this to
1307 * implement accept(2). If that is the case, we have already
1308 * called accept, and we have stored the file descriptor in
1309 * afd. We find the file descriptor that the code wants to use
1310 * in fd insert, and then we dup2() our accepted file descriptor
1314 struct svr4_strm *st = svr4_stream_get(fp);
1315 struct svr4_strfdinsert fdi;
1316 struct dup2_args d2p;
1317 struct close_args clp;
1320 DPRINTF(("fdinsert: bad file type\n"));
1324 if (st->s_afd == -1) {
1325 DPRINTF(("fdinsert: accept fd not found\n"));
1329 if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) {
1330 DPRINTF(("fdinsert: copyin failed %d\n", error));
1334 SCARG(&d2p, from) = st->s_afd;
1335 SCARG(&d2p, to) = fdi.fd;
1337 if ((error = dup2(&d2p)) != 0) {
1338 DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n",
1339 st->s_afd, fdi.fd, error));
1343 SCARG(&clp, fd) = st->s_afd;
1345 if ((error = close(&clp)) != 0) {
1346 DPRINTF(("fdinsert: close(%d) failed %d\n",
1359 _i_bind_rsvd(fp, td, retval, fd, cmd, dat)
1367 struct mkfifo_args ap;
1370 * This is a supposed to be a kernel and library only ioctl.
1371 * It gets called before ti_bind, when we have a unix
1372 * socket, to physically create the socket transport and
1373 * ``reserve'' it. I don't know how this get reserved inside
1374 * the kernel, but we are going to create it nevertheless.
1376 SCARG(&ap, path) = dat;
1377 SCARG(&ap, mode) = S_IFIFO;
1383 _i_rele_rsvd(fp, td, retval, fd, cmd, dat)
1391 struct unlink_args ap;
1394 * This is a supposed to be a kernel and library only ioctl.
1395 * I guess it is supposed to release the socket.
1397 SCARG(&ap, path) = dat;
1403 i_str(fp, td, retval, fd, cmd, dat)
1412 struct svr4_strioctl ioc;
1414 if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0)
1418 if ((error = show_ioc(">", &ioc)) != 0)
1420 #endif /* DEBUG_SVR4 */
1422 switch (ioc.cmd & 0xff00) {
1424 if ((error = sockmod(fp, fd, &ioc, td)) != 0)
1429 if ((error = timod(fp, fd, &ioc, td)) != 0)
1434 DPRINTF(("Unimplemented module %c %ld\n",
1435 (char) (cmd >> 8), cmd & 0xff));
1440 if ((error = show_ioc("<", &ioc)) != 0)
1442 #endif /* DEBUG_SVR4 */
1443 return copyout(&ioc, dat, sizeof(ioc));
1447 i_setsig(fp, td, retval, fd, cmd, dat)
1456 * This is the best we can do for now; we cannot generate
1457 * signals only for specific events so the signal mask gets
1458 * ignored; we save it just to pass it to a possible I_GETSIG...
1460 * We alse have to fix the O_ASYNC fcntl bit, so the
1461 * process will get SIGPOLLs.
1463 struct proc *p = td->td_proc;
1464 struct fcntl_args fa;
1466 register_t oflags, flags;
1467 struct svr4_strm *st = svr4_stream_get(fp);
1472 DPRINTF(("i_setsig: bad file descriptor\n"));
1475 /* get old status flags */
1476 SCARG(&fa, fd) = fd;
1477 SCARG(&fa, cmd) = F_GETFL;
1478 if ((error = fcntl(&fa)) != 0)
1481 oflags = fa.sysmsg_result;
1483 /* update the flags */
1487 flags = oflags | O_ASYNC;
1488 if ((error = copyin(dat, &mask, sizeof(mask))) != 0) {
1489 DPRINTF(("i_setsig: bad eventmask pointer\n"));
1492 if (mask & SVR4_S_ALLMASK) {
1493 DPRINTF(("i_setsig: bad eventmask data %x\n", mask));
1496 st->s_eventmask = mask;
1499 flags = oflags & ~O_ASYNC;
1500 st->s_eventmask = 0;
1503 /* set the new flags, if changed */
1504 if (flags != oflags) {
1505 SCARG(&fa, cmd) = F_SETFL;
1506 SCARG(&fa, arg) = (long) flags;
1507 if ((error = fcntl(&fa)) != 0)
1509 flags =fa.sysmsg_result;
1512 /* set up SIGIO receiver if needed */
1514 SCARG(&fa, cmd) = F_SETOWN;
1515 SCARG(&fa, arg) = (long) p->p_pid;
1517 *retval = fa.sysmsg_result;
1520 *retval = fa.sysmsg_result;
1525 i_getsig(fp, td, retval, fd, cmd, dat)
1536 struct svr4_strm *st = svr4_stream_get(fp);
1539 DPRINTF(("i_getsig: bad file descriptor\n"));
1542 if ((error = copyout(&st->s_eventmask, dat,
1543 sizeof(st->s_eventmask))) != 0) {
1544 DPRINTF(("i_getsig: bad eventmask pointer\n"));
1552 svr4_stream_ioctl(fp, td, retval, fd, cmd, dat)
1563 * All the following stuff assumes "sockmod" is pushed...
1567 DPRINTF(("I_NREAD\n"));
1568 return i_nread(fp, td, retval, fd, cmd, dat);
1571 DPRINTF(("I_PUSH %p\n", dat));
1572 #if defined(DEBUG_SVR4)
1573 show_strbuf((void *)dat);
1578 DPRINTF(("I_POP\n"));
1582 DPRINTF(("I_LOOK\n"));
1586 DPRINTF(("I_FLUSH\n"));
1590 DPRINTF(("I_SRDOPT\n"));
1594 DPRINTF(("I_GRDOPT\n"));
1598 DPRINTF(("I_STR\n"));
1599 return i_str(fp, td, retval, fd, cmd, dat);
1602 DPRINTF(("I_SETSIG\n"));
1603 return i_setsig(fp, td, retval, fd, cmd, dat);
1606 DPRINTF(("I_GETSIG\n"));
1607 return i_getsig(fp, td, retval, fd, cmd, dat);
1610 DPRINTF(("I_FIND\n"));
1612 * Here we are not pushing modules really, we just
1613 * pretend all are present
1619 DPRINTF(("I_LINK\n"));
1623 DPRINTF(("I_UNLINK\n"));
1626 case SVR4_I_ERECVFD:
1627 DPRINTF(("I_ERECVFD\n"));
1631 DPRINTF(("I_PEEK\n"));
1634 case SVR4_I_FDINSERT:
1635 DPRINTF(("I_FDINSERT\n"));
1636 return i_fdinsert(fp, td, retval, fd, cmd, dat);
1639 DPRINTF(("I_SENDFD\n"));
1643 DPRINTF(("I_RECVFD\n"));
1647 DPRINTF(("I_SWROPT\n"));
1651 DPRINTF(("I_GWROPT\n"));
1655 DPRINTF(("I_LIST\n"));
1659 DPRINTF(("I_PLINK\n"));
1662 case SVR4_I_PUNLINK:
1663 DPRINTF(("I_PUNLINK\n"));
1667 DPRINTF(("I_SETEV\n"));
1671 DPRINTF(("I_GETEV\n"));
1675 DPRINTF(("I_STREV\n"));
1678 case SVR4_I_UNSTREV:
1679 DPRINTF(("I_UNSTREV\n"));
1682 case SVR4_I_FLUSHBAND:
1683 DPRINTF(("I_FLUSHBAND\n"));
1687 DPRINTF(("I_CKBAND\n"));
1690 case SVR4_I_GETBAND:
1691 DPRINTF(("I_GETBANK\n"));
1695 DPRINTF(("I_ATMARK\n"));
1698 case SVR4_I_SETCLTIME:
1699 DPRINTF(("I_SETCLTIME\n"));
1702 case SVR4_I_GETCLTIME:
1703 DPRINTF(("I_GETCLTIME\n"));
1707 DPRINTF(("I_CANPUT\n"));
1710 case SVR4__I_BIND_RSVD:
1711 DPRINTF(("_I_BIND_RSVD\n"));
1712 return _i_bind_rsvd(fp, td, retval, fd, cmd, dat);
1714 case SVR4__I_RELE_RSVD:
1715 DPRINTF(("_I_RELE_RSVD\n"));
1716 return _i_rele_rsvd(fp, td, retval, fd, cmd, dat);
1719 DPRINTF(("unimpl cmd = %lx\n", cmd));
1729 svr4_sys_putmsg(struct svr4_sys_putmsg_args *uap)
1731 struct thread *td = curthread;
1732 struct proc *p = td->td_proc;
1733 struct filedesc *fdp;
1735 struct svr4_strbuf dat, ctl;
1736 struct svr4_strmcmd sc;
1737 struct sockaddr_in sain;
1738 struct sockaddr_un saun;
1740 int sasize, *retval;
1741 struct svr4_strm *st;
1747 retval = &uap->sysmsg_result;
1748 fp = fdp->fd_files[SCARG(uap, fd)].fp;
1750 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) {
1752 uprintf("putmsg: bad fp\n");
1758 show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl),
1759 SCARG(uap, dat), SCARG(uap, flags));
1760 #endif /* DEBUG_SVR4 */
1762 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) {
1764 uprintf("putmsg: bad fp(2)\n");
1769 if (SCARG(uap, ctl) != NULL) {
1770 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) {
1772 uprintf("putmsg: copyin(): %d\n", error);
1780 if (SCARG(uap, dat) != NULL) {
1781 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0) {
1783 uprintf("putmsg: copyin(): %d (2)\n", error);
1792 * Only for sockets for now.
1794 if ((st = svr4_stream_get(fp)) == NULL) {
1795 DPRINTF(("putmsg: bad file type\n"));
1799 if (ctl.len > sizeof(sc)) {
1800 DPRINTF(("putmsg: Bad control size %d != %d\n", ctl.len,
1801 sizeof(struct svr4_strmcmd)));
1805 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
1808 switch (st->s_family) {
1810 if (sc.len != sizeof(sain)) {
1811 if (sc.cmd == SVR4_TI_DATA_REQUEST) {
1812 struct write_args wa;
1814 /* Solaris seems to use sc.cmd = 3 to
1815 * send "expedited" data. telnet uses
1816 * this for options processing, sending EOF,
1817 * etc. I'm sure other things use it too.
1818 * I don't have any documentation
1819 * on it, so I'm making a guess that this
1820 * is how it works. newton@atdot.dotat.org XXX
1822 DPRINTF(("sending expedited data ??\n"));
1823 SCARG(&wa, fd) = SCARG(uap, fd);
1824 SCARG(&wa, buf) = dat.buf;
1825 SCARG(&wa, nbyte) = dat.len;
1826 wa.sysmsg_result = 0;
1829 *retval = wa.sysmsg_result;
1832 DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len));
1835 netaddr_to_sockaddr_in(&sain, &sc);
1837 sasize = sizeof(sain);
1838 error = sain.sin_family != st->s_family;
1843 /* We are doing an accept; succeed */
1844 DPRINTF(("putmsg: Do nothing\n"));
1849 /* Maybe we've been given a device/inode pair */
1850 udev_t *dev = SVR4_ADDROF(&sc);
1851 ino_t *ino = (ino_t *) &dev[1];
1852 skp = svr4_find_socket(td, fp, *dev, *ino);
1855 /* I guess we have it by name */
1856 netaddr_to_sockaddr_un(skp, &sc);
1858 sasize = sizeof(saun);
1863 DPRINTF(("putmsg: Unsupported address family %d\n",
1868 sg = stackgap_init();
1869 sup = stackgap_alloc(&sg, sasize);
1871 if ((error = copyout(skp, sup, sasize)) != 0)
1874 switch (st->s_cmd = sc.cmd) {
1875 case SVR4_TI_CONNECT_REQUEST: /* connect */
1877 struct connect_args co;
1879 SCARG(&co, s) = SCARG(uap, fd);
1880 SCARG(&co, name) = (void *) sup;
1881 SCARG(&co, namelen) = (int) sasize;
1882 co.sysmsg_result = 0;
1884 error = connect(&co);
1885 *retval = co.sysmsg_result;
1889 case SVR4_TI_SENDTO_REQUEST: /* sendto */
1894 msg.msg_name = (caddr_t) sup;
1895 msg.msg_namelen = sasize;
1896 msg.msg_iov = &aiov;
1898 msg.msg_control = 0;
1900 aiov.iov_base = dat.buf;
1901 aiov.iov_len = dat.len;
1903 error = so_pru_sosend(so, NULL, uio, NULL, NULL, 0,
1906 error = svr4_sendit(td, SCARG(uap, fd), &msg,
1907 SCARG(uap, flags), retval);
1908 DPRINTF(("sendto_request error: %d\n", error));
1914 DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd));
1920 svr4_sys_getmsg(struct svr4_sys_getmsg_args *uap)
1922 struct thread *td = curthread;
1923 struct proc *p = td->td_proc;
1924 struct filedesc *fdp;
1926 struct getpeername_args ga;
1927 struct accept_args aa;
1928 struct svr4_strbuf dat, ctl;
1929 struct svr4_strmcmd sc;
1933 struct sockaddr_in sain;
1934 struct sockaddr_un saun;
1937 struct svr4_strm *st;
1944 retval = &uap->sysmsg_result;
1945 fp = fdp->fd_files[SCARG(uap, fd)].fp;
1947 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL))
1950 memset(&sc, 0, sizeof(sc));
1953 show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl),
1954 SCARG(uap, dat), 0);
1955 #endif /* DEBUG_SVR4 */
1957 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL))
1960 if (SCARG(uap, ctl) != NULL) {
1961 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0)
1969 if (SCARG(uap, dat) != NULL) {
1970 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0)
1979 * Only for sockets for now.
1981 if ((st = svr4_stream_get(fp)) == NULL) {
1982 DPRINTF(("getmsg: bad file type\n"));
1986 if (ctl.maxlen == -1 || dat.maxlen == -1) {
1987 DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n"));
1991 switch (st->s_family) {
1994 sasize = sizeof(sain);
1999 sasize = sizeof(saun);
2003 DPRINTF(("getmsg: Unsupported address family %d\n",
2008 sg = stackgap_init();
2009 sup = stackgap_alloc(&sg, sasize);
2010 flen = (int *) stackgap_alloc(&sg, sizeof(*flen));
2013 if ((error = copyout(&fl, flen, sizeof(fl))) != 0)
2016 switch (st->s_cmd) {
2017 case SVR4_TI_CONNECT_REQUEST:
2018 DPRINTF(("getmsg: TI_CONNECT_REQUEST\n"));
2020 * We do the connect in one step, so the putmsg should
2021 * have gotten the error.
2023 sc.cmd = SVR4_TI_OK_REPLY;
2032 case SVR4_TI_OK_REPLY:
2033 DPRINTF(("getmsg: TI_OK_REPLY\n"));
2035 * We are immediately after a connect reply, so we send
2036 * a connect verification.
2039 SCARG(&ga, fdes) = SCARG(uap, fd);
2040 SCARG(&ga, asa) = (void *) sup;
2041 SCARG(&ga, alen) = flen;
2043 if ((error = getpeername(&ga)) != 0) {
2044 DPRINTF(("getmsg: getpeername failed %d\n", error));
2048 if ((error = copyin(sup, skp, sasize)) != 0)
2051 sc.cmd = SVR4_TI_CONNECT_REPLY;
2055 sc.pad[2] = 0x04000402;
2057 switch (st->s_family) {
2060 sockaddr_to_netaddr_in(&sc, &sain);
2064 sc.len = sasize + 4;
2065 sockaddr_to_netaddr_un(&sc, &saun);
2078 case SVR4_TI__ACCEPT_OK:
2079 DPRINTF(("getmsg: TI__ACCEPT_OK\n"));
2081 * We do the connect in one step, so the putmsg should
2082 * have gotten the error.
2084 sc.cmd = SVR4_TI_OK_REPLY;
2090 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
2093 case SVR4_TI__ACCEPT_WAIT:
2094 DPRINTF(("getmsg: TI__ACCEPT_WAIT\n"));
2096 * We are after a listen, so we try to accept...
2098 SCARG(&aa, s) = SCARG(uap, fd);
2099 SCARG(&aa, name) = (void *) sup;
2100 SCARG(&aa, anamelen) = flen;
2102 if ((error = accept(&aa)) != 0) {
2103 DPRINTF(("getmsg: accept failed %d\n", error));
2107 st->s_afd = *retval;
2109 DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd));
2111 if ((error = copyin(sup, skp, sasize)) != 0)
2114 sc.cmd = SVR4_TI_ACCEPT_REPLY;
2118 switch (st->s_family) {
2121 sockaddr_to_netaddr_in(&sc, &sain);
2127 sc.pad[1] = 0x00010000;
2128 sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */
2129 sc.pad[3] = 0x00010000;
2131 sc.len = sasize + 4;
2140 st->s_cmd = SVR4_TI__ACCEPT_OK;
2143 case SVR4_TI_SENDTO_REQUEST:
2144 DPRINTF(("getmsg: TI_SENDTO_REQUEST\n"));
2145 if (ctl.maxlen > 36 && ctl.len < 36)
2148 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
2151 switch (st->s_family) {
2153 sockaddr_to_netaddr_in(&sc, &sain);
2157 sockaddr_to_netaddr_un(&sc, &saun);
2164 msg.msg_name = (caddr_t) sup;
2165 msg.msg_namelen = sasize;
2166 msg.msg_iov = &aiov;
2168 msg.msg_control = 0;
2169 aiov.iov_base = dat.buf;
2170 aiov.iov_len = dat.maxlen;
2173 error = svr4_recvit(td, SCARG(uap, fd), &msg, (caddr_t) flen, retval);
2176 DPRINTF(("getmsg: recvit failed %d\n", error));
2180 if ((error = copyin(msg.msg_name, skp, sasize)) != 0)
2183 sc.cmd = SVR4_TI_RECVFROM_IND;
2185 switch (st->s_family) {
2188 sockaddr_to_netaddr_in(&sc, &sain);
2192 sc.len = sasize + 4;
2193 sockaddr_to_netaddr_un(&sc, &saun);
2207 if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) {
2208 struct read_args ra;
2210 /* More weirdness: Again, I can't find documentation
2211 * to back this up, but when a process does a generic
2212 * "getmsg()" call it seems that the command field is
2213 * zero and the length of the data area is zero. I
2214 * think processes expect getmsg() to fill in dat.len
2215 * after reading at most dat.maxlen octets from the
2216 * stream. Since we're using sockets I can let
2217 * read() look after it and frob return values
2218 * appropriately (or inappropriately :-)
2219 * -- newton@atdot.dotat.org XXX
2221 SCARG(&ra, fd) = SCARG(uap, fd);
2222 SCARG(&ra, buf) = dat.buf;
2223 SCARG(&ra, nbyte) = dat.maxlen;
2224 if ((error = read(&ra)) != 0) {
2229 st->s_cmd = SVR4_TI_SENDTO_REQUEST;
2232 DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd));
2236 if (SCARG(uap, ctl)) {
2238 if ((error = copyout(&sc, ctl.buf, ctl.len)) != 0)
2241 if ((error = copyout(&ctl, SCARG(uap, ctl), sizeof(ctl))) != 0)
2245 if (SCARG(uap, dat)) {
2246 if ((error = copyout(&dat, SCARG(uap, dat), sizeof(dat))) != 0)
2250 if (SCARG(uap, flags)) { /* XXX: Need translation */
2251 if ((error = copyout(&fl, SCARG(uap, flags), sizeof(fl))) != 0)
2258 show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl),
2259 SCARG(uap, dat), fl);
2260 #endif /* DEBUG_SVR4 */
2264 int svr4_sys_send(struct svr4_sys_send_args *uap)
2266 struct osend_args osa;
2269 SCARG(&osa, s) = SCARG(uap, s);
2270 SCARG(&osa, buf) = SCARG(uap, buf);
2271 SCARG(&osa, len) = SCARG(uap, len);
2272 SCARG(&osa, flags) = SCARG(uap, flags);
2273 osa.sysmsg_result = 0;
2274 error = osend(&osa);
2275 uap->sysmsg_result = osa.sysmsg_result;
2279 int svr4_sys_recv(struct svr4_sys_recv_args *uap)
2281 struct orecv_args ora;
2284 SCARG(&ora, s) = SCARG(uap, s);
2285 SCARG(&ora, buf) = SCARG(uap, buf);
2286 SCARG(&ora, len) = SCARG(uap, len);
2287 SCARG(&ora, flags) = SCARG(uap, flags);
2288 ora.sysmsg_result = 0;
2289 error = orecv(&ora);
2290 uap->sysmsg_result = ora.sysmsg_result;
2295 * XXX This isn't necessary, but it's handy for inserting debug code into
2296 * sendto(). Let's leave it here for now...
2299 svr4_sys_sendto(struct svr4_sys_sendto_args *uap)
2301 struct sendto_args sa;
2304 SCARG(&sa, s) = SCARG(uap, s);
2305 SCARG(&sa, buf) = SCARG(uap, buf);
2306 SCARG(&sa, len) = SCARG(uap, len);
2307 SCARG(&sa, flags) = SCARG(uap, flags);
2308 SCARG(&sa, to) = (caddr_t)SCARG(uap, to);
2309 SCARG(&sa, tolen) = SCARG(uap, tolen);
2311 DPRINTF(("calling sendto()\n"));
2312 sa.sysmsg_result = 0;
2313 error = sendto(&sa);
2314 uap->sysmsg_result = sa.sysmsg_result;