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 $
34 * Pretend that we have streams...
37 * ToDo: The state machine for getmsg needs re-thinking
42 #include <sys/param.h>
43 #include <sys/systm.h>
45 #include <sys/malloc.h>
47 #include <sys/filedesc.h>
48 #include <sys/fcntl.h>
49 #include <sys/filio.h>
50 #include <sys/select.h>
51 #include <sys/socket.h>
52 #include <sys/socketvar.h>
54 #include <netinet/in.h>
56 #include <sys/protosw.h>
57 #include <sys/signal.h>
58 #include <sys/signalvar.h>
60 #include <sys/ktrace.h>
64 #include <sys/sysproto.h>
66 #include <svr4/svr4.h>
67 #include <svr4/svr4_types.h>
68 #include <svr4/svr4_util.h>
69 #include <svr4/svr4_signal.h>
70 #include <svr4/svr4_proto.h>
71 #include <svr4/svr4_stropts.h>
72 #include <svr4/svr4_timod.h>
73 #include <svr4/svr4_sockmod.h>
74 #include <svr4/svr4_ioctl.h>
75 #include <svr4/svr4_socket.h>
78 static int clean_pipe __P((struct proc *, const char *));
79 static void getparm __P((struct file *, struct svr4_si_sockparms *));
81 /* Address Conversions */
82 static void sockaddr_to_netaddr_in __P((struct svr4_strmcmd *,
83 const struct sockaddr_in *));
84 static void sockaddr_to_netaddr_un __P((struct svr4_strmcmd *,
85 const struct sockaddr_un *));
86 static void netaddr_to_sockaddr_in __P((struct sockaddr_in *,
87 const struct svr4_strmcmd *));
88 static void netaddr_to_sockaddr_un __P((struct sockaddr_un *,
89 const struct svr4_strmcmd *));
92 static int i_nread __P((struct file *, struct proc *, register_t *, int,
94 static int i_fdinsert __P((struct file *, struct proc *, register_t *, int,
96 static int i_str __P((struct file *, struct proc *, register_t *, int,
98 static int i_setsig __P((struct file *, struct proc *, register_t *, int,
100 static int i_getsig __P((struct file *, struct proc *, register_t *, int,
102 static int _i_bind_rsvd __P((struct file *, struct proc *, register_t *, int,
104 static int _i_rele_rsvd __P((struct file *, struct proc *, register_t *, int,
107 /* i_str sockmod calls */
108 static int sockmod __P((struct file *, int, struct svr4_strioctl *,
110 static int si_listen __P((struct file *, int, struct svr4_strioctl *,
112 static int si_ogetudata __P((struct file *, int, struct svr4_strioctl *,
114 static int si_sockparams __P((struct file *, int, struct svr4_strioctl *,
116 static int si_shutdown __P((struct file *, int, struct svr4_strioctl *,
118 static int si_getudata __P((struct file *, int, struct svr4_strioctl *,
121 /* i_str timod calls */
122 static int timod __P((struct file *, int, struct svr4_strioctl *,
124 static int ti_getinfo __P((struct file *, int, struct svr4_strioctl *,
126 static int ti_bind __P((struct file *, int, struct svr4_strioctl *,
130 static int svr4_sendit __P((struct proc *p, int s, struct msghdr *mp,
133 static int svr4_recvit __P((struct proc *p, int s, struct msghdr *mp,
136 /* <sigh> Ok, so we shouldn't use sendit() in uipc_syscalls.c because
137 * it isn't part of a "public" interface; We're supposed to use
138 * pru_sosend instead. Same goes for recvit()/pru_soreceive() for
139 * that matter. Solution: Suck sendit()/recvit() into here where we
140 * can do what we like.
142 * I hate code duplication.
144 * I will take out all the #ifdef COMPAT_OLDSOCK gumph, though.
147 svr4_sendit(p, s, mp, flags)
148 register struct proc *p;
150 register struct msghdr *mp;
155 register struct iovec *iov;
157 struct mbuf *control;
162 struct iovec *ktriov = NULL;
166 error = holdsock(p->p_fd, s, &fp);
169 auio.uio_iov = mp->msg_iov;
170 auio.uio_iovcnt = mp->msg_iovlen;
171 auio.uio_segflg = UIO_USERSPACE;
172 auio.uio_rw = UIO_WRITE;
174 auio.uio_offset = 0; /* XXX */
177 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
178 if ((auio.uio_resid += iov->iov_len) < 0) {
184 error = getsockaddr(&to, mp->msg_name, mp->msg_namelen);
192 if (mp->msg_control) {
193 if (mp->msg_controllen < sizeof(struct cmsghdr)) {
197 error = sockargs(&control, mp->msg_control,
198 mp->msg_controllen, MT_CONTROL);
205 if (KTRPOINT(p, KTR_GENIO)) {
206 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
208 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
209 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
213 len = auio.uio_resid;
214 so = (struct socket *)fp->f_data;
215 error = so->so_proto->pr_usrreqs->pru_sosend(so, to, &auio, 0, control,
218 if (auio.uio_resid != len && (error == ERESTART ||
219 error == EINTR || error == EWOULDBLOCK))
225 p->p_retval[0] = len - auio.uio_resid;
227 if (ktriov != NULL) {
229 ktruio.uio_iov = ktriov;
230 ktruio.uio_resid = p->p_retval[0];
231 ktrgenio(p->p_tracep, s, UIO_WRITE, &ktruio, error);
233 FREE(ktriov, M_TEMP);
244 svr4_recvit(p, s, mp, namelenp)
245 register struct proc *p;
247 register struct msghdr *mp;
252 register struct iovec *iov;
255 struct mbuf *m, *control = 0;
258 struct sockaddr *fromsa = 0;
260 struct iovec *ktriov = NULL;
264 error = holdsock(p->p_fd, s, &fp);
267 auio.uio_iov = mp->msg_iov;
268 auio.uio_iovcnt = mp->msg_iovlen;
269 auio.uio_segflg = UIO_USERSPACE;
270 auio.uio_rw = UIO_READ;
272 auio.uio_offset = 0; /* XXX */
275 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
276 if ((auio.uio_resid += iov->iov_len) < 0) {
282 if (KTRPOINT(p, KTR_GENIO)) {
283 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
285 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
286 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
290 len = auio.uio_resid;
291 so = (struct socket *)fp->f_data;
292 error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio,
293 (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
296 if (auio.uio_resid != len && (error == ERESTART ||
297 error == EINTR || error == EWOULDBLOCK))
301 if (ktriov != NULL) {
303 ktruio.uio_iov = ktriov;
304 ktruio.uio_resid = len - auio.uio_resid;
305 ktrgenio(p->p_tracep, s, UIO_READ, &ktruio, error);
307 FREE(ktriov, M_TEMP);
312 p->p_retval[0] = len - auio.uio_resid;
314 len = mp->msg_namelen;
315 if (len <= 0 || fromsa == 0)
319 #define MIN(a,b) ((a)>(b)?(b):(a))
321 /* save sa_len before it is destroyed by MSG_COMPAT */
322 len = MIN(len, fromsa->sa_len);
323 error = copyout(fromsa,
324 (caddr_t)mp->msg_name, (unsigned)len);
328 mp->msg_namelen = len;
330 (error = copyout((caddr_t)&len, namelenp, sizeof (int)))) {
334 if (mp->msg_control) {
335 len = mp->msg_controllen;
337 mp->msg_controllen = 0;
338 ctlbuf = (caddr_t) mp->msg_control;
340 while (m && len > 0) {
346 mp->msg_flags |= MSG_CTRUNC;
350 if ((error = copyout((caddr_t)mtod(m, caddr_t),
351 ctlbuf, tocopy)) != 0)
358 mp->msg_controllen = ctlbuf - (caddr_t)mp->msg_control;
362 FREE(fromsa, M_SONAME);
370 static void bufprint __P((u_char *, size_t));
371 static int show_ioc __P((const char *, struct svr4_strioctl *));
372 static int show_strbuf __P((struct svr4_strbuf *));
373 static void show_msg __P((const char *, int, struct svr4_strbuf *,
374 struct svr4_strbuf *, int));
384 for (i = 0; i < len; i++) {
385 uprintf("%x ", buf[i]);
386 if (i && (i % 16) == 0)
394 struct svr4_strioctl *ioc;
396 u_char *ptr = (u_char *) malloc(ioc->len, M_TEMP, M_WAITOK);
399 uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ",
400 str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf);
402 if ((error = copyin(ioc->buf, ptr, ioc->len)) != 0) {
403 free((char *) ptr, M_TEMP);
407 bufprint(ptr, ioc->len);
411 free((char *) ptr, M_TEMP);
418 struct svr4_strbuf *str;
422 int maxlen = str->maxlen;
432 ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK);
434 if ((error = copyin(str->buf, ptr, len)) != 0) {
435 free((char *) ptr, M_TEMP);
440 uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf);
448 free((char *) ptr, M_TEMP);
455 show_msg(str, fd, ctl, dat, flags)
458 struct svr4_strbuf *ctl;
459 struct svr4_strbuf *dat;
462 struct svr4_strbuf buf;
465 uprintf("%s(%d", str, fd);
467 if ((error = copyin(ctl, &buf, sizeof(buf))) != 0)
475 if ((error = copyin(dat, &buf, sizeof(buf))) != 0)
482 uprintf(", %x);\n", flags);
485 #endif /* DEBUG_SVR4 */
488 * We are faced with an interesting situation. On svr4 unix sockets
489 * are really pipes. But we really have sockets, and we might as
490 * well use them. At the point where svr4 calls TI_BIND, it has
491 * already created a named pipe for the socket using mknod(2).
492 * We need to create a socket with the same name when we bind,
493 * so we need to remove the pipe before, otherwise we'll get address
494 * already in use. So we *carefully* remove the pipe, to avoid
495 * using this as a random file removal tool. We use system calls
496 * to avoid code duplication.
503 struct lstat_args la;
504 struct unlink_args ua;
507 caddr_t sg = stackgap_init();
508 size_t l = strlen(path) + 1;
511 tpath = stackgap_alloc(&sg, l);
512 SCARG(&la, ub) = stackgap_alloc(&sg, sizeof(struct stat));
514 if ((error = copyout(path, tpath, l)) != 0)
517 SCARG(&la, path) = tpath;
519 if ((error = lstat(p, &la)) != 0)
522 if ((error = copyin(SCARG(&la, ub), &st, sizeof(st))) != 0)
526 * Make sure we are dealing with a mode 0 named pipe.
528 if ((st.st_mode & S_IFMT) != S_IFIFO)
531 if ((st.st_mode & ALLPERMS) != 0)
534 SCARG(&ua, path) = SCARG(&la, path);
536 if ((error = unlink(p, &ua)) != 0) {
537 DPRINTF(("clean_pipe: unlink failed %d\n", error));
546 sockaddr_to_netaddr_in(sc, sain)
547 struct svr4_strmcmd *sc;
548 const struct sockaddr_in *sain;
550 struct svr4_netaddr_in *na;
551 na = SVR4_ADDROF(sc);
553 na->family = sain->sin_family;
554 na->port = sain->sin_port;
555 na->addr = sain->sin_addr.s_addr;
556 DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port,
562 sockaddr_to_netaddr_un(sc, saun)
563 struct svr4_strmcmd *sc;
564 const struct sockaddr_un *saun;
566 struct svr4_netaddr_un *na;
567 char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 -
571 na = SVR4_ADDROF(sc);
572 na->family = saun->sun_family;
573 for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; )
576 DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path));
581 netaddr_to_sockaddr_in(sain, sc)
582 struct sockaddr_in *sain;
583 const struct svr4_strmcmd *sc;
585 const struct svr4_netaddr_in *na;
588 na = SVR4_C_ADDROF(sc);
589 memset(sain, 0, sizeof(*sain));
590 sain->sin_len = sizeof(*sain);
591 sain->sin_family = na->family;
592 sain->sin_port = na->port;
593 sain->sin_addr.s_addr = na->addr;
594 DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family,
595 sain->sin_port, sain->sin_addr.s_addr));
600 netaddr_to_sockaddr_un(saun, sc)
601 struct sockaddr_un *saun;
602 const struct svr4_strmcmd *sc;
604 const struct svr4_netaddr_un *na;
605 char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1];
608 na = SVR4_C_ADDROF(sc);
609 memset(saun, 0, sizeof(*saun));
610 saun->sun_family = na->family;
611 for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; )
614 saun->sun_len = dst - saun->sun_path;
615 DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family,
623 struct svr4_si_sockparms *pa;
625 struct svr4_strm *st = svr4_stream_get(fp);
626 struct socket *so = (struct socket *) fp->f_data;
631 pa->family = st->s_family;
633 switch (so->so_type) {
635 pa->type = SVR4_T_CLTS;
636 pa->protocol = IPPROTO_UDP;
637 DPRINTF(("getparm(dgram)\n"));
641 pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */
642 pa->protocol = IPPROTO_IP;
643 DPRINTF(("getparm(stream)\n"));
647 pa->type = SVR4_T_CLTS;
648 pa->protocol = IPPROTO_RAW;
649 DPRINTF(("getparm(raw)\n"));
655 DPRINTF(("getparm(type %d?)\n", so->so_type));
662 si_ogetudata(fp, fd, ioc, p)
665 struct svr4_strioctl *ioc;
669 struct svr4_si_oudata ud;
670 struct svr4_si_sockparms pa;
672 if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) {
673 DPRINTF(("SI_OGETUDATA: Wrong size %d != %d\n",
674 sizeof(ud), ioc->len));
678 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
686 ud.addrsize = sizeof(struct svr4_sockaddr_in);
687 if (pa.type == SVR4_SOCK_STREAM)
700 DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n",
705 /* I have no idea what these should be! */
709 ud.servtype = pa.type;
714 return copyout(&ud, ioc->buf, ioc->len);
719 si_sockparams(fp, fd, ioc, p)
722 struct svr4_strioctl *ioc;
725 struct svr4_si_sockparms pa;
728 return copyout(&pa, ioc->buf, sizeof(pa));
733 si_listen(fp, fd, ioc, p)
736 struct svr4_strioctl *ioc;
740 struct svr4_strm *st = svr4_stream_get(fp);
741 struct svr4_strmcmd lst;
742 struct listen_args la;
747 if ((error = copyin(ioc->buf, &lst, ioc->len)) != 0)
750 if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) {
751 DPRINTF(("si_listen: bad request %ld\n", lst.cmd));
756 * We are making assumptions again...
759 DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5));
760 SCARG(&la, backlog) = 5;
762 if ((error = listen(p, &la)) != 0) {
763 DPRINTF(("SI_LISTEN: listen failed %d\n", error));
767 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
768 lst.cmd = SVR4_TI_BIND_REPLY;
770 switch (st->s_family) {
772 /* XXX: Fill the length here */
777 lst.pad[28] = 0x00000000; /* magic again */
778 lst.pad[29] = 0x00000800; /* magic again */
779 lst.pad[30] = 0x80001400; /* magic again */
783 DPRINTF(("SI_LISTEN: Unsupported address family %d\n",
789 if ((error = copyout(&lst, ioc->buf, ioc->len)) != 0)
797 si_getudata(fp, fd, ioc, p)
800 struct svr4_strioctl *ioc;
804 struct svr4_si_udata ud;
806 if (sizeof(ud) != ioc->len) {
807 DPRINTF(("SI_GETUDATA: Wrong size %d != %d\n",
808 sizeof(ud), ioc->len));
812 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
815 getparm(fp, &ud.sockparms);
817 switch (ud.sockparms.family) {
819 DPRINTF(("getudata_inet\n"));
822 ud.addrsize = sizeof(struct svr4_sockaddr_in);
823 if (ud.sockparms.type == SVR4_SOCK_STREAM)
831 DPRINTF(("getudata_local\n"));
840 DPRINTF(("SI_GETUDATA: Unsupported address family %d\n",
841 ud.sockparms.family));
846 ud.servtype = ud.sockparms.type;
847 DPRINTF(("ud.servtype = %d\n", ud.servtype));
851 return copyout(&ud, ioc->buf, sizeof(ud));
856 si_shutdown(fp, fd, ioc, p)
859 struct svr4_strioctl *ioc;
863 struct shutdown_args ap;
865 if (ioc->len != sizeof(SCARG(&ap, how))) {
866 DPRINTF(("SI_SHUTDOWN: Wrong size %d != %d\n",
867 sizeof(SCARG(&ap, how)), ioc->len));
871 if ((error = copyin(ioc->buf, &SCARG(&ap, how), ioc->len)) != 0)
876 return shutdown(p, &ap);
881 sockmod(fp, fd, ioc, p)
884 struct svr4_strioctl *ioc;
888 case SVR4_SI_OGETUDATA:
889 DPRINTF(("SI_OGETUDATA\n"));
890 return si_ogetudata(fp, fd, ioc, p);
892 case SVR4_SI_SHUTDOWN:
893 DPRINTF(("SI_SHUTDOWN\n"));
894 return si_shutdown(fp, fd, ioc, p);
897 DPRINTF(("SI_LISTEN\n"));
898 return si_listen(fp, fd, ioc, p);
900 case SVR4_SI_SETMYNAME:
901 DPRINTF(("SI_SETMYNAME\n"));
904 case SVR4_SI_SETPEERNAME:
905 DPRINTF(("SI_SETPEERNAME\n"));
908 case SVR4_SI_GETINTRANSIT:
909 DPRINTF(("SI_GETINTRANSIT\n"));
912 case SVR4_SI_TCL_LINK:
913 DPRINTF(("SI_TCL_LINK\n"));
916 case SVR4_SI_TCL_UNLINK:
917 DPRINTF(("SI_TCL_UNLINK\n"));
920 case SVR4_SI_SOCKPARAMS:
921 DPRINTF(("SI_SOCKPARAMS\n"));
922 return si_sockparams(fp, fd, ioc, p);
924 case SVR4_SI_GETUDATA:
925 DPRINTF(("SI_GETUDATA\n"));
926 return si_getudata(fp, fd, ioc, p);
929 DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd));
937 ti_getinfo(fp, fd, ioc, p)
940 struct svr4_strioctl *ioc;
944 struct svr4_infocmd info;
946 memset(&info, 0, sizeof(info));
948 if ((error = copyin(ioc->buf, &info, ioc->len)) != 0)
951 if (info.cmd != SVR4_TI_INFO_REQUEST)
954 info.cmd = SVR4_TI_INFO_REPLY;
966 ioc->len = sizeof(info);
967 if ((error = copyout(&info, ioc->buf, ioc->len)) != 0)
975 ti_bind(fp, fd, ioc, p)
978 struct svr4_strioctl *ioc;
982 struct svr4_strm *st = svr4_stream_get(fp);
983 struct sockaddr_in sain;
984 struct sockaddr_un saun;
986 void *skp, *sup = NULL;
988 struct svr4_strmcmd bnd;
992 DPRINTF(("ti_bind: bad file descriptor\n"));
996 if ((error = copyin(ioc->buf, &bnd, ioc->len)) != 0)
999 if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) {
1000 DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd));
1004 switch (st->s_family) {
1007 sasize = sizeof(sain);
1012 netaddr_to_sockaddr_in(&sain, &bnd);
1014 DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n",
1015 sain.sin_family, sain.sin_port,
1016 sain.sin_addr.s_addr));
1021 sasize = sizeof(saun);
1025 netaddr_to_sockaddr_un(&saun, &bnd);
1027 if (saun.sun_path[0] == '\0')
1030 DPRINTF(("TI_BIND: fam %d, path %s\n",
1031 saun.sun_family, saun.sun_path));
1033 if ((error = clean_pipe(p, saun.sun_path)) != 0)
1036 bnd.pad[28] = 0x00001000; /* magic again */
1040 DPRINTF(("TI_BIND: Unsupported address family %d\n",
1045 sg = stackgap_init();
1046 sup = stackgap_alloc(&sg, sasize);
1048 if ((error = copyout(skp, sup, sasize)) != 0)
1052 DPRINTF(("TI_BIND: fileno %d\n", fd));
1053 SCARG(&ba, name) = (void *) sup;
1054 SCARG(&ba, namelen) = sasize;
1056 if ((error = bind(p, &ba)) != 0) {
1057 DPRINTF(("TI_BIND: bind failed %d\n", error));
1063 memset(&bnd, 0, sizeof(bnd));
1064 bnd.len = sasize + 4;
1065 bnd.offs = 0x10; /* XXX */
1068 bnd.cmd = SVR4_TI_BIND_REPLY;
1070 if ((error = copyout(&bnd, ioc->buf, ioc->len)) != 0)
1078 timod(fp, fd, ioc, p)
1081 struct svr4_strioctl *ioc;
1085 case SVR4_TI_GETINFO:
1086 DPRINTF(("TI_GETINFO\n"));
1087 return ti_getinfo(fp, fd, ioc, p);
1089 case SVR4_TI_OPTMGMT:
1090 DPRINTF(("TI_OPTMGMT\n"));
1094 DPRINTF(("TI_BIND\n"));
1095 return ti_bind(fp, fd, ioc, p);
1097 case SVR4_TI_UNBIND:
1098 DPRINTF(("TI_UNBIND\n"));
1102 DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd));
1109 svr4_stream_ti_ioctl(fp, p, retval, fd, cmd, dat)
1117 struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat;
1118 struct svr4_strm *st = svr4_stream_get(fp);
1121 struct sockaddr_in sain;
1122 struct sockaddr_un saun;
1123 struct svr4_strmcmd sc;
1128 DPRINTF(("svr4_stream_ti_ioctl\n"));
1135 if ((error = copyin(sub, &skb, sizeof(skb))) != 0) {
1136 DPRINTF(("ti_ioctl: error copying in strbuf\n"));
1140 switch (st->s_family) {
1143 sasize = sizeof(sain);
1148 sasize = sizeof(saun);
1152 DPRINTF(("ti_ioctl: Unsupported address family %d\n",
1157 sg = stackgap_init();
1158 sup = stackgap_alloc(&sg, sasize);
1159 lenp = stackgap_alloc(&sg, sizeof(*lenp));
1161 if ((error = copyout(&sasize, lenp, sizeof(*lenp))) != 0) {
1162 DPRINTF(("ti_ioctl: error copying out lenp\n"));
1167 case SVR4_TI_GETMYNAME:
1168 DPRINTF(("TI_GETMYNAME\n"));
1170 struct getsockname_args ap;
1171 SCARG(&ap, fdes) = fd;
1172 SCARG(&ap, asa) = sup;
1173 SCARG(&ap, alen) = lenp;
1174 if ((error = getsockname(p, &ap)) != 0) {
1175 DPRINTF(("ti_ioctl: getsockname error\n"));
1181 case SVR4_TI_GETPEERNAME:
1182 DPRINTF(("TI_GETPEERNAME\n"));
1184 struct getpeername_args ap;
1185 SCARG(&ap, fdes) = fd;
1186 SCARG(&ap, asa) = sup;
1187 SCARG(&ap, alen) = lenp;
1188 if ((error = getpeername(p, &ap)) != 0) {
1189 DPRINTF(("ti_ioctl: getpeername error\n"));
1195 case SVR4_TI_SETMYNAME:
1196 DPRINTF(("TI_SETMYNAME\n"));
1199 case SVR4_TI_SETPEERNAME:
1200 DPRINTF(("TI_SETPEERNAME\n"));
1203 DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd));
1207 if ((error = copyin(sup, skp, sasize)) != 0) {
1208 DPRINTF(("ti_ioctl: error copying in socket data\n"));
1212 if ((error = copyin(lenp, &sasize, sizeof(*lenp))) != 0) {
1213 DPRINTF(("ti_ioctl: error copying in socket size\n"));
1217 switch (st->s_family) {
1219 sockaddr_to_netaddr_in(&sc, &sain);
1224 sockaddr_to_netaddr_un(&sc, &saun);
1225 skb.len = sasize + 4;
1233 if ((error = copyout(SVR4_ADDROF(&sc), skb.buf, sasize)) != 0) {
1234 DPRINTF(("ti_ioctl: error copying out socket data\n"));
1239 if ((error = copyout(&skb, sub, sizeof(skb))) != 0) {
1240 DPRINTF(("ti_ioctl: error copying out strbuf\n"));
1251 i_nread(fp, p, retval, fd, cmd, dat)
1263 * We are supposed to return the message length in nread, and the
1264 * number of messages in retval. We don't have the notion of number
1265 * of stream messages, so we just find out if we have any bytes waiting
1266 * for us, and if we do, then we assume that we have at least one
1267 * message waiting for us.
1269 if ((error = fo_ioctl(fp, FIONREAD, (caddr_t) &nread, p)) != 0)
1277 return copyout(&nread, dat, sizeof(nread));
1281 i_fdinsert(fp, p, retval, fd, cmd, dat)
1290 * Major hack again here. We assume that we are using this to
1291 * implement accept(2). If that is the case, we have already
1292 * called accept, and we have stored the file descriptor in
1293 * afd. We find the file descriptor that the code wants to use
1294 * in fd insert, and then we dup2() our accepted file descriptor
1298 struct svr4_strm *st = svr4_stream_get(fp);
1299 struct svr4_strfdinsert fdi;
1300 struct dup2_args d2p;
1301 struct close_args clp;
1304 DPRINTF(("fdinsert: bad file type\n"));
1308 if (st->s_afd == -1) {
1309 DPRINTF(("fdinsert: accept fd not found\n"));
1313 if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) {
1314 DPRINTF(("fdinsert: copyin failed %d\n", error));
1318 SCARG(&d2p, from) = st->s_afd;
1319 SCARG(&d2p, to) = fdi.fd;
1321 if ((error = dup2(p, &d2p)) != 0) {
1322 DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n",
1323 st->s_afd, fdi.fd, error));
1327 SCARG(&clp, fd) = st->s_afd;
1329 if ((error = close(p, &clp)) != 0) {
1330 DPRINTF(("fdinsert: close(%d) failed %d\n",
1343 _i_bind_rsvd(fp, p, retval, fd, cmd, dat)
1351 struct mkfifo_args ap;
1354 * This is a supposed to be a kernel and library only ioctl.
1355 * It gets called before ti_bind, when we have a unix
1356 * socket, to physically create the socket transport and
1357 * ``reserve'' it. I don't know how this get reserved inside
1358 * the kernel, but we are going to create it nevertheless.
1360 SCARG(&ap, path) = dat;
1361 SCARG(&ap, mode) = S_IFIFO;
1363 return mkfifo(p, &ap);
1367 _i_rele_rsvd(fp, p, retval, fd, cmd, dat)
1375 struct unlink_args ap;
1378 * This is a supposed to be a kernel and library only ioctl.
1379 * I guess it is supposed to release the socket.
1381 SCARG(&ap, path) = dat;
1383 return unlink(p, &ap);
1387 i_str(fp, p, retval, fd, cmd, dat)
1396 struct svr4_strioctl ioc;
1398 if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0)
1402 if ((error = show_ioc(">", &ioc)) != 0)
1404 #endif /* DEBUG_SVR4 */
1406 switch (ioc.cmd & 0xff00) {
1408 if ((error = sockmod(fp, fd, &ioc, p)) != 0)
1413 if ((error = timod(fp, fd, &ioc, p)) != 0)
1418 DPRINTF(("Unimplemented module %c %ld\n",
1419 (char) (cmd >> 8), cmd & 0xff));
1424 if ((error = show_ioc("<", &ioc)) != 0)
1426 #endif /* DEBUG_SVR4 */
1427 return copyout(&ioc, dat, sizeof(ioc));
1431 i_setsig(fp, p, retval, fd, cmd, dat)
1440 * This is the best we can do for now; we cannot generate
1441 * signals only for specific events so the signal mask gets
1442 * ignored; we save it just to pass it to a possible I_GETSIG...
1444 * We alse have to fix the O_ASYNC fcntl bit, so the
1445 * process will get SIGPOLLs.
1447 struct fcntl_args fa;
1449 register_t oflags, flags;
1450 struct svr4_strm *st = svr4_stream_get(fp);
1453 DPRINTF(("i_setsig: bad file descriptor\n"));
1456 /* get old status flags */
1457 SCARG(&fa, fd) = fd;
1458 SCARG(&fa, cmd) = F_GETFL;
1459 if ((error = fcntl(p, &fa)) != 0)
1462 oflags = p->p_retval[0];
1464 /* update the flags */
1468 flags = oflags | O_ASYNC;
1469 if ((error = copyin(dat, &mask, sizeof(mask))) != 0) {
1470 DPRINTF(("i_setsig: bad eventmask pointer\n"));
1473 if (mask & SVR4_S_ALLMASK) {
1474 DPRINTF(("i_setsig: bad eventmask data %x\n", mask));
1477 st->s_eventmask = mask;
1480 flags = oflags & ~O_ASYNC;
1481 st->s_eventmask = 0;
1484 /* set the new flags, if changed */
1485 if (flags != oflags) {
1486 SCARG(&fa, cmd) = F_SETFL;
1487 SCARG(&fa, arg) = (long) flags;
1488 if ((error = fcntl(p, &fa)) != 0)
1490 flags = p->p_retval[0];
1493 /* set up SIGIO receiver if needed */
1495 SCARG(&fa, cmd) = F_SETOWN;
1496 SCARG(&fa, arg) = (long) p->p_pid;
1497 return fcntl(p, &fa);
1503 i_getsig(fp, p, retval, fd, cmd, dat)
1514 struct svr4_strm *st = svr4_stream_get(fp);
1517 DPRINTF(("i_getsig: bad file descriptor\n"));
1520 if ((error = copyout(&st->s_eventmask, dat,
1521 sizeof(st->s_eventmask))) != 0) {
1522 DPRINTF(("i_getsig: bad eventmask pointer\n"));
1530 svr4_stream_ioctl(fp, p, retval, fd, cmd, dat)
1541 * All the following stuff assumes "sockmod" is pushed...
1545 DPRINTF(("I_NREAD\n"));
1546 return i_nread(fp, p, retval, fd, cmd, dat);
1549 DPRINTF(("I_PUSH %x\n", dat));
1550 #if defined(DEBUG_SVR4)
1556 DPRINTF(("I_POP\n"));
1560 DPRINTF(("I_LOOK\n"));
1564 DPRINTF(("I_FLUSH\n"));
1568 DPRINTF(("I_SRDOPT\n"));
1572 DPRINTF(("I_GRDOPT\n"));
1576 DPRINTF(("I_STR\n"));
1577 return i_str(fp, p, retval, fd, cmd, dat);
1580 DPRINTF(("I_SETSIG\n"));
1581 return i_setsig(fp, p, retval, fd, cmd, dat);
1584 DPRINTF(("I_GETSIG\n"));
1585 return i_getsig(fp, p, retval, fd, cmd, dat);
1588 DPRINTF(("I_FIND\n"));
1590 * Here we are not pushing modules really, we just
1591 * pretend all are present
1597 DPRINTF(("I_LINK\n"));
1601 DPRINTF(("I_UNLINK\n"));
1604 case SVR4_I_ERECVFD:
1605 DPRINTF(("I_ERECVFD\n"));
1609 DPRINTF(("I_PEEK\n"));
1612 case SVR4_I_FDINSERT:
1613 DPRINTF(("I_FDINSERT\n"));
1614 return i_fdinsert(fp, p, retval, fd, cmd, dat);
1617 DPRINTF(("I_SENDFD\n"));
1621 DPRINTF(("I_RECVFD\n"));
1625 DPRINTF(("I_SWROPT\n"));
1629 DPRINTF(("I_GWROPT\n"));
1633 DPRINTF(("I_LIST\n"));
1637 DPRINTF(("I_PLINK\n"));
1640 case SVR4_I_PUNLINK:
1641 DPRINTF(("I_PUNLINK\n"));
1645 DPRINTF(("I_SETEV\n"));
1649 DPRINTF(("I_GETEV\n"));
1653 DPRINTF(("I_STREV\n"));
1656 case SVR4_I_UNSTREV:
1657 DPRINTF(("I_UNSTREV\n"));
1660 case SVR4_I_FLUSHBAND:
1661 DPRINTF(("I_FLUSHBAND\n"));
1665 DPRINTF(("I_CKBAND\n"));
1668 case SVR4_I_GETBAND:
1669 DPRINTF(("I_GETBANK\n"));
1673 DPRINTF(("I_ATMARK\n"));
1676 case SVR4_I_SETCLTIME:
1677 DPRINTF(("I_SETCLTIME\n"));
1680 case SVR4_I_GETCLTIME:
1681 DPRINTF(("I_GETCLTIME\n"));
1685 DPRINTF(("I_CANPUT\n"));
1688 case SVR4__I_BIND_RSVD:
1689 DPRINTF(("_I_BIND_RSVD\n"));
1690 return _i_bind_rsvd(fp, p, retval, fd, cmd, dat);
1692 case SVR4__I_RELE_RSVD:
1693 DPRINTF(("_I_RELE_RSVD\n"));
1694 return _i_rele_rsvd(fp, p, retval, fd, cmd, dat);
1697 DPRINTF(("unimpl cmd = %lx\n", cmd));
1707 svr4_sys_putmsg(p, uap)
1708 register struct proc *p;
1709 struct svr4_sys_putmsg_args *uap;
1711 struct filedesc *fdp = p->p_fd;
1713 struct svr4_strbuf dat, ctl;
1714 struct svr4_strmcmd sc;
1715 struct sockaddr_in sain;
1716 struct sockaddr_un saun;
1718 int sasize, *retval;
1719 struct svr4_strm *st;
1723 retval = p->p_retval;
1724 fp = fdp->fd_ofiles[SCARG(uap, fd)];
1726 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) {
1728 uprintf("putmsg: bad fp\n");
1734 show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl),
1735 SCARG(uap, dat), SCARG(uap, flags));
1736 #endif /* DEBUG_SVR4 */
1738 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL)) {
1740 uprintf("putmsg: bad fp(2)\n");
1745 if (SCARG(uap, ctl) != NULL) {
1746 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) {
1748 uprintf("putmsg: copyin(): %d\n", error);
1756 if (SCARG(uap, dat) != NULL) {
1757 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0) {
1759 uprintf("putmsg: copyin(): %d (2)\n", error);
1768 * Only for sockets for now.
1770 if ((st = svr4_stream_get(fp)) == NULL) {
1771 DPRINTF(("putmsg: bad file type\n"));
1775 if (ctl.len > sizeof(sc)) {
1776 DPRINTF(("putmsg: Bad control size %d != %d\n", ctl.len,
1777 sizeof(struct svr4_strmcmd)));
1781 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
1784 switch (st->s_family) {
1786 if (sc.len != sizeof(sain)) {
1787 if (sc.cmd == SVR4_TI_DATA_REQUEST) {
1788 struct write_args wa;
1790 /* Solaris seems to use sc.cmd = 3 to
1791 * send "expedited" data. telnet uses
1792 * this for options processing, sending EOF,
1793 * etc. I'm sure other things use it too.
1794 * I don't have any documentation
1795 * on it, so I'm making a guess that this
1796 * is how it works. newton@atdot.dotat.org XXX
1798 DPRINTF(("sending expedited data ??\n"));
1799 SCARG(&wa, fd) = SCARG(uap, fd);
1800 SCARG(&wa, buf) = dat.buf;
1801 SCARG(&wa, nbyte) = dat.len;
1802 return write(p, &wa);
1804 DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len));
1807 netaddr_to_sockaddr_in(&sain, &sc);
1809 sasize = sizeof(sain);
1810 error = sain.sin_family != st->s_family;
1815 /* We are doing an accept; succeed */
1816 DPRINTF(("putmsg: Do nothing\n"));
1821 /* Maybe we've been given a device/inode pair */
1822 udev_t *dev = SVR4_ADDROF(&sc);
1823 ino_t *ino = (ino_t *) &dev[1];
1824 skp = svr4_find_socket(p, fp, *dev, *ino);
1827 /* I guess we have it by name */
1828 netaddr_to_sockaddr_un(skp, &sc);
1830 sasize = sizeof(saun);
1835 DPRINTF(("putmsg: Unsupported address family %d\n",
1840 sg = stackgap_init();
1841 sup = stackgap_alloc(&sg, sasize);
1843 if ((error = copyout(skp, sup, sasize)) != 0)
1846 switch (st->s_cmd = sc.cmd) {
1847 case SVR4_TI_CONNECT_REQUEST: /* connect */
1849 struct connect_args co;
1851 SCARG(&co, s) = SCARG(uap, fd);
1852 SCARG(&co, name) = (void *) sup;
1853 SCARG(&co, namelen) = (int) sasize;
1855 return connect(p, &co);
1858 case SVR4_TI_SENDTO_REQUEST: /* sendto */
1863 msg.msg_name = (caddr_t) sup;
1864 msg.msg_namelen = sasize;
1865 msg.msg_iov = &aiov;
1867 msg.msg_control = 0;
1869 aiov.iov_base = dat.buf;
1870 aiov.iov_len = dat.len;
1872 error = so->so_proto->pr_usrreqs->pru_sosend(so, 0,
1873 uio, 0, 0, 0, uio->uio_procp);
1875 error = svr4_sendit(p, SCARG(uap, fd), &msg,
1877 DPRINTF(("sendto_request error: %d\n", error));
1883 DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd));
1889 svr4_sys_getmsg(p, uap)
1890 register struct proc *p;
1891 struct svr4_sys_getmsg_args *uap;
1893 struct filedesc *fdp = p->p_fd;
1895 struct getpeername_args ga;
1896 struct accept_args aa;
1897 struct svr4_strbuf dat, ctl;
1898 struct svr4_strmcmd sc;
1902 struct sockaddr_in sain;
1903 struct sockaddr_un saun;
1906 struct svr4_strm *st;
1911 retval = p->p_retval;
1912 fp = fdp->fd_ofiles[SCARG(uap, fd)];
1914 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL))
1917 memset(&sc, 0, sizeof(sc));
1920 show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl),
1921 SCARG(uap, dat), 0);
1922 #endif /* DEBUG_SVR4 */
1924 if (((u_int)SCARG(uap, fd) >= fdp->fd_nfiles) || (fp == NULL))
1927 if (SCARG(uap, ctl) != NULL) {
1928 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0)
1936 if (SCARG(uap, dat) != NULL) {
1937 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0)
1946 * Only for sockets for now.
1948 if ((st = svr4_stream_get(fp)) == NULL) {
1949 DPRINTF(("getmsg: bad file type\n"));
1953 if (ctl.maxlen == -1 || dat.maxlen == -1) {
1954 DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n"));
1958 switch (st->s_family) {
1961 sasize = sizeof(sain);
1966 sasize = sizeof(saun);
1970 DPRINTF(("getmsg: Unsupported address family %d\n",
1975 sg = stackgap_init();
1976 sup = stackgap_alloc(&sg, sasize);
1977 flen = (int *) stackgap_alloc(&sg, sizeof(*flen));
1980 if ((error = copyout(&fl, flen, sizeof(fl))) != 0)
1983 switch (st->s_cmd) {
1984 case SVR4_TI_CONNECT_REQUEST:
1985 DPRINTF(("getmsg: TI_CONNECT_REQUEST\n"));
1987 * We do the connect in one step, so the putmsg should
1988 * have gotten the error.
1990 sc.cmd = SVR4_TI_OK_REPLY;
1999 case SVR4_TI_OK_REPLY:
2000 DPRINTF(("getmsg: TI_OK_REPLY\n"));
2002 * We are immediately after a connect reply, so we send
2003 * a connect verification.
2006 SCARG(&ga, fdes) = SCARG(uap, fd);
2007 SCARG(&ga, asa) = (void *) sup;
2008 SCARG(&ga, alen) = flen;
2010 if ((error = getpeername(p, &ga)) != 0) {
2011 DPRINTF(("getmsg: getpeername failed %d\n", error));
2015 if ((error = copyin(sup, skp, sasize)) != 0)
2018 sc.cmd = SVR4_TI_CONNECT_REPLY;
2022 sc.pad[2] = 0x04000402;
2024 switch (st->s_family) {
2027 sockaddr_to_netaddr_in(&sc, &sain);
2031 sc.len = sasize + 4;
2032 sockaddr_to_netaddr_un(&sc, &saun);
2045 case SVR4_TI__ACCEPT_OK:
2046 DPRINTF(("getmsg: TI__ACCEPT_OK\n"));
2048 * We do the connect in one step, so the putmsg should
2049 * have gotten the error.
2051 sc.cmd = SVR4_TI_OK_REPLY;
2057 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
2060 case SVR4_TI__ACCEPT_WAIT:
2061 DPRINTF(("getmsg: TI__ACCEPT_WAIT\n"));
2063 * We are after a listen, so we try to accept...
2065 SCARG(&aa, s) = SCARG(uap, fd);
2066 SCARG(&aa, name) = (void *) sup;
2067 SCARG(&aa, anamelen) = flen;
2069 if ((error = accept(p, &aa)) != 0) {
2070 DPRINTF(("getmsg: accept failed %d\n", error));
2074 st->s_afd = *retval;
2076 DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd));
2078 if ((error = copyin(sup, skp, sasize)) != 0)
2081 sc.cmd = SVR4_TI_ACCEPT_REPLY;
2085 switch (st->s_family) {
2088 sockaddr_to_netaddr_in(&sc, &sain);
2094 sc.pad[1] = 0x00010000;
2095 sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */
2096 sc.pad[3] = 0x00010000;
2098 sc.len = sasize + 4;
2107 st->s_cmd = SVR4_TI__ACCEPT_OK;
2110 case SVR4_TI_SENDTO_REQUEST:
2111 DPRINTF(("getmsg: TI_SENDTO_REQUEST\n"));
2112 if (ctl.maxlen > 36 && ctl.len < 36)
2115 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
2118 switch (st->s_family) {
2120 sockaddr_to_netaddr_in(&sc, &sain);
2124 sockaddr_to_netaddr_un(&sc, &saun);
2131 msg.msg_name = (caddr_t) sup;
2132 msg.msg_namelen = sasize;
2133 msg.msg_iov = &aiov;
2135 msg.msg_control = 0;
2136 aiov.iov_base = dat.buf;
2137 aiov.iov_len = dat.maxlen;
2140 error = svr4_recvit(p, SCARG(uap, fd), &msg, (caddr_t) flen);
2143 DPRINTF(("getmsg: recvit failed %d\n", error));
2147 if ((error = copyin(msg.msg_name, skp, sasize)) != 0)
2150 sc.cmd = SVR4_TI_RECVFROM_IND;
2152 switch (st->s_family) {
2155 sockaddr_to_netaddr_in(&sc, &sain);
2159 sc.len = sasize + 4;
2160 sockaddr_to_netaddr_un(&sc, &saun);
2174 if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) {
2175 struct read_args ra;
2177 /* More wierdness: Again, I can't find documentation
2178 * to back this up, but when a process does a generic
2179 * "getmsg()" call it seems that the command field is
2180 * zero and the length of the data area is zero. I
2181 * think processes expect getmsg() to fill in dat.len
2182 * after reading at most dat.maxlen octets from the
2183 * stream. Since we're using sockets I can let
2184 * read() look after it and frob return values
2185 * appropriately (or inappropriately :-)
2186 * -- newton@atdot.dotat.org XXX
2188 SCARG(&ra, fd) = SCARG(uap, fd);
2189 SCARG(&ra, buf) = dat.buf;
2190 SCARG(&ra, nbyte) = dat.maxlen;
2191 if ((error = read(p, &ra)) != 0) {
2196 st->s_cmd = SVR4_TI_SENDTO_REQUEST;
2199 DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd));
2203 if (SCARG(uap, ctl)) {
2205 if ((error = copyout(&sc, ctl.buf, ctl.len)) != 0)
2208 if ((error = copyout(&ctl, SCARG(uap, ctl), sizeof(ctl))) != 0)
2212 if (SCARG(uap, dat)) {
2213 if ((error = copyout(&dat, SCARG(uap, dat), sizeof(dat))) != 0)
2217 if (SCARG(uap, flags)) { /* XXX: Need translation */
2218 if ((error = copyout(&fl, SCARG(uap, flags), sizeof(fl))) != 0)
2225 show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl),
2226 SCARG(uap, dat), fl);
2227 #endif /* DEBUG_SVR4 */
2231 int svr4_sys_send(p, uap)
2233 struct svr4_sys_send_args *uap;
2235 struct osend_args osa;
2236 SCARG(&osa, s) = SCARG(uap, s);
2237 SCARG(&osa, buf) = SCARG(uap, buf);
2238 SCARG(&osa, len) = SCARG(uap, len);
2239 SCARG(&osa, flags) = SCARG(uap, flags);
2240 return osend(p, &osa);
2243 int svr4_sys_recv(p, uap)
2245 struct svr4_sys_recv_args *uap;
2247 struct orecv_args ora;
2248 SCARG(&ora, s) = SCARG(uap, s);
2249 SCARG(&ora, buf) = SCARG(uap, buf);
2250 SCARG(&ora, len) = SCARG(uap, len);
2251 SCARG(&ora, flags) = SCARG(uap, flags);
2252 return orecv(p, &ora);
2256 * XXX This isn't necessary, but it's handy for inserting debug code into
2257 * sendto(). Let's leave it here for now...
2260 svr4_sys_sendto(p, uap)
2262 struct svr4_sys_sendto_args *uap;
2264 struct sendto_args sa;
2266 SCARG(&sa, s) = SCARG(uap, s);
2267 SCARG(&sa, buf) = SCARG(uap, buf);
2268 SCARG(&sa, len) = SCARG(uap, len);
2269 SCARG(&sa, flags) = SCARG(uap, flags);
2270 SCARG(&sa, to) = SCARG(uap, to);
2271 SCARG(&sa, tolen) = SCARG(uap, tolen);
2273 DPRINTF(("calling sendto()\n"));
2274 return sendto(p, &sa);