2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
3 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #if defined(HAVE_SYS_STREAM_H) || defined(linux)
40 int maxlen; /* no. of bytes in buffer */
41 int len; /* no. of bytes returned */
42 char *buf; /* pointer to data */
52 #include <sys/stream.h>
53 #include <sys/tihdr.h>
57 #ifdef HAVE_SYS_TIUSER_H
58 #include <sys/tiuser.h>
59 #include <sys/sockmod.h>
60 #include <sys/timod.h>
61 #endif /* HAVE_SYS_TIUSER_H */
63 static struct xlat msgflags[] = {
64 { RS_HIPRI, "RS_HIPRI" },
70 printstrbuf(tcp, sbp, getting)
75 if (sbp->maxlen == -1 && getting)
76 tprintf("{maxlen=-1}");
80 tprintf("maxlen=%d, ", sbp->maxlen);
81 tprintf("len=%d, buf=", sbp->len);
82 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
88 printstrbufarg(tcp, arg, getting)
97 else if (umove(tcp, arg, &buf) < 0)
100 printstrbuf(tcp, &buf, getting);
112 tprintf("%ld, ", tcp->u_arg[0]);
113 /* control and data */
114 for (i = 1; i < 3; i++)
115 printstrbufarg(tcp, tcp->u_arg[i], 0);
117 if (!printflags(msgflags, tcp->u_arg[3]))
131 tprintf("%lu, ", tcp->u_arg[0]);
134 tprintf("%#lx, %#lx, %#lx",
135 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
138 /* control and data */
139 for (i = 1; i < 3; i++)
140 printstrbufarg(tcp, tcp->u_arg[i], 1);
141 /* pointer to flags */
142 if (tcp->u_arg[3] == 0)
144 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
148 if (!printflags(msgflags, flags))
152 /* decode return value */
153 switch (tcp->u_rval) {
155 tcp->auxstr = "MORECTL";
157 case MORECTL|MOREDATA:
158 tcp->auxstr = "MORECTL|MOREDATA";
161 tcp->auxstr = "MORECTL";
168 return RVAL_HEX | RVAL_STR;
173 static struct xlat pmsgflags[] = {
174 { MSG_HIPRI, "MSG_HIPRI" },
175 { MSG_ANY, "MSG_ANY" },
176 { MSG_BAND, "MSG_BAND" },
188 tprintf("%ld, ", tcp->u_arg[0]);
189 /* control and data */
190 for (i = 1; i < 3; i++)
191 printstrbufarg(tcp, tcp->u_arg[i], 0);
193 tprintf("%ld, ", tcp->u_arg[3]);
195 if (!printflags(pmsgflags, tcp->u_arg[4]))
209 tprintf("%lu, ", tcp->u_arg[0]);
212 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
213 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
216 /* control and data */
217 for (i = 1; i < 3; i++)
218 printstrbufarg(tcp, tcp->u_arg[i], 1);
219 /* pointer to band */
220 printnum(tcp, tcp->u_arg[3], "%d");
222 /* pointer to flags */
223 if (tcp->u_arg[4] == 0)
225 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
229 if (!printflags(pmsgflags, flags))
233 /* decode return value */
234 switch (tcp->u_rval) {
236 tcp->auxstr = "MORECTL";
238 case MORECTL|MOREDATA:
239 tcp->auxstr = "MORECTL|MOREDATA";
242 tcp->auxstr = "MORECTL";
249 return RVAL_HEX | RVAL_STR;
252 #endif /* HAVE_PUTPMSG */
255 static struct xlat pollflags[] = {
256 { POLLIN, "POLLIN" },
257 { POLLPRI, "POLLPRI" },
258 { POLLOUT, "POLLOUT" },
260 { POLLRDNORM, "POLLRDNORM" },
263 { POLLWRNORM, "POLLWRNORM" },
266 { POLLRDBAND, "POLLRDBAND" },
269 { POLLWRBAND, "POLLWRBAND" },
271 { POLLERR, "POLLERR" },
272 { POLLHUP, "POLLHUP" },
273 { POLLNVAL, "POLLNVAL" },
281 struct pollfd *pollp;
285 int nfds = tcp->u_arg[1];
288 tprintf("%#lx, %d, %ld\n",
289 tcp->u_arg[0], nfds, tcp->u_arg[2]);
292 pollp = (struct pollfd *) malloc(nfds * sizeof(*pollp));
294 fprintf(stderr, "sys_poll: no memory\n");
295 tprintf("%#lx, %d, %ld",
296 tcp->u_arg[0], nfds, tcp->u_arg[2]);
299 if (umoven(tcp, tcp->u_arg[0],
300 (nfds * sizeof(*pollp)), (char *) pollp) < 0) {
301 tprintf("%#lx", tcp->u_arg[0]);
305 for (i = 0; i < nfds; i++) {
308 if (pollp[i].fd < 0) {
309 tprintf("{fd=%d}", pollp[i].fd);
312 tprintf("{fd=%d, events=", pollp[i].fd);
313 if (!printflags(pollflags, pollp[i].events))
315 if (!syserror(tcp) && pollp[i].revents) {
316 tprintf(", revents=");
317 if (!printflags(pollflags,
325 tprintf(", %d, ", nfds);
327 if (tcp->u_arg[2] == INFTIM)
331 tprintf("%ld", tcp->u_arg[2]);
339 static struct xlat stream_flush_options[] = {
340 { FLUSHR, "FLUSHR" },
341 { FLUSHW, "FLUSHW" },
342 { FLUSHRW, "FLUSHRW" },
344 { FLUSHBAND, "FLUSHBAND" },
349 static struct xlat stream_setsig_flags[] = {
350 { S_INPUT, "S_INPUT" },
351 { S_HIPRI, "S_HIPRI" },
352 { S_OUTPUT, "S_OUTPUT" },
355 { S_ERROR, "S_ERROR" },
358 { S_HANGUP, "S_HANGUP" },
361 { S_RDNORM, "S_RDNORM" },
364 { S_WRNORM, "S_WRNORM" },
367 { S_RDBAND, "S_RDBAND" },
370 { S_WRBAND, "S_WRBAND" },
373 { S_BANDURG, "S_BANDURG" },
378 static struct xlat stream_read_options[] = {
385 static struct xlat stream_read_flags[] = {
387 { RPROTDAT, "RPROTDAT" },
390 { RPROTDIS, "RPROTDIS" },
393 { RPROTNORM, "RPROTNORM" },
399 #define RMODEMASK (~0)
403 static struct xlat stream_write_flags[] = {
404 { SNDZERO, "SNDZERO" },
405 { SNDPIPE, "SNDPIPE" },
408 #endif /* I_SWROPT */
411 static struct xlat stream_atmark_options[] = {
412 { ANYMARK, "ANYMARK" },
413 { LASTMARK, "LASTMARK" },
416 #endif /* I_ATMARK */
419 static struct xlat transport_user_options[] = {
420 { T_CONN_REQ, "T_CONN_REQ" },
421 { T_CONN_RES, "T_CONN_RES" },
422 { T_DISCON_REQ, "T_DISCON_REQ" },
423 { T_DATA_REQ, "T_DATA_REQ" },
424 { T_EXDATA_REQ, "T_EXDATA_REQ" },
425 { T_INFO_REQ, "T_INFO_REQ" },
426 { T_BIND_REQ, "T_BIND_REQ" },
427 { T_UNBIND_REQ, "T_UNBIND_REQ" },
428 { T_UNITDATA_REQ,"T_UNITDATA_REQ"},
429 { T_OPTMGMT_REQ,"T_OPTMGMT_REQ" },
430 { T_ORDREL_REQ, "T_ORDREL_REQ" },
434 static struct xlat transport_provider_options[] = {
435 { T_CONN_IND, "T_CONN_IND" },
436 { T_CONN_CON, "T_CONN_CON" },
437 { T_DISCON_IND, "T_DISCON_IND" },
438 { T_DATA_IND, "T_DATA_IND" },
439 { T_EXDATA_IND, "T_EXDATA_IND" },
440 { T_INFO_ACK, "T_INFO_ACK" },
441 { T_BIND_ACK, "T_BIND_ACK" },
442 { T_ERROR_ACK, "T_ERROR_ACK" },
443 { T_OK_ACK, "T_OK_ACK" },
444 { T_UNITDATA_IND,"T_UNITDATA_IND"},
445 { T_UDERROR_IND,"T_UDERROR_IND" },
446 { T_OPTMGMT_ACK,"T_OPTMGMT_ACK" },
447 { T_ORDREL_IND, "T_ORDREL_IND" },
453 internal_stream_ioctl(tcp, arg)
461 struct si_udata udata;
462 #endif /* SI_GETUDATA */
466 if (umove(tcp, arg, &si) < 0) {
472 name = ioctl_lookup(si.ic_cmd);
474 tprintf(", {ic_cmd=%s", name);
476 tprintf(", {ic_cmd=%#x", si.ic_cmd);
477 if (si.ic_timout == INFTIM)
478 tprintf(", ic_timout=INFTIM, ");
480 tprintf(" ic_timout=%d, ", si.ic_timout);
488 #endif /* SI_GETUDATA */
492 tprintf("/* in */ ");
494 tprintf(", /* out */ ");
496 if (in_and_out || entering(tcp))
497 tprintf("ic_len=%d, ic_dp=", si.ic_len);
501 /* in T_BIND_REQ, out T_BIND_ACK */
503 struct T_bind_req data;
506 tprintf("struct T_bind_req ");
508 if (umove(tcp, (int) si.ic_dp, &data) < 0)
511 tprintf("{PRIM_type=");
512 printxval(transport_user_options,
513 data.PRIM_type, "T_???");
514 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
515 data.ADDR_length, data.ADDR_offset);
516 tprintf(", CONIND_number=%ld}",
521 struct T_bind_ack data;
524 tprintf("struct T_bind_ack ");
526 if (umove(tcp, (int) si.ic_dp, &data) < 0)
530 tprintf("{PRIM_type=");
531 printxval(transport_provider_options,
532 data.PRIM_type, "T_???");
533 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
534 data.ADDR_length, data.ADDR_offset);
535 tprintf(", CONIND_number=%ld}",
539 (int) si.ic_dp + data.ADDR_offset,
549 /* in T_UNBIND_REQ, out T_OK_ACK */
551 #endif /* TI_UNBIND */
554 /* in T_INFO_REQ, out T_INFO_ACK */
556 #endif /* TI_GETINFO */
559 /* in T_OPTMGMT_REQ, out T_OPTMGMT_ACK */
561 #endif /* TI_OPTMGMT */
568 tprintf("struct si_udata ");
570 if (umove(tcp, (int) si.ic_dp, &udata) < 0)
573 tprintf("{tidusize=%d, addrsize=%d, ",
574 udata.tidusize, udata.addrsize);
575 tprintf("optsize=%d, etsdusize=%d, ",
576 udata.optsize, udata.etsdusize);
577 tprintf("servtype=%d, so_state=%d, ",
578 udata.servtype, udata.so_state);
579 tprintf("so_options=%d", udata.so_options);
581 tprintf(", tsdusize=%d", udata.tsdusize);
586 #endif /* SI_GETUDATA */
588 printstr(tcp, (int) si.ic_dp, si.ic_len);
597 stream_ioctl(tcp, code, arg)
609 struct strfdinsert sfi;
610 struct strrecvfd srf;
615 /* I_STR is a special case because the data is read & written. */
617 return internal_stream_ioctl(tcp, arg);
625 /* arg is a string */
630 /* doesn't take an argument */
633 /* argument is an option */
635 printxval(stream_flush_options, arg, "FLUSH???");
639 /* argument is a pointer to a bandinfo struct */
640 if (umove(tcp, arg, &bi) < 0)
643 tprintf(", {bi_pri=%d, bi_flag=", bi.bi_pri);
644 if (!printflags(stream_flush_options, bi.bi_flag))
649 #endif /* I_FLUSHBAND */
651 /* argument is a set of flags */
653 if (!printflags(stream_setsig_flags, arg))
657 /* argument is a pointer to a set of flags */
661 if (umove(tcp, arg, &val) < 0)
663 else if (!printflags(stream_setsig_flags, val))
668 /* argument is a pointer to a strpeek structure */
669 if (syserror(tcp) || !arg)
671 if (umove(tcp, arg, &sp) < 0) {
675 tprintf(", {ctlbuf=");
676 printstrbuf(tcp, &sp.ctlbuf, 1);
677 tprintf(", databuf=");
678 printstrbuf(tcp, &sp.databuf, 1);
679 if (!printflags(msgflags, sp.flags))
683 /* argument is an option with flags */
685 printxval(stream_read_options, arg & RMODEMASK, "R???");
686 addflags(stream_read_flags, arg & ~RMODEMASK);
689 /* argument is an pointer to an option with flags */
693 if (umove(tcp, arg, &val) < 0)
696 printxval(stream_read_options,
697 arg & RMODEMASK, "R???");
698 addflags(stream_read_flags, arg & ~RMODEMASK);
712 /* argument is a pointer to a decimal integer */
716 printnum(tcp, arg, "%d");
719 /* argument is a pointer to a strfdinsert structure */
720 if (syserror(tcp) || !arg)
722 if (umove(tcp, arg, &sfi) < 0) {
726 tprintf(", {ctlbuf=");
727 printstrbuf(tcp, &sfi.ctlbuf, 1);
728 tprintf(", databuf=");
729 printstrbuf(tcp, &sfi.databuf, 1);
730 if (!printflags(msgflags, sfi.flags))
732 tprintf(", filedes=%d, offset=%d}", sfi.fildes, sfi.offset);
736 /* argument is a set of flags */
738 if (!printflags(stream_write_flags, arg))
741 #endif /* I_SWROPT */
744 /* argument is an pointer to an option with flags */
748 if (umove(tcp, arg, &val) < 0)
750 else if (!printflags(stream_write_flags, arg))
754 #endif /* I_GWROPT */
766 /* argument is a decimal integer */
767 tprintf(", %d", arg);
770 /* argument is a pointer to a strrecvfd structure */
771 if (syserror(tcp) || !arg)
773 if (umove(tcp, arg, &srf) < 0) {
777 tprintf(", {fd=%d, uid=%lu, gid=%lu}", srf.fd,
778 (unsigned long) srf.uid, (unsigned long) srf.gid);
788 if (umove(tcp, arg, &sl) < 0) {
792 tprintf(", {sl_nmods=%d, sl_modlist=[", sl.sl_nmods);
793 for (i = 0; i < tcp->u_rval; i++) {
796 printpath(tcp, (int) sl.sl_modlist[i].l_name);
804 printxval(stream_atmark_options, arg, "???MARK");
806 #endif /* I_ATMARK */
814 #endif /* LINUXSPARC && linux */