2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
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. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #if defined(HAVE_SYS_STREAM_H) || defined(linux)
39 int maxlen; /* no. of bytes in buffer */
40 int len; /* no. of bytes returned */
41 char *buf; /* pointer to data */
51 #include <sys/stream.h>
52 #include <sys/tihdr.h>
56 #ifdef HAVE_SYS_TIUSER_H
57 #include <sys/tiuser.h>
58 #include <sys/sockmod.h>
59 #include <sys/timod.h>
60 #endif /* HAVE_SYS_TIUSER_H */
62 static struct xlat msgflags[] = {
63 { RS_HIPRI, "RS_HIPRI" },
69 printstrbuf(tcp, sbp, getting)
74 if (sbp->maxlen == -1 && getting)
75 tprintf("{maxlen=-1}");
79 tprintf("maxlen=%d, ", sbp->maxlen);
80 tprintf("len=%d, buf=", sbp->len);
81 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
87 printstrbufarg(tcp, arg, getting)
96 else if (umove(tcp, arg, &buf) < 0)
99 printstrbuf(tcp, &buf, getting);
111 tprintf("%ld, ", tcp->u_arg[0]);
112 /* control and data */
113 for (i = 1; i < 3; i++)
114 printstrbufarg(tcp, tcp->u_arg[i], 0);
116 if (!printflags(msgflags, tcp->u_arg[3]))
130 tprintf("%lu, ", tcp->u_arg[0]);
133 tprintf("%#lx, %#lx, %#lx",
134 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
137 /* control and data */
138 for (i = 1; i < 3; i++)
139 printstrbufarg(tcp, tcp->u_arg[i], 1);
140 /* pointer to flags */
141 if (tcp->u_arg[3] == 0)
143 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
147 if (!printflags(msgflags, flags))
151 /* decode return value */
152 switch (tcp->u_rval) {
154 tcp->auxstr = "MORECTL";
156 case MORECTL|MOREDATA:
157 tcp->auxstr = "MORECTL|MOREDATA";
160 tcp->auxstr = "MORECTL";
167 return RVAL_HEX | RVAL_STR;
172 static struct xlat pmsgflags[] = {
173 { MSG_HIPRI, "MSG_HIPRI" },
174 { MSG_ANY, "MSG_ANY" },
175 { MSG_BAND, "MSG_BAND" },
187 tprintf("%ld, ", tcp->u_arg[0]);
188 /* control and data */
189 for (i = 1; i < 3; i++)
190 printstrbufarg(tcp, tcp->u_arg[i], 0);
192 tprintf("%ld, ", tcp->u_arg[3]);
194 if (!printflags(pmsgflags, tcp->u_arg[4]))
208 tprintf("%lu, ", tcp->u_arg[0]);
211 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
212 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
215 /* control and data */
216 for (i = 1; i < 3; i++)
217 printstrbufarg(tcp, tcp->u_arg[i], 1);
218 /* pointer to band */
219 printnum(tcp, tcp->u_arg[3], "%d");
221 /* pointer to flags */
222 if (tcp->u_arg[4] == 0)
224 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
228 if (!printflags(pmsgflags, flags))
232 /* decode return value */
233 switch (tcp->u_rval) {
235 tcp->auxstr = "MORECTL";
237 case MORECTL|MOREDATA:
238 tcp->auxstr = "MORECTL|MOREDATA";
241 tcp->auxstr = "MORECTL";
248 return RVAL_HEX | RVAL_STR;
251 #endif /* HAVE_PUTPMSG */
254 static struct xlat pollflags[] = {
255 { POLLIN, "POLLIN" },
256 { POLLPRI, "POLLPRI" },
257 { POLLOUT, "POLLOUT" },
259 { POLLRDNORM, "POLLRDNORM" },
262 { POLLWRNORM, "POLLWRNORM" },
265 { POLLRDBAND, "POLLRDBAND" },
268 { POLLWRBAND, "POLLWRBAND" },
270 { POLLERR, "POLLERR" },
271 { POLLHUP, "POLLHUP" },
272 { POLLNVAL, "POLLNVAL" },
280 struct pollfd *pollp;
284 int nfds = tcp->u_arg[1];
287 tprintf("%#lx, %d, %ld\n",
288 tcp->u_arg[0], nfds, tcp->u_arg[2]);
291 pollp = (struct pollfd *) malloc(nfds * sizeof(*pollp));
293 fprintf(stderr, "sys_poll: no memory\n");
294 tprintf("%#lx, %d, %ld",
295 tcp->u_arg[0], nfds, tcp->u_arg[2]);
298 if (umoven(tcp, tcp->u_arg[0],
299 (nfds * sizeof(*pollp)), (char *) pollp) < 0) {
300 tprintf("%#lx", tcp->u_arg[0]);
304 for (i = 0; i < nfds; i++) {
307 if (pollp[i].fd < 0) {
308 tprintf("{fd=%d}", pollp[i].fd);
311 tprintf("{fd=%d, events=", pollp[i].fd);
312 if (!printflags(pollflags, pollp[i].events))
314 if (!syserror(tcp) && pollp[i].revents) {
315 tprintf(", revents=");
316 if (!printflags(pollflags,
324 tprintf(", %d, ", nfds);
326 if (tcp->u_arg[2] == INFTIM)
330 tprintf("%ld", tcp->u_arg[2]);
338 static struct xlat stream_flush_options[] = {
339 { FLUSHR, "FLUSHR" },
340 { FLUSHW, "FLUSHW" },
341 { FLUSHRW, "FLUSHRW" },
343 { FLUSHBAND, "FLUSHBAND" },
348 static struct xlat stream_setsig_flags[] = {
349 { S_INPUT, "S_INPUT" },
350 { S_HIPRI, "S_HIPRI" },
351 { S_OUTPUT, "S_OUTPUT" },
354 { S_ERROR, "S_ERROR" },
357 { S_HANGUP, "S_HANGUP" },
360 { S_RDNORM, "S_RDNORM" },
363 { S_WRNORM, "S_WRNORM" },
366 { S_RDBAND, "S_RDBAND" },
369 { S_WRBAND, "S_WRBAND" },
372 { S_BANDURG, "S_BANDURG" },
377 static struct xlat stream_read_options[] = {
384 static struct xlat stream_read_flags[] = {
386 { RPROTDAT, "RPROTDAT" },
389 { RPROTDIS, "RPROTDIS" },
392 { RPROTNORM, "RPROTNORM" },
398 #define RMODEMASK (~0)
402 static struct xlat stream_write_flags[] = {
403 { SNDZERO, "SNDZERO" },
404 { SNDPIPE, "SNDPIPE" },
407 #endif /* I_SWROPT */
410 static struct xlat stream_atmark_options[] = {
411 { ANYMARK, "ANYMARK" },
412 { LASTMARK, "LASTMARK" },
415 #endif /* I_ATMARK */
418 static struct xlat transport_user_options[] = {
419 { T_CONN_REQ, "T_CONN_REQ" },
420 { T_CONN_RES, "T_CONN_RES" },
421 { T_DISCON_REQ, "T_DISCON_REQ" },
422 { T_DATA_REQ, "T_DATA_REQ" },
423 { T_EXDATA_REQ, "T_EXDATA_REQ" },
424 { T_INFO_REQ, "T_INFO_REQ" },
425 { T_BIND_REQ, "T_BIND_REQ" },
426 { T_UNBIND_REQ, "T_UNBIND_REQ" },
427 { T_UNITDATA_REQ,"T_UNITDATA_REQ"},
428 { T_OPTMGMT_REQ,"T_OPTMGMT_REQ" },
429 { T_ORDREL_REQ, "T_ORDREL_REQ" },
433 static struct xlat transport_provider_options[] = {
434 { T_CONN_IND, "T_CONN_IND" },
435 { T_CONN_CON, "T_CONN_CON" },
436 { T_DISCON_IND, "T_DISCON_IND" },
437 { T_DATA_IND, "T_DATA_IND" },
438 { T_EXDATA_IND, "T_EXDATA_IND" },
439 { T_INFO_ACK, "T_INFO_ACK" },
440 { T_BIND_ACK, "T_BIND_ACK" },
441 { T_ERROR_ACK, "T_ERROR_ACK" },
442 { T_OK_ACK, "T_OK_ACK" },
443 { T_UNITDATA_IND,"T_UNITDATA_IND"},
444 { T_UDERROR_IND,"T_UDERROR_IND" },
445 { T_OPTMGMT_ACK,"T_OPTMGMT_ACK" },
446 { T_ORDREL_IND, "T_ORDREL_IND" },
452 internal_stream_ioctl(tcp, arg)
460 struct si_udata udata;
461 #endif /* SI_GETUDATA */
465 if (umove(tcp, arg, &si) < 0) {
471 name = ioctl_lookup(si.ic_cmd);
473 tprintf(", {ic_cmd=%s", name);
475 tprintf(", {ic_cmd=%#x", si.ic_cmd);
476 if (si.ic_timout == INFTIM)
477 tprintf(", ic_timout=INFTIM, ");
479 tprintf(" ic_timout=%d, ", si.ic_timout);
487 #endif /* SI_GETUDATA */
491 tprintf("/* in */ ");
493 tprintf(", /* out */ ");
495 if (in_and_out || entering(tcp))
496 tprintf("ic_len=%d, ic_dp=", si.ic_len);
500 /* in T_BIND_REQ, out T_BIND_ACK */
502 struct T_bind_req data;
505 tprintf("struct T_bind_req ");
507 if (umove(tcp, (int) si.ic_dp, &data) < 0)
510 tprintf("{PRIM_type=");
511 printxval(transport_user_options,
512 data.PRIM_type, "T_???");
513 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
514 data.ADDR_length, data.ADDR_offset);
515 tprintf(", CONIND_number=%ld}",
520 struct T_bind_ack data;
523 tprintf("struct T_bind_ack ");
525 if (umove(tcp, (int) si.ic_dp, &data) < 0)
529 tprintf("{PRIM_type=");
530 printxval(transport_provider_options,
531 data.PRIM_type, "T_???");
532 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
533 data.ADDR_length, data.ADDR_offset);
534 tprintf(", CONIND_number=%ld}",
538 (int) si.ic_dp + data.ADDR_offset,
548 /* in T_UNBIND_REQ, out T_OK_ACK */
550 #endif /* TI_UNBIND */
553 /* in T_INFO_REQ, out T_INFO_ACK */
555 #endif /* TI_GETINFO */
558 /* in T_OPTMGMT_REQ, out T_OPTMGMT_ACK */
560 #endif /* TI_OPTMGMT */
567 tprintf("struct si_udata ");
569 if (umove(tcp, (int) si.ic_dp, &udata) < 0)
572 tprintf("{tidusize=%d, addrsize=%d, ",
573 udata.tidusize, udata.addrsize);
574 tprintf("optsize=%d, etsdusize=%d, ",
575 udata.optsize, udata.etsdusize);
576 tprintf("servtype=%d, so_state=%d, ",
577 udata.servtype, udata.so_state);
578 tprintf("so_options=%d", udata.so_options);
580 tprintf(", tsdusize=%d", udata.tsdusize);
585 #endif /* SI_GETUDATA */
587 printstr(tcp, (int) si.ic_dp, si.ic_len);
596 stream_ioctl(tcp, code, arg)
608 struct strfdinsert sfi;
609 struct strrecvfd srf;
614 /* I_STR is a special case because the data is read & written. */
616 return internal_stream_ioctl(tcp, arg);
624 /* arg is a string */
629 /* doesn't take an argument */
632 /* argument is an option */
634 printxval(stream_flush_options, arg, "FLUSH???");
638 /* argument is a pointer to a bandinfo struct */
639 if (umove(tcp, arg, &bi) < 0)
642 tprintf(", {bi_pri=%d, bi_flag=", bi.bi_pri);
643 if (!printflags(stream_flush_options, bi.bi_flag))
648 #endif /* I_FLUSHBAND */
650 /* argument is a set of flags */
652 if (!printflags(stream_setsig_flags, arg))
656 /* argument is a pointer to a set of flags */
660 if (umove(tcp, arg, &val) < 0)
662 else if (!printflags(stream_setsig_flags, val))
667 /* argument is a pointer to a strpeek structure */
668 if (syserror(tcp) || !arg)
670 if (umove(tcp, arg, &sp) < 0) {
674 tprintf(", {ctlbuf=");
675 printstrbuf(tcp, &sp.ctlbuf, 1);
676 tprintf(", databuf=");
677 printstrbuf(tcp, &sp.databuf, 1);
678 if (!printflags(msgflags, sp.flags))
682 /* argument is an option with flags */
684 printxval(stream_read_options, arg & RMODEMASK, "R???");
685 addflags(stream_read_flags, arg & ~RMODEMASK);
688 /* argument is an pointer to an option with flags */
692 if (umove(tcp, arg, &val) < 0)
695 printxval(stream_read_options,
696 arg & RMODEMASK, "R???");
697 addflags(stream_read_flags, arg & ~RMODEMASK);
711 /* argument is a pointer to a decimal integer */
715 printnum(tcp, arg, "%d");
718 /* argument is a pointer to a strfdinsert structure */
719 if (syserror(tcp) || !arg)
721 if (umove(tcp, arg, &sfi) < 0) {
725 tprintf(", {ctlbuf=");
726 printstrbuf(tcp, &sfi.ctlbuf, 1);
727 tprintf(", databuf=");
728 printstrbuf(tcp, &sfi.databuf, 1);
729 if (!printflags(msgflags, sfi.flags))
731 tprintf(", filedes=%d, offset=%d}", sfi.fildes, sfi.offset);
735 /* argument is a set of flags */
737 if (!printflags(stream_write_flags, arg))
740 #endif /* I_SWROPT */
743 /* argument is an pointer to an option with flags */
747 if (umove(tcp, arg, &val) < 0)
749 else if (!printflags(stream_write_flags, arg))
753 #endif /* I_GWROPT */
765 /* argument is a decimal integer */
766 tprintf(", %d", arg);
769 /* argument is a pointer to a strrecvfd structure */
770 if (syserror(tcp) || !arg)
772 if (umove(tcp, arg, &srf) < 0) {
776 tprintf(", {fd=%d, uid=%lu, gid=%lu}", srf.fd,
777 (unsigned long) srf.uid, (unsigned long) srf.gid);
787 if (umove(tcp, arg, &sl) < 0) {
791 tprintf(", {sl_nmods=%d, sl_modlist=[", sl.sl_nmods);
792 for (i = 0; i < tcp->u_rval; i++) {
795 printpath(tcp, (int) sl.sl_modlist[i].l_name);
803 printxval(stream_atmark_options, arg, "???MARK");
805 #endif /* I_ATMARK */
813 #endif /* LINUXSPARC && linux */