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[] = {
181 { MSG_HIPRI, "MSG_HIPRI" },
182 { MSG_ANY, "MSG_ANY" },
183 { MSG_BAND, "MSG_BAND" },
195 tprintf("%ld, ", tcp->u_arg[0]);
196 /* control and data */
197 for (i = 1; i < 3; i++)
198 printstrbufarg(tcp, tcp->u_arg[i], 0);
200 tprintf("%ld, ", tcp->u_arg[3]);
202 if (!printflags(pmsgflags, tcp->u_arg[4]))
216 tprintf("%lu, ", tcp->u_arg[0]);
219 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
220 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
223 /* control and data */
224 for (i = 1; i < 3; i++)
225 printstrbufarg(tcp, tcp->u_arg[i], 1);
226 /* pointer to band */
227 printnum(tcp, tcp->u_arg[3], "%d");
229 /* pointer to flags */
230 if (tcp->u_arg[4] == 0)
232 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
236 if (!printflags(pmsgflags, flags))
240 /* decode return value */
241 switch (tcp->u_rval) {
243 tcp->auxstr = "MORECTL";
245 case MORECTL|MOREDATA:
246 tcp->auxstr = "MORECTL|MOREDATA";
249 tcp->auxstr = "MORECTL";
256 return RVAL_HEX | RVAL_STR;
259 #endif /* HAVE_PUTPMSG */
260 #endif /* !FREEBSD */
263 #ifdef HAVE_SYS_POLL_H
265 static struct xlat pollflags[] = {
267 { POLLIN, "POLLIN" },
268 { POLLPRI, "POLLPRI" },
269 { POLLOUT, "POLLOUT" },
271 { POLLRDNORM, "POLLRDNORM" },
274 { POLLWRNORM, "POLLWRNORM" },
277 { POLLRDBAND, "POLLRDBAND" },
280 { POLLWRBAND, "POLLWRBAND" },
282 { POLLERR, "POLLERR" },
283 { POLLHUP, "POLLHUP" },
284 { POLLNVAL, "POLLNVAL" },
293 struct pollfd *pollp;
297 int nfds = tcp->u_arg[1];
300 tprintf("%#lx, %d, %ld\n",
301 tcp->u_arg[0], nfds, tcp->u_arg[2]);
304 pollp = (struct pollfd *) malloc(nfds * sizeof(*pollp));
306 fprintf(stderr, "sys_poll: no memory\n");
307 tprintf("%#lx, %d, %ld",
308 tcp->u_arg[0], nfds, tcp->u_arg[2]);
311 if (umoven(tcp, tcp->u_arg[0],
312 (nfds * sizeof(*pollp)), (char *) pollp) < 0) {
313 tprintf("%#lx", tcp->u_arg[0]);
317 for (i = 0; i < nfds; i++) {
320 if (pollp[i].fd < 0) {
321 tprintf("{fd=%d}", pollp[i].fd);
324 tprintf("{fd=%d, events=", pollp[i].fd);
325 if (!printflags(pollflags, pollp[i].events))
327 if (!syserror(tcp) && pollp[i].revents) {
328 tprintf(", revents=");
329 if (!printflags(pollflags,
337 tprintf(", %d, ", nfds);
339 if (tcp->u_arg[2] == INFTIM)
343 tprintf("%ld", tcp->u_arg[2]);
349 #else /* !HAVE_SYS_POLL_H */
358 #if !defined(linux) && !defined(FREEBSD)
360 static struct xlat stream_flush_options[] = {
361 { FLUSHR, "FLUSHR" },
362 { FLUSHW, "FLUSHW" },
363 { FLUSHRW, "FLUSHRW" },
365 { FLUSHBAND, "FLUSHBAND" },
370 static struct xlat stream_setsig_flags[] = {
371 { S_INPUT, "S_INPUT" },
372 { S_HIPRI, "S_HIPRI" },
373 { S_OUTPUT, "S_OUTPUT" },
376 { S_ERROR, "S_ERROR" },
379 { S_HANGUP, "S_HANGUP" },
382 { S_RDNORM, "S_RDNORM" },
385 { S_WRNORM, "S_WRNORM" },
388 { S_RDBAND, "S_RDBAND" },
391 { S_WRBAND, "S_WRBAND" },
394 { S_BANDURG, "S_BANDURG" },
399 static struct xlat stream_read_options[] = {
406 static struct xlat stream_read_flags[] = {
408 { RPROTDAT, "RPROTDAT" },
411 { RPROTDIS, "RPROTDIS" },
414 { RPROTNORM, "RPROTNORM" },
420 #define RMODEMASK (~0)
424 static struct xlat stream_write_flags[] = {
425 { SNDZERO, "SNDZERO" },
426 { SNDPIPE, "SNDPIPE" },
429 #endif /* I_SWROPT */
432 static struct xlat stream_atmark_options[] = {
433 { ANYMARK, "ANYMARK" },
434 { LASTMARK, "LASTMARK" },
437 #endif /* I_ATMARK */
440 static struct xlat transport_user_options[] = {
441 { T_CONN_REQ, "T_CONN_REQ" },
442 { T_CONN_RES, "T_CONN_RES" },
443 { T_DISCON_REQ, "T_DISCON_REQ" },
444 { T_DATA_REQ, "T_DATA_REQ" },
445 { T_EXDATA_REQ, "T_EXDATA_REQ" },
446 { T_INFO_REQ, "T_INFO_REQ" },
447 { T_BIND_REQ, "T_BIND_REQ" },
448 { T_UNBIND_REQ, "T_UNBIND_REQ" },
449 { T_UNITDATA_REQ,"T_UNITDATA_REQ"},
450 { T_OPTMGMT_REQ,"T_OPTMGMT_REQ" },
451 { T_ORDREL_REQ, "T_ORDREL_REQ" },
455 static struct xlat transport_provider_options[] = {
456 { T_CONN_IND, "T_CONN_IND" },
457 { T_CONN_CON, "T_CONN_CON" },
458 { T_DISCON_IND, "T_DISCON_IND" },
459 { T_DATA_IND, "T_DATA_IND" },
460 { T_EXDATA_IND, "T_EXDATA_IND" },
461 { T_INFO_ACK, "T_INFO_ACK" },
462 { T_BIND_ACK, "T_BIND_ACK" },
463 { T_ERROR_ACK, "T_ERROR_ACK" },
464 { T_OK_ACK, "T_OK_ACK" },
465 { T_UNITDATA_IND,"T_UNITDATA_IND"},
466 { T_UDERROR_IND,"T_UDERROR_IND" },
467 { T_OPTMGMT_ACK,"T_OPTMGMT_ACK" },
468 { T_ORDREL_IND, "T_ORDREL_IND" },
474 internal_stream_ioctl(tcp, arg)
482 struct si_udata udata;
483 #endif /* SI_GETUDATA */
487 if (umove(tcp, arg, &si) < 0) {
493 name = ioctl_lookup(si.ic_cmd);
495 tprintf(", {ic_cmd=%s", name);
497 tprintf(", {ic_cmd=%#x", si.ic_cmd);
498 if (si.ic_timout == INFTIM)
499 tprintf(", ic_timout=INFTIM, ");
501 tprintf(" ic_timout=%d, ", si.ic_timout);
509 #endif /* SI_GETUDATA */
513 tprintf("/* in */ ");
515 tprintf(", /* out */ ");
517 if (in_and_out || entering(tcp))
518 tprintf("ic_len=%d, ic_dp=", si.ic_len);
522 /* in T_BIND_REQ, out T_BIND_ACK */
524 struct T_bind_req data;
527 tprintf("struct T_bind_req ");
529 if (umove(tcp, (int) si.ic_dp, &data) < 0)
532 tprintf("{PRIM_type=");
533 printxval(transport_user_options,
534 data.PRIM_type, "T_???");
535 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
536 data.ADDR_length, data.ADDR_offset);
537 tprintf(", CONIND_number=%ld}",
542 struct T_bind_ack data;
545 tprintf("struct T_bind_ack ");
547 if (umove(tcp, (int) si.ic_dp, &data) < 0)
551 tprintf("{PRIM_type=");
552 printxval(transport_provider_options,
553 data.PRIM_type, "T_???");
554 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
555 data.ADDR_length, data.ADDR_offset);
556 tprintf(", CONIND_number=%ld}",
560 (int) si.ic_dp + data.ADDR_offset,
570 /* in T_UNBIND_REQ, out T_OK_ACK */
572 #endif /* TI_UNBIND */
575 /* in T_INFO_REQ, out T_INFO_ACK */
577 #endif /* TI_GETINFO */
580 /* in T_OPTMGMT_REQ, out T_OPTMGMT_ACK */
582 #endif /* TI_OPTMGMT */
589 tprintf("struct si_udata ");
591 if (umove(tcp, (int) si.ic_dp, &udata) < 0)
594 tprintf("{tidusize=%d, addrsize=%d, ",
595 udata.tidusize, udata.addrsize);
596 tprintf("optsize=%d, etsdusize=%d, ",
597 udata.optsize, udata.etsdusize);
598 tprintf("servtype=%d, so_state=%d, ",
599 udata.servtype, udata.so_state);
600 tprintf("so_options=%d", udata.so_options);
602 tprintf(", tsdusize=%d", udata.tsdusize);
607 #endif /* SI_GETUDATA */
609 printstr(tcp, (int) si.ic_dp, si.ic_len);
618 stream_ioctl(tcp, code, arg)
630 struct strfdinsert sfi;
631 struct strrecvfd srf;
636 /* I_STR is a special case because the data is read & written. */
638 return internal_stream_ioctl(tcp, arg);
646 /* arg is a string */
651 /* doesn't take an argument */
654 /* argument is an option */
656 printxval(stream_flush_options, arg, "FLUSH???");
660 /* argument is a pointer to a bandinfo struct */
661 if (umove(tcp, arg, &bi) < 0)
664 tprintf(", {bi_pri=%d, bi_flag=", bi.bi_pri);
665 if (!printflags(stream_flush_options, bi.bi_flag))
670 #endif /* I_FLUSHBAND */
672 /* argument is a set of flags */
674 if (!printflags(stream_setsig_flags, arg))
678 /* argument is a pointer to a set of flags */
682 if (umove(tcp, arg, &val) < 0)
684 else if (!printflags(stream_setsig_flags, val))
689 /* argument is a pointer to a strpeek structure */
690 if (syserror(tcp) || !arg)
692 if (umove(tcp, arg, &sp) < 0) {
696 tprintf(", {ctlbuf=");
697 printstrbuf(tcp, &sp.ctlbuf, 1);
698 tprintf(", databuf=");
699 printstrbuf(tcp, &sp.databuf, 1);
700 if (!printflags(msgflags, sp.flags))
704 /* argument is an option with flags */
706 printxval(stream_read_options, arg & RMODEMASK, "R???");
707 addflags(stream_read_flags, arg & ~RMODEMASK);
710 /* argument is an pointer to an option with flags */
714 if (umove(tcp, arg, &val) < 0)
717 printxval(stream_read_options,
718 arg & RMODEMASK, "R???");
719 addflags(stream_read_flags, arg & ~RMODEMASK);
733 /* argument is a pointer to a decimal integer */
737 printnum(tcp, arg, "%d");
740 /* argument is a pointer to a strfdinsert structure */
741 if (syserror(tcp) || !arg)
743 if (umove(tcp, arg, &sfi) < 0) {
747 tprintf(", {ctlbuf=");
748 printstrbuf(tcp, &sfi.ctlbuf, 1);
749 tprintf(", databuf=");
750 printstrbuf(tcp, &sfi.databuf, 1);
751 if (!printflags(msgflags, sfi.flags))
753 tprintf(", filedes=%d, offset=%d}", sfi.fildes, sfi.offset);
757 /* argument is a set of flags */
759 if (!printflags(stream_write_flags, arg))
762 #endif /* I_SWROPT */
765 /* argument is an pointer to an option with flags */
769 if (umove(tcp, arg, &val) < 0)
771 else if (!printflags(stream_write_flags, arg))
775 #endif /* I_GWROPT */
787 /* argument is a decimal integer */
788 tprintf(", %d", arg);
791 /* argument is a pointer to a strrecvfd structure */
792 if (syserror(tcp) || !arg)
794 if (umove(tcp, arg, &srf) < 0) {
798 tprintf(", {fd=%d, uid=%lu, gid=%lu}", srf.fd,
799 (unsigned long) srf.uid, (unsigned long) srf.gid);
809 if (umove(tcp, arg, &sl) < 0) {
813 tprintf(", {sl_nmods=%d, sl_modlist=[", sl.sl_nmods);
814 for (i = 0; i < tcp->u_rval; i++) {
817 printpath(tcp, (int) sl.sl_modlist[i].l_name);
825 printxval(stream_atmark_options, arg, "???MARK");
827 #endif /* I_ATMARK */
833 #endif /* !linux && !FREEBSD */
835 #endif /* HAVE_SYS_STREAM_H || linux || FREEBSD */