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");
220 /* pointer to flags */
221 if (tcp->u_arg[4] == 0)
223 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
227 if (!printflags(pmsgflags, flags))
231 /* decode return value */
232 switch (tcp->u_rval) {
234 tcp->auxstr = "MORECTL";
236 case MORECTL|MOREDATA:
237 tcp->auxstr = "MORECTL|MOREDATA";
240 tcp->auxstr = "MORECTL";
247 return RVAL_HEX | RVAL_STR;
250 #endif /* HAVE_PUTPMSG */
253 static struct xlat pollflags[] = {
254 { POLLIN, "POLLIN" },
255 { POLLPRI, "POLLPRI" },
256 { POLLOUT, "POLLOUT" },
258 { POLLRDNORM, "POLLRDNORM" },
261 { POLLWRNORM, "POLLWRNORM" },
264 { POLLRDBAND, "POLLRDBAND" },
267 { POLLWRBAND, "POLLWRBAND" },
269 { POLLERR, "POLLERR" },
270 { POLLHUP, "POLLHUP" },
271 { POLLNVAL, "POLLNVAL" },
279 struct pollfd *pollp;
283 int nfds = tcp->u_arg[1];
286 tprintf("%#lx, %d, %ld\n",
287 tcp->u_arg[0], nfds, tcp->u_arg[2]);
290 pollp = (struct pollfd *) malloc(nfds * sizeof(*pollp));
292 fprintf(stderr, "sys_poll: no memory\n");
293 tprintf("%#lx, %d, %ld",
294 tcp->u_arg[0], nfds, tcp->u_arg[2]);
297 if (umoven(tcp, tcp->u_arg[0],
298 (nfds * sizeof(*pollp)), (char *) pollp) < 0) {
299 tprintf("%#lx", tcp->u_arg[0]);
303 for (i = 0; i < nfds; i++) {
306 if (pollp[i].fd < 0) {
307 tprintf("{fd=%d}", pollp[i].fd);
310 tprintf("{fd=%d, events=", pollp[i].fd);
311 if (!printflags(pollflags, pollp[i].events))
313 if (!syserror(tcp) && pollp[i].revents) {
314 tprintf(", revents=");
315 if (!printflags(pollflags,
323 tprintf(", %d, ", nfds);
325 if (tcp->u_arg[2] == INFTIM)
329 tprintf("%ld", tcp->u_arg[2]);
337 static struct xlat stream_flush_options[] = {
338 { FLUSHR, "FLUSHR" },
339 { FLUSHW, "FLUSHW" },
340 { FLUSHRW, "FLUSHRW" },
342 { FLUSHBAND, "FLUSHBAND" },
347 static struct xlat stream_setsig_flags[] = {
348 { S_INPUT, "S_INPUT" },
349 { S_HIPRI, "S_HIPRI" },
350 { S_OUTPUT, "S_OUTPUT" },
353 { S_ERROR, "S_ERROR" },
356 { S_HANGUP, "S_HANGUP" },
359 { S_RDNORM, "S_RDNORM" },
362 { S_WRNORM, "S_WRNORM" },
365 { S_RDBAND, "S_RDBAND" },
368 { S_WRBAND, "S_WRBAND" },
371 { S_BANDURG, "S_BANDURG" },
376 static struct xlat stream_read_options[] = {
383 static struct xlat stream_read_flags[] = {
385 { RPROTDAT, "RPROTDAT" },
388 { RPROTDIS, "RPROTDIS" },
391 { RPROTNORM, "RPROTNORM" },
397 #define RMODEMASK (~0)
401 static struct xlat stream_write_flags[] = {
402 { SNDZERO, "SNDZERO" },
403 { SNDPIPE, "SNDPIPE" },
406 #endif /* I_SWROPT */
409 static struct xlat stream_atmark_options[] = {
410 { ANYMARK, "ANYMARK" },
411 { LASTMARK, "LASTMARK" },
414 #endif /* I_ATMARK */
417 static struct xlat transport_user_options[] = {
418 { T_CONN_REQ, "T_CONN_REQ" },
419 { T_CONN_RES, "T_CONN_RES" },
420 { T_DISCON_REQ, "T_DISCON_REQ" },
421 { T_DATA_REQ, "T_DATA_REQ" },
422 { T_EXDATA_REQ, "T_EXDATA_REQ" },
423 { T_INFO_REQ, "T_INFO_REQ" },
424 { T_BIND_REQ, "T_BIND_REQ" },
425 { T_UNBIND_REQ, "T_UNBIND_REQ" },
426 { T_UNITDATA_REQ,"T_UNITDATA_REQ"},
427 { T_OPTMGMT_REQ,"T_OPTMGMT_REQ" },
428 { T_ORDREL_REQ, "T_ORDREL_REQ" },
432 static struct xlat transport_provider_options[] = {
433 { T_CONN_IND, "T_CONN_IND" },
434 { T_CONN_CON, "T_CONN_CON" },
435 { T_DISCON_IND, "T_DISCON_IND" },
436 { T_DATA_IND, "T_DATA_IND" },
437 { T_EXDATA_IND, "T_EXDATA_IND" },
438 { T_INFO_ACK, "T_INFO_ACK" },
439 { T_BIND_ACK, "T_BIND_ACK" },
440 { T_ERROR_ACK, "T_ERROR_ACK" },
441 { T_OK_ACK, "T_OK_ACK" },
442 { T_UNITDATA_IND,"T_UNITDATA_IND"},
443 { T_UDERROR_IND,"T_UDERROR_IND" },
444 { T_OPTMGMT_ACK,"T_OPTMGMT_ACK" },
445 { T_ORDREL_IND, "T_ORDREL_IND" },
451 internal_stream_ioctl(tcp, arg)
459 struct si_udata udata;
460 #endif /* SI_GETUDATA */
464 if (umove(tcp, arg, &si) < 0) {
470 name = ioctl_lookup(si.ic_cmd);
472 tprintf(", {ic_cmd=%s", name);
474 tprintf(", {ic_cmd=%#x", si.ic_cmd);
475 if (si.ic_timout == INFTIM)
476 tprintf(", ic_timout=INFTIM, ");
478 tprintf(" ic_timout=%d, ", si.ic_timout);
486 #endif /* SI_GETUDATA */
490 tprintf("/* in */ ");
492 tprintf(", /* out */ ");
494 if (in_and_out || entering(tcp))
495 tprintf("ic_len=%d, ic_dp=", si.ic_len);
499 /* in T_BIND_REQ, out T_BIND_ACK */
501 struct T_bind_req data;
504 tprintf("struct T_bind_req ");
506 if (umove(tcp, (int) si.ic_dp, &data) < 0)
509 tprintf("{PRIM_type=");
510 printxval(transport_user_options,
511 data.PRIM_type, "T_???");
512 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
513 data.ADDR_length, data.ADDR_offset);
514 tprintf(", CONIND_number=%ld}",
519 struct T_bind_ack data;
522 tprintf("struct T_bind_ack ");
524 if (umove(tcp, (int) si.ic_dp, &data) < 0)
528 tprintf("{PRIM_type=");
529 printxval(transport_provider_options,
530 data.PRIM_type, "T_???");
531 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
532 data.ADDR_length, data.ADDR_offset);
533 tprintf(", CONIND_number=%ld}",
537 (int) si.ic_dp + data.ADDR_offset,
547 /* in T_UNBIND_REQ, out T_OK_ACK */
549 #endif /* TI_UNBIND */
552 /* in T_INFO_REQ, out T_INFO_ACK */
554 #endif /* TI_GETINFO */
557 /* in T_OPTMGMT_REQ, out T_OPTMGMT_ACK */
559 #endif /* TI_OPTMGMT */
566 tprintf("struct si_udata ");
568 if (umove(tcp, (int) si.ic_dp, &udata) < 0)
571 tprintf("{tidusize=%d, addrsize=%d, ",
572 udata.tidusize, udata.addrsize);
573 tprintf("optsize=%d, etsdusize=%d, ",
574 udata.optsize, udata.etsdusize);
575 tprintf("servtype=%d, so_state=%d, ",
576 udata.servtype, udata.so_state);
577 tprintf("so_options=%d", udata.so_options);
579 tprintf(", tsdusize=%d", udata.tsdusize);
584 #endif /* SI_GETUDATA */
586 printstr(tcp, (int) si.ic_dp, si.ic_len);
595 stream_ioctl(tcp, code, arg)
607 struct strfdinsert sfi;
608 struct strrecvfd srf;
613 /* I_STR is a special case because the data is read & written. */
615 return internal_stream_ioctl(tcp, arg);
623 /* arg is a string */
628 /* doesn't take an argument */
631 /* argument is an option */
633 printxval(stream_flush_options, arg, "FLUSH???");
637 /* argument is a pointer to a bandinfo struct */
638 if (umove(tcp, arg, &bi) < 0)
641 tprintf(", {bi_pri=%d, bi_flag=", bi.bi_pri);
642 if (!printflags(stream_flush_options, bi.bi_flag))
647 #endif /* I_FLUSHBAND */
649 /* argument is a set of flags */
651 if (!printflags(stream_setsig_flags, arg))
655 /* argument is a pointer to a set of flags */
659 if (umove(tcp, arg, &val) < 0)
661 else if (!printflags(stream_setsig_flags, val))
666 /* argument is a pointer to a strpeek structure */
667 if (syserror(tcp) || !arg)
669 if (umove(tcp, arg, &sp) < 0) {
673 tprintf(", {ctlbuf=");
674 printstrbuf(tcp, &sp.ctlbuf, 1);
675 tprintf(", databuf=");
676 printstrbuf(tcp, &sp.databuf, 1);
677 if (!printflags(msgflags, sp.flags))
681 /* argument is an option with flags */
683 printxval(stream_read_options, arg & RMODEMASK, "R???");
684 addflags(stream_read_flags, arg & ~RMODEMASK);
687 /* argument is an pointer to an option with flags */
691 if (umove(tcp, arg, &val) < 0)
694 printxval(stream_read_options,
695 arg & RMODEMASK, "R???");
696 addflags(stream_read_flags, arg & ~RMODEMASK);
710 /* argument is a pointer to a decimal integer */
714 printnum(tcp, arg, "%d");
717 /* argument is a pointer to a strfdinsert structure */
718 if (syserror(tcp) || !arg)
720 if (umove(tcp, arg, &sfi) < 0) {
724 tprintf(", {ctlbuf=");
725 printstrbuf(tcp, &sfi.ctlbuf, 1);
726 tprintf(", databuf=");
727 printstrbuf(tcp, &sfi.databuf, 1);
728 if (!printflags(msgflags, sfi.flags))
730 tprintf(", filedes=%d, offset=%d}", sfi.fildes, sfi.offset);
734 /* argument is a set of flags */
736 if (!printflags(stream_write_flags, arg))
739 #endif /* I_SWROPT */
742 /* argument is an pointer to an option with flags */
746 if (umove(tcp, arg, &val) < 0)
748 else if (!printflags(stream_write_flags, arg))
752 #endif /* I_GWROPT */
764 /* argument is a decimal integer */
765 tprintf(", %d", arg);
768 /* argument is a pointer to a strrecvfd structure */
769 if (syserror(tcp) || !arg)
771 if (umove(tcp, arg, &srf) < 0) {
775 tprintf(", {fd=%d, uid=%lu, gid=%lu}", srf.fd,
776 (unsigned long) srf.uid, (unsigned long) srf.gid);
786 if (umove(tcp, arg, &sl) < 0) {
790 tprintf(", {sl_nmods=%d, sl_modlist=[", sl.sl_nmods);
791 for (i = 0; i < tcp->u_rval; i++) {
794 printpath(tcp, (int) sl.sl_modlist[i].l_name);
802 printxval(stream_atmark_options, arg, "???MARK");
804 #endif /* I_ATMARK */
812 #endif /* LINUXSPARC && linux */