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.
36 #ifdef HAVE_SYS_POLL_H
42 #ifdef HAVE_SYS_CONF_H
45 #ifdef HAVE_SYS_STREAM_H
46 #include <sys/stream.h>
48 #ifdef HAVE_SYS_TIHDR_H
49 #include <sys/tihdr.h>
52 #if defined(HAVE_SYS_STREAM_H) || defined(linux) || defined(FREEBSD)
54 #ifndef HAVE_STROPTS_H
57 int maxlen; /* no. of bytes in buffer */
58 int len; /* no. of bytes returned */
59 char *buf; /* pointer to data */
63 #endif /* !HAVE_STROPTS_H */
65 #ifdef HAVE_SYS_TIUSER_H
66 #include <sys/tiuser.h>
67 #include <sys/sockmod.h>
68 #include <sys/timod.h>
69 #endif /* HAVE_SYS_TIUSER_H */
72 static struct xlat msgflags[] = {
73 { RS_HIPRI, "RS_HIPRI" },
79 printstrbuf(tcp, sbp, getting)
84 if (sbp->maxlen == -1 && getting)
85 tprintf("{maxlen=-1}");
89 tprintf("maxlen=%d, ", sbp->maxlen);
90 tprintf("len=%d, buf=", sbp->len);
91 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
97 printstrbufarg(tcp, arg, getting)
106 else if (umove(tcp, arg, &buf) < 0)
109 printstrbuf(tcp, &buf, getting);
121 tprintf("%ld, ", tcp->u_arg[0]);
122 /* control and data */
123 for (i = 1; i < 3; i++)
124 printstrbufarg(tcp, tcp->u_arg[i], 0);
126 if (!printflags(msgflags, tcp->u_arg[3]))
140 tprintf("%lu, ", tcp->u_arg[0]);
143 tprintf("%#lx, %#lx, %#lx",
144 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
147 /* control and data */
148 for (i = 1; i < 3; i++)
149 printstrbufarg(tcp, tcp->u_arg[i], 1);
150 /* pointer to flags */
151 if (tcp->u_arg[3] == 0)
153 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
157 if (!printflags(msgflags, flags))
161 /* decode return value */
162 switch (tcp->u_rval) {
164 tcp->auxstr = "MORECTL";
166 case MORECTL|MOREDATA:
167 tcp->auxstr = "MORECTL|MOREDATA";
170 tcp->auxstr = "MORECTL";
177 return RVAL_HEX | RVAL_STR;
182 static struct xlat pmsgflags[] = {
184 { MSG_HIPRI, "MSG_HIPRI" },
187 { MSG_ANY, "MSG_ANY" },
190 { MSG_BAND, "MSG_BAND" },
203 tprintf("%ld, ", tcp->u_arg[0]);
204 /* control and data */
205 for (i = 1; i < 3; i++)
206 printstrbufarg(tcp, tcp->u_arg[i], 0);
208 tprintf("%ld, ", tcp->u_arg[3]);
210 if (!printflags(pmsgflags, tcp->u_arg[4]))
224 tprintf("%lu, ", tcp->u_arg[0]);
227 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
228 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
231 /* control and data */
232 for (i = 1; i < 3; i++)
233 printstrbufarg(tcp, tcp->u_arg[i], 1);
234 /* pointer to band */
235 printnum(tcp, tcp->u_arg[3], "%d");
237 /* pointer to flags */
238 if (tcp->u_arg[4] == 0)
240 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
244 if (!printflags(pmsgflags, flags))
248 /* decode return value */
249 switch (tcp->u_rval) {
251 tcp->auxstr = "MORECTL";
253 case MORECTL|MOREDATA:
254 tcp->auxstr = "MORECTL|MOREDATA";
257 tcp->auxstr = "MORECTL";
264 return RVAL_HEX | RVAL_STR;
267 #endif /* HAVE_PUTPMSG */
268 #endif /* !FREEBSD */
271 #ifdef HAVE_SYS_POLL_H
273 static struct xlat pollflags[] = {
275 { POLLIN, "POLLIN" },
276 { POLLPRI, "POLLPRI" },
277 { POLLOUT, "POLLOUT" },
279 { POLLRDNORM, "POLLRDNORM" },
282 { POLLWRNORM, "POLLWRNORM" },
285 { POLLRDBAND, "POLLRDBAND" },
288 { POLLWRBAND, "POLLWRBAND" },
290 { POLLERR, "POLLERR" },
291 { POLLHUP, "POLLHUP" },
292 { POLLNVAL, "POLLNVAL" },
301 struct pollfd *pollp;
305 int nfds = tcp->u_arg[1];
308 tprintf("%#lx, %d, %ld\n",
309 tcp->u_arg[0], nfds, tcp->u_arg[2]);
312 pollp = (struct pollfd *) malloc(nfds * sizeof(*pollp));
314 fprintf(stderr, "sys_poll: no memory\n");
315 tprintf("%#lx, %d, %ld",
316 tcp->u_arg[0], nfds, tcp->u_arg[2]);
319 if (umoven(tcp, tcp->u_arg[0],
320 (nfds * sizeof(*pollp)), (char *) pollp) < 0) {
321 tprintf("%#lx", tcp->u_arg[0]);
325 for (i = 0; i < nfds; i++) {
328 if (pollp[i].fd < 0) {
329 tprintf("{fd=%d}", pollp[i].fd);
332 tprintf("{fd=%d, events=", pollp[i].fd);
333 if (!printflags(pollflags, pollp[i].events))
335 if (!syserror(tcp) && pollp[i].revents) {
336 tprintf(", revents=");
337 if (!printflags(pollflags,
345 tprintf(", %d, ", nfds);
347 if (tcp->u_arg[2] == INFTIM)
351 tprintf("%ld", tcp->u_arg[2]);
357 #else /* !HAVE_SYS_POLL_H */
366 #if !defined(linux) && !defined(FREEBSD)
368 static struct xlat stream_flush_options[] = {
369 { FLUSHR, "FLUSHR" },
370 { FLUSHW, "FLUSHW" },
371 { FLUSHRW, "FLUSHRW" },
373 { FLUSHBAND, "FLUSHBAND" },
378 static struct xlat stream_setsig_flags[] = {
379 { S_INPUT, "S_INPUT" },
380 { S_HIPRI, "S_HIPRI" },
381 { S_OUTPUT, "S_OUTPUT" },
384 { S_ERROR, "S_ERROR" },
387 { S_HANGUP, "S_HANGUP" },
390 { S_RDNORM, "S_RDNORM" },
393 { S_WRNORM, "S_WRNORM" },
396 { S_RDBAND, "S_RDBAND" },
399 { S_WRBAND, "S_WRBAND" },
402 { S_BANDURG, "S_BANDURG" },
407 static struct xlat stream_read_options[] = {
414 static struct xlat stream_read_flags[] = {
416 { RPROTDAT, "RPROTDAT" },
419 { RPROTDIS, "RPROTDIS" },
422 { RPROTNORM, "RPROTNORM" },
428 #define RMODEMASK (~0)
432 static struct xlat stream_write_flags[] = {
433 { SNDZERO, "SNDZERO" },
434 { SNDPIPE, "SNDPIPE" },
437 #endif /* I_SWROPT */
440 static struct xlat stream_atmark_options[] = {
441 { ANYMARK, "ANYMARK" },
442 { LASTMARK, "LASTMARK" },
445 #endif /* I_ATMARK */
448 static struct xlat transport_user_options[] = {
449 { T_CONN_REQ, "T_CONN_REQ" },
450 { T_CONN_RES, "T_CONN_RES" },
451 { T_DISCON_REQ, "T_DISCON_REQ" },
452 { T_DATA_REQ, "T_DATA_REQ" },
453 { T_EXDATA_REQ, "T_EXDATA_REQ" },
454 { T_INFO_REQ, "T_INFO_REQ" },
455 { T_BIND_REQ, "T_BIND_REQ" },
456 { T_UNBIND_REQ, "T_UNBIND_REQ" },
457 { T_UNITDATA_REQ,"T_UNITDATA_REQ"},
458 { T_OPTMGMT_REQ,"T_OPTMGMT_REQ" },
459 { T_ORDREL_REQ, "T_ORDREL_REQ" },
463 static struct xlat transport_provider_options[] = {
464 { T_CONN_IND, "T_CONN_IND" },
465 { T_CONN_CON, "T_CONN_CON" },
466 { T_DISCON_IND, "T_DISCON_IND" },
467 { T_DATA_IND, "T_DATA_IND" },
468 { T_EXDATA_IND, "T_EXDATA_IND" },
469 { T_INFO_ACK, "T_INFO_ACK" },
470 { T_BIND_ACK, "T_BIND_ACK" },
471 { T_ERROR_ACK, "T_ERROR_ACK" },
472 { T_OK_ACK, "T_OK_ACK" },
473 { T_UNITDATA_IND,"T_UNITDATA_IND"},
474 { T_UDERROR_IND,"T_UDERROR_IND" },
475 { T_OPTMGMT_ACK,"T_OPTMGMT_ACK" },
476 { T_ORDREL_IND, "T_ORDREL_IND" },
482 internal_stream_ioctl(tcp, arg)
490 struct si_udata udata;
491 #endif /* SI_GETUDATA */
495 if (umove(tcp, arg, &si) < 0) {
501 name = ioctl_lookup(si.ic_cmd);
503 tprintf(", {ic_cmd=%s", name);
505 tprintf(", {ic_cmd=%#x", si.ic_cmd);
506 if (si.ic_timout == INFTIM)
507 tprintf(", ic_timout=INFTIM, ");
509 tprintf(" ic_timout=%d, ", si.ic_timout);
517 #endif /* SI_GETUDATA */
521 tprintf("/* in */ ");
523 tprintf(", /* out */ ");
525 if (in_and_out || entering(tcp))
526 tprintf("ic_len=%d, ic_dp=", si.ic_len);
530 /* in T_BIND_REQ, out T_BIND_ACK */
532 struct T_bind_req data;
535 tprintf("struct T_bind_req ");
537 if (umove(tcp, (int) si.ic_dp, &data) < 0)
540 tprintf("{PRIM_type=");
541 printxval(transport_user_options,
542 data.PRIM_type, "T_???");
543 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
544 data.ADDR_length, data.ADDR_offset);
545 tprintf(", CONIND_number=%ld}",
550 struct T_bind_ack data;
553 tprintf("struct T_bind_ack ");
555 if (umove(tcp, (int) si.ic_dp, &data) < 0)
559 tprintf("{PRIM_type=");
560 printxval(transport_provider_options,
561 data.PRIM_type, "T_???");
562 tprintf(", ADDR_length=%ld, ADDR_offset=%ld",
563 data.ADDR_length, data.ADDR_offset);
564 tprintf(", CONIND_number=%ld}",
568 (int) si.ic_dp + data.ADDR_offset,
578 /* in T_UNBIND_REQ, out T_OK_ACK */
580 #endif /* TI_UNBIND */
583 /* in T_INFO_REQ, out T_INFO_ACK */
585 #endif /* TI_GETINFO */
588 /* in T_OPTMGMT_REQ, out T_OPTMGMT_ACK */
590 #endif /* TI_OPTMGMT */
597 tprintf("struct si_udata ");
599 if (umove(tcp, (int) si.ic_dp, &udata) < 0)
602 tprintf("{tidusize=%d, addrsize=%d, ",
603 udata.tidusize, udata.addrsize);
604 tprintf("optsize=%d, etsdusize=%d, ",
605 udata.optsize, udata.etsdusize);
606 tprintf("servtype=%d, so_state=%d, ",
607 udata.servtype, udata.so_state);
608 tprintf("so_options=%d", udata.so_options);
610 tprintf(", tsdusize=%d", udata.tsdusize);
615 #endif /* SI_GETUDATA */
617 printstr(tcp, (int) si.ic_dp, si.ic_len);
626 stream_ioctl(tcp, code, arg)
638 struct strfdinsert sfi;
639 struct strrecvfd srf;
644 /* I_STR is a special case because the data is read & written. */
646 return internal_stream_ioctl(tcp, arg);
654 /* arg is a string */
659 /* doesn't take an argument */
662 /* argument is an option */
664 printxval(stream_flush_options, arg, "FLUSH???");
668 /* argument is a pointer to a bandinfo struct */
669 if (umove(tcp, arg, &bi) < 0)
672 tprintf(", {bi_pri=%d, bi_flag=", bi.bi_pri);
673 if (!printflags(stream_flush_options, bi.bi_flag))
678 #endif /* I_FLUSHBAND */
680 /* argument is a set of flags */
682 if (!printflags(stream_setsig_flags, arg))
686 /* argument is a pointer to a set of flags */
690 if (umove(tcp, arg, &val) < 0)
692 else if (!printflags(stream_setsig_flags, val))
697 /* argument is a pointer to a strpeek structure */
698 if (syserror(tcp) || !arg)
700 if (umove(tcp, arg, &sp) < 0) {
704 tprintf(", {ctlbuf=");
705 printstrbuf(tcp, &sp.ctlbuf, 1);
706 tprintf(", databuf=");
707 printstrbuf(tcp, &sp.databuf, 1);
708 if (!printflags(msgflags, sp.flags))
712 /* argument is an option with flags */
714 printxval(stream_read_options, arg & RMODEMASK, "R???");
715 addflags(stream_read_flags, arg & ~RMODEMASK);
718 /* argument is an pointer to an option with flags */
722 if (umove(tcp, arg, &val) < 0)
725 printxval(stream_read_options,
726 arg & RMODEMASK, "R???");
727 addflags(stream_read_flags, arg & ~RMODEMASK);
741 /* argument is a pointer to a decimal integer */
745 printnum(tcp, arg, "%d");
748 /* argument is a pointer to a strfdinsert structure */
749 if (syserror(tcp) || !arg)
751 if (umove(tcp, arg, &sfi) < 0) {
755 tprintf(", {ctlbuf=");
756 printstrbuf(tcp, &sfi.ctlbuf, 1);
757 tprintf(", databuf=");
758 printstrbuf(tcp, &sfi.databuf, 1);
759 if (!printflags(msgflags, sfi.flags))
761 tprintf(", filedes=%d, offset=%d}", sfi.fildes, sfi.offset);
765 /* argument is a set of flags */
767 if (!printflags(stream_write_flags, arg))
770 #endif /* I_SWROPT */
773 /* argument is an pointer to an option with flags */
777 if (umove(tcp, arg, &val) < 0)
779 else if (!printflags(stream_write_flags, arg))
783 #endif /* I_GWROPT */
795 /* argument is a decimal integer */
796 tprintf(", %d", arg);
799 /* argument is a pointer to a strrecvfd structure */
800 if (syserror(tcp) || !arg)
802 if (umove(tcp, arg, &srf) < 0) {
806 tprintf(", {fd=%d, uid=%lu, gid=%lu}", srf.fd,
807 (unsigned long) srf.uid, (unsigned long) srf.gid);
817 if (umove(tcp, arg, &sl) < 0) {
821 tprintf(", {sl_nmods=%d, sl_modlist=[", sl.sl_nmods);
822 for (i = 0; i < tcp->u_rval; i++) {
825 printpath(tcp, (int) sl.sl_modlist[i].l_name);
833 printxval(stream_atmark_options, arg, "???MARK");
835 #endif /* I_ATMARK */
841 #endif /* !linux && !FREEBSD */
843 #endif /* HAVE_SYS_STREAM_H || linux || FREEBSD */