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.
34 * Pretend that we have streams...
37 * ToDo: The state machine for getmsg needs re-thinking
42 #include <sys/param.h>
43 #include <sys/kernel.h>
44 #include <sys/systm.h>
46 #include <sys/malloc.h>
49 #include <sys/filedesc.h>
50 #include <sys/unistd.h>
51 #include <sys/fcntl.h>
52 #include <sys/filio.h>
53 #include <sys/select.h>
54 #include <sys/socket.h>
55 #include <sys/socketvar.h>
58 #include <netinet/in.h>
59 #include <sys/mount.h>
61 #include <sys/protosw.h>
62 #include <sys/signal.h>
63 #include <sys/signalvar.h>
65 #include <sys/ktrace.h>
67 #include <sys/vnode.h>
70 #include <sys/sysproto.h>
72 #include <svr4/svr4.h>
73 #include <svr4/svr4_types.h>
74 #include <svr4/svr4_util.h>
75 #include <svr4/svr4_signal.h>
76 #include <svr4/svr4_proto.h>
77 #include <svr4/svr4_stropts.h>
78 #include <svr4/svr4_timod.h>
79 #include <svr4/svr4_sockmod.h>
80 #include <svr4/svr4_ioctl.h>
81 #include <svr4/svr4_socket.h>
84 static int clean_pipe __P((struct proc *, const char *));
85 static void getparm __P((struct file *, struct svr4_si_sockparms *));
87 /* Address Conversions */
88 static void sockaddr_to_netaddr_in __P((struct svr4_strmcmd *,
89 const struct sockaddr_in *));
90 static void sockaddr_to_netaddr_un __P((struct svr4_strmcmd *,
91 const struct sockaddr_un *));
92 static void netaddr_to_sockaddr_in __P((struct sockaddr_in *,
93 const struct svr4_strmcmd *));
94 static void netaddr_to_sockaddr_un __P((struct sockaddr_un *,
95 const struct svr4_strmcmd *));
98 static int i_nread __P((struct file *, struct proc *, register_t *, int,
100 static int i_fdinsert __P((struct file *, struct proc *, register_t *, int,
102 static int i_str __P((struct file *, struct proc *, register_t *, int,
104 static int i_setsig __P((struct file *, struct proc *, register_t *, int,
106 static int i_getsig __P((struct file *, struct proc *, register_t *, int,
108 static int _i_bind_rsvd __P((struct file *, struct proc *, register_t *, int,
110 static int _i_rele_rsvd __P((struct file *, struct proc *, register_t *, int,
113 /* i_str sockmod calls */
114 static int sockmod __P((struct file *, int, struct svr4_strioctl *,
116 static int si_listen __P((struct file *, int, struct svr4_strioctl *,
118 static int si_ogetudata __P((struct file *, int, struct svr4_strioctl *,
120 static int si_sockparams __P((struct file *, int, struct svr4_strioctl *,
122 static int si_shutdown __P((struct file *, int, struct svr4_strioctl *,
124 static int si_getudata __P((struct file *, int, struct svr4_strioctl *,
127 /* i_str timod calls */
128 static int timod __P((struct file *, int, struct svr4_strioctl *,
130 static int ti_getinfo __P((struct file *, int, struct svr4_strioctl *,
132 static int ti_bind __P((struct file *, int, struct svr4_strioctl *,
136 static int svr4_sendit __P((struct proc *p, int s, struct msghdr *mp,
139 static int svr4_recvit __P((struct proc *p, int s, struct msghdr *mp,
142 /* <sigh> Ok, so we shouldn't use sendit() in uipc_syscalls.c because
143 * it isn't part of a "public" interface; We're supposed to use
144 * pru_sosend instead. Same goes for recvit()/pru_soreceive() for
145 * that matter. Solution: Suck sendit()/recvit() into here where we
146 * can do what we like.
148 * I hate code duplication.
150 * I will take out all the #ifdef COMPAT_OLDSOCK gumph, though.
153 svr4_sendit(p, s, mp, flags)
154 register struct proc *p;
156 register struct msghdr *mp;
161 register struct iovec *iov;
163 struct mbuf *control;
168 struct iovec *ktriov = NULL;
171 error = getsock(p->p_fd, s, &fp);
174 auio.uio_iov = mp->msg_iov;
175 auio.uio_iovcnt = mp->msg_iovlen;
176 auio.uio_segflg = UIO_USERSPACE;
177 auio.uio_rw = UIO_WRITE;
179 auio.uio_offset = 0; /* XXX */
182 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
183 if ((auio.uio_resid += iov->iov_len) < 0)
187 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);
204 if (KTRPOINT(p, KTR_GENIO)) {
205 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
207 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
208 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
211 len = auio.uio_resid;
212 so = (struct socket *)fp->f_data;
213 error = so->so_proto->pr_usrreqs->pru_sosend(so, to, &auio, 0, control,
216 if (auio.uio_resid != len && (error == ERESTART ||
217 error == EINTR || error == EWOULDBLOCK))
223 p->p_retval[0] = len - auio.uio_resid;
225 if (ktriov != NULL) {
227 ktrgenio(p->p_tracep, s, UIO_WRITE,
228 ktriov, p->p_retval[0], error);
229 FREE(ktriov, M_TEMP);
239 svr4_recvit(p, s, mp, namelenp)
240 register struct proc *p;
242 register struct msghdr *mp;
247 register struct iovec *iov;
250 struct mbuf *m, *control = 0;
253 struct sockaddr *fromsa = 0;
255 struct iovec *ktriov = NULL;
258 error = getsock(p->p_fd, s, &fp);
261 auio.uio_iov = mp->msg_iov;
262 auio.uio_iovcnt = mp->msg_iovlen;
263 auio.uio_segflg = UIO_USERSPACE;
264 auio.uio_rw = UIO_READ;
266 auio.uio_offset = 0; /* XXX */
269 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
270 if ((auio.uio_resid += iov->iov_len) < 0)
274 if (KTRPOINT(p, KTR_GENIO)) {
275 int iovlen = auio.uio_iovcnt * sizeof (struct iovec);
277 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
278 bcopy((caddr_t)auio.uio_iov, (caddr_t)ktriov, iovlen);
281 len = auio.uio_resid;
282 so = (struct socket *)fp->f_data;
283 error = so->so_proto->pr_usrreqs->pru_soreceive(so, &fromsa, &auio,
284 (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0,
287 if (auio.uio_resid != len && (error == ERESTART ||
288 error == EINTR || error == EWOULDBLOCK))
292 if (ktriov != NULL) {
294 ktrgenio(p->p_tracep, s, UIO_READ,
295 ktriov, len - auio.uio_resid, error);
296 FREE(ktriov, M_TEMP);
301 p->p_retval[0] = len - auio.uio_resid;
303 len = mp->msg_namelen;
304 if (len <= 0 || fromsa == 0)
308 #define MIN(a,b) ((a)>(b)?(b):(a))
310 /* save sa_len before it is destroyed by MSG_COMPAT */
311 len = MIN(len, fromsa->sa_len);
312 error = copyout(fromsa,
313 (caddr_t)mp->msg_name, (unsigned)len);
317 mp->msg_namelen = len;
319 (error = copyout((caddr_t)&len, namelenp, sizeof (int)))) {
323 if (mp->msg_control) {
324 len = mp->msg_controllen;
326 mp->msg_controllen = 0;
327 ctlbuf = (caddr_t) mp->msg_control;
329 while (m && len > 0) {
335 mp->msg_flags |= MSG_CTRUNC;
339 if ((error = copyout((caddr_t)mtod(m, caddr_t),
340 ctlbuf, tocopy)) != 0)
347 mp->msg_controllen = ctlbuf - mp->msg_control;
351 FREE(fromsa, M_SONAME);
358 static void bufprint __P((u_char *, size_t));
359 static int show_ioc __P((const char *, struct svr4_strioctl *));
360 static int show_strbuf __P((struct svr4_strbuf *));
361 static void show_msg __P((const char *, int, struct svr4_strbuf *,
362 struct svr4_strbuf *, int));
372 for (i = 0; i < len; i++) {
373 uprintf("%x ", buf[i]);
374 if (i && (i % 16) == 0)
382 struct svr4_strioctl *ioc;
384 u_char *ptr = (u_char *) malloc(ioc->len, M_TEMP, M_WAITOK);
387 uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ",
388 str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf);
390 if ((error = copyin(ioc->buf, ptr, ioc->len)) != 0) {
391 free((char *) ptr, M_TEMP);
395 bufprint(ptr, ioc->len);
399 free((char *) ptr, M_TEMP);
406 struct svr4_strbuf *str;
410 int maxlen = str->maxlen;
420 ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK);
422 if ((error = copyin(str->buf, ptr, len)) != 0) {
423 free((char *) ptr, M_TEMP);
428 uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf);
436 free((char *) ptr, M_TEMP);
443 show_msg(str, fd, ctl, dat, flags)
446 struct svr4_strbuf *ctl;
447 struct svr4_strbuf *dat;
450 struct svr4_strbuf buf;
453 uprintf("%s(%d", str, fd);
455 if ((error = copyin(ctl, &buf, sizeof(buf))) != 0)
463 if ((error = copyin(dat, &buf, sizeof(buf))) != 0)
470 uprintf(", %x);\n", flags);
473 #endif /* DEBUG_SVR4 */
476 * We are faced with an interesting situation. On svr4 unix sockets
477 * are really pipes. But we really have sockets, and we might as
478 * well use them. At the point where svr4 calls TI_BIND, it has
479 * already created a named pipe for the socket using mknod(2).
480 * We need to create a socket with the same name when we bind,
481 * so we need to remove the pipe before, otherwise we'll get address
482 * already in use. So we *carefully* remove the pipe, to avoid
483 * using this as a random file removal tool. We use system calls
484 * to avoid code duplication.
491 struct lstat_args la;
492 struct unlink_args ua;
495 caddr_t sg = stackgap_init();
496 size_t l = strlen(path) + 1;
499 tpath = stackgap_alloc(&sg, l);
500 SCARG(&la, ub) = stackgap_alloc(&sg, sizeof(struct stat));
502 if ((error = copyout(path, tpath, l)) != 0)
505 SCARG(&la, path) = tpath;
507 if ((error = lstat(p, &la)) != 0)
510 if ((error = copyin(SCARG(&la, ub), &st, sizeof(st))) != 0)
514 * Make sure we are dealing with a mode 0 named pipe.
516 if ((st.st_mode & S_IFMT) != S_IFIFO)
519 if ((st.st_mode & ALLPERMS) != 0)
522 SCARG(&ua, path) = SCARG(&la, path);
524 if ((error = unlink(p, &ua)) != 0) {
525 DPRINTF(("clean_pipe: unlink failed %d\n", error));
534 sockaddr_to_netaddr_in(sc, sain)
535 struct svr4_strmcmd *sc;
536 const struct sockaddr_in *sain;
538 struct svr4_netaddr_in *na;
539 na = SVR4_ADDROF(sc);
541 na->family = sain->sin_family;
542 na->port = sain->sin_port;
543 na->addr = sain->sin_addr.s_addr;
544 DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port,
550 sockaddr_to_netaddr_un(sc, saun)
551 struct svr4_strmcmd *sc;
552 const struct sockaddr_un *saun;
554 struct svr4_netaddr_un *na;
555 char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 -
559 na = SVR4_ADDROF(sc);
560 na->family = saun->sun_family;
561 for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; )
564 DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path));
569 netaddr_to_sockaddr_in(sain, sc)
570 struct sockaddr_in *sain;
571 const struct svr4_strmcmd *sc;
573 const struct svr4_netaddr_in *na;
576 na = SVR4_C_ADDROF(sc);
577 memset(sain, 0, sizeof(*sain));
578 sain->sin_len = sizeof(*sain);
579 sain->sin_family = na->family;
580 sain->sin_port = na->port;
581 sain->sin_addr.s_addr = na->addr;
582 DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family,
583 sain->sin_port, sain->sin_addr.s_addr));
588 netaddr_to_sockaddr_un(saun, sc)
589 struct sockaddr_un *saun;
590 const struct svr4_strmcmd *sc;
592 const struct svr4_netaddr_un *na;
593 char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1];
596 na = SVR4_C_ADDROF(sc);
597 memset(saun, 0, sizeof(*saun));
598 saun->sun_family = na->family;
599 for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; )
602 saun->sun_len = dst - saun->sun_path;
603 DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family,
611 struct svr4_si_sockparms *pa;
613 struct svr4_strm *st = svr4_stream_get(fp);
614 struct socket *so = (struct socket *) fp->f_data;
619 pa->family = st->s_family;
621 switch (so->so_type) {
623 pa->type = SVR4_T_CLTS;
624 pa->protocol = IPPROTO_UDP;
625 DPRINTF(("getparm(dgram)\n"));
629 pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */
630 pa->protocol = IPPROTO_IP;
631 DPRINTF(("getparm(stream)\n"));
635 pa->type = SVR4_T_CLTS;
636 pa->protocol = IPPROTO_RAW;
637 DPRINTF(("getparm(raw)\n"));
643 DPRINTF(("getparm(type %d?)\n", so->so_type));
650 si_ogetudata(fp, fd, ioc, p)
653 struct svr4_strioctl *ioc;
657 struct svr4_si_oudata ud;
658 struct svr4_si_sockparms pa;
660 if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) {
661 DPRINTF(("SI_OGETUDATA: Wrong size %d != %d\n",
662 sizeof(ud), ioc->len));
666 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
674 ud.addrsize = sizeof(struct svr4_sockaddr_in);
675 if (pa.type == SVR4_SOCK_STREAM)
688 DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n",
693 /* I have no idea what these should be! */
697 ud.servtype = pa.type;
702 return copyout(&ud, ioc->buf, ioc->len);
707 si_sockparams(fp, fd, ioc, p)
710 struct svr4_strioctl *ioc;
713 struct svr4_si_sockparms pa;
716 return copyout(&pa, ioc->buf, sizeof(pa));
721 si_listen(fp, fd, ioc, p)
724 struct svr4_strioctl *ioc;
728 struct svr4_strm *st = svr4_stream_get(fp);
729 struct svr4_strmcmd lst;
730 struct listen_args la;
735 if ((error = copyin(ioc->buf, &lst, ioc->len)) != 0)
738 if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) {
739 DPRINTF(("si_listen: bad request %ld\n", lst.cmd));
744 * We are making assumptions again...
747 DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5));
748 SCARG(&la, backlog) = 5;
750 if ((error = listen(p, &la)) != 0) {
751 DPRINTF(("SI_LISTEN: listen failed %d\n", error));
755 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
756 lst.cmd = SVR4_TI_BIND_REPLY;
758 switch (st->s_family) {
760 /* XXX: Fill the length here */
765 lst.pad[28] = 0x00000000; /* magic again */
766 lst.pad[29] = 0x00000800; /* magic again */
767 lst.pad[30] = 0x80001400; /* magic again */
771 DPRINTF(("SI_LISTEN: Unsupported address family %d\n",
777 if ((error = copyout(&lst, ioc->buf, ioc->len)) != 0)
785 si_getudata(fp, fd, ioc, p)
788 struct svr4_strioctl *ioc;
792 struct svr4_si_udata ud;
794 if (sizeof(ud) != ioc->len) {
795 DPRINTF(("SI_GETUDATA: Wrong size %d != %d\n",
796 sizeof(ud), ioc->len));
800 if ((error = copyin(ioc->buf, &ud, sizeof(ud))) != 0)
803 getparm(fp, &ud.sockparms);
805 switch (ud.sockparms.family) {
807 DPRINTF(("getudata_inet\n"));
810 ud.addrsize = sizeof(struct svr4_sockaddr_in);
811 if (ud.sockparms.type == SVR4_SOCK_STREAM)
819 DPRINTF(("getudata_local\n"));
828 DPRINTF(("SI_GETUDATA: Unsupported address family %d\n",
829 ud.sockparms.family));
834 ud.servtype = ud.sockparms.type;
835 DPRINTF(("ud.servtype = %d\n", ud.servtype));
839 return copyout(&ud, ioc->buf, sizeof(ud));
844 si_shutdown(fp, fd, ioc, p)
847 struct svr4_strioctl *ioc;
851 struct shutdown_args ap;
853 if (ioc->len != sizeof(SCARG(&ap, how))) {
854 DPRINTF(("SI_SHUTDOWN: Wrong size %d != %d\n",
855 sizeof(SCARG(&ap, how)), ioc->len));
859 if ((error = copyin(ioc->buf, &SCARG(&ap, how), ioc->len)) != 0)
864 return shutdown(p, &ap);
869 sockmod(fp, fd, ioc, p)
872 struct svr4_strioctl *ioc;
876 case SVR4_SI_OGETUDATA:
877 DPRINTF(("SI_OGETUDATA\n"));
878 return si_ogetudata(fp, fd, ioc, p);
880 case SVR4_SI_SHUTDOWN:
881 DPRINTF(("SI_SHUTDOWN\n"));
882 return si_shutdown(fp, fd, ioc, p);
885 DPRINTF(("SI_LISTEN\n"));
886 return si_listen(fp, fd, ioc, p);
888 case SVR4_SI_SETMYNAME:
889 DPRINTF(("SI_SETMYNAME\n"));
892 case SVR4_SI_SETPEERNAME:
893 DPRINTF(("SI_SETPEERNAME\n"));
896 case SVR4_SI_GETINTRANSIT:
897 DPRINTF(("SI_GETINTRANSIT\n"));
900 case SVR4_SI_TCL_LINK:
901 DPRINTF(("SI_TCL_LINK\n"));
904 case SVR4_SI_TCL_UNLINK:
905 DPRINTF(("SI_TCL_UNLINK\n"));
908 case SVR4_SI_SOCKPARAMS:
909 DPRINTF(("SI_SOCKPARAMS\n"));
910 return si_sockparams(fp, fd, ioc, p);
912 case SVR4_SI_GETUDATA:
913 DPRINTF(("SI_GETUDATA\n"));
914 return si_getudata(fp, fd, ioc, p);
917 DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd));
925 ti_getinfo(fp, fd, ioc, p)
928 struct svr4_strioctl *ioc;
932 struct svr4_infocmd info;
934 memset(&info, 0, sizeof(info));
936 if ((error = copyin(ioc->buf, &info, ioc->len)) != 0)
939 if (info.cmd != SVR4_TI_INFO_REQUEST)
942 info.cmd = SVR4_TI_INFO_REPLY;
954 ioc->len = sizeof(info);
955 if ((error = copyout(&info, ioc->buf, ioc->len)) != 0)
963 ti_bind(fp, fd, ioc, p)
966 struct svr4_strioctl *ioc;
970 struct svr4_strm *st = svr4_stream_get(fp);
971 struct sockaddr_in sain;
972 struct sockaddr_un saun;
974 void *skp, *sup = NULL;
976 struct svr4_strmcmd bnd;
980 DPRINTF(("ti_bind: bad file descriptor\n"));
984 if ((error = copyin(ioc->buf, &bnd, ioc->len)) != 0)
987 if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) {
988 DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd));
992 switch (st->s_family) {
995 sasize = sizeof(sain);
1000 netaddr_to_sockaddr_in(&sain, &bnd);
1002 DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n",
1003 sain.sin_family, sain.sin_port,
1004 sain.sin_addr.s_addr));
1009 sasize = sizeof(saun);
1013 netaddr_to_sockaddr_un(&saun, &bnd);
1015 if (saun.sun_path[0] == '\0')
1018 DPRINTF(("TI_BIND: fam %d, path %s\n",
1019 saun.sun_family, saun.sun_path));
1021 if ((error = clean_pipe(p, saun.sun_path)) != 0)
1024 bnd.pad[28] = 0x00001000; /* magic again */
1028 DPRINTF(("TI_BIND: Unsupported address family %d\n",
1033 sg = stackgap_init();
1034 sup = stackgap_alloc(&sg, sasize);
1036 if ((error = copyout(skp, sup, sasize)) != 0)
1040 DPRINTF(("TI_BIND: fileno %d\n", fd));
1041 SCARG(&ba, name) = (void *) sup;
1042 SCARG(&ba, namelen) = sasize;
1044 if ((error = bind(p, &ba)) != 0) {
1045 DPRINTF(("TI_BIND: bind failed %d\n", error));
1051 memset(&bnd, 0, sizeof(bnd));
1052 bnd.len = sasize + 4;
1053 bnd.offs = 0x10; /* XXX */
1056 bnd.cmd = SVR4_TI_BIND_REPLY;
1058 if ((error = copyout(&bnd, ioc->buf, ioc->len)) != 0)
1066 timod(fp, fd, ioc, p)
1069 struct svr4_strioctl *ioc;
1073 case SVR4_TI_GETINFO:
1074 DPRINTF(("TI_GETINFO\n"));
1075 return ti_getinfo(fp, fd, ioc, p);
1077 case SVR4_TI_OPTMGMT:
1078 DPRINTF(("TI_OPTMGMT\n"));
1082 DPRINTF(("TI_BIND\n"));
1083 return ti_bind(fp, fd, ioc, p);
1085 case SVR4_TI_UNBIND:
1086 DPRINTF(("TI_UNBIND\n"));
1090 DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd));
1097 svr4_stream_ti_ioctl(fp, p, retval, fd, cmd, dat)
1105 struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat;
1106 struct svr4_strm *st = svr4_stream_get(fp);
1109 struct sockaddr_in sain;
1110 struct sockaddr_un saun;
1111 struct svr4_strmcmd sc;
1116 DPRINTF(("svr4_stream_ti_ioctl\n"));
1123 if ((error = copyin(sub, &skb, sizeof(skb))) != 0) {
1124 DPRINTF(("ti_ioctl: error copying in strbuf\n"));
1128 switch (st->s_family) {
1131 sasize = sizeof(sain);
1136 sasize = sizeof(saun);
1140 DPRINTF(("ti_ioctl: Unsupported address family %d\n",
1145 sg = stackgap_init();
1146 sup = stackgap_alloc(&sg, sasize);
1147 lenp = stackgap_alloc(&sg, sizeof(*lenp));
1149 if ((error = copyout(&sasize, lenp, sizeof(*lenp))) != 0) {
1150 DPRINTF(("ti_ioctl: error copying out lenp\n"));
1155 case SVR4_TI_GETMYNAME:
1156 DPRINTF(("TI_GETMYNAME\n"));
1158 struct getsockname_args ap;
1159 SCARG(&ap, fdes) = fd;
1160 SCARG(&ap, asa) = sup;
1161 SCARG(&ap, alen) = lenp;
1162 if ((error = getsockname(p, &ap)) != 0) {
1163 DPRINTF(("ti_ioctl: getsockname error\n"));
1169 case SVR4_TI_GETPEERNAME:
1170 DPRINTF(("TI_GETPEERNAME\n"));
1172 struct getpeername_args ap;
1173 SCARG(&ap, fdes) = fd;
1174 SCARG(&ap, asa) = sup;
1175 SCARG(&ap, alen) = lenp;
1176 if ((error = getpeername(p, &ap)) != 0) {
1177 DPRINTF(("ti_ioctl: getpeername error\n"));
1183 case SVR4_TI_SETMYNAME:
1184 DPRINTF(("TI_SETMYNAME\n"));
1187 case SVR4_TI_SETPEERNAME:
1188 DPRINTF(("TI_SETPEERNAME\n"));
1191 DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd));
1195 if ((error = copyin(sup, skp, sasize)) != 0) {
1196 DPRINTF(("ti_ioctl: error copying in socket data\n"));
1200 if ((error = copyin(lenp, &sasize, sizeof(*lenp))) != 0) {
1201 DPRINTF(("ti_ioctl: error copying in socket size\n"));
1205 switch (st->s_family) {
1207 sockaddr_to_netaddr_in(&sc, &sain);
1212 sockaddr_to_netaddr_un(&sc, &saun);
1213 skb.len = sasize + 4;
1221 if ((error = copyout(SVR4_ADDROF(&sc), skb.buf, sasize)) != 0) {
1222 DPRINTF(("ti_ioctl: error copying out socket data\n"));
1227 if ((error = copyout(&skb, sub, sizeof(skb))) != 0) {
1228 DPRINTF(("ti_ioctl: error copying out strbuf\n"));
1239 i_nread(fp, p, retval, fd, cmd, dat)
1251 * We are supposed to return the message length in nread, and the
1252 * number of messages in retval. We don't have the notion of number
1253 * of stream messages, so we just find out if we have any bytes waiting
1254 * for us, and if we do, then we assume that we have at least one
1255 * message waiting for us.
1257 if ((error = fo_ioctl(fp, FIONREAD, (caddr_t) &nread, p)) != 0)
1265 return copyout(&nread, dat, sizeof(nread));
1269 i_fdinsert(fp, p, retval, fd, cmd, dat)
1278 * Major hack again here. We assume that we are using this to
1279 * implement accept(2). If that is the case, we have already
1280 * called accept, and we have stored the file descriptor in
1281 * afd. We find the file descriptor that the code wants to use
1282 * in fd insert, and then we dup2() our accepted file descriptor
1286 struct svr4_strm *st = svr4_stream_get(fp);
1287 struct svr4_strfdinsert fdi;
1288 struct dup2_args d2p;
1289 struct close_args clp;
1292 DPRINTF(("fdinsert: bad file type\n"));
1296 if (st->s_afd == -1) {
1297 DPRINTF(("fdinsert: accept fd not found\n"));
1301 if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) {
1302 DPRINTF(("fdinsert: copyin failed %d\n", error));
1306 SCARG(&d2p, from) = st->s_afd;
1307 SCARG(&d2p, to) = fdi.fd;
1309 if ((error = dup2(p, &d2p)) != 0) {
1310 DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n",
1311 st->s_afd, fdi.fd, error));
1315 SCARG(&clp, fd) = st->s_afd;
1317 if ((error = close(p, &clp)) != 0) {
1318 DPRINTF(("fdinsert: close(%d) failed %d\n",
1331 _i_bind_rsvd(fp, p, retval, fd, cmd, dat)
1339 struct mkfifo_args ap;
1342 * This is a supposed to be a kernel and library only ioctl.
1343 * It gets called before ti_bind, when we have a unix
1344 * socket, to physically create the socket transport and
1345 * ``reserve'' it. I don't know how this get reserved inside
1346 * the kernel, but we are going to create it nevertheless.
1348 SCARG(&ap, path) = dat;
1349 SCARG(&ap, mode) = S_IFIFO;
1351 return mkfifo(p, &ap);
1355 _i_rele_rsvd(fp, p, retval, fd, cmd, dat)
1363 struct unlink_args ap;
1366 * This is a supposed to be a kernel and library only ioctl.
1367 * I guess it is supposed to release the socket.
1369 SCARG(&ap, path) = dat;
1371 return unlink(p, &ap);
1375 i_str(fp, p, retval, fd, cmd, dat)
1384 struct svr4_strioctl ioc;
1386 if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0)
1390 if ((error = show_ioc(">", &ioc)) != 0)
1392 #endif /* DEBUG_SVR4 */
1394 switch (ioc.cmd & 0xff00) {
1396 if ((error = sockmod(fp, fd, &ioc, p)) != 0)
1401 if ((error = timod(fp, fd, &ioc, p)) != 0)
1406 DPRINTF(("Unimplemented module %c %ld\n",
1407 (char) (cmd >> 8), cmd & 0xff));
1412 if ((error = show_ioc("<", &ioc)) != 0)
1414 #endif /* DEBUG_SVR4 */
1415 return copyout(&ioc, dat, sizeof(ioc));
1419 i_setsig(fp, p, retval, fd, cmd, dat)
1428 * This is the best we can do for now; we cannot generate
1429 * signals only for specific events so the signal mask gets
1430 * ignored; we save it just to pass it to a possible I_GETSIG...
1432 * We alse have to fix the O_ASYNC fcntl bit, so the
1433 * process will get SIGPOLLs.
1435 struct fcntl_args fa;
1437 register_t oflags, flags;
1438 struct svr4_strm *st = svr4_stream_get(fp);
1441 DPRINTF(("i_setsig: bad file descriptor\n"));
1444 /* get old status flags */
1445 SCARG(&fa, fd) = fd;
1446 SCARG(&fa, cmd) = F_GETFL;
1447 if ((error = fcntl(p, &fa)) != 0)
1450 oflags = p->p_retval[0];
1452 /* update the flags */
1456 flags = oflags | O_ASYNC;
1457 if ((error = copyin(dat, &mask, sizeof(mask))) != 0) {
1458 DPRINTF(("i_setsig: bad eventmask pointer\n"));
1461 if (mask & SVR4_S_ALLMASK) {
1462 DPRINTF(("i_setsig: bad eventmask data %x\n", mask));
1465 st->s_eventmask = mask;
1468 flags = oflags & ~O_ASYNC;
1469 st->s_eventmask = 0;
1472 /* set the new flags, if changed */
1473 if (flags != oflags) {
1474 SCARG(&fa, cmd) = F_SETFL;
1475 SCARG(&fa, arg) = (long) flags;
1476 if ((error = fcntl(p, &fa)) != 0)
1478 flags = p->p_retval[0];
1481 /* set up SIGIO receiver if needed */
1483 SCARG(&fa, cmd) = F_SETOWN;
1484 SCARG(&fa, arg) = (long) p->p_pid;
1485 return fcntl(p, &fa);
1491 i_getsig(fp, p, retval, fd, cmd, dat)
1502 struct svr4_strm *st = svr4_stream_get(fp);
1505 DPRINTF(("i_getsig: bad file descriptor\n"));
1508 if ((error = copyout(&st->s_eventmask, dat,
1509 sizeof(st->s_eventmask))) != 0) {
1510 DPRINTF(("i_getsig: bad eventmask pointer\n"));
1518 svr4_stream_ioctl(fp, p, retval, fd, cmd, dat)
1529 * All the following stuff assumes "sockmod" is pushed...
1533 DPRINTF(("I_NREAD\n"));
1534 return i_nread(fp, p, retval, fd, cmd, dat);
1537 DPRINTF(("I_PUSH %x\n", dat));
1538 #if defined(DEBUG_SVR4)
1544 DPRINTF(("I_POP\n"));
1548 DPRINTF(("I_LOOK\n"));
1552 DPRINTF(("I_FLUSH\n"));
1556 DPRINTF(("I_SRDOPT\n"));
1560 DPRINTF(("I_GRDOPT\n"));
1564 DPRINTF(("I_STR\n"));
1565 return i_str(fp, p, retval, fd, cmd, dat);
1568 DPRINTF(("I_SETSIG\n"));
1569 return i_setsig(fp, p, retval, fd, cmd, dat);
1572 DPRINTF(("I_GETSIG\n"));
1573 return i_getsig(fp, p, retval, fd, cmd, dat);
1576 DPRINTF(("I_FIND\n"));
1578 * Here we are not pushing modules really, we just
1579 * pretend all are present
1585 DPRINTF(("I_LINK\n"));
1589 DPRINTF(("I_UNLINK\n"));
1592 case SVR4_I_ERECVFD:
1593 DPRINTF(("I_ERECVFD\n"));
1597 DPRINTF(("I_PEEK\n"));
1600 case SVR4_I_FDINSERT:
1601 DPRINTF(("I_FDINSERT\n"));
1602 return i_fdinsert(fp, p, retval, fd, cmd, dat);
1605 DPRINTF(("I_SENDFD\n"));
1609 DPRINTF(("I_RECVFD\n"));
1613 DPRINTF(("I_SWROPT\n"));
1617 DPRINTF(("I_GWROPT\n"));
1621 DPRINTF(("I_LIST\n"));
1625 DPRINTF(("I_PLINK\n"));
1628 case SVR4_I_PUNLINK:
1629 DPRINTF(("I_PUNLINK\n"));
1633 DPRINTF(("I_SETEV\n"));
1637 DPRINTF(("I_GETEV\n"));
1641 DPRINTF(("I_STREV\n"));
1644 case SVR4_I_UNSTREV:
1645 DPRINTF(("I_UNSTREV\n"));
1648 case SVR4_I_FLUSHBAND:
1649 DPRINTF(("I_FLUSHBAND\n"));
1653 DPRINTF(("I_CKBAND\n"));
1656 case SVR4_I_GETBAND:
1657 DPRINTF(("I_GETBANK\n"));
1661 DPRINTF(("I_ATMARK\n"));
1664 case SVR4_I_SETCLTIME:
1665 DPRINTF(("I_SETCLTIME\n"));
1668 case SVR4_I_GETCLTIME:
1669 DPRINTF(("I_GETCLTIME\n"));
1673 DPRINTF(("I_CANPUT\n"));
1676 case SVR4__I_BIND_RSVD:
1677 DPRINTF(("_I_BIND_RSVD\n"));
1678 return _i_bind_rsvd(fp, p, retval, fd, cmd, dat);
1680 case SVR4__I_RELE_RSVD:
1681 DPRINTF(("_I_RELE_RSVD\n"));
1682 return _i_rele_rsvd(fp, p, retval, fd, cmd, dat);
1685 DPRINTF(("unimpl cmd = %lx\n", cmd));
1695 svr4_sys_putmsg(p, uap)
1696 register struct proc *p;
1697 struct svr4_sys_putmsg_args *uap;
1699 struct filedesc *fdp = p->p_fd;
1701 struct svr4_strbuf dat, ctl;
1702 struct svr4_strmcmd sc;
1703 struct sockaddr_in sain;
1704 struct sockaddr_un saun;
1706 int sasize, *retval;
1707 struct svr4_strm *st;
1711 retval = p->p_retval;
1712 if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
1713 (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) {
1715 uprintf("putmsg: bad fp\n");
1721 show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl),
1722 SCARG(uap, dat), SCARG(uap, flags));
1723 #endif /* DEBUG_SVR4 */
1725 if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
1726 (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) {
1728 uprintf("putmsg: bad fp(2)\n");
1733 if (SCARG(uap, ctl) != NULL) {
1734 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) {
1736 uprintf("putmsg: copyin(): %d\n", error);
1744 if (SCARG(uap, dat) != NULL) {
1745 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0) {
1747 uprintf("putmsg: copyin(): %d (2)\n", error);
1756 * Only for sockets for now.
1758 if ((st = svr4_stream_get(fp)) == NULL) {
1759 DPRINTF(("putmsg: bad file type\n"));
1763 if (ctl.len > sizeof(sc)) {
1764 DPRINTF(("putmsg: Bad control size %d != %d\n", ctl.len,
1765 sizeof(struct svr4_strmcmd)));
1769 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
1772 switch (st->s_family) {
1774 if (sc.len != sizeof(sain)) {
1775 if (sc.cmd == SVR4_TI_DATA_REQUEST) {
1776 struct write_args wa;
1778 /* Solaris seems to use sc.cmd = 3 to
1779 * send "expedited" data. telnet uses
1780 * this for options processing, sending EOF,
1781 * etc. I'm sure other things use it too.
1782 * I don't have any documentation
1783 * on it, so I'm making a guess that this
1784 * is how it works. newton@atdot.dotat.org XXX
1786 DPRINTF(("sending expedited data ??\n"));
1787 SCARG(&wa, fd) = SCARG(uap, fd);
1788 SCARG(&wa, buf) = dat.buf;
1789 SCARG(&wa, nbyte) = dat.len;
1790 return write(p, &wa);
1792 DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len));
1795 netaddr_to_sockaddr_in(&sain, &sc);
1797 sasize = sizeof(sain);
1798 error = sain.sin_family != st->s_family;
1803 /* We are doing an accept; succeed */
1804 DPRINTF(("putmsg: Do nothing\n"));
1809 /* Maybe we've been given a device/inode pair */
1810 udev_t *dev = SVR4_ADDROF(&sc);
1811 ino_t *ino = (ino_t *) &dev[1];
1812 skp = svr4_find_socket(p, fp, *dev, *ino);
1815 /* I guess we have it by name */
1816 netaddr_to_sockaddr_un(skp, &sc);
1818 sasize = sizeof(saun);
1823 DPRINTF(("putmsg: Unsupported address family %d\n",
1828 sg = stackgap_init();
1829 sup = stackgap_alloc(&sg, sasize);
1831 if ((error = copyout(skp, sup, sasize)) != 0)
1834 switch (st->s_cmd = sc.cmd) {
1835 case SVR4_TI_CONNECT_REQUEST: /* connect */
1837 struct connect_args co;
1839 SCARG(&co, s) = SCARG(uap, fd);
1840 SCARG(&co, name) = (void *) sup;
1841 SCARG(&co, namelen) = (int) sasize;
1843 return connect(p, &co);
1846 case SVR4_TI_SENDTO_REQUEST: /* sendto */
1851 msg.msg_name = (caddr_t) sup;
1852 msg.msg_namelen = sasize;
1853 msg.msg_iov = &aiov;
1855 msg.msg_control = 0;
1857 aiov.iov_base = dat.buf;
1858 aiov.iov_len = dat.len;
1860 error = so->so_proto->pr_usrreqs->pru_sosend(so, 0,
1861 uio, 0, 0, 0, uio->uio_procp);
1863 error = svr4_sendit(p, SCARG(uap, fd), &msg,
1865 DPRINTF(("sendto_request error: %d\n", error));
1871 DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd));
1877 svr4_sys_getmsg(p, uap)
1878 register struct proc *p;
1879 struct svr4_sys_getmsg_args *uap;
1881 struct filedesc *fdp = p->p_fd;
1883 struct getpeername_args ga;
1884 struct accept_args aa;
1885 struct svr4_strbuf dat, ctl;
1886 struct svr4_strmcmd sc;
1890 struct sockaddr_in sain;
1891 struct sockaddr_un saun;
1894 struct svr4_strm *st;
1899 retval = p->p_retval;
1900 if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
1901 (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL)
1904 memset(&sc, 0, sizeof(sc));
1907 show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl),
1908 SCARG(uap, dat), 0);
1909 #endif /* DEBUG_SVR4 */
1911 if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
1912 (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL)
1915 if (SCARG(uap, ctl) != NULL) {
1916 if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0)
1924 if (SCARG(uap, dat) != NULL) {
1925 if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0)
1934 * Only for sockets for now.
1936 if ((st = svr4_stream_get(fp)) == NULL) {
1937 DPRINTF(("getmsg: bad file type\n"));
1941 if (ctl.maxlen == -1 || dat.maxlen == -1) {
1942 DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n"));
1946 switch (st->s_family) {
1949 sasize = sizeof(sain);
1954 sasize = sizeof(saun);
1958 DPRINTF(("getmsg: Unsupported address family %d\n",
1963 sg = stackgap_init();
1964 sup = stackgap_alloc(&sg, sasize);
1965 flen = (int *) stackgap_alloc(&sg, sizeof(*flen));
1968 if ((error = copyout(&fl, flen, sizeof(fl))) != 0)
1971 switch (st->s_cmd) {
1972 case SVR4_TI_CONNECT_REQUEST:
1973 DPRINTF(("getmsg: TI_CONNECT_REQUEST\n"));
1975 * We do the connect in one step, so the putmsg should
1976 * have gotten the error.
1978 sc.cmd = SVR4_TI_OK_REPLY;
1987 case SVR4_TI_OK_REPLY:
1988 DPRINTF(("getmsg: TI_OK_REPLY\n"));
1990 * We are immediately after a connect reply, so we send
1991 * a connect verification.
1994 SCARG(&ga, fdes) = SCARG(uap, fd);
1995 SCARG(&ga, asa) = (void *) sup;
1996 SCARG(&ga, alen) = flen;
1998 if ((error = getpeername(p, &ga)) != 0) {
1999 DPRINTF(("getmsg: getpeername failed %d\n", error));
2003 if ((error = copyin(sup, skp, sasize)) != 0)
2006 sc.cmd = SVR4_TI_CONNECT_REPLY;
2010 sc.pad[2] = 0x04000402;
2012 switch (st->s_family) {
2015 sockaddr_to_netaddr_in(&sc, &sain);
2019 sc.len = sasize + 4;
2020 sockaddr_to_netaddr_un(&sc, &saun);
2033 case SVR4_TI__ACCEPT_OK:
2034 DPRINTF(("getmsg: TI__ACCEPT_OK\n"));
2036 * We do the connect in one step, so the putmsg should
2037 * have gotten the error.
2039 sc.cmd = SVR4_TI_OK_REPLY;
2045 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
2048 case SVR4_TI__ACCEPT_WAIT:
2049 DPRINTF(("getmsg: TI__ACCEPT_WAIT\n"));
2051 * We are after a listen, so we try to accept...
2053 SCARG(&aa, s) = SCARG(uap, fd);
2054 SCARG(&aa, name) = (void *) sup;
2055 SCARG(&aa, anamelen) = flen;
2057 if ((error = accept(p, &aa)) != 0) {
2058 DPRINTF(("getmsg: accept failed %d\n", error));
2062 st->s_afd = *retval;
2064 DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd));
2066 if ((error = copyin(sup, skp, sasize)) != 0)
2069 sc.cmd = SVR4_TI_ACCEPT_REPLY;
2073 switch (st->s_family) {
2076 sockaddr_to_netaddr_in(&sc, &sain);
2082 sc.pad[1] = 0x00010000;
2083 sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */
2084 sc.pad[3] = 0x00010000;
2086 sc.len = sasize + 4;
2095 st->s_cmd = SVR4_TI__ACCEPT_OK;
2098 case SVR4_TI_SENDTO_REQUEST:
2099 DPRINTF(("getmsg: TI_SENDTO_REQUEST\n"));
2100 if (ctl.maxlen > 36 && ctl.len < 36)
2103 if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0)
2106 switch (st->s_family) {
2108 sockaddr_to_netaddr_in(&sc, &sain);
2112 sockaddr_to_netaddr_un(&sc, &saun);
2119 msg.msg_name = (caddr_t) sup;
2120 msg.msg_namelen = sasize;
2121 msg.msg_iov = &aiov;
2123 msg.msg_control = 0;
2124 aiov.iov_base = dat.buf;
2125 aiov.iov_len = dat.maxlen;
2128 error = svr4_recvit(p, SCARG(uap, fd), &msg, (caddr_t) flen);
2131 DPRINTF(("getmsg: recvit failed %d\n", error));
2135 if ((error = copyin(msg.msg_name, skp, sasize)) != 0)
2138 sc.cmd = SVR4_TI_RECVFROM_IND;
2140 switch (st->s_family) {
2143 sockaddr_to_netaddr_in(&sc, &sain);
2147 sc.len = sasize + 4;
2148 sockaddr_to_netaddr_un(&sc, &saun);
2162 if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) {
2163 struct read_args ra;
2165 /* More wierdness: Again, I can't find documentation
2166 * to back this up, but when a process does a generic
2167 * "getmsg()" call it seems that the command field is
2168 * zero and the length of the data area is zero. I
2169 * think processes expect getmsg() to fill in dat.len
2170 * after reading at most dat.maxlen octets from the
2171 * stream. Since we're using sockets I can let
2172 * read() look after it and frob return values
2173 * appropriately (or inappropriately :-)
2174 * -- newton@atdot.dotat.org XXX
2176 SCARG(&ra, fd) = SCARG(uap, fd);
2177 SCARG(&ra, buf) = dat.buf;
2178 SCARG(&ra, nbyte) = dat.maxlen;
2179 if ((error = read(p, &ra)) != 0) {
2184 st->s_cmd = SVR4_TI_SENDTO_REQUEST;
2187 DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd));
2191 if (SCARG(uap, ctl)) {
2193 if ((error = copyout(&sc, ctl.buf, ctl.len)) != 0)
2196 if ((error = copyout(&ctl, SCARG(uap, ctl), sizeof(ctl))) != 0)
2200 if (SCARG(uap, dat)) {
2201 if ((error = copyout(&dat, SCARG(uap, dat), sizeof(dat))) != 0)
2205 if (SCARG(uap, flags)) { /* XXX: Need translation */
2206 if ((error = copyout(&fl, SCARG(uap, flags), sizeof(fl))) != 0)
2213 show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl),
2214 SCARG(uap, dat), fl);
2215 #endif /* DEBUG_SVR4 */
2219 int svr4_sys_send(p, uap)
2221 struct svr4_sys_send_args *uap;
2223 struct osend_args osa;
2224 SCARG(&osa, s) = SCARG(uap, s);
2225 SCARG(&osa, buf) = SCARG(uap, buf);
2226 SCARG(&osa, len) = SCARG(uap, len);
2227 SCARG(&osa, flags) = SCARG(uap, flags);
2228 return osend(p, &osa);
2231 int svr4_sys_recv(p, uap)
2233 struct svr4_sys_recv_args *uap;
2235 struct orecv_args ora;
2236 SCARG(&ora, s) = SCARG(uap, s);
2237 SCARG(&ora, buf) = SCARG(uap, buf);
2238 SCARG(&ora, len) = SCARG(uap, len);
2239 SCARG(&ora, flags) = SCARG(uap, flags);
2240 return orecv(p, &ora);
2244 * XXX This isn't necessary, but it's handy for inserting debug code into
2245 * sendto(). Let's leave it here for now...
2248 svr4_sys_sendto(p, uap)
2250 struct svr4_sys_sendto_args *uap;
2252 struct sendto_args sa;
2254 SCARG(&sa, s) = SCARG(uap, s);
2255 SCARG(&sa, buf) = SCARG(uap, buf);
2256 SCARG(&sa, len) = SCARG(uap, len);
2257 SCARG(&sa, flags) = SCARG(uap, flags);
2258 SCARG(&sa, to) = SCARG(uap, to);
2259 SCARG(&sa, tolen) = SCARG(uap, tolen);
2261 DPRINTF(("calling sendto()\n"));
2262 return sendto(p, &sa);