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) || defined(FREEBSD)
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 */
55 #include <sys/stream.h>
56 #include <sys/tihdr.h>
63 #ifdef HAVE_SYS_TIUSER_H
64 #include <sys/tiuser.h>
65 #include <sys/sockmod.h>
66 #include <sys/timod.h>
67 #endif /* HAVE_SYS_TIUSER_H */
70 static struct xlat msgflags[] = {
71 { RS_HIPRI, "RS_HIPRI" },
77 printstrbuf(tcp, sbp, getting)
82 if (sbp->maxlen == -1 && getting)
83 tprintf("{maxlen=-1}");
87 tprintf("maxlen=%d, ", sbp->maxlen);
88 tprintf("len=%d, buf=", sbp->len);
89 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
95 printstrbufarg(tcp, arg, getting)
104 else if (umove(tcp, arg, &buf) < 0)
107 printstrbuf(tcp, &buf, getting);
119 tprintf("%ld, ", tcp->u_arg[0]);
120 /* control and data */
121 for (i = 1; i < 3; i++)
122 printstrbufarg(tcp, tcp->u_arg[i], 0);
124 if (!printflags(msgflags, tcp->u_arg[3]))
138 tprintf("%lu, ", tcp->u_arg[0]);
141 tprintf("%#lx, %#lx, %#lx",
142 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
145 /* control and data */
146 for (i = 1; i < 3; i++)
147 printstrbufarg(tcp, tcp->u_arg[i], 1);
148 /* pointer to flags */
149 if (tcp->u_arg[3] == 0)
151 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
155 if (!printflags(msgflags, flags))
159 /* decode return value */
160 switch (tcp->u_rval) {
162 tcp->auxstr = "MORECTL";
164 case MORECTL|MOREDATA:
165 tcp->auxstr = "MORECTL|MOREDATA";
168 tcp->auxstr = "MORECTL";
175 return RVAL_HEX | RVAL_STR;
180 static struct xlat pmsgflags[] = {
182 { MSG_HIPRI, "MSG_HIPRI" },
185 { MSG_ANY, "MSG_ANY" },
188 { MSG_BAND, "MSG_BAND" },
201 tprintf("%ld, ", tcp->u_arg[0]);
202 /* control and data */
203 for (i = 1; i < 3; i++)
204 printstrbufarg(tcp, tcp->u_arg[i], 0);
206 tprintf("%ld, ", tcp->u_arg[3]);
208 if (!printflags(pmsgflags, tcp->u_arg[4]))
222 tprintf("%lu, ", tcp->u_arg[0]);
225 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
226 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
229 /* control and data */
230 for (i = 1; i < 3; i++)
231 printstrbufarg(tcp, tcp->u_arg[i], 1);
232 /* pointer to band */
233 printnum(tcp, tcp->u_arg[3], "%d");
235 /* pointer to flags */
236 if (tcp->u_arg[4] == 0)
238 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
242 if (!printflags(pmsgflags, flags))
246 /* decode return value */
247 switch (tcp->u_rval) {
249 tcp->auxstr = "MORECTL";
251 case MORECTL|MOREDATA:
252 tcp->auxstr = "MORECTL|MOREDATA";
255 tcp->auxstr = "MORECTL";
262 return RVAL_HEX | RVAL_STR;
265 #endif /* HAVE_PUTPMSG */
266 #endif /* !FREEBSD */
269 #ifdef HAVE_SYS_POLL_H
271 static struct xlat pollflags[] = {
273 { POLLIN, "POLLIN" },
274 { POLLPRI, "POLLPRI" },
275 { POLLOUT, "POLLOUT" },
277 { POLLRDNORM, "POLLRDNORM" },
280 { POLLWRNORM, "POLLWRNORM" },
283 { POLLRDBAND, "POLLRDBAND" },
286 { POLLWRBAND, "POLLWRBAND" },
288 { POLLERR, "POLLERR" },
289 { POLLHUP, "POLLHUP" },
290 { POLLNVAL, "POLLNVAL" },
299 struct pollfd *pollp;
303 int nfds = tcp->u_arg[1];
306 tprintf("%#lx, %d, %ld\n",
307 tcp->u_arg[0], nfds, tcp->u_arg[2]);
310 pollp = (struct pollfd *) malloc(nfds * sizeof(*pollp));
312 fprintf(stderr, "sys_poll: no memory\n");
313 tprintf("%#lx, %d, %ld",
314 tcp->u_arg[0], nfds, tcp->u_arg[2]);
317 if (umoven(tcp, tcp->u_arg[0],
318 (nfds * sizeof(*pollp)), (char *) pollp) < 0) {
319 tprintf("%#lx", tcp->u_arg[0]);
323 for (i = 0; i < nfds; i++) {
326 if (pollp[i].fd < 0) {
327 tprintf("{fd=%d}", pollp[i].fd);
330 tprintf("{fd=%d, events=", pollp[i].fd);
331 if (!printflags(pollflags, pollp[i].events))
333 if (!syserror(tcp) && pollp[i].revents) {
334 tprintf(", revents=");
335 if (!printflags(pollflags,
343 tprintf(", %d, ", nfds);
345 if (tcp->u_arg[2] == INFTIM)
349 tprintf("%ld", tcp->u_arg[2]);
355 #else /* !HAVE_SYS_POLL_H */
364 #if !defined(linux) && !defined(FREEBSD)
366 static struct xlat stream_flush_options[] = {
367 { FLUSHR, "FLUSHR" },
368 { FLUSHW, "FLUSHW" },
369 { FLUSHRW, "FLUSHRW" },
371 { FLUSHBAND, "FLUSHBAND" },
376 static struct xlat stream_setsig_flags[] = {
377 { S_INPUT, "S_INPUT" },
378 { S_HIPRI, "S_HIPRI" },
379 { S_OUTPUT, "S_OUTPUT" },
382 { S_ERROR, "S_ERROR" },
385 { S_HANGUP, "S_HANGUP" },
388 { S_RDNORM, "S_RDNORM" },
391 { S_WRNORM, "S_WRNORM" },
394 { S_RDBAND, "S_RDBAND" },
397 { S_WRBAND, "S_WRBAND" },
400 { S_BANDURG, "S_BANDURG" },
405 static struct xlat stream_read_options[] = {
412 static struct xlat stream_read_flags[] = {
414 { RPROTDAT, "RPROTDAT" },
417 { RPROTDIS, "RPROTDIS" },
420 { RPROTNORM, "RPROTNORM" },
426 #define RMODEMASK (~0)
430 static struct xlat stream_write_flags[] = {
431 { SNDZERO, "SNDZERO" },
432 { SNDPIPE, "SNDPIPE" },
435 #endif /* I_SWROPT */
438 static struct xlat stream_atmark_options[] = {
439 { ANYMARK, "ANYMARK" },
440 { LASTMARK, "LASTMARK" },
443 #endif /* I_ATMARK */
446 static struct xlat transport_user_options[] = {
447 { T_CONN_REQ, "T_CONN_REQ" },
448 { T_CONN_RES, "T_CONN_RES" },
449 { T_DISCON_REQ, "T_DISCON_REQ" },
450 { T_DATA_REQ, "T_DATA_REQ" },
451 { T_EXDATA_REQ, "T_EXDATA_REQ" },
452 { T_INFO_REQ, "T_INFO_REQ" },
453 { T_BIND_REQ, "T_BIND_REQ" },
454 { T_UNBIND_REQ, "T_UNBIND_REQ" },
455 { T_UNITDATA_REQ,"T_UNITDATA_REQ"},
456 { T_OPTMGMT_REQ,"T_OPTMGMT_REQ" },
457 { T_ORDREL_REQ, "T_ORDREL_REQ" },
461 static struct xlat transport_provider_options[] = {
462 { T_CONN_IND, "T_CONN_IND" },
463 { T_CONN_CON, "T_CONN_CON" },
464 { T_DISCON_IND, "T_DISCON_IND" },
465 { T_DATA_IND, "T_DATA_IND" },
466 { T_EXDATA_IND, "T_EXDATA_IND" },
467 { T_INFO_ACK, "T_INFO_ACK" },
468 { T_BIND_ACK, "T_BIND_ACK" },
469 { T_ERROR_ACK, "T_ERROR_ACK" },
470 { T_OK_ACK, "T_OK_ACK" },
471 { T_UNITDATA_IND,"T_UNITDATA_IND"},
472 { T_UDERROR_IND,"T_UDERROR_IND" },
473 { T_OPTMGMT_ACK,"T_OPTMGMT_ACK" },
474 { T_ORDREL_IND, "T_ORDREL_IND" },
480 internal_stream_ioctl(tcp, arg)
488 struct si_udata udata;
489 #endif /* SI_GETUDATA */
493 if (umove(tcp, arg, &si) < 0) {
499 name = ioctl_lookup(si.ic_cmd);
501 tprintf(", {ic_cmd=%s", name);
503 tprintf(", {ic_cmd=%#x", si.ic_cmd);
504 if (si.ic_timout == INFTIM)
505 tprintf(", ic_timout=INFTIM, ");
507 tprintf(" ic_timout=%d, ", si.ic_timout);
515 #endif /* SI_GETUDATA */
519 tprintf("/* in */ ");
521 tprintf(", /* out */ ");
523 if (in_and_out || entering(tcp))
524 tprintf("ic_len=%d, ic_dp=", si.ic_len);
528 /* in T_BIND_REQ, out T_BIND_ACK */
530 struct T_bind_req data;
533 tprintf("struct T_bind_req ");
535 if (umove(tcp, (int) si.ic_dp, &data) < 0)
538 tprintf("{PRIM_type=");
539 printxval(transport_user_options,
540 data.PRIM_type, "T_???");
541 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
542 data.ADDR_length, data.ADDR_offset);
543 tprintf(", CONIND_number=%ld}",
548 struct T_bind_ack data;
551 tprintf("struct T_bind_ack ");
553 if (umove(tcp, (int) si.ic_dp, &data) < 0)
557 tprintf("{PRIM_type=");
558 printxval(transport_provider_options,
559 data.PRIM_type, "T_???");
560 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
561 data.ADDR_length, data.ADDR_offset);
562 tprintf(", CONIND_number=%ld}",
566 (int) si.ic_dp + data.ADDR_offset,
576 /* in T_UNBIND_REQ, out T_OK_ACK */
578 #endif /* TI_UNBIND */
581 /* in T_INFO_REQ, out T_INFO_ACK */
583 #endif /* TI_GETINFO */
586 /* in T_OPTMGMT_REQ, out T_OPTMGMT_ACK */
588 #endif /* TI_OPTMGMT */
595 tprintf("struct si_udata ");
597 if (umove(tcp, (int) si.ic_dp, &udata) < 0)
600 tprintf("{tidusize=%d, addrsize=%d, ",
601 udata.tidusize, udata.addrsize);
602 tprintf("optsize=%d, etsdusize=%d, ",
603 udata.optsize, udata.etsdusize);
604 tprintf("servtype=%d, so_state=%d, ",
605 udata.servtype, udata.so_state);
606 tprintf("so_options=%d", udata.so_options);
608 tprintf(", tsdusize=%d", udata.tsdusize);
613 #endif /* SI_GETUDATA */
615 printstr(tcp, (int) si.ic_dp, si.ic_len);
624 stream_ioctl(tcp, code, arg)
636 struct strfdinsert sfi;
637 struct strrecvfd srf;
642 /* I_STR is a special case because the data is read & written. */
644 return internal_stream_ioctl(tcp, arg);
652 /* arg is a string */
657 /* doesn't take an argument */
660 /* argument is an option */
662 printxval(stream_flush_options, arg, "FLUSH???");
666 /* argument is a pointer to a bandinfo struct */
667 if (umove(tcp, arg, &bi) < 0)
670 tprintf(", {bi_pri=%d, bi_flag=", bi.bi_pri);
671 if (!printflags(stream_flush_options, bi.bi_flag))
676 #endif /* I_FLUSHBAND */
678 /* argument is a set of flags */
680 if (!printflags(stream_setsig_flags, arg))
684 /* argument is a pointer to a set of flags */
688 if (umove(tcp, arg, &val) < 0)
690 else if (!printflags(stream_setsig_flags, val))
695 /* argument is a pointer to a strpeek structure */
696 if (syserror(tcp) || !arg)
698 if (umove(tcp, arg, &sp) < 0) {
702 tprintf(", {ctlbuf=");
703 printstrbuf(tcp, &sp.ctlbuf, 1);
704 tprintf(", databuf=");
705 printstrbuf(tcp, &sp.databuf, 1);
706 if (!printflags(msgflags, sp.flags))
710 /* argument is an option with flags */
712 printxval(stream_read_options, arg & RMODEMASK, "R???");
713 addflags(stream_read_flags, arg & ~RMODEMASK);
716 /* argument is an pointer to an option with flags */
720 if (umove(tcp, arg, &val) < 0)
723 printxval(stream_read_options,
724 arg & RMODEMASK, "R???");
725 addflags(stream_read_flags, arg & ~RMODEMASK);
739 /* argument is a pointer to a decimal integer */
743 printnum(tcp, arg, "%d");
746 /* argument is a pointer to a strfdinsert structure */
747 if (syserror(tcp) || !arg)
749 if (umove(tcp, arg, &sfi) < 0) {
753 tprintf(", {ctlbuf=");
754 printstrbuf(tcp, &sfi.ctlbuf, 1);
755 tprintf(", databuf=");
756 printstrbuf(tcp, &sfi.databuf, 1);
757 if (!printflags(msgflags, sfi.flags))
759 tprintf(", filedes=%d, offset=%d}", sfi.fildes, sfi.offset);
763 /* argument is a set of flags */
765 if (!printflags(stream_write_flags, arg))
768 #endif /* I_SWROPT */
771 /* argument is an pointer to an option with flags */
775 if (umove(tcp, arg, &val) < 0)
777 else if (!printflags(stream_write_flags, arg))
781 #endif /* I_GWROPT */
793 /* argument is a decimal integer */
794 tprintf(", %d", arg);
797 /* argument is a pointer to a strrecvfd structure */
798 if (syserror(tcp) || !arg)
800 if (umove(tcp, arg, &srf) < 0) {
804 tprintf(", {fd=%d, uid=%lu, gid=%lu}", srf.fd,
805 (unsigned long) srf.uid, (unsigned long) srf.gid);
815 if (umove(tcp, arg, &sl) < 0) {
819 tprintf(", {sl_nmods=%d, sl_modlist=[", sl.sl_nmods);
820 for (i = 0; i < tcp->u_rval; i++) {
823 printpath(tcp, (int) sl.sl_modlist[i].l_name);
831 printxval(stream_atmark_options, arg, "???MARK");
833 #endif /* I_ATMARK */
839 #endif /* !linux && !FREEBSD */
841 #endif /* HAVE_SYS_STREAM_H || linux || FREEBSD */