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.9 2003/08/27 06:07:10 rob Exp $
35 * Pretend that we have streams...
38 * ToDo: The state machine for getmsg needs re-thinking
43 #include <sys/param.h>
44 #include <sys/systm.h>
46 #include <sys/malloc.h>
48 #include <sys/filedesc.h>
49 #include <sys/fcntl.h>
50 #include <sys/filio.h>
51 #include <sys/select.h>
52 #include <sys/socket.h>
53 #include <sys/socketvar.h>
55 #include <netinet/in.h>
57 #include <sys/protosw.h>
58 #include <sys/signal.h>
59 #include <sys/signalvar.h>
61 #include <sys/ktrace.h>
64 #include <sys/file2.h>
66 #include <sys/sysproto.h>
69 #include "svr4_types.h"
70 #include "svr4_util.h"
71 #include "svr4_signal.h"
72 #include "svr4_proto.h"
73 #include "svr4_stropts.h"
74 #include "svr4_timod.h"
75 #include "svr4_sockmod.h"
76 #include "svr4_ioctl.h"
77 #include "svr4_socket.h"
80 static int clean_pipe (const char *);
81 static void getparm (struct file *, struct svr4_si_sockparms *);
83 /* Address Conversions */
84 static void sockaddr_to_netaddr_in (struct svr4_strmcmd *,
85 const struct sockaddr_in *);
86 static void sockaddr_to_netaddr_un (struct svr4_strmcmd *,
87 const struct sockaddr_un *);
88 static void netaddr_to_sockaddr_in (struct sockaddr_in *,
89 const struct svr4_strmcmd *);
90 static void netaddr_to_sockaddr_un (struct sockaddr_un *,
91 const struct svr4_strmcmd *);
94 static int i_nread (struct file *, struct thread *, register_t *, int,
96 static int i_fdinsert (struct file *, struct thread *, register_t *, int,
98 static int i_str (struct file *, struct thread *, register_t *, int,
100 static int i_setsig (struct file *, struct thread *, register_t *, int,
102 static int i_getsig (struct file *, struct thread *, register_t *, int,
104 static int _i_bind_rsvd (struct file *, struct thread *, register_t *, int,
106 static int _i_rele_rsvd (struct file *, struct thread *, register_t *, int,
109 /* i_str sockmod calls */
110 static int sockmod (struct file *, int, struct svr4_strioctl *,
112 static int si_listen (struct file *, int, struct svr4_strioctl *,
114 static int si_ogetudata (struct file *, int, struct svr4_strioctl *,
116 static int si_sockparams (struct file *, int, struct svr4_strioctl *,
118 static int si_shutdown (struct file *, int, struct svr4_strioctl *,
120 static int si_getudata (struct file *, int, struct svr4_strioctl *,
123 /* i_str timod calls */
124 static int timod (struct file *, int, struct svr4_strioctl *,
126 static int ti_getinfo (struct file *, int, struct svr4_strioctl *,
128 static int ti_bind (struct file *, int, struct svr4_strioctl *,
132 static int svr4_sendit (struct thread *td, int s, struct msghdr *mp,
133 int flags, int *retval);
135 static int svr4_recvit (struct thread *td, int s, struct msghdr *mp,
136 caddr_t namelenp, int *retval);
138 /* <sigh> Ok, so we shouldn't use sendit() in uipc_syscalls.c because
139 * it isn't part of a "public" interface; We're supposed to use
140 * pru_sosend instead. Same goes for recvit()/pru_soreceive() for
141 * that matter. Solution: Suck sendit()/recvit() into here where we
142 * can do what we like.
144 * I hate code duplication.
146 * I will take out all the #ifdef COMPAT_OLDSOCK gumph, though.
149 svr4_sendit(td, s, mp, flags, retval)
161 struct mbuf *control;
166 struct iovec *ktriov = NULL;
173 error = holdsock(p->p_fd, s, &fp);
176 auio.uio_iov = mp->msg_iov;
177 auio.uio_iovcnt = mp->msg_iovlen;
178 auio.uio_segflg = UIO_USERSPACE;
179 auio.uio_rw = UIO_WRITE;
181 auio.uio_offset = 0; /* XXX */
184 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
185 if ((auio.uio_resid += iov->iov_len) < 0) {
191 error = getsockaddr(&to, mp->msg_name, mp->msg_namelen);
199 if (mp->msg_control) {
200 if (mp->msg_controllen < sizeof(struct cmsghdr)) {
204 error = sockargs(&control, mp->msg_control,
205 mp->msg_controllen, MT_CONTROL);
212 if (KTRPOINT(p->p_thread, KTR_GENIO)) {
213 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
215 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
216 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
220 len = auio.uio_resid;
221 so = (struct socket *)fp->f_data;
222 error = so->so_proto->pr_usrreqs->pru_sosend
223 (so, to, &auio, 0, control, flags, td);
225 if (auio.uio_resid != len && (error == ERESTART ||
226 error == EINTR || error == EWOULDBLOCK))
232 *retval = len - auio.uio_resid;
234 if (ktriov != NULL) {
236 ktruio.uio_iov = ktriov;
237 ktruio.uio_resid = *retval;
238 ktrgenio(p->p_tracep, s, UIO_WRITE, &ktruio, error);
240 FREE(ktriov, M_TEMP);
251 svr4_recvit(td, s, mp, namelenp, retval)
258 struct proc *p = td->td_proc;
264 struct mbuf *m, *control = 0;
267 struct sockaddr *fromsa = 0;
269 struct iovec *ktriov = NULL;
275 error = holdsock(p->p_fd, s, &fp);
278 auio.uio_iov = mp->msg_iov;
279 auio.uio_iovcnt = mp->msg_iovlen;
280 auio.uio_segflg = UIO_USERSPACE;
281 auio.uio_rw = UIO_READ;
283 auio.uio_offset = 0; /* XXX */
286 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
287 if ((auio.uio_resid += iov->iov_len) < 0) {
293 if (KTRPOINT(p->p_thread, KTR_GENIO)) {
294 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
296 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
297 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
301 len = auio.uio_resid;
302 so = (struct socket *)fp->f_data;
303 error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio,
304 (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
307 if (auio.uio_resid != len && (error == ERESTART ||
308 error == EINTR || error == EWOULDBLOCK))
312 if (ktriov != NULL) {
314 ktruio.uio_iov = ktriov;
315 ktruio.uio_resid = len - auio.uio_resid;
316 ktrgenio(p->p_tracep, s, UIO_READ, &ktruio, error);
318 FREE(ktriov, M_TEMP);
323 *retval = len - auio.uio_resid;
325 len = mp->msg_namelen;
326 if (len <= 0 || fromsa == 0)
330 #define MIN(a,b) ((a)>(b)?(b):(a))
332 /* save sa_len before it is destroyed by MSG_COMPAT */
333 len = MIN(len, fromsa->sa_len);
334 error = copyout(fromsa,
335 (caddr_t)mp->msg_name, (unsigned)len);
339 mp->msg_namelen = len;
341 (error = copyout((caddr_t)&len, namelenp, sizeof (int)))) {
345 if (mp->msg_control) {
346 len = mp->msg_controllen;
348 mp->msg_controllen = 0;
349 ctlbuf = (caddr_t) mp->msg_control;
351 while (m && len > 0) {
357 mp->msg_flags |= MSG_CTRUNC;
361 if ((error = copyout((caddr_t)mtod(m, caddr_t),
362 ctlbuf, tocopy)) != 0)
369 mp->msg_controllen = ctlbuf - (caddr_t)mp->msg_control;
373 FREE(fromsa, M_SONAME);
381 static void bufprint (u_char *, size_t);
382 static int show_ioc (const char *, struct svr4_strioctl *);
383 static int show_strbuf (struct svr4_strbuf *);
384 static void show_msg (const char *, int, struct svr4_strbuf *,
385 struct svr4_strbuf *, int);
395 for (i = 0; i < len; i++) {
396 uprintf("%x ", buf[i]);
397 if (i && (i % 16) == 0)
405 struct svr4_strioctl *ioc;
407 u_char *ptr = (u_char *) malloc(ioc->len, M_TEMP, M_WAITOK);
410 uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ",
411 str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf);
413 if ((error = copyin(ioc->buf, ptr, ioc->len)) != 0) {
414 free((char *) ptr, M_TEMP);
418 bufprint(ptr, ioc->len);
422 free((char *) ptr, M_TEMP);
429 struct svr4_strbuf *str;
433 int maxlen = str->maxlen;
443 ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK);
445 if ((error = copyin(str->buf, ptr, len)) != 0) {
446 free((char *) ptr, M_TEMP);
451 uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf);
459 free((char *) ptr, M_TEMP);
466 show_msg(str, fd, ctl, dat, flags)
469 struct svr4_strbuf *ctl;
470 struct svr4_strbuf *dat;
473 struct svr4_strbuf buf;
476 uprintf("%s(%d", str, fd);
478 if ((error = copyin(ctl, &buf, sizeof(buf))) != 0)
486 if ((error = copyin(dat, &buf, sizeof(buf))) != 0)
493 uprintf(", %x);\n", flags);
496 #endif /* DEBUG_SVR4 */
499 * We are faced with an interesting situation. On svr4 unix sockets
500 * are really pipes. But we really have sockets, and we might as
501 * well use them. At the point where svr4 calls TI_BIND, it has
502 * already created a named pipe for the socket using mknod(2).
503 * We need to create a socket with the same name when we bind,
504 * so we need to remove the pipe before, otherwise we'll get address
505 * already in use. So we *carefully* remove the pipe, to avoid
506 * using this as a random file removal tool. We use system calls
507 * to avoid code duplication.
510 clean_pipe(const char *path)
512 struct lstat_args la;
513 struct unlink_args ua;
516 caddr_t sg = stackgap_init();
517 size_t l = strlen(path) + 1;
520 tpath = stackgap_alloc(&sg, l);
521 SCARG(&la, ub) = stackgap_alloc(&sg, sizeof(struct stat));
523 if ((error = copyout(path, tpath, l)) != 0)
526 SCARG(&la, path) = tpath;
528 if ((error = lstat(&la)) != 0)
531 if ((error = copyin(SCARG(&la, ub), &st, sizeof(st))) != 0)
535 * Make sure we are dealing with a mode 0 named pipe.
537 if ((st.st_mode & S_IFMT) != S_IFIFO)
540 if ((st.st_mode & ALLPERMS) != 0)
543 SCARG(&ua, path) = SCARG(&la, path);
545 if ((error = unlink(&ua)) != 0) {
546 DPRINTF(("clean_pipe: unlink failed %d\n", error));
555 sockaddr_to_netaddr_in(sc, sain)
556 struct svr4_strmcmd *sc;
557 const struct sockaddr_in *sain;
559 struct svr4_netaddr_in *na;
560 na = SVR4_ADDROF(sc);
562 na->family = sain->sin_family;
563 na->port = sain->sin_port;
564 na->addr = sain->sin_addr.s_addr;
565 DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port,
571 sockaddr_to_netaddr_un(sc, saun)
572 struct svr4_strmcmd *sc;
573 const struct sockaddr_un *saun;
575 struct svr4_netaddr_un *na;
576 char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 -
580 na = SVR4_ADDROF(sc);
581 na->family = saun->sun_family;
582 for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; )
585 DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path));
590 netaddr_to_sockaddr_in(sain, sc)
591 struct sockaddr_in *sain;
592 const struct svr4_strmcmd *sc;
594 const struct svr4_netaddr_in *na;
597 na = SVR4_C_ADDROF(sc);
598 memset(sain, 0, sizeof(*sain));
599 sain->sin_len = sizeof(*sain);
600 sain->sin_family = na->family;
601 sain->sin_port = na->port;
602 sain->sin_addr.s_addr = na->addr;
603 DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family,
604 sain->sin_port, sain->sin_addr.s_addr));
609 netaddr_to_sockaddr_un(saun, sc)
610 struct sockaddr_un *saun;
611 const struct svr4_strmcmd *sc;
613 const struct svr4_netaddr_un *na;
614 char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1];
617 na = SVR4_C_ADDROF(sc);
618 memset(saun, 0, sizeof(*saun));
619 saun->sun_family = na->family;
620 for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; )
623 saun->sun_len = dst - saun->sun_path;
624 DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family,
632 struct svr4_si_sockparms *pa;
634 struct svr4_strm *st = svr4_stream_get(fp);
635 struct socket *so = (struct socket *) fp->f_data;
640 pa->family = st->s_family;
642 switch (so->so_type) {
644 pa->type = SVR4_T_CLTS;
645 pa->protocol = IPPROTO_UDP;
646 DPRINTF(("getparm(dgram)\n"));
650 pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */
651 pa->protocol = IPPROTO_IP;
652 DPRINTF(("getparm(stream)\n"));
656 pa->type = SVR4_T_CLTS;
657 pa->protocol = IPPROTO_RAW;
658 DPRINTF(("getparm(raw)\n"));
664 DPRINTF(("getparm(type %d?)\n", so->so_type));
671 si_ogetudata(fp, fd, ioc, td)
674 struct svr4_strioctl *ioc;
678 struct svr4_si_oudata ud;
679 struct svr4_si_sockparms pa;
681 if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) {
682 DPRINTF(("SI_OGETUDATA: Wrong size %d != %d\n",
683 sizeof(ud), ioc->len));
687 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
695 ud.addrsize = sizeof(struct svr4_sockaddr_in);
696 if (pa.type == SVR4_SOCK_STREAM)
709 DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n",
714 /* I have no idea what these should be! */
718 ud.servtype = pa.type;
723 return copyout(&ud, ioc->buf, ioc->len);
728 si_sockparams(fp, fd, ioc, td)
731 struct svr4_strioctl *ioc;
734 struct svr4_si_sockparms pa;
737 return copyout(&pa, ioc->buf, sizeof(pa));
742 si_listen(fp, fd, ioc, td)
745 struct svr4_strioctl *ioc;
749 struct svr4_strm *st = svr4_stream_get(fp);
750 struct svr4_strmcmd lst;
751 struct listen_args la;
756 if ((error = copyin(ioc->buf, &lst, ioc->len)) != 0)
759 if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) {
760 DPRINTF(("si_listen: bad request %ld\n", lst.cmd));
765 * We are making assumptions again...
768 DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5));
769 SCARG(&la, backlog) = 5;
771 if ((error = listen(&la)) != 0) {
772 DPRINTF(("SI_LISTEN: listen failed %d\n", error));
776 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
777 lst.cmd = SVR4_TI_BIND_REPLY;
779 switch (st->s_family) {
781 /* XXX: Fill the length here */
786 lst.pad[28] = 0x00000000; /* magic again */
787 lst.pad[29] = 0x00000800; /* magic again */
788 lst.pad[30] = 0x80001400; /* magic again */
792 DPRINTF(("SI_LISTEN: Unsupported address family %d\n",
798 if ((error = copyout(&lst, ioc->buf, ioc->len)) != 0)
806 si_getudata(fp, fd, ioc, td)
809 struct svr4_strioctl *ioc;
813 struct svr4_si_udata ud;
815 if (sizeof(ud) != ioc->len) {
816 DPRINTF(("SI_GETUDATA: Wrong size %d != %d\n",
817 sizeof(ud), ioc->len));
821 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
824 getparm(fp, &ud.sockparms);
826 switch (ud.sockparms.family) {
828 DPRINTF(("getudata_inet\n"));
831 ud.addrsize = sizeof(struct svr4_sockaddr_in);
832 if (ud.sockparms.type == SVR4_SOCK_STREAM)
840 DPRINTF(("getudata_local\n"));
849 DPRINTF(("SI_GETUDATA: Unsupported address family %d\n",
850 ud.sockparms.family));
855 ud.servtype = ud.sockparms.type;
856 DPRINTF(("ud.servtype = %d\n", ud.servtype));
860 return copyout(&ud, ioc->buf, sizeof(ud));
865 si_shutdown(fp, fd, ioc, td)
868 struct svr4_strioctl *ioc;
872 struct shutdown_args ap;
874 if (ioc->len != sizeof(SCARG(&ap, how))) {
875 DPRINTF(("SI_SHUTDOWN: Wrong size %d != %d\n",
876 sizeof(SCARG(&ap, how)), ioc->len));
880 if ((error = copyin(ioc->buf, &SCARG(&ap, how), ioc->len)) != 0)
885 return shutdown(&ap);
890 sockmod(fp, fd, ioc, td)
893 struct svr4_strioctl *ioc;
897 case SVR4_SI_OGETUDATA:
898 DPRINTF(("SI_OGETUDATA\n"));
899 return si_ogetudata(fp, fd, ioc, td);
901 case SVR4_SI_SHUTDOWN:
902 DPRINTF(("SI_SHUTDOWN\n"));
903 return si_shutdown(fp, fd, ioc, td);
906 DPRINTF(("SI_LISTEN\n"));
907 return si_listen(fp, fd, ioc, td);
909 case SVR4_SI_SETMYNAME:
910 DPRINTF(("SI_SETMYNAME\n"));
913 case SVR4_SI_SETPEERNAME:
914 DPRINTF(("SI_SETPEERNAME\n"));
917 case SVR4_SI_GETINTRANSIT:
918 DPRINTF(("SI_GETINTRANSIT\n"));
921 case SVR4_SI_TCL_LINK:
922 DPRINTF(("SI_TCL_LINK\n"));
925 case SVR4_SI_TCL_UNLINK:
926 DPRINTF(("SI_TCL_UNLINK\n"));
929 case SVR4_SI_SOCKPARAMS:
930 DPRINTF(("SI_SOCKPARAMS\n"));
931 return si_sockparams(fp, fd, ioc, td);
933 case SVR4_SI_GETUDATA:
934 DPRINTF(("SI_GETUDATA\n"));
935 return si_getudata(fp, fd, ioc, td);
938 DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd));
946 ti_getinfo(fp, fd, ioc, td)
949 struct svr4_strioctl *ioc;
953 struct svr4_infocmd info;
955 memset(&info, 0, sizeof(info));
957 if ((error = copyin(ioc->buf, &info, ioc->len)) != 0)
960 if (info.cmd != SVR4_TI_INFO_REQUEST)
963 info.cmd = SVR4_TI_INFO_REPLY;
975 ioc->len = sizeof(info);
976 if ((error = copyout(&info, ioc->buf, ioc->len)) != 0)
984 ti_bind(fp, fd, ioc, td)
987 struct svr4_strioctl *ioc;
991 struct svr4_strm *st = svr4_stream_get(fp);
992 struct sockaddr_in sain;
993 struct sockaddr_un saun;
995 void *skp, *sup = NULL;
997 struct svr4_strmcmd bnd;
1001 DPRINTF(("ti_bind: bad file descriptor\n"));
1005 if ((error = copyin(ioc->buf, &bnd, ioc->len)) != 0)
1008 if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) {
1009 DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd));
1013 switch (st->s_family) {
1016 sasize = sizeof(sain);
1021 netaddr_to_sockaddr_in(&sain, &bnd);
1023 DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n",
1024 sain.sin_family, sain.sin_port,
1025 sain.sin_addr.s_addr));
1030 sasize = sizeof(saun);
1034 netaddr_to_sockaddr_un(&saun, &bnd);
1036 if (saun.sun_path[0] == '\0')
1039 DPRINTF(("TI_BIND: fam %d, path %s\n",
1040 saun.sun_family, saun.sun_path));
1042 if ((error = clean_pipe(saun.sun_path)) != 0)
1045 bnd.pad[28] = 0x00001000; /* magic again */
1049 DPRINTF(("TI_BIND: Unsupported address family %d\n",
1054 sg = stackgap_init();
1055 sup = stackgap_alloc(&sg, sasize);
1057 if ((error = copyout(skp, sup, sasize)) != 0)
1061 DPRINTF(("TI_BIND: fileno %d\n", fd));
1062 SCARG(&ba, name) = (void *) sup;
1063 SCARG(&ba, namelen) = sasize;
1065 if ((error = bind(&ba)) != 0) {
1066 DPRINTF(("TI_BIND: bind failed %d\n", error));
1072 memset(&bnd, 0, sizeof(bnd));
1073 bnd.len = sasize + 4;
1074 bnd.offs = 0x10; /* XXX */
1077 bnd.cmd = SVR4_TI_BIND_REPLY;
1079 if ((error = copyout(&bnd, ioc->buf, ioc->len)) != 0)
1087 timod(fp, fd, ioc, td)
1090 struct svr4_strioctl *ioc;
1094 case SVR4_TI_GETINFO:
1095 DPRINTF(("TI_GETINFO\n"));
1096 return ti_getinfo(fp, fd, ioc, td);
1098 case SVR4_TI_OPTMGMT:
1099 DPRINTF(("TI_OPTMGMT\n"));
1103 DPRINTF(("TI_BIND\n"));
1104 return ti_bind(fp, fd, ioc, td);
1106 case SVR4_TI_UNBIND:
1107 DPRINTF(("TI_UNBIND\n"));
1111 DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd));
1118 svr4_stream_ti_ioctl(fp, td, retval, fd, cmd, dat)
1126 struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat;
1127 struct svr4_strm *st = svr4_stream_get(fp);
1130 struct sockaddr_in sain;
1131 struct sockaddr_un saun;
1132 struct svr4_strmcmd sc;
1137 DPRINTF(("svr4_stream_ti_ioctl\n"));
1144 if ((error = copyin(sub, &skb, sizeof(skb))) != 0) {
1145 DPRINTF(("ti_ioctl: error copying in strbuf\n"));
1149 switch (st->s_family) {
1152 sasize = sizeof(sain);
1157 sasize = sizeof(saun);
1161 DPRINTF(("ti_ioctl: Unsupported address family %d\n",
1166 sg = stackgap_init();
1167 sup = stackgap_alloc(&sg, sasize);
1168 lenp = stackgap_alloc(&sg, sizeof(*lenp));
1170 if ((error = copyout(&sasize, lenp, sizeof(*lenp))) != 0) {
1171 DPRINTF(("ti_ioctl: error copying out lenp\n"));
1176 case SVR4_TI_GETMYNAME:
1177 DPRINTF(("TI_GETMYNAME\n"));
1179 struct getsockname_args ap;
1180 SCARG(&ap, fdes) = fd;
1181 SCARG(&ap, asa) = sup;
1182 SCARG(&ap, alen) = lenp;
1183 if ((error = getsockname(&ap)) != 0) {
1184 DPRINTF(("ti_ioctl: getsockname error\n"));
1190 case SVR4_TI_GETPEERNAME:
1191 DPRINTF(("TI_GETPEERNAME\n"));
1193 struct getpeername_args ap;
1194 SCARG(&ap, fdes) = fd;
1195 SCARG(&ap, asa) = sup;
1196 SCARG(&ap, alen) = lenp;
1197 if ((error = getpeername(&ap)) != 0) {
1198 DPRINTF(("ti_ioctl: getpeername error\n"));
1204 case SVR4_TI_SETMYNAME:
1205 DPRINTF(("TI_SETMYNAME\n"));
1208 case SVR4_TI_SETPEERNAME:
1209 DPRINTF(("TI_SETPEERNAME\n"));
1212 DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd));
1216 if ((error = copyin(sup, skp, sasize)) != 0) {
1217 DPRINTF(("ti_ioctl: error copying in socket data\n"));
1221 if ((error = copyin(lenp, &sasize, sizeof(*lenp))) != 0) {
1222 DPRINTF(("ti_ioctl: error copying in socket size\n"));
1226 switch (st->s_family) {
1228 sockaddr_to_netaddr_in(&sc, &sain);
1233 sockaddr_to_netaddr_un(&sc, &saun);
1234 skb.len = sasize + 4;
1242 if ((error = copyout(SVR4_ADDROF(&sc), skb.buf, sasize)) != 0) {
1243 DPRINTF(("ti_ioctl: error copying out socket data\n"));
1248 if ((error = copyout(&skb, sub, sizeof(skb))) != 0) {
1249 DPRINTF(("ti_ioctl: error copying out strbuf\n"));
1260 i_nread(fp, td, retval, fd, cmd, dat)
1272 * We are supposed to return the message length in nread, and the
1273 * number of messages in retval. We don't have the notion of number
1274 * of stream messages, so we just find out if we have any bytes waiting
1275 * for us, and if we do, then we assume that we have at least one
1276 * message waiting for us.
1278 if ((error = fo_ioctl(fp, FIONREAD, (caddr_t) &nread, td)) != 0)
1286 return copyout(&nread, dat, sizeof(nread));
1290 i_fdinsert(fp, td, retval, fd, cmd, dat)
1299 * Major hack again here. We assume that we are using this to
1300 * implement accept(2). If that is the case, we have already
1301 * called accept, and we have stored the file descriptor in
1302 * afd. We find the file descriptor that the code wants to use
1303 * in fd insert, and then we dup2() our accepted file descriptor
1307 struct svr4_strm *st = svr4_stream_get(fp);
1308 struct svr4_strfdinsert fdi;
1309 struct dup2_args d2p;
1310 struct close_args clp;
1313 DPRINTF(("fdinsert: bad file type\n"));
1317 if (st->s_afd == -1) {
1318 DPRINTF(("fdinsert: accept fd not found\n"));
1322 if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) {
1323 DPRINTF(("fdinsert: copyin failed %d\n", error));
1327 SCARG(&d2p, from) = st->s_afd;
1328 SCARG(&d2p, to) = fdi.fd;
1330 if ((error = dup2(&d2p)) != 0) {
1331 DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n",
1332 st->s_afd, fdi.fd, error));
1336 SCARG(&clp, fd) = st->s_afd;
1338 if ((error = close(&clp)) != 0) {
1339 DPRINTF(("fdinsert: close(%d) failed %d\n",
1352 _i_bind_rsvd(fp, td, retval, fd, cmd, dat)
1360 struct mkfifo_args ap;
1363 * This is a supposed to be a kernel and library only ioctl.
1364 * It gets called before ti_bind, when we have a unix
1365 * socket, to physically create the socket transport and
1366 * ``reserve'' it. I don't know how this get reserved inside
1367 * the kernel, but we are going to create it nevertheless.
1369 SCARG(&ap, path) = dat;
1370 SCARG(&ap, mode) = S_IFIFO;
1376 _i_rele_rsvd(fp, td, retval, fd, cmd, dat)
1384 struct unlink_args ap;
1387 * This is a supposed to be a kernel and library only ioctl.
1388 * I guess it is supposed to release the socket.
1390 SCARG(&ap, path) = dat;
1396 i_str(fp, td, retval, fd, cmd, dat)
1405 struct svr4_strioctl ioc;
1407 if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0)
1411 if ((error = show_ioc(">", &ioc)) != 0)
1413 #endif /* DEBUG_SVR4 */
1415 switch (ioc.cmd & 0xff00) {
1417 if ((error = sockmod(fp, fd, &ioc, td)) != 0)
1422 if ((error = timod(fp, fd, &ioc, td)) != 0)
1427 DPRINTF(("Unimplemented module %c %ld\n",
1428 (char) (cmd >> 8), cmd & 0xff));
1433 if ((error = show_ioc("<", &ioc)) != 0)
1435 #endif /* DEBUG_SVR4 */
1436 return copyout(&ioc, dat, sizeof(ioc));
1440 i_setsig(fp, td, retval, fd, cmd, dat)
1449 * This is the best we can do for now; we cannot generate
1450 * signals only for specific events so the signal mask gets
1451 * ignored; we save it just to pass it to a possible I_GETSIG...
1453 * We alse have to fix the O_ASYNC fcntl bit, so the
1454 * process will get SIGPOLLs.
1456 struct proc *p = td->td_proc;
1457 struct fcntl_args fa;
1459 register_t oflags, flags;
1460 struct svr4_strm *st = svr4_stream_get(fp);
1465 DPRINTF(("i_setsig: bad file descriptor\n"));
1468 /* get old status flags */
1469 SCARG(&fa, fd) = fd;
1470 SCARG(&fa, cmd) = F_GETFL;
1471 if ((error = fcntl(&fa)) != 0)
1474 oflags = fa.sysmsg_result;
1476 /* update the flags */
1480 flags = oflags | O_ASYNC;
1481 if ((error = copyin(dat, &mask, sizeof(mask))) != 0) {
1482 DPRINTF(("i_setsig: bad eventmask pointer\n"));
1485 if (mask & SVR4_S_ALLMASK) {
1486 DPRINTF(("i_setsig: bad eventmask data %x\n", mask));
1489 st->s_eventmask = mask;
1492 flags = oflags & ~O_ASYNC;
1493 st->s_eventmask = 0;
1496 /* set the new flags, if changed */
1497 if (flags != oflags) {
1498 SCARG(&fa, cmd) = F_SETFL;
1499 SCARG(&fa, arg) = (long) flags;
1500 if ((error = fcntl(&fa)) != 0)
1502 flags =fa.sysmsg_result;
1505 /* set up SIGIO receiver if needed */
1507 SCARG(&fa, cmd) = F_SETOWN;
1508 SCARG(&fa, arg) = (long) p->p_pid;
1510 *retval = fa.sysmsg_result;
1513 *retval = fa.sysmsg_result;
1518 i_getsig(fp, td, retval, fd, cmd, dat)
1529 struct svr4_strm *st = svr4_stream_get(fp);
1532 DPRINTF(("i_getsig: bad file descriptor\n"));
1535 if ((error = copyout(&st->s_eventmask, dat,
1536 sizeof(st->s_eventmask))) != 0) {
1537 DPRINTF(("i_getsig: bad eventmask pointer\n"));
1545 svr4_stream_ioctl(fp, td, retval, fd, cmd, dat)
1556 * All the following stuff assumes "sockmod" is pushed...
1560 DPRINTF(("I_NREAD\n"));
1561 return i_nread(fp, td, retval, fd, cmd, dat);
1564 DPRINTF(("I_PUSH %p\n", dat));
1565 #if defined(DEBUG_SVR4)
1566 show_strbuf((void *)dat);
1571 DPRINTF(("I_POP\n"));
1575 DPRINTF(("I_LOOK\n"));
1579 DPRINTF(("I_FLUSH\n"));
1583 DPRINTF(("I_SRDOPT\n"));
1587 DPRINTF(("I_GRDOPT\n"));
1591 DPRINTF(("I_STR\n"));
1592 return i_str(fp, td, retval, fd, cmd, dat);
1595 DPRINTF(("I_SETSIG\n"));
1596 return i_setsig(fp, td, retval, fd, cmd, dat);
1599 DPRINTF(("I_GETSIG\n"));
1600 return i_getsig(fp, td, retval, fd, cmd, dat);
1603 DPRINTF(("I_FIND\n"));
1605 * Here we are not pushing modules really, we just
1606 * pretend all are present
1612 DPRINTF(("I_LINK\n"));
1616 DPRINTF(("I_UNLINK\n"));
1619 case SVR4_I_ERECVFD:
1620 DPRINTF(("I_ERECVFD\n"));
1624 DPRINTF(("I_PEEK\n"));
1627 case SVR4_I_FDINSERT:
1628 DPRINTF(("I_FDINSERT\n"));
1629 return i_fdinsert(fp, td, retval, fd, cmd, dat);
1632 DPRINTF(("I_SENDFD\n"));
1636 DPRINTF(("I_RECVFD\n"));
1640 DPRINTF(("I_SWROPT\n"));
1644 DPRINTF(("I_GWROPT\n"));
1648 DPRINTF(("I_LIST\n"));
1652 DPRINTF(("I_PLINK\n"));
1655 case SVR4_I_PUNLINK:
1656 DPRINTF(("I_PUNLINK\n"));
1660 DPRINTF(("I_SETEV\n"));
1664 DPRINTF(("I_GETEV\n"));
1668 DPRINTF(("I_STREV\n"));
1671 case SVR4_I_UNSTREV:
1672 DPRINTF(("I_UNSTREV\n"));
1675 case SVR4_I_FLUSHBAND:
1676 DPRINTF(("I_FLUSHBAND\n"));
1680 DPRINTF(("I_CKBAND\n"));
1683 case SVR4_I_GETBAND:
1684 DPRINTF(("I_GETBANK\n"));
1688 DPRINTF(("I_ATMARK\n"));
1691 case SVR4_I_SETCLTIME:
1692 DPRINTF(("I_SETCLTIME\n"));
1695 case SVR4_I_GETCLTIME:
1696 DPRINTF(("I_GETCLTIME\n"));
1700 DPRINTF(("I_CANPUT\n"));
1703 case SVR4__I_BIND_RSVD:
1704 DPRINTF(("_I_BIND_RSVD\n"));
1705 return _i_bind_rsvd(fp, td, retval, fd, cmd, dat);
1707 case SVR4__I_RELE_RSVD:
1708 DPRINTF(("_I_RELE_RSVD\n"));
1709 return _i_rele_rsvd(fp, td, retval, fd, cmd, dat);
1712 DPRINTF(("unimpl cmd = %lx\n", cmd));
1722 svr4_sys_putmsg(struct svr4_sys_putmsg_args *uap)
1724 struct thread *td = curthread;
1725 struct proc *p = td->td_proc;
1726 struct filedesc *fdp;
1728 struct svr4_strbuf dat, ctl;
1729 struct svr4_strmcmd sc;
1730 struct sockaddr_in sain;
1731 struct sockaddr_un saun;
1733 int sasize, *retval;
1734 struct svr4_strm *st;
1740 retval = &uap->sysmsg_result;
1741 fp = fdp->fd_ofiles[SCARG(uap, fd)];
1743 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) {
1745 uprintf("putmsg: bad fp\n");
1751 show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl),
1752 SCARG(uap, dat), SCARG(uap, flags));
1753 #endif /* DEBUG_SVR4 */
1755 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) {
1757 uprintf("putmsg: bad fp(2)\n");
1762 if (SCARG(uap, ctl) != NULL) {
1763 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) {
1765 uprintf("putmsg: copyin(): %d\n", error);
1773 if (SCARG(uap, dat) != NULL) {
1774 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0) {
1776 uprintf("putmsg: copyin(): %d (2)\n", error);
1785 * Only for sockets for now.
1787 if ((st = svr4_stream_get(fp)) == NULL) {
1788 DPRINTF(("putmsg: bad file type\n"));
1792 if (ctl.len > sizeof(sc)) {
1793 DPRINTF(("putmsg: Bad control size %d != %d\n", ctl.len,
1794 sizeof(struct svr4_strmcmd)));
1798 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
1801 switch (st->s_family) {
1803 if (sc.len != sizeof(sain)) {
1804 if (sc.cmd == SVR4_TI_DATA_REQUEST) {
1805 struct write_args wa;
1807 /* Solaris seems to use sc.cmd = 3 to
1808 * send "expedited" data. telnet uses
1809 * this for options processing, sending EOF,
1810 * etc. I'm sure other things use it too.
1811 * I don't have any documentation
1812 * on it, so I'm making a guess that this
1813 * is how it works. newton@atdot.dotat.org XXX
1815 DPRINTF(("sending expedited data ??\n"));
1816 SCARG(&wa, fd) = SCARG(uap, fd);
1817 SCARG(&wa, buf) = dat.buf;
1818 SCARG(&wa, nbyte) = dat.len;
1819 wa.sysmsg_result = 0;
1822 *retval = wa.sysmsg_result;
1825 DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len));
1828 netaddr_to_sockaddr_in(&sain, &sc);
1830 sasize = sizeof(sain);
1831 error = sain.sin_family != st->s_family;
1836 /* We are doing an accept; succeed */
1837 DPRINTF(("putmsg: Do nothing\n"));
1842 /* Maybe we've been given a device/inode pair */
1843 udev_t *dev = SVR4_ADDROF(&sc);
1844 ino_t *ino = (ino_t *) &dev[1];
1845 skp = svr4_find_socket(td, fp, *dev, *ino);
1848 /* I guess we have it by name */
1849 netaddr_to_sockaddr_un(skp, &sc);
1851 sasize = sizeof(saun);
1856 DPRINTF(("putmsg: Unsupported address family %d\n",
1861 sg = stackgap_init();
1862 sup = stackgap_alloc(&sg, sasize);
1864 if ((error = copyout(skp, sup, sasize)) != 0)
1867 switch (st->s_cmd = sc.cmd) {
1868 case SVR4_TI_CONNECT_REQUEST: /* connect */
1870 struct connect_args co;
1872 SCARG(&co, s) = SCARG(uap, fd);
1873 SCARG(&co, name) = (void *) sup;
1874 SCARG(&co, namelen) = (int) sasize;
1875 co.sysmsg_result = 0;
1877 error = connect(&co);
1878 *retval = co.sysmsg_result;
1882 case SVR4_TI_SENDTO_REQUEST: /* sendto */
1887 msg.msg_name = (caddr_t) sup;
1888 msg.msg_namelen = sasize;
1889 msg.msg_iov = &aiov;
1891 msg.msg_control = 0;
1893 aiov.iov_base = dat.buf;
1894 aiov.iov_len = dat.len;
1896 error = so->so_proto->pr_usrreqs->pru_sosend
1897 (so, 0, uio, 0, 0, 0, uio->uio_td);
1899 error = svr4_sendit(td, SCARG(uap, fd), &msg,
1900 SCARG(uap, flags), retval);
1901 DPRINTF(("sendto_request error: %d\n", error));
1907 DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd));
1913 svr4_sys_getmsg(struct svr4_sys_getmsg_args *uap)
1915 struct thread *td = curthread;
1916 struct proc *p = td->td_proc;
1917 struct filedesc *fdp;
1919 struct getpeername_args ga;
1920 struct accept_args aa;
1921 struct svr4_strbuf dat, ctl;
1922 struct svr4_strmcmd sc;
1926 struct sockaddr_in sain;
1927 struct sockaddr_un saun;
1930 struct svr4_strm *st;
1937 retval = &uap->sysmsg_result;
1938 fp = fdp->fd_ofiles[SCARG(uap, fd)];
1940 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL))
1943 memset(&sc, 0, sizeof(sc));
1946 show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl),
1947 SCARG(uap, dat), 0);
1948 #endif /* DEBUG_SVR4 */
1950 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL))
1953 if (SCARG(uap, ctl) != NULL) {
1954 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0)
1962 if (SCARG(uap, dat) != NULL) {
1963 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0)
1972 * Only for sockets for now.
1974 if ((st = svr4_stream_get(fp)) == NULL) {
1975 DPRINTF(("getmsg: bad file type\n"));
1979 if (ctl.maxlen == -1 || dat.maxlen == -1) {
1980 DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n"));
1984 switch (st->s_family) {
1987 sasize = sizeof(sain);
1992 sasize = sizeof(saun);
1996 DPRINTF(("getmsg: Unsupported address family %d\n",
2001 sg = stackgap_init();
2002 sup = stackgap_alloc(&sg, sasize);
2003 flen = (int *) stackgap_alloc(&sg, sizeof(*flen));
2006 if ((error = copyout(&fl, flen, sizeof(fl))) != 0)
2009 switch (st->s_cmd) {
2010 case SVR4_TI_CONNECT_REQUEST:
2011 DPRINTF(("getmsg: TI_CONNECT_REQUEST\n"));
2013 * We do the connect in one step, so the putmsg should
2014 * have gotten the error.
2016 sc.cmd = SVR4_TI_OK_REPLY;
2025 case SVR4_TI_OK_REPLY:
2026 DPRINTF(("getmsg: TI_OK_REPLY\n"));
2028 * We are immediately after a connect reply, so we send
2029 * a connect verification.
2032 SCARG(&ga, fdes) = SCARG(uap, fd);
2033 SCARG(&ga, asa) = (void *) sup;
2034 SCARG(&ga, alen) = flen;
2036 if ((error = getpeername(&ga)) != 0) {
2037 DPRINTF(("getmsg: getpeername failed %d\n", error));
2041 if ((error = copyin(sup, skp, sasize)) != 0)
2044 sc.cmd = SVR4_TI_CONNECT_REPLY;
2048 sc.pad[2] = 0x04000402;
2050 switch (st->s_family) {
2053 sockaddr_to_netaddr_in(&sc, &sain);
2057 sc.len = sasize + 4;
2058 sockaddr_to_netaddr_un(&sc, &saun);
2071 case SVR4_TI__ACCEPT_OK:
2072 DPRINTF(("getmsg: TI__ACCEPT_OK\n"));
2074 * We do the connect in one step, so the putmsg should
2075 * have gotten the error.
2077 sc.cmd = SVR4_TI_OK_REPLY;
2083 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
2086 case SVR4_TI__ACCEPT_WAIT:
2087 DPRINTF(("getmsg: TI__ACCEPT_WAIT\n"));
2089 * We are after a listen, so we try to accept...
2091 SCARG(&aa, s) = SCARG(uap, fd);
2092 SCARG(&aa, name) = (void *) sup;
2093 SCARG(&aa, anamelen) = flen;
2095 if ((error = accept(&aa)) != 0) {
2096 DPRINTF(("getmsg: accept failed %d\n", error));
2100 st->s_afd = *retval;
2102 DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd));
2104 if ((error = copyin(sup, skp, sasize)) != 0)
2107 sc.cmd = SVR4_TI_ACCEPT_REPLY;
2111 switch (st->s_family) {
2114 sockaddr_to_netaddr_in(&sc, &sain);
2120 sc.pad[1] = 0x00010000;
2121 sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */
2122 sc.pad[3] = 0x00010000;
2124 sc.len = sasize + 4;
2133 st->s_cmd = SVR4_TI__ACCEPT_OK;
2136 case SVR4_TI_SENDTO_REQUEST:
2137 DPRINTF(("getmsg: TI_SENDTO_REQUEST\n"));
2138 if (ctl.maxlen > 36 && ctl.len < 36)
2141 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
2144 switch (st->s_family) {
2146 sockaddr_to_netaddr_in(&sc, &sain);
2150 sockaddr_to_netaddr_un(&sc, &saun);
2157 msg.msg_name = (caddr_t) sup;
2158 msg.msg_namelen = sasize;
2159 msg.msg_iov = &aiov;
2161 msg.msg_control = 0;
2162 aiov.iov_base = dat.buf;
2163 aiov.iov_len = dat.maxlen;
2166 error = svr4_recvit(td, SCARG(uap, fd), &msg, (caddr_t) flen, retval);
2169 DPRINTF(("getmsg: recvit failed %d\n", error));
2173 if ((error = copyin(msg.msg_name, skp, sasize)) != 0)
2176 sc.cmd = SVR4_TI_RECVFROM_IND;
2178 switch (st->s_family) {
2181 sockaddr_to_netaddr_in(&sc, &sain);
2185 sc.len = sasize + 4;
2186 sockaddr_to_netaddr_un(&sc, &saun);
2200 if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) {
2201 struct read_args ra;
2203 /* More wierdness: Again, I can't find documentation
2204 * to back this up, but when a process does a generic
2205 * "getmsg()" call it seems that the command field is
2206 * zero and the length of the data area is zero. I
2207 * think processes expect getmsg() to fill in dat.len
2208 * after reading at most dat.maxlen octets from the
2209 * stream. Since we're using sockets I can let
2210 * read() look after it and frob return values
2211 * appropriately (or inappropriately :-)
2212 * -- newton@atdot.dotat.org XXX
2214 SCARG(&ra, fd) = SCARG(uap, fd);
2215 SCARG(&ra, buf) = dat.buf;
2216 SCARG(&ra, nbyte) = dat.maxlen;
2217 if ((error = read(&ra)) != 0) {
2222 st->s_cmd = SVR4_TI_SENDTO_REQUEST;
2225 DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd));
2229 if (SCARG(uap, ctl)) {
2231 if ((error = copyout(&sc, ctl.buf, ctl.len)) != 0)
2234 if ((error = copyout(&ctl, SCARG(uap, ctl), sizeof(ctl))) != 0)
2238 if (SCARG(uap, dat)) {
2239 if ((error = copyout(&dat, SCARG(uap, dat), sizeof(dat))) != 0)
2243 if (SCARG(uap, flags)) { /* XXX: Need translation */
2244 if ((error = copyout(&fl, SCARG(uap, flags), sizeof(fl))) != 0)
2251 show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl),
2252 SCARG(uap, dat), fl);
2253 #endif /* DEBUG_SVR4 */
2257 int svr4_sys_send(struct svr4_sys_send_args *uap)
2259 struct osend_args osa;
2262 SCARG(&osa, s) = SCARG(uap, s);
2263 SCARG(&osa, buf) = SCARG(uap, buf);
2264 SCARG(&osa, len) = SCARG(uap, len);
2265 SCARG(&osa, flags) = SCARG(uap, flags);
2266 osa.sysmsg_result = 0;
2267 error = osend(&osa);
2268 uap->sysmsg_result = osa.sysmsg_result;
2272 int svr4_sys_recv(struct svr4_sys_recv_args *uap)
2274 struct orecv_args ora;
2277 SCARG(&ora, s) = SCARG(uap, s);
2278 SCARG(&ora, buf) = SCARG(uap, buf);
2279 SCARG(&ora, len) = SCARG(uap, len);
2280 SCARG(&ora, flags) = SCARG(uap, flags);
2281 ora.sysmsg_result = 0;
2282 error = orecv(&ora);
2283 uap->sysmsg_result = ora.sysmsg_result;
2288 * XXX This isn't necessary, but it's handy for inserting debug code into
2289 * sendto(). Let's leave it here for now...
2292 svr4_sys_sendto(struct svr4_sys_sendto_args *uap)
2294 struct sendto_args sa;
2297 SCARG(&sa, s) = SCARG(uap, s);
2298 SCARG(&sa, buf) = SCARG(uap, buf);
2299 SCARG(&sa, len) = SCARG(uap, len);
2300 SCARG(&sa, flags) = SCARG(uap, flags);
2301 SCARG(&sa, to) = (caddr_t)SCARG(uap, to);
2302 SCARG(&sa, tolen) = SCARG(uap, tolen);
2304 DPRINTF(("calling sendto()\n"));
2305 sa.sysmsg_result = 0;
2306 error = sendto(&sa);
2307 uap->sysmsg_result = sa.sysmsg_result;