]> granicus.if.org Git - strace/blob - stream.c
Optimization: eliminate all remaining usages of strcat()
[strace] / stream.c
1 /*
2  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
3  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
16  *
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.
27  *
28  *      $Id$
29  */
30
31 #include "defs.h"
32 #include <sys/syscall.h>
33
34 #ifdef HAVE_POLL_H
35 #include <poll.h>
36 #endif
37 #ifdef HAVE_SYS_POLL_H
38 #include <sys/poll.h>
39 #endif
40 #ifdef HAVE_STROPTS_H
41 #include <stropts.h>
42 #endif
43 #ifdef HAVE_SYS_CONF_H
44 #include <sys/conf.h>
45 #endif
46 #ifdef HAVE_SYS_STREAM_H
47 #include <sys/stream.h>
48 #endif
49 #ifdef HAVE_SYS_TIHDR_H
50 #include <sys/tihdr.h>
51 #endif
52
53 #if defined(HAVE_SYS_STREAM_H) || defined(LINUX) || defined(FREEBSD)
54
55 #ifndef HAVE_STROPTS_H
56 #define RS_HIPRI 1
57 struct strbuf {
58         int     maxlen;                 /* no. of bytes in buffer */
59         int     len;                    /* no. of bytes returned */
60         const char *buf;                /* pointer to data */
61 };
62 #define MORECTL 1
63 #define MOREDATA 2
64 #endif /* !HAVE_STROPTS_H */
65
66 #ifdef HAVE_SYS_TIUSER_H
67 #include <sys/tiuser.h>
68 #include <sys/sockmod.h>
69 #include <sys/timod.h>
70 #endif /* HAVE_SYS_TIUSER_H */
71
72 #ifndef FREEBSD
73 static const struct xlat msgflags[] = {
74         { RS_HIPRI,     "RS_HIPRI"      },
75         { 0,            NULL            },
76 };
77
78
79 static void
80 printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting)
81 {
82         if (sbp->maxlen == -1 && getting)
83                 tprintf("{maxlen=-1}");
84         else {
85                 tprintf("{");
86                 if (getting)
87                         tprintf("maxlen=%d, ", sbp->maxlen);
88                 tprintf("len=%d, buf=", sbp->len);
89                 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
90                 tprintf("}");
91         }
92 }
93
94 static void
95 printstrbufarg(struct tcb *tcp, int arg, int getting)
96 {
97         struct strbuf buf;
98
99         if (arg == 0)
100                 tprintf("NULL");
101         else if (umove(tcp, arg, &buf) < 0)
102                 tprintf("{...}");
103         else
104                 printstrbuf(tcp, &buf, getting);
105         tprintf(", ");
106 }
107
108 int
109 sys_putmsg(struct tcb *tcp)
110 {
111         int i;
112
113         if (entering(tcp)) {
114                 /* fd */
115                 tprintf("%ld, ", tcp->u_arg[0]);
116                 /* control and data */
117                 for (i = 1; i < 3; i++)
118                         printstrbufarg(tcp, tcp->u_arg[i], 0);
119                 /* flags */
120                 printflags(msgflags, tcp->u_arg[3], "RS_???");
121         }
122         return 0;
123 }
124
125 #if defined(SPARC) || defined(SPARC64) || defined(SUNOS4) || defined(SVR4)
126 int
127 sys_getmsg(struct tcb *tcp)
128 {
129         int i, flags;
130
131         if (entering(tcp)) {
132                 /* fd */
133                 tprintf("%lu, ", tcp->u_arg[0]);
134         } else {
135                 if (syserror(tcp)) {
136                         tprintf("%#lx, %#lx, %#lx",
137                                 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
138                         return 0;
139                 }
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)
145                         tprintf("NULL");
146                 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
147                         tprintf("[?]");
148                 else {
149                         tprintf("[");
150                         printflags(msgflags, flags, "RS_???");
151                         tprintf("]");
152                 }
153                 /* decode return value */
154                 switch (tcp->u_rval) {
155                 case MORECTL:
156                         tcp->auxstr = "MORECTL";
157                         break;
158                 case MORECTL|MOREDATA:
159                         tcp->auxstr = "MORECTL|MOREDATA";
160                         break;
161                 case MOREDATA:
162                         tcp->auxstr = "MORECTL";
163                         break;
164                 default:
165                         tcp->auxstr = NULL;
166                         break;
167                 }
168         }
169         return RVAL_HEX | RVAL_STR;
170 }
171 #endif /* SPARC || SPARC64 || SUNOS4 || SVR4 */
172
173 #if defined SYS_putpmsg || defined SYS_getpmsg
174 static const struct xlat pmsgflags[] = {
175 #ifdef MSG_HIPRI
176         { MSG_HIPRI,    "MSG_HIPRI"     },
177 #endif
178 #ifdef MSG_AND
179         { MSG_ANY,      "MSG_ANY"       },
180 #endif
181 #ifdef MSG_BAND
182         { MSG_BAND,     "MSG_BAND"      },
183 #endif
184         { 0,            NULL            },
185 };
186 #endif
187
188 #ifdef SYS_putpmsg
189 int
190 sys_putpmsg(struct tcb *tcp)
191 {
192         int i;
193
194         if (entering(tcp)) {
195                 /* fd */
196                 tprintf("%ld, ", tcp->u_arg[0]);
197                 /* control and data */
198                 for (i = 1; i < 3; i++)
199                         printstrbufarg(tcp, tcp->u_arg[i], 0);
200                 /* band */
201                 tprintf("%ld, ", tcp->u_arg[3]);
202                 /* flags */
203                 printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
204         }
205         return 0;
206 }
207 #endif /* SYS_putpmsg */
208
209 #ifdef SYS_getpmsg
210 int
211 sys_getpmsg(struct tcb *tcp)
212 {
213         int i, flags;
214
215         if (entering(tcp)) {
216                 /* fd */
217                 tprintf("%lu, ", tcp->u_arg[0]);
218         } else {
219                 if (syserror(tcp)) {
220                         tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
221                                 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
222                         return 0;
223                 }
224                 /* control and data */
225                 for (i = 1; i < 3; i++)
226                         printstrbufarg(tcp, tcp->u_arg[i], 1);
227                 /* pointer to band */
228                 printnum(tcp, tcp->u_arg[3], "%d");
229                 tprintf(", ");
230                 /* pointer to flags */
231                 if (tcp->u_arg[4] == 0)
232                         tprintf("NULL");
233                 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
234                         tprintf("[?]");
235                 else {
236                         tprintf("[");
237                         printflags(pmsgflags, flags, "MSG_???");
238                         tprintf("]");
239                 }
240                 /* decode return value */
241                 switch (tcp->u_rval) {
242                 case MORECTL:
243                         tcp->auxstr = "MORECTL";
244                         break;
245                 case MORECTL|MOREDATA:
246                         tcp->auxstr = "MORECTL|MOREDATA";
247                         break;
248                 case MOREDATA:
249                         tcp->auxstr = "MORECTL";
250                         break;
251                 default:
252                         tcp->auxstr = NULL;
253                         break;
254                 }
255         }
256         return RVAL_HEX | RVAL_STR;
257 }
258 #endif /* SYS_getpmsg */
259
260 #endif /* !FREEBSD */
261
262
263 #ifdef HAVE_SYS_POLL_H
264
265 static const struct xlat pollflags[] = {
266 #ifdef POLLIN
267         { POLLIN,       "POLLIN"        },
268         { POLLPRI,      "POLLPRI"       },
269         { POLLOUT,      "POLLOUT"       },
270 #ifdef POLLRDNORM
271         { POLLRDNORM,   "POLLRDNORM"    },
272 #endif
273 #ifdef POLLWRNORM
274         { POLLWRNORM,   "POLLWRNORM"    },
275 #endif
276 #ifdef POLLRDBAND
277         { POLLRDBAND,   "POLLRDBAND"    },
278 #endif
279 #ifdef POLLWRBAND
280         { POLLWRBAND,   "POLLWRBAND"    },
281 #endif
282         { POLLERR,      "POLLERR"       },
283         { POLLHUP,      "POLLHUP"       },
284         { POLLNVAL,     "POLLNVAL"      },
285 #endif
286         { 0,            NULL            },
287 };
288
289 static int
290 decode_poll(struct tcb *tcp, long pts)
291 {
292         struct pollfd fds;
293         unsigned nfds;
294         unsigned long size, start, cur, end, abbrev_end;
295         int failed = 0;
296
297         if (entering(tcp)) {
298                 nfds = tcp->u_arg[1];
299                 size = sizeof(fds) * nfds;
300                 start = tcp->u_arg[0];
301                 end = start + size;
302                 if (nfds == 0 || size / sizeof(fds) != nfds || end < start) {
303                         tprintf("%#lx, %d, ",
304                                 tcp->u_arg[0], nfds);
305                         return 0;
306                 }
307                 if (abbrev(tcp)) {
308                         abbrev_end = start + max_strlen * sizeof(fds);
309                         if (abbrev_end < start)
310                                 abbrev_end = end;
311                 } else {
312                         abbrev_end = end;
313                 }
314                 tprintf("[");
315                 for (cur = start; cur < end; cur += sizeof(fds)) {
316                         if (cur > start)
317                                 tprintf(", ");
318                         if (cur >= abbrev_end) {
319                                 tprintf("...");
320                                 break;
321                         }
322                         if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
323                                 tprintf("?");
324                                 failed = 1;
325                                 break;
326                         }
327                         if (fds.fd < 0) {
328                                 tprintf("{fd=%d}", fds.fd);
329                                 continue;
330                         }
331                         tprintf("{fd=");
332                         printfd(tcp, fds.fd);
333                         tprintf(", events=");
334                         printflags(pollflags, fds.events, "POLL???");
335                         tprintf("}");
336                 }
337                 tprintf("]");
338                 if (failed)
339                         tprintf(" %#lx", start);
340                 tprintf(", %d, ", nfds);
341                 return 0;
342         } else {
343                 static char outstr[1024];
344                 char *outptr;
345 #define end_outstr (outstr + sizeof(outstr))
346                 const char *flagstr;
347
348                 if (syserror(tcp))
349                         return 0;
350                 if (tcp->u_rval == 0) {
351                         tcp->auxstr = "Timeout";
352                         return RVAL_STR;
353                 }
354
355                 nfds = tcp->u_arg[1];
356                 size = sizeof(fds) * nfds;
357                 start = tcp->u_arg[0];
358                 end = start + size;
359                 if (nfds == 0 || size / sizeof(fds) != nfds || end < start)
360                         return 0;
361                 if (abbrev(tcp)) {
362                         abbrev_end = start + max_strlen * sizeof(fds);
363                         if (abbrev_end < start)
364                                 abbrev_end = end;
365                 } else {
366                         abbrev_end = end;
367                 }
368
369                 outptr = outstr;
370
371                 for (cur = start; cur < end; cur += sizeof(fds)) {
372                         if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
373                                 if (outptr < end_outstr - 2)
374                                         *outptr++ = '?';
375                                 failed = 1;
376                                 break;
377                         }
378                         if (!fds.revents)
379                                 continue;
380                         if (outptr == outstr) {
381                                 *outptr++ = '[';
382                         } else {
383                                 if (outptr < end_outstr - 3)
384                                         outptr = stpcpy(outptr, ", ");
385                         }
386                         if (cur >= abbrev_end) {
387                                 if (outptr < end_outstr - 4)
388                                         outptr = stpcpy(outptr, "...");
389                                 break;
390                         }
391                         if (outptr < end_outstr - (sizeof("{fd=%d, revents=") + sizeof(int)*3) + 1)
392                                 outptr += sprintf(outptr, "{fd=%d, revents=", fds.fd);
393                         flagstr = sprintflags("", pollflags, fds.revents);
394                         if (outptr < end_outstr - (strlen(flagstr) + 2)) {
395                                 outptr = stpcpy(outptr, flagstr);
396                                 *outptr++ = '}';
397                         }
398                 }
399                 if (failed)
400                         return 0;
401
402                 if (outptr != outstr /* && outptr < end_outstr - 1 (always true)*/)
403                         *outptr++ = ']';
404
405                 *outptr = '\0';
406                 if (pts) {
407                         if (outptr < end_outstr - 128) {
408                                 outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
409                                 sprint_timespec(outptr, tcp, pts);
410                         }
411                 }
412
413                 if (outptr == outstr)
414                         return 0;
415
416                 tcp->auxstr = outstr;
417                 return RVAL_STR;
418 #undef end_outstr
419         }
420 }
421
422 int
423 sys_poll(struct tcb *tcp)
424 {
425         int rc = decode_poll(tcp, 0);
426         if (entering(tcp)) {
427 #ifdef INFTIM
428                 if (tcp->u_arg[2] == INFTIM)
429                         tprintf("INFTIM");
430                 else
431 #endif
432                         tprintf("%ld", tcp->u_arg[2]);
433         }
434         return rc;
435 }
436
437 #ifdef LINUX
438 int
439 sys_ppoll(struct tcb *tcp)
440 {
441         int rc = decode_poll(tcp, tcp->u_arg[2]);
442         if (entering(tcp)) {
443                 print_timespec(tcp, tcp->u_arg[2]);
444                 tprintf(", ");
445                 print_sigset(tcp, tcp->u_arg[3], 0);
446                 tprintf(", %lu", tcp->u_arg[4]);
447         }
448         return rc;
449 }
450 #endif
451
452 #else /* !HAVE_SYS_POLL_H */
453 int
454 sys_poll(struct tcb *tcp)
455 {
456         return 0;
457 }
458 #endif
459
460 #if !defined(LINUX) && !defined(FREEBSD)
461
462 static const struct xlat stream_flush_options[] = {
463         { FLUSHR,       "FLUSHR"        },
464         { FLUSHW,       "FLUSHW"        },
465         { FLUSHRW,      "FLUSHRW"       },
466 #ifdef FLUSHBAND
467         { FLUSHBAND,    "FLUSHBAND"     },
468 #endif
469         { 0,            NULL            },
470 };
471
472 static const struct xlat stream_setsig_flags[] = {
473         { S_INPUT,      "S_INPUT"       },
474         { S_HIPRI,      "S_HIPRI"       },
475         { S_OUTPUT,     "S_OUTPUT"      },
476         { S_MSG,        "S_MSG"         },
477 #ifdef S_ERROR
478         { S_ERROR,      "S_ERROR"       },
479 #endif
480 #ifdef S_HANGUP
481         { S_HANGUP,     "S_HANGUP"      },
482 #endif
483 #ifdef S_RDNORM
484         { S_RDNORM,     "S_RDNORM"      },
485 #endif
486 #ifdef S_WRNORM
487         { S_WRNORM,     "S_WRNORM"      },
488 #endif
489 #ifdef S_RDBAND
490         { S_RDBAND,     "S_RDBAND"      },
491 #endif
492 #ifdef S_WRBAND
493         { S_WRBAND,     "S_WRBAND"      },
494 #endif
495 #ifdef S_BANDURG
496         { S_BANDURG,    "S_BANDURG"     },
497 #endif
498         { 0,            NULL            },
499 };
500
501 static const struct xlat stream_read_options[] = {
502         { RNORM,        "RNORM"         },
503         { RMSGD,        "RMSGD"         },
504         { RMSGN,        "RMSGN"         },
505         { 0,            NULL            },
506 };
507
508 static const struct xlat stream_read_flags[] = {
509 #ifdef RPROTDAT
510         { RPROTDAT,     "RPROTDAT"      },
511 #endif
512 #ifdef RPROTDIS
513         { RPROTDIS,     "RPROTDIS"      },
514 #endif
515 #ifdef RPROTNORM
516         { RPROTNORM,    "RPROTNORM"     },
517 #endif
518         { 0,            NULL            },
519 };
520
521 #ifndef RMODEMASK
522 #define RMODEMASK (~0)
523 #endif
524
525 #ifdef I_SWROPT
526 static const struct xlat stream_write_flags[] = {
527         { SNDZERO,      "SNDZERO"       },
528         { SNDPIPE,      "SNDPIPE"       },
529         { 0,            NULL            },
530 };
531 #endif /* I_SWROPT */
532
533 #ifdef I_ATMARK
534 static const struct xlat stream_atmark_options[] = {
535         { ANYMARK,      "ANYMARK"       },
536         { LASTMARK,     "LASTMARK"      },
537         { 0,            NULL            },
538 };
539 #endif /* I_ATMARK */
540
541 #ifdef TI_BIND
542 static const struct xlat transport_user_options[] = {
543         { T_CONN_REQ,   "T_CONN_REQ"    },
544         { T_CONN_RES,   "T_CONN_RES"    },
545         { T_DISCON_REQ, "T_DISCON_REQ"  },
546         { T_DATA_REQ,   "T_DATA_REQ"    },
547         { T_EXDATA_REQ, "T_EXDATA_REQ"  },
548         { T_INFO_REQ,   "T_INFO_REQ"    },
549         { T_BIND_REQ,   "T_BIND_REQ"    },
550         { T_UNBIND_REQ, "T_UNBIND_REQ"  },
551         { T_UNITDATA_REQ,"T_UNITDATA_REQ"},
552         { T_OPTMGMT_REQ,"T_OPTMGMT_REQ" },
553         { T_ORDREL_REQ, "T_ORDREL_REQ"  },
554         { 0,            NULL            },
555 };
556
557 static const struct xlat transport_user_flags[] = {
558         { 0,            "0"             },
559         { T_MORE,       "T_MORE"        },
560         { T_EXPEDITED,  "T_EXPEDITED"   },
561         { T_NEGOTIATE,  "T_NEGOTIATE"   },
562         { T_CHECK,      "T_CHECK"       },
563         { T_DEFAULT,    "T_DEFAULT"     },
564         { T_SUCCESS,    "T_SUCCESS"     },
565         { T_FAILURE,    "T_FAILURE"     },
566         { T_CURRENT,    "T_CURRENT"     },
567         { T_PARTSUCCESS,"T_PARTSUCCESS" },
568         { T_READONLY,   "T_READONLY"    },
569         { T_NOTSUPPORT, "T_NOTSUPPORT"  },
570         { 0,            NULL            },
571 };
572
573
574 #ifdef HAVE_STRUCT_T_OPTHDR
575
576 static const struct xlat xti_level[] = {
577         { XTI_GENERIC,  "XTI_GENERIC"   },
578         { 0,            NULL            },
579 };
580
581 static const struct xlat xti_generic[] = {
582         { XTI_DEBUG,    "XTI_DEBUG"     },
583         { XTI_LINGER,   "XTI_LINGER"    },
584         { XTI_RCVBUF,   "XTI_RCVBUF"    },
585         { XTI_RCVLOWAT, "XTI_RCVLOWAT"  },
586         { XTI_SNDBUF,   "XTI_SNDBUF"    },
587         { XTI_SNDLOWAT, "XTI_SNDLOWAT"  },
588         { 0,            NULL            },
589 };
590
591
592
593 void
594 print_xti_optmgmt(struct tcb *tcp, long addr, int len)
595 {
596         int c = 0;
597         struct t_opthdr hdr;
598
599         while (len >= (int) sizeof hdr) {
600                 if (umove(tcp, addr, &hdr) < 0) break;
601                 if (c++) {
602                         tprintf(", ");
603                 }
604                 else if (len > hdr.len + sizeof hdr) {
605                         tprintf("[");
606                 }
607                 tprintf("{level=");
608                 printxval(xti_level, hdr.level, "???");
609                 tprintf(", name=");
610                 switch (hdr.level) {
611                     case XTI_GENERIC:
612                         printxval(xti_generic, hdr.name, "XTI_???");
613                         break;
614                     default:
615                         tprintf("%ld", hdr.name);
616                         break;
617                 }
618                 tprintf(", status=");
619                 printxval(transport_user_flags, hdr.status, "T_???");
620                 addr += sizeof hdr;
621                 len -= sizeof hdr;
622                 if ((hdr.len -= sizeof hdr) > 0) {
623                         if (hdr.len > len) break;
624                         tprintf(", val=");
625                         if (len == sizeof(int))
626                                 printnum(tcp, addr, "%d");
627                         else
628                                 printstr(tcp, addr, hdr.len);
629                         addr += hdr.len;
630                         len -= hdr.len;
631                 }
632                 tprintf("}");
633         }
634         if (len > 0) {
635                 if (c++) tprintf(", ");
636                 printstr(tcp, addr, len);
637         }
638         if (c > 1) tprintf("]");
639 }
640
641 #endif
642
643
644 static void
645 print_optmgmt(struct tcb *tcp, long addr, int len)
646 {
647         /* We don't know how to tell if TLI (socket) or XTI
648            optmgmt is being used yet, assume TLI. */
649 #if defined (HAVE_STRUCT_OPTHDR)
650         print_sock_optmgmt(tcp, addr, len);
651 #elif defined (HAVE_STRUCT_T_OPTHDR)
652         print_xti_optmgmt(tcp, addr, len);
653 #else
654         printstr(tcp, addr, len);
655 #endif
656 }
657
658
659
660
661 static const struct xlat service_type[] = {
662         { T_COTS,       "T_COTS"        },
663         { T_COTS_ORD,   "T_COTS_ORD"    },
664         { T_CLTS,       "T_CLTS"        },
665         { 0,            NULL            },
666 };
667
668 static const struct xlat ts_state[] = {
669         { TS_UNBND,     "TS_UNBND"      },
670         { TS_WACK_BREQ, "TS_WACK_BREQ"  },
671         { TS_WACK_UREQ, "TS_WACK_UREQ"  },
672         { TS_IDLE,      "TS_IDLE"       },
673         { TS_WACK_OPTREQ,"TS_WACK_OPTREQ"},
674         { TS_WACK_CREQ, "TS_WACK_CREQ"  },
675         { TS_WCON_CREQ, "TS_WCON_CREQ"  },
676         { TS_WRES_CIND, "TS_WRES_CIND"  },
677         { TS_WACK_CRES, "TS_WACK_CRES"  },
678         { TS_DATA_XFER, "TS_DATA_XFER"  },
679         { TS_WIND_ORDREL,"TS_WIND_ORDREL"},
680         { TS_WREQ_ORDREL,"TS_WREQ_ORDREL"},
681         { TS_WACK_DREQ6,"TS_WACK_DREQ6" },
682         { TS_WACK_DREQ7,"TS_WACK_DREQ7" },
683         { TS_WACK_DREQ9,"TS_WACK_DREQ9" },
684         { TS_WACK_DREQ10,"TS_WACK_DREQ10"},
685         { TS_WACK_DREQ11,"TS_WACK_DREQ11"},
686         { 0,            NULL            },
687 };
688
689 static const struct xlat provider_flags[] = {
690         { 0,            "0"             },
691         { SENDZERO,     "SENDZERO"      },
692         { EXPINLINE,    "EXPINLINE"     },
693         { XPG4_1,       "XPG4_1"        },
694         { 0,            NULL            },
695 };
696
697
698 static const struct xlat tli_errors[] = {
699         { TBADADDR,     "TBADADDR"      },
700         { TBADOPT,      "TBADOPT"       },
701         { TACCES,       "TACCES"        },
702         { TBADF,        "TBADF"         },
703         { TNOADDR,      "TNOADDR"       },
704         { TOUTSTATE,    "TOUTSTATE"     },
705         { TBADSEQ,      "TBADSEQ"       },
706         { TSYSERR,      "TSYSERR"       },
707         { TLOOK,        "TLOOK"         },
708         { TBADDATA,     "TBADDATA"      },
709         { TBUFOVFLW,    "TBUFOVFLW"     },
710         { TFLOW,        "TFLOW"         },
711         { TNODATA,      "TNODATA"       },
712         { TNODIS,       "TNODIS"        },
713         { TNOUDERR,     "TNOUDERR"      },
714         { TBADFLAG,     "TBADFLAG"      },
715         { TNOREL,       "TNOREL"        },
716         { TNOTSUPPORT,  "TNOTSUPPORT"   },
717         { TSTATECHNG,   "TSTATECHNG"    },
718         { TNOSTRUCTYPE, "TNOSTRUCTYPE"  },
719         { TBADNAME,     "TBADNAME"      },
720         { TBADQLEN,     "TBADQLEN"      },
721         { TADDRBUSY,    "TADDRBUSY"     },
722         { TINDOUT,      "TINDOUT"       },
723         { TPROVMISMATCH,"TPROVMISMATCH" },
724         { TRESQLEN,     "TRESQLEN"      },
725         { TRESADDR,     "TRESADDR"      },
726         { TQFULL,       "TQFULL"        },
727         { TPROTO,       "TPROTO"        },
728         { 0,            NULL            },
729 };
730
731
732 static int
733 print_transport_message(struct tcb *tcp, int expect, long addr, int len)
734 {
735         union T_primitives m;
736         int c = 0;
737
738         if (len < sizeof m.type) goto dump;
739
740         if (umove(tcp, addr, &m.type) < 0) goto dump;
741
742 #define GET(type, struct)       \
743         do {                                                    \
744                 if (len < sizeof m.struct) goto dump;           \
745                 if (umove(tcp, addr, &m.struct) < 0) goto dump;\
746                 tprintf("{");                                   \
747                 if (expect != type) {                           \
748                         ++c;                                    \
749                         tprintf(#type);                 \
750                 }                                               \
751         }                                                       \
752         while (0)
753
754 #define COMMA() \
755         do { if (c++) tprintf(", "); } while (0)
756
757
758 #define STRUCT(struct, elem, print)                                     \
759         do {                                                            \
760                 COMMA();                                                \
761                 if (m.struct.elem##_length < 0 ||                       \
762                     m.struct.elem##_offset < sizeof m.struct ||         \
763                     m.struct.elem##_offset + m.struct.elem##_length > len) \
764                 {                                                       \
765                         tprintf(#elem "_length=%ld, " #elem "_offset=%ld",\
766                                 m.struct.elem##_length,                 \
767                                 m.struct.elem##_offset);                \
768                 }                                                       \
769                 else {                                                  \
770                         tprintf(#elem "=");                             \
771                         print(tcp,                                      \
772                                  addr + m.struct.elem##_offset,         \
773                                  m.struct.elem##_length);               \
774                 }                                                       \
775         }                                                               \
776         while (0)
777
778 #define ADDR(struct, elem) STRUCT(struct, elem, printstr)
779
780         switch (m.type) {
781 #ifdef T_CONN_REQ
782             case T_CONN_REQ:    /* connect request   */
783                 GET(T_CONN_REQ, conn_req);
784                 ADDR(conn_req, DEST);
785                 ADDR(conn_req, OPT);
786                 break;
787 #endif
788 #ifdef T_CONN_RES
789             case T_CONN_RES:    /* connect response   */
790                 GET(T_CONN_RES, conn_res);
791 #ifdef HAVE_STRUCT_T_CONN_RES_QUEUE_PTR
792                 COMMA();
793                 tprintf("QUEUE=%p", m.conn_res.QUEUE_ptr);
794 #elif defined HAVE_STRUCT_T_CONN_RES_ACCEPTOR_ID
795                 COMMA();
796                 tprintf("ACCEPTOR=%#lx", m.conn_res.ACCEPTOR_id);
797 #endif
798                 ADDR(conn_res, OPT);
799                 COMMA();
800                 tprintf("SEQ=%ld", m.conn_res.SEQ_number);
801                 break;
802 #endif
803 #ifdef T_DISCON_REQ
804             case T_DISCON_REQ:  /* disconnect request */
805                 GET(T_DISCON_REQ, discon_req);
806                 COMMA();
807                 tprintf("SEQ=%ld", m.discon_req.SEQ_number);
808                 break;
809 #endif
810 #ifdef T_DATA_REQ
811             case T_DATA_REQ:    /* data request       */
812                 GET(T_DATA_REQ, data_req);
813                 COMMA();
814                 tprintf("MORE=%ld", m.data_req.MORE_flag);
815                 break;
816 #endif
817 #ifdef T_EXDATA_REQ
818             case T_EXDATA_REQ:  /* expedited data req */
819                 GET(T_EXDATA_REQ, exdata_req);
820                 COMMA();
821                 tprintf("MORE=%ld", m.exdata_req.MORE_flag);
822                 break;
823 #endif
824 #ifdef T_INFO_REQ
825             case T_INFO_REQ:    /* information req    */
826                 GET(T_INFO_REQ, info_req);
827                 break;
828 #endif
829 #ifdef T_BIND_REQ
830             case T_BIND_REQ:    /* bind request       */
831 #ifdef O_T_BIND_REQ
832             case O_T_BIND_REQ:  /* Ugly xti/tli hack */
833 #endif
834                 GET(T_BIND_REQ, bind_req);
835                 ADDR(bind_req, ADDR);
836                 COMMA();
837                 tprintf("CONIND=%ld", m.bind_req.CONIND_number);
838                 break;
839 #endif
840 #ifdef T_UNBIND_REQ
841             case T_UNBIND_REQ:  /* unbind request     */
842                 GET(T_UNBIND_REQ, unbind_req);
843                 break;
844 #endif
845 #ifdef T_UNITDATA_REQ
846             case T_UNITDATA_REQ:        /* unitdata requset   */
847                 GET(T_UNITDATA_REQ, unitdata_req);
848                 ADDR(unitdata_req, DEST);
849                 ADDR(unitdata_req, OPT);
850                 break;
851 #endif
852 #ifdef T_OPTMGMT_REQ
853             case T_OPTMGMT_REQ: /* manage opt req     */
854                 GET(T_OPTMGMT_REQ, optmgmt_req);
855                 COMMA();
856                 tprintf("MGMT=");
857                 printflags(transport_user_flags, m.optmgmt_req.MGMT_flags,
858                             "T_???");
859                 STRUCT(optmgmt_req, OPT, print_optmgmt);
860                 break;
861 #endif
862 #ifdef T_ORDREL_REQ
863             case T_ORDREL_REQ:  /* orderly rel req    */
864                 GET(T_ORDREL_REQ, ordrel_req);
865                 break;
866 #endif
867 #ifdef T_CONN_IND
868             case T_CONN_IND:    /* connect indication */
869                 GET(T_CONN_IND, conn_ind);
870                 ADDR(conn_ind, SRC);
871                 ADDR(conn_ind, OPT);
872                 tprintf(", SEQ=%ld", m.conn_ind.SEQ_number);
873                 break;
874 #endif
875 #ifdef T_CONN_CON
876             case T_CONN_CON:    /* connect corfirm    */
877                 GET(T_CONN_CON, conn_con);
878                 ADDR(conn_con, RES);
879                 ADDR(conn_con, OPT);
880                 break;
881 #endif
882 #ifdef T_DISCON_IND
883             case T_DISCON_IND:  /* discon indication  */
884                 GET(T_DISCON_IND, discon_ind);
885                 COMMA();
886                 tprintf("DISCON=%ld, SEQ=%ld",
887                          m.discon_ind.DISCON_reason, m.discon_ind.SEQ_number);
888                 break;
889 #endif
890 #ifdef T_DATA_IND
891             case T_DATA_IND:    /* data indication    */
892                 GET(T_DATA_IND, data_ind);
893                 COMMA();
894                 tprintf("MORE=%ld", m.data_ind.MORE_flag);
895                 break;
896 #endif
897 #ifdef T_EXDATA_IND
898             case T_EXDATA_IND:  /* expedited data ind */
899                 GET(T_EXDATA_IND, exdata_ind);
900                 COMMA();
901                 tprintf("MORE=%ld", m.exdata_ind.MORE_flag);
902                 break;
903 #endif
904 #ifdef T_INFO_ACK
905             case T_INFO_ACK:    /* info ack           */
906                 GET(T_INFO_ACK, info_ack);
907                 COMMA();
908                 tprintf("TSDU=%ld, ETSDU=%ld, CDATA=%ld, DDATA=%ld, "
909                          "ADDR=%ld, OPT=%ld, TIDU=%ld, SERV=",
910                          m.info_ack.TSDU_size, m.info_ack.ETSDU_size,
911                          m.info_ack.CDATA_size, m.info_ack.DDATA_size,
912                          m.info_ack.ADDR_size, m.info_ack.OPT_size,
913                          m.info_ack.TIDU_size);
914                 printxval(service_type, m.info_ack.SERV_type, "T_???");
915                 tprintf(", CURRENT=");
916                 printxval(ts_state, m.info_ack.CURRENT_state, "TS_???");
917                 tprintf(", PROVIDER=");
918                 printflags(provider_flags, m.info_ack.PROVIDER_flag, "???");
919                 break;
920 #endif
921 #ifdef T_BIND_ACK
922             case T_BIND_ACK:    /* bind ack           */
923                 GET(T_BIND_ACK, bind_ack);
924                 ADDR(bind_ack, ADDR);
925                 tprintf(", CONIND=%ld", m.bind_ack.CONIND_number);
926                 break;
927 #endif
928 #ifdef T_ERROR_ACK
929             case T_ERROR_ACK:   /* error ack          */
930                 GET(T_ERROR_ACK, error_ack);
931                 COMMA();
932                 tprintf("ERROR=");
933                 printxval(transport_user_options,
934                            m.error_ack.ERROR_prim, "TI_???");
935                 tprintf(", TLI=");
936                 printxval(tli_errors, m.error_ack.TLI_error, "T???");
937                 tprintf("UNIX=%s", strerror(m.error_ack.UNIX_error));
938                 break;
939 #endif
940 #ifdef T_OK_ACK
941             case T_OK_ACK:      /* ok ack             */
942                 GET(T_OK_ACK, ok_ack);
943                 COMMA();
944                 tprintf("CORRECT=");
945                 printxval(transport_user_options,
946                            m.ok_ack.CORRECT_prim, "TI_???");
947                 break;
948 #endif
949 #ifdef T_UNITDATA_IND
950             case T_UNITDATA_IND:        /* unitdata ind       */
951                 GET(T_UNITDATA_IND, unitdata_ind);
952                 ADDR(unitdata_ind, SRC);
953                 ADDR(unitdata_ind, OPT);
954                 break;
955 #endif
956 #ifdef T_UDERROR_IND
957             case T_UDERROR_IND: /* unitdata error ind */
958                 GET(T_UDERROR_IND, uderror_ind);
959                 ADDR(uderror_ind, DEST);
960                 ADDR(uderror_ind, OPT);
961                 tprintf(", ERROR=%ld", m.uderror_ind.ERROR_type);
962                 break;
963 #endif
964 #ifdef T_OPTMGMT_ACK
965             case T_OPTMGMT_ACK: /* manage opt ack     */
966                 GET(T_OPTMGMT_ACK, optmgmt_ack);
967                 COMMA();
968                 tprintf("MGMT=");
969                 printflags(transport_user_flags, m.optmgmt_ack.MGMT_flags,
970                             "T_???");
971                 STRUCT(optmgmt_ack, OPT, print_optmgmt);
972                 break;
973 #endif
974 #ifdef T_ORDREL_IND
975         case T_ORDREL_IND:      /* orderly rel ind    */
976                 GET(T_ORDREL_IND, ordrel_ind);
977                 break;
978 #endif
979 #ifdef T_ADDR_REQ
980             case T_ADDR_REQ:    /* address req        */
981                 GET(T_ADDR_REQ, addr_req);
982                 break;
983 #endif
984 #ifdef T_ADDR_ACK
985             case T_ADDR_ACK:    /* address response   */
986                 GET(T_ADDR_ACK, addr_ack);
987                 ADDR(addr_ack, LOCADDR);
988                 ADDR(addr_ack, REMADDR);
989                 break;
990 #endif
991             default:
992             dump:
993                 c = -1;
994                 printstr(tcp, addr, len);
995                 break;
996         }
997
998         if (c >= 0) tprintf("}");
999
1000 #undef ADDR
1001 #undef COMMA
1002 #undef STRUCT
1003
1004         return 0;
1005 }
1006
1007
1008 #endif /* TI_BIND */
1009
1010
1011 static int internal_stream_ioctl(struct tcb *tcp, int arg)
1012 {
1013         struct strioctl si;
1014         struct ioctlent *iop;
1015         int in_and_out;
1016         int timod = 0;
1017 #ifdef SI_GETUDATA
1018         struct si_udata udata;
1019 #endif /* SI_GETUDATA */
1020
1021         if (!arg)
1022                 return 0;
1023         if (umove(tcp, arg, &si) < 0) {
1024                 if (entering(tcp))
1025                         tprintf(", {...}");
1026                 return 1;
1027         }
1028         if (entering(tcp)) {
1029                 iop = ioctl_lookup(si.ic_cmd);
1030                 if (iop) {
1031                         tprintf(", {ic_cmd=%s", iop->symbol);
1032                         while ((iop = ioctl_next_match(iop)))
1033                                 tprintf(" or %s", iop->symbol);
1034                 } else
1035                         tprintf(", {ic_cmd=%#x", si.ic_cmd);
1036                 if (si.ic_timout == INFTIM)
1037                         tprintf(", ic_timout=INFTIM, ");
1038                 else
1039                         tprintf(" ic_timout=%d, ", si.ic_timout);
1040         }
1041         in_and_out = 1;
1042         switch (si.ic_cmd) {
1043 #ifdef SI_GETUDATA
1044         case SI_GETUDATA:
1045                 in_and_out = 0;
1046                 break;
1047 #endif /* SI_GETUDATA */
1048         }
1049         if (in_and_out) {
1050                 if (entering(tcp))
1051                         tprintf("/* in */ ");
1052                 else
1053                         tprintf(", /* out */ ");
1054         }
1055         if (in_and_out || entering(tcp))
1056                 tprintf("ic_len=%d, ic_dp=", si.ic_len);
1057         switch (si.ic_cmd) {
1058 #ifdef TI_BIND
1059         case TI_BIND:
1060                 /* in T_BIND_REQ, out T_BIND_ACK */
1061                 ++timod;
1062                 if (entering(tcp)) {
1063                         print_transport_message(tcp,
1064                                                  T_BIND_REQ,
1065                                                  si.ic_dp, si.ic_len);
1066                 }
1067                 else {
1068                         print_transport_message(tcp,
1069                                                  T_BIND_ACK,
1070                                                  si.ic_dp, si.ic_len);
1071                 }
1072                 break;
1073 #endif /* TI_BIND */
1074 #ifdef TI_UNBIND
1075         case TI_UNBIND:
1076                 /* in T_UNBIND_REQ, out T_OK_ACK */
1077                 ++timod;
1078                 if (entering(tcp)) {
1079                         print_transport_message(tcp,
1080                                                  T_UNBIND_REQ,
1081                                                  si.ic_dp, si.ic_len);
1082                 }
1083                 else {
1084                         print_transport_message(tcp,
1085                                                  T_OK_ACK,
1086                                                  si.ic_dp, si.ic_len);
1087                 }
1088                 break;
1089 #endif /* TI_UNBIND */
1090 #ifdef TI_GETINFO
1091         case TI_GETINFO:
1092                 /* in T_INFO_REQ, out T_INFO_ACK */
1093                 ++timod;
1094                 if (entering(tcp)) {
1095                         print_transport_message(tcp,
1096                                                  T_INFO_REQ,
1097                                                  si.ic_dp, si.ic_len);
1098                 }
1099                 else {
1100                         print_transport_message(tcp,
1101                                                  T_INFO_ACK,
1102                                                  si.ic_dp, si.ic_len);
1103                 }
1104                 break;
1105 #endif /* TI_GETINFO */
1106 #ifdef TI_OPTMGMT
1107         case TI_OPTMGMT:
1108                 /* in T_OPTMGMT_REQ, out T_OPTMGMT_ACK */
1109                 ++timod;
1110                 if (entering(tcp)) {
1111                         print_transport_message(tcp,
1112                                                  T_OPTMGMT_REQ,
1113                                                  si.ic_dp, si.ic_len);
1114                 }
1115                 else {
1116                         print_transport_message(tcp,
1117                                                  T_OPTMGMT_ACK,
1118                                                  si.ic_dp, si.ic_len);
1119                 }
1120                 break;
1121 #endif /* TI_OPTMGMT */
1122 #ifdef SI_GETUDATA
1123         case SI_GETUDATA:
1124                 if (entering(tcp))
1125                         break;
1126                 if (umove(tcp, (int) si.ic_dp, &udata) < 0)
1127                         tprintf("{...}");
1128                 else {
1129                         tprintf("{tidusize=%d, addrsize=%d, ",
1130                                 udata.tidusize, udata.addrsize);
1131                         tprintf("optsize=%d, etsdusize=%d, ",
1132                                 udata.optsize, udata.etsdusize);
1133                         tprintf("servtype=%d, so_state=%d, ",
1134                                 udata.servtype, udata.so_state);
1135                         tprintf("so_options=%d", udata.so_options);
1136                         tprintf("}");
1137                 }
1138                 break;
1139 #endif /* SI_GETUDATA */
1140         default:
1141                 printstr(tcp, (long) si.ic_dp, si.ic_len);
1142                 break;
1143         }
1144         if (exiting(tcp)) {
1145                 tprintf("}");
1146                 if (timod && tcp->u_rval && !syserror(tcp)) {
1147                         tcp->auxstr = xlookup(tli_errors, tcp->u_rval);
1148                         return RVAL_STR + 1;
1149                 }
1150         }
1151
1152         return 1;
1153 }
1154
1155 int
1156 stream_ioctl(struct tcb *tcp, int code, int arg)
1157 {
1158 #ifdef I_LIST
1159         int i;
1160 #endif
1161         int val;
1162 #ifdef I_FLUSHBAND
1163         struct bandinfo bi;
1164 #endif
1165         struct strpeek sp;
1166         struct strfdinsert sfi;
1167         struct strrecvfd srf;
1168 #ifdef I_LIST
1169         struct str_list sl;
1170 #endif
1171
1172         /* I_STR is a special case because the data is read & written. */
1173         if (code == I_STR)
1174                 return internal_stream_ioctl(tcp, arg);
1175         if (entering(tcp))
1176                 return 0;
1177
1178         switch (code) {
1179         case I_PUSH:
1180         case I_LOOK:
1181         case I_FIND:
1182                 /* arg is a string */
1183                 tprintf(", ");
1184                 printpath(tcp, arg);
1185                 return 1;
1186         case I_POP:
1187                 /* doesn't take an argument */
1188                 return 1;
1189         case I_FLUSH:
1190                 /* argument is an option */
1191                 tprintf(", ");
1192                 printxval(stream_flush_options, arg, "FLUSH???");
1193                 return 1;
1194 #ifdef I_FLUSHBAND
1195         case I_FLUSHBAND:
1196                 /* argument is a pointer to a bandinfo struct */
1197                 if (umove(tcp, arg, &bi) < 0)
1198                         tprintf(", {...}");
1199                 else {
1200                         tprintf(", {bi_pri=%d, bi_flag=", bi.bi_pri);
1201                         printflags(stream_flush_options, bi.bi_flag, "FLUSH???");
1202                         tprintf("}");
1203                 }
1204                 return 1;
1205 #endif /* I_FLUSHBAND */
1206         case I_SETSIG:
1207                 /* argument is a set of flags */
1208                 tprintf(", ");
1209                 printflags(stream_setsig_flags, arg, "S_???");
1210                 return 1;
1211         case I_GETSIG:
1212                 /* argument is a pointer to a set of flags */
1213                 if (syserror(tcp))
1214                         return 0;
1215                 tprintf(", [");
1216                 if (umove(tcp, arg, &val) < 0)
1217                         tprintf("?");
1218                 else
1219                         printflags(stream_setsig_flags, val, "S_???");
1220                 tprintf("]");
1221                 return 1;
1222         case I_PEEK:
1223                 /* argument is a pointer to a strpeek structure */
1224                 if (syserror(tcp) || !arg)
1225                         return 0;
1226                 if (umove(tcp, arg, &sp) < 0) {
1227                         tprintf(", {...}");
1228                         return 1;
1229                 }
1230                 tprintf(", {ctlbuf=");
1231                 printstrbuf(tcp, &sp.ctlbuf, 1);
1232                 tprintf(", databuf=");
1233                 printstrbuf(tcp, &sp.databuf, 1);
1234                 tprintf(", flags=");
1235                 printflags(msgflags, sp.flags, "RS_???");
1236                 tprintf("}");
1237                 return 1;
1238         case I_SRDOPT:
1239                 /* argument is an option with flags */
1240                 tprintf(", ");
1241                 printxval(stream_read_options, arg & RMODEMASK, "R???");
1242                 addflags(stream_read_flags, arg & ~RMODEMASK);
1243                 return 1;
1244         case I_GRDOPT:
1245                 /* argument is an pointer to an option with flags */
1246                 if (syserror(tcp))
1247                         return 0;
1248                 tprintf(", [");
1249                 if (umove(tcp, arg, &val) < 0)
1250                         tprintf("?");
1251                 else {
1252                         printxval(stream_read_options,
1253                                   arg & RMODEMASK, "R???");
1254                         addflags(stream_read_flags, arg & ~RMODEMASK);
1255                 }
1256                 tprintf("]");
1257                 return 1;
1258         case I_NREAD:
1259 #ifdef I_GETBAND
1260         case I_GETBAND:
1261 #endif
1262 #ifdef I_SETCLTIME
1263         case I_SETCLTIME:
1264 #endif
1265 #ifdef I_GETCLTIME
1266         case I_GETCLTIME:
1267 #endif
1268                 /* argument is a pointer to a decimal integer */
1269                 if (syserror(tcp))
1270                         return 0;
1271                 tprintf(", ");
1272                 printnum(tcp, arg, "%d");
1273                 return 1;
1274         case I_FDINSERT:
1275                 /* argument is a pointer to a strfdinsert structure */
1276                 if (syserror(tcp) || !arg)
1277                         return 0;
1278                 if (umove(tcp, arg, &sfi) < 0) {
1279                         tprintf(", {...}");
1280                         return 1;
1281                 }
1282                 tprintf(", {ctlbuf=");
1283                 printstrbuf(tcp, &sfi.ctlbuf, 1);
1284                 tprintf(", databuf=");
1285                 printstrbuf(tcp, &sfi.databuf, 1);
1286                 tprintf(", flags=");
1287                 printflags(msgflags, sfi.flags, "RS_???");
1288                 tprintf(", filedes=%d, offset=%d}", sfi.fildes, sfi.offset);
1289                 return 1;
1290 #ifdef I_SWROPT
1291         case I_SWROPT:
1292                 /* argument is a set of flags */
1293                 tprintf(", ");
1294                 printflags(stream_write_flags, arg, "SND???");
1295                 return 1;
1296 #endif /* I_SWROPT */
1297 #ifdef I_GWROPT
1298         case I_GWROPT:
1299                 /* argument is an pointer to an option with flags */
1300                 if (syserror(tcp))
1301                         return 0;
1302                 tprintf(", [");
1303                 if (umove(tcp, arg, &val) < 0)
1304                         tprintf("?");
1305                 else
1306                         printflags(stream_write_flags, arg, "SND???");
1307                 tprintf("]");
1308                 return 1;
1309 #endif /* I_GWROPT */
1310         case I_SENDFD:
1311 #ifdef I_CKBAND
1312         case I_CKBAND:
1313 #endif
1314 #ifdef I_CANPUT
1315         case I_CANPUT:
1316 #endif
1317         case I_LINK:
1318         case I_UNLINK:
1319         case I_PLINK:
1320         case I_PUNLINK:
1321                 /* argument is a decimal integer */
1322                 tprintf(", %d", arg);
1323                 return 1;
1324         case I_RECVFD:
1325                 /* argument is a pointer to a strrecvfd structure */
1326                 if (syserror(tcp) || !arg)
1327                         return 0;
1328                 if (umove(tcp, arg, &srf) < 0) {
1329                         tprintf(", {...}");
1330                         return 1;
1331                 }
1332                 tprintf(", {fd=%d, uid=%lu, gid=%lu}", srf.fd,
1333                         (unsigned long) srf.uid, (unsigned long) srf.gid);
1334                 return 1;
1335 #ifdef I_LIST
1336         case I_LIST:
1337                 if (syserror(tcp))
1338                         return 0;
1339                 if (arg == 0) {
1340                         tprintf(", NULL");
1341                         return 1;
1342                 }
1343                 if (umove(tcp, arg, &sl) < 0) {
1344                         tprintf(", {...}");
1345                         return 1;
1346                 }
1347                 tprintf(", {sl_nmods=%d, sl_modlist=[", sl.sl_nmods);
1348                 for (i = 0; i < tcp->u_rval; i++) {
1349                         if (i)
1350                                 tprintf(", ");
1351                         printpath(tcp, (int) sl.sl_modlist[i].l_name);
1352                 }
1353                 tprintf("]}");
1354                 return 1;
1355 #endif /* I_LIST */
1356 #ifdef I_ATMARK
1357         case I_ATMARK:
1358                 tprintf(", ");
1359                 printxval(stream_atmark_options, arg, "???MARK");
1360                 return 1;
1361 #endif /* I_ATMARK */
1362         default:
1363                 return 0;
1364         }
1365 }
1366
1367 #endif /* !LINUX && !FREEBSD */
1368
1369 #endif /* HAVE_SYS_STREAM_H || LINUX || FREEBSD */