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)
36 #ifdef HAVE_SYS_POLL_H
42 int maxlen; /* no. of bytes in buffer */
43 int len; /* no. of bytes returned */
44 char *buf; /* pointer to data */
54 #include <sys/stream.h>
55 #include <sys/tihdr.h>
59 #ifdef HAVE_SYS_TIUSER_H
60 #include <sys/tiuser.h>
61 #include <sys/sockmod.h>
62 #include <sys/timod.h>
63 #endif /* HAVE_SYS_TIUSER_H */
65 static struct xlat msgflags[] = {
66 { RS_HIPRI, "RS_HIPRI" },
72 printstrbuf(tcp, sbp, getting)
77 if (sbp->maxlen == -1 && getting)
78 tprintf("{maxlen=-1}");
82 tprintf("maxlen=%d, ", sbp->maxlen);
83 tprintf("len=%d, buf=", sbp->len);
84 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
90 printstrbufarg(tcp, arg, getting)
99 else if (umove(tcp, arg, &buf) < 0)
102 printstrbuf(tcp, &buf, getting);
114 tprintf("%ld, ", tcp->u_arg[0]);
115 /* control and data */
116 for (i = 1; i < 3; i++)
117 printstrbufarg(tcp, tcp->u_arg[i], 0);
119 if (!printflags(msgflags, tcp->u_arg[3]))
133 tprintf("%lu, ", tcp->u_arg[0]);
136 tprintf("%#lx, %#lx, %#lx",
137 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
140 /* control and data */
141 for (i = 1; i < 3; i++)
142 printstrbufarg(tcp, tcp->u_arg[i], 1);
143 /* pointer to flags */
144 if (tcp->u_arg[3] == 0)
146 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
150 if (!printflags(msgflags, flags))
154 /* decode return value */
155 switch (tcp->u_rval) {
157 tcp->auxstr = "MORECTL";
159 case MORECTL|MOREDATA:
160 tcp->auxstr = "MORECTL|MOREDATA";
163 tcp->auxstr = "MORECTL";
170 return RVAL_HEX | RVAL_STR;
175 static struct xlat pmsgflags[] = {
176 { MSG_HIPRI, "MSG_HIPRI" },
177 { MSG_ANY, "MSG_ANY" },
178 { MSG_BAND, "MSG_BAND" },
190 tprintf("%ld, ", tcp->u_arg[0]);
191 /* control and data */
192 for (i = 1; i < 3; i++)
193 printstrbufarg(tcp, tcp->u_arg[i], 0);
195 tprintf("%ld, ", tcp->u_arg[3]);
197 if (!printflags(pmsgflags, tcp->u_arg[4]))
211 tprintf("%lu, ", tcp->u_arg[0]);
214 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
215 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
218 /* control and data */
219 for (i = 1; i < 3; i++)
220 printstrbufarg(tcp, tcp->u_arg[i], 1);
221 /* pointer to band */
222 printnum(tcp, tcp->u_arg[3], "%d");
224 /* pointer to flags */
225 if (tcp->u_arg[4] == 0)
227 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
231 if (!printflags(pmsgflags, flags))
235 /* decode return value */
236 switch (tcp->u_rval) {
238 tcp->auxstr = "MORECTL";
240 case MORECTL|MOREDATA:
241 tcp->auxstr = "MORECTL|MOREDATA";
244 tcp->auxstr = "MORECTL";
251 return RVAL_HEX | RVAL_STR;
254 #endif /* HAVE_PUTPMSG */
257 static struct xlat pollflags[] = {
259 { POLLIN, "POLLIN" },
260 { POLLPRI, "POLLPRI" },
261 { POLLOUT, "POLLOUT" },
263 { POLLRDNORM, "POLLRDNORM" },
266 { POLLWRNORM, "POLLWRNORM" },
269 { POLLRDBAND, "POLLRDBAND" },
272 { POLLWRBAND, "POLLWRBAND" },
274 { POLLERR, "POLLERR" },
275 { POLLHUP, "POLLHUP" },
276 { POLLNVAL, "POLLNVAL" },
285 struct pollfd *pollp;
287 #ifdef HAVE_SYS_POLL_H
290 int nfds = tcp->u_arg[1];
293 tprintf("%#lx, %d, %ld\n",
294 tcp->u_arg[0], nfds, tcp->u_arg[2]);
297 pollp = (struct pollfd *) malloc(nfds * sizeof(*pollp));
299 fprintf(stderr, "sys_poll: no memory\n");
300 tprintf("%#lx, %d, %ld",
301 tcp->u_arg[0], nfds, tcp->u_arg[2]);
304 if (umoven(tcp, tcp->u_arg[0],
305 (nfds * sizeof(*pollp)), (char *) pollp) < 0) {
306 tprintf("%#lx", tcp->u_arg[0]);
310 for (i = 0; i < nfds; i++) {
313 if (pollp[i].fd < 0) {
314 tprintf("{fd=%d}", pollp[i].fd);
317 tprintf("{fd=%d, events=", pollp[i].fd);
318 if (!printflags(pollflags, pollp[i].events))
320 if (!syserror(tcp) && pollp[i].revents) {
321 tprintf(", revents=");
322 if (!printflags(pollflags,
330 tprintf(", %d, ", nfds);
332 if (tcp->u_arg[2] == INFTIM)
336 tprintf("%ld", tcp->u_arg[2]);
345 static struct xlat stream_flush_options[] = {
346 { FLUSHR, "FLUSHR" },
347 { FLUSHW, "FLUSHW" },
348 { FLUSHRW, "FLUSHRW" },
350 { FLUSHBAND, "FLUSHBAND" },
355 static struct xlat stream_setsig_flags[] = {
356 { S_INPUT, "S_INPUT" },
357 { S_HIPRI, "S_HIPRI" },
358 { S_OUTPUT, "S_OUTPUT" },
361 { S_ERROR, "S_ERROR" },
364 { S_HANGUP, "S_HANGUP" },
367 { S_RDNORM, "S_RDNORM" },
370 { S_WRNORM, "S_WRNORM" },
373 { S_RDBAND, "S_RDBAND" },
376 { S_WRBAND, "S_WRBAND" },
379 { S_BANDURG, "S_BANDURG" },
384 static struct xlat stream_read_options[] = {
391 static struct xlat stream_read_flags[] = {
393 { RPROTDAT, "RPROTDAT" },
396 { RPROTDIS, "RPROTDIS" },
399 { RPROTNORM, "RPROTNORM" },
405 #define RMODEMASK (~0)
409 static struct xlat stream_write_flags[] = {
410 { SNDZERO, "SNDZERO" },
411 { SNDPIPE, "SNDPIPE" },
414 #endif /* I_SWROPT */
417 static struct xlat stream_atmark_options[] = {
418 { ANYMARK, "ANYMARK" },
419 { LASTMARK, "LASTMARK" },
422 #endif /* I_ATMARK */
425 static struct xlat transport_user_options[] = {
426 { T_CONN_REQ, "T_CONN_REQ" },
427 { T_CONN_RES, "T_CONN_RES" },
428 { T_DISCON_REQ, "T_DISCON_REQ" },
429 { T_DATA_REQ, "T_DATA_REQ" },
430 { T_EXDATA_REQ, "T_EXDATA_REQ" },
431 { T_INFO_REQ, "T_INFO_REQ" },
432 { T_BIND_REQ, "T_BIND_REQ" },
433 { T_UNBIND_REQ, "T_UNBIND_REQ" },
434 { T_UNITDATA_REQ,"T_UNITDATA_REQ"},
435 { T_OPTMGMT_REQ,"T_OPTMGMT_REQ" },
436 { T_ORDREL_REQ, "T_ORDREL_REQ" },
440 static struct xlat transport_provider_options[] = {
441 { T_CONN_IND, "T_CONN_IND" },
442 { T_CONN_CON, "T_CONN_CON" },
443 { T_DISCON_IND, "T_DISCON_IND" },
444 { T_DATA_IND, "T_DATA_IND" },
445 { T_EXDATA_IND, "T_EXDATA_IND" },
446 { T_INFO_ACK, "T_INFO_ACK" },
447 { T_BIND_ACK, "T_BIND_ACK" },
448 { T_ERROR_ACK, "T_ERROR_ACK" },
449 { T_OK_ACK, "T_OK_ACK" },
450 { T_UNITDATA_IND,"T_UNITDATA_IND"},
451 { T_UDERROR_IND,"T_UDERROR_IND" },
452 { T_OPTMGMT_ACK,"T_OPTMGMT_ACK" },
453 { T_ORDREL_IND, "T_ORDREL_IND" },
459 internal_stream_ioctl(tcp, arg)
467 struct si_udata udata;
468 #endif /* SI_GETUDATA */
472 if (umove(tcp, arg, &si) < 0) {
478 name = ioctl_lookup(si.ic_cmd);
480 tprintf(", {ic_cmd=%s", name);
482 tprintf(", {ic_cmd=%#x", si.ic_cmd);
483 if (si.ic_timout == INFTIM)
484 tprintf(", ic_timout=INFTIM, ");
486 tprintf(" ic_timout=%d, ", si.ic_timout);
494 #endif /* SI_GETUDATA */
498 tprintf("/* in */ ");
500 tprintf(", /* out */ ");
502 if (in_and_out || entering(tcp))
503 tprintf("ic_len=%d, ic_dp=", si.ic_len);
507 /* in T_BIND_REQ, out T_BIND_ACK */
509 struct T_bind_req data;
512 tprintf("struct T_bind_req ");
514 if (umove(tcp, (int) si.ic_dp, &data) < 0)
517 tprintf("{PRIM_type=");
518 printxval(transport_user_options,
519 data.PRIM_type, "T_???");
520 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
521 data.ADDR_length, data.ADDR_offset);
522 tprintf(", CONIND_number=%ld}",
527 struct T_bind_ack data;
530 tprintf("struct T_bind_ack ");
532 if (umove(tcp, (int) si.ic_dp, &data) < 0)
536 tprintf("{PRIM_type=");
537 printxval(transport_provider_options,
538 data.PRIM_type, "T_???");
539 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
540 data.ADDR_length, data.ADDR_offset);
541 tprintf(", CONIND_number=%ld}",
545 (int) si.ic_dp + data.ADDR_offset,
555 /* in T_UNBIND_REQ, out T_OK_ACK */
557 #endif /* TI_UNBIND */
560 /* in T_INFO_REQ, out T_INFO_ACK */
562 #endif /* TI_GETINFO */
565 /* in T_OPTMGMT_REQ, out T_OPTMGMT_ACK */
567 #endif /* TI_OPTMGMT */
574 tprintf("struct si_udata ");
576 if (umove(tcp, (int) si.ic_dp, &udata) < 0)
579 tprintf("{tidusize=%d, addrsize=%d, ",
580 udata.tidusize, udata.addrsize);
581 tprintf("optsize=%d, etsdusize=%d, ",
582 udata.optsize, udata.etsdusize);
583 tprintf("servtype=%d, so_state=%d, ",
584 udata.servtype, udata.so_state);
585 tprintf("so_options=%d", udata.so_options);
587 tprintf(", tsdusize=%d", udata.tsdusize);
592 #endif /* SI_GETUDATA */
594 printstr(tcp, (int) si.ic_dp, si.ic_len);
603 stream_ioctl(tcp, code, arg)
615 struct strfdinsert sfi;
616 struct strrecvfd srf;
621 /* I_STR is a special case because the data is read & written. */
623 return internal_stream_ioctl(tcp, arg);
631 /* arg is a string */
636 /* doesn't take an argument */
639 /* argument is an option */
641 printxval(stream_flush_options, arg, "FLUSH???");
645 /* argument is a pointer to a bandinfo struct */
646 if (umove(tcp, arg, &bi) < 0)
649 tprintf(", {bi_pri=%d, bi_flag=", bi.bi_pri);
650 if (!printflags(stream_flush_options, bi.bi_flag))
655 #endif /* I_FLUSHBAND */
657 /* argument is a set of flags */
659 if (!printflags(stream_setsig_flags, arg))
663 /* argument is a pointer to a set of flags */
667 if (umove(tcp, arg, &val) < 0)
669 else if (!printflags(stream_setsig_flags, val))
674 /* argument is a pointer to a strpeek structure */
675 if (syserror(tcp) || !arg)
677 if (umove(tcp, arg, &sp) < 0) {
681 tprintf(", {ctlbuf=");
682 printstrbuf(tcp, &sp.ctlbuf, 1);
683 tprintf(", databuf=");
684 printstrbuf(tcp, &sp.databuf, 1);
685 if (!printflags(msgflags, sp.flags))
689 /* argument is an option with flags */
691 printxval(stream_read_options, arg & RMODEMASK, "R???");
692 addflags(stream_read_flags, arg & ~RMODEMASK);
695 /* argument is an pointer to an option with flags */
699 if (umove(tcp, arg, &val) < 0)
702 printxval(stream_read_options,
703 arg & RMODEMASK, "R???");
704 addflags(stream_read_flags, arg & ~RMODEMASK);
718 /* argument is a pointer to a decimal integer */
722 printnum(tcp, arg, "%d");
725 /* argument is a pointer to a strfdinsert structure */
726 if (syserror(tcp) || !arg)
728 if (umove(tcp, arg, &sfi) < 0) {
732 tprintf(", {ctlbuf=");
733 printstrbuf(tcp, &sfi.ctlbuf, 1);
734 tprintf(", databuf=");
735 printstrbuf(tcp, &sfi.databuf, 1);
736 if (!printflags(msgflags, sfi.flags))
738 tprintf(", filedes=%d, offset=%d}", sfi.fildes, sfi.offset);
742 /* argument is a set of flags */
744 if (!printflags(stream_write_flags, arg))
747 #endif /* I_SWROPT */
750 /* argument is an pointer to an option with flags */
754 if (umove(tcp, arg, &val) < 0)
756 else if (!printflags(stream_write_flags, arg))
760 #endif /* I_GWROPT */
772 /* argument is a decimal integer */
773 tprintf(", %d", arg);
776 /* argument is a pointer to a strrecvfd structure */
777 if (syserror(tcp) || !arg)
779 if (umove(tcp, arg, &srf) < 0) {
783 tprintf(", {fd=%d, uid=%lu, gid=%lu}", srf.fd,
784 (unsigned long) srf.uid, (unsigned long) srf.gid);
794 if (umove(tcp, arg, &sl) < 0) {
798 tprintf(", {sl_nmods=%d, sl_modlist=[", sl.sl_nmods);
799 for (i = 0; i < tcp->u_rval; i++) {
802 printpath(tcp, (int) sl.sl_modlist[i].l_name);
810 printxval(stream_atmark_options, arg, "???MARK");
812 #endif /* I_ATMARK */
820 #endif /* LINUXSPARC && linux */