blob: eb72d6228f8c0a86daccacb16b1209f43ca7b973 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00003 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00004 * 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"
Roland McGrath34e014a2002-12-16 20:40:59 +000032#include <sys/syscall.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000033
Wichert Akkerman42080d82001-04-10 10:32:26 +000034#ifdef HAVE_POLL_H
35#include <poll.h>
36#endif
Pavel Machek245a6ac2000-02-01 16:12:33 +000037#ifdef HAVE_SYS_POLL_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000038#include <sys/poll.h>
Pavel Machek245a6ac2000-02-01 16:12:33 +000039#endif
Wichert Akkerman42080d82001-04-10 10:32:26 +000040#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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052
Roland McGrath561c7992003-04-02 01:10:44 +000053#if defined(HAVE_SYS_STREAM_H) || defined(LINUX) || defined(FREEBSD)
Wichert Akkerman42080d82001-04-10 10:32:26 +000054
55#ifndef HAVE_STROPTS_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000056#define RS_HIPRI 1
57struct strbuf {
58 int maxlen; /* no. of bytes in buffer */
59 int len; /* no. of bytes returned */
60 char *buf; /* pointer to data */
61};
62#define MORECTL 1
63#define MOREDATA 2
Wichert Akkerman42080d82001-04-10 10:32:26 +000064#endif /* !HAVE_STROPTS_H */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000065
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
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000072#ifndef FREEBSD
Roland McGrathd9f816f2004-09-04 03:39:20 +000073static const struct xlat msgflags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074 { RS_HIPRI, "RS_HIPRI" },
75 { 0, NULL },
76};
77
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000078
79static void
80printstrbuf(tcp, sbp, getting)
81struct tcb *tcp;
82struct strbuf *sbp;
83int getting;
84{
85 if (sbp->maxlen == -1 && getting)
86 tprintf("{maxlen=-1}");
87 else {
88 tprintf("{");
89 if (getting)
90 tprintf("maxlen=%d, ", sbp->maxlen);
91 tprintf("len=%d, buf=", sbp->len);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000092 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000093 tprintf("}");
94 }
95}
96
97static void
98printstrbufarg(tcp, arg, getting)
99struct tcb *tcp;
100int arg;
101int getting;
102{
103 struct strbuf buf;
104
105 if (arg == 0)
106 tprintf("NULL");
107 else if (umove(tcp, arg, &buf) < 0)
108 tprintf("{...}");
109 else
110 printstrbuf(tcp, &buf, getting);
111 tprintf(", ");
112}
113
114int
115sys_putmsg(tcp)
116struct tcb *tcp;
117{
118 int i;
119
120 if (entering(tcp)) {
121 /* fd */
122 tprintf("%ld, ", tcp->u_arg[0]);
123 /* control and data */
124 for (i = 1; i < 3; i++)
125 printstrbufarg(tcp, tcp->u_arg[i], 0);
126 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000127 printflags(msgflags, tcp->u_arg[3], "RS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000128 }
129 return 0;
130}
131
132int
133sys_getmsg(tcp)
134struct tcb *tcp;
135{
136 int i, flags;
137
138 if (entering(tcp)) {
139 /* fd */
140 tprintf("%lu, ", tcp->u_arg[0]);
141 } else {
142 if (syserror(tcp)) {
143 tprintf("%#lx, %#lx, %#lx",
144 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
145 return 0;
146 }
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)
152 tprintf("NULL");
153 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
154 tprintf("[?]");
155 else {
156 tprintf("[");
Roland McGrathb2dee132005-06-01 19:02:36 +0000157 printflags(msgflags, flags, "RS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000158 tprintf("]");
159 }
160 /* decode return value */
161 switch (tcp->u_rval) {
162 case MORECTL:
163 tcp->auxstr = "MORECTL";
164 break;
165 case MORECTL|MOREDATA:
166 tcp->auxstr = "MORECTL|MOREDATA";
167 break;
168 case MOREDATA:
169 tcp->auxstr = "MORECTL";
170 break;
171 default:
172 tcp->auxstr = NULL;
173 break;
174 }
175 }
176 return RVAL_HEX | RVAL_STR;
177}
178
Roland McGrath34e014a2002-12-16 20:40:59 +0000179#if defined SYS_putpmsg || defined SYS_getpmsg
Roland McGrathd9f816f2004-09-04 03:39:20 +0000180static const struct xlat pmsgflags[] = {
Wichert Akkermand856b992000-10-13 12:47:12 +0000181#ifdef MSG_HIPRI
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182 { MSG_HIPRI, "MSG_HIPRI" },
Wichert Akkermand856b992000-10-13 12:47:12 +0000183#endif
184#ifdef MSG_AND
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185 { MSG_ANY, "MSG_ANY" },
Wichert Akkermand856b992000-10-13 12:47:12 +0000186#endif
187#ifdef MSG_BAND
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000188 { MSG_BAND, "MSG_BAND" },
Wichert Akkermand856b992000-10-13 12:47:12 +0000189#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000190 { 0, NULL },
191};
Roland McGrath34e014a2002-12-16 20:40:59 +0000192#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000193
Roland McGrath34e014a2002-12-16 20:40:59 +0000194#ifdef SYS_putpmsg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000195int
196sys_putpmsg(tcp)
197struct tcb *tcp;
198{
199 int i;
200
201 if (entering(tcp)) {
202 /* fd */
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);
207 /* band */
208 tprintf("%ld, ", tcp->u_arg[3]);
209 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000210 printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000211 }
212 return 0;
213}
Roland McGrath34e014a2002-12-16 20:40:59 +0000214#endif /* SYS_putpmsg */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000215
Roland McGrath34e014a2002-12-16 20:40:59 +0000216#ifdef SYS_getpmsg
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000217int
218sys_getpmsg(tcp)
219struct tcb *tcp;
220{
221 int i, flags;
222
223 if (entering(tcp)) {
224 /* fd */
225 tprintf("%lu, ", tcp->u_arg[0]);
226 } else {
227 if (syserror(tcp)) {
228 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
229 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
230 return 0;
231 }
232 /* control and data */
233 for (i = 1; i < 3; i++)
234 printstrbufarg(tcp, tcp->u_arg[i], 1);
235 /* pointer to band */
236 printnum(tcp, tcp->u_arg[3], "%d");
Wichert Akkerman906dade1999-11-26 09:18:37 +0000237 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000238 /* pointer to flags */
239 if (tcp->u_arg[4] == 0)
240 tprintf("NULL");
241 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
242 tprintf("[?]");
243 else {
244 tprintf("[");
Roland McGrathb2dee132005-06-01 19:02:36 +0000245 printflags(pmsgflags, flags, "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000246 tprintf("]");
247 }
248 /* decode return value */
249 switch (tcp->u_rval) {
250 case MORECTL:
251 tcp->auxstr = "MORECTL";
252 break;
253 case MORECTL|MOREDATA:
254 tcp->auxstr = "MORECTL|MOREDATA";
255 break;
256 case MOREDATA:
257 tcp->auxstr = "MORECTL";
258 break;
259 default:
260 tcp->auxstr = NULL;
261 break;
262 }
263 }
264 return RVAL_HEX | RVAL_STR;
265}
Roland McGrath34e014a2002-12-16 20:40:59 +0000266#endif /* SYS_getpmsg */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000267
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000268#endif /* !FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000269
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000271#ifdef HAVE_SYS_POLL_H
272
Roland McGrathd9f816f2004-09-04 03:39:20 +0000273static const struct xlat pollflags[] = {
Pavel Machek245a6ac2000-02-01 16:12:33 +0000274#ifdef POLLIN
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275 { POLLIN, "POLLIN" },
276 { POLLPRI, "POLLPRI" },
277 { POLLOUT, "POLLOUT" },
278#ifdef POLLRDNORM
279 { POLLRDNORM, "POLLRDNORM" },
280#endif
281#ifdef POLLWRNORM
282 { POLLWRNORM, "POLLWRNORM" },
283#endif
284#ifdef POLLRDBAND
285 { POLLRDBAND, "POLLRDBAND" },
286#endif
287#ifdef POLLWRBAND
288 { POLLWRBAND, "POLLWRBAND" },
289#endif
290 { POLLERR, "POLLERR" },
291 { POLLHUP, "POLLHUP" },
292 { POLLNVAL, "POLLNVAL" },
Pavel Machek245a6ac2000-02-01 16:12:33 +0000293#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000294 { 0, NULL },
295};
296
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000297static int
298decode_poll(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000299{
Roland McGrathaa524c82005-06-01 19:22:06 +0000300 struct pollfd fds;
301 unsigned nfds;
302 unsigned long size, start, cur, end, abbrev_end;
303 int failed = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000304
Roland McGrathaa524c82005-06-01 19:22:06 +0000305 if (entering(tcp))
306 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000307
Roland McGrathaa524c82005-06-01 19:22:06 +0000308 nfds = tcp->u_arg[1];
309 size = sizeof(fds) * nfds;
310 start = tcp->u_arg[0];
311 end = start + size;
312 if (nfds == 0 || size / sizeof(fds) != nfds || end < start) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000313 tprintf("%#lx, %d, ",
314 tcp->u_arg[0], nfds);
Roland McGrathaa524c82005-06-01 19:22:06 +0000315 return 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000316 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000317 if (abbrev(tcp)) {
318 abbrev_end = start + max_strlen * sizeof(fds);
319 if (abbrev_end < start)
320 abbrev_end = end;
321 } else {
322 abbrev_end = end;
323 }
324 tprintf("[");
325 for (cur = start; cur < end; cur += sizeof(fds)) {
326 if (cur > start)
327 tprintf(", ");
328 if (cur >= abbrev_end) {
329 tprintf("...");
330 break;
331 }
332 if (umoven(tcp, cur, sizeof fds, (char *) &fds) < 0) {
333 tprintf("?");
334 failed = 1;
335 break;
336 }
337 if (fds.fd < 0) {
338 tprintf("{fd=%d}", fds.fd);
339 continue;
340 }
341 tprintf("{fd=%d, events=", fds.fd);
342 printflags(pollflags, fds.events, "POLL???");
343 if (!syserror(tcp) && fds.revents) {
344 tprintf(", revents=");
345 printflags(pollflags, fds.revents, "POLL???");
346 }
347 tprintf("}");
348 }
349 tprintf("]");
350 if (failed)
351 tprintf(" %#lx", start);
352 tprintf(", %d, ", nfds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000353 return 0;
354}
355
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000356int
357sys_poll(struct tcb *tcp)
358{
359 int rc = decode_poll(tcp);
360 if (exiting(tcp)) {
361#ifdef INFTIM
362 if (tcp->u_arg[2] == INFTIM)
363 tprintf("INFTIM");
364 else
365#endif
366 tprintf("%ld", tcp->u_arg[2]);
367 }
368 return rc;
369}
370
371#ifdef LINUX
372int
373sys_ppoll(struct tcb *tcp)
374{
375 int rc = decode_poll(tcp);
376 if (exiting(tcp)) {
377 struct timespec ts;
378 if (umove(tcp, tcp->u_arg[2], &ts) == 0)
379 tprintf("{%lu, %lu}, ", ts.tv_sec, ts.tv_nsec);
380 else
381 tprintf("{...}, ");
382 print_sigset(tcp, tcp->u_arg[3], 0);
383 tprintf(", %lu", tcp->u_arg[4]);
384 }
385 return rc;
386}
387#endif
Roland McGrathaa524c82005-06-01 19:22:06 +0000388
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000389#else /* !HAVE_SYS_POLL_H */
390int
391sys_poll(tcp)
392struct tcb *tcp;
393{
394 return 0;
395}
396#endif
397
Roland McGrath561c7992003-04-02 01:10:44 +0000398#if !defined(LINUX) && !defined(FREEBSD)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000399
Roland McGrathd9f816f2004-09-04 03:39:20 +0000400static const struct xlat stream_flush_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000401 { FLUSHR, "FLUSHR" },
402 { FLUSHW, "FLUSHW" },
403 { FLUSHRW, "FLUSHRW" },
404#ifdef FLUSHBAND
405 { FLUSHBAND, "FLUSHBAND" },
406#endif
407 { 0, NULL },
408};
409
Roland McGrathd9f816f2004-09-04 03:39:20 +0000410static const struct xlat stream_setsig_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000411 { S_INPUT, "S_INPUT" },
412 { S_HIPRI, "S_HIPRI" },
413 { S_OUTPUT, "S_OUTPUT" },
414 { S_MSG, "S_MSG" },
415#ifdef S_ERROR
416 { S_ERROR, "S_ERROR" },
417#endif
418#ifdef S_HANGUP
419 { S_HANGUP, "S_HANGUP" },
420#endif
421#ifdef S_RDNORM
422 { S_RDNORM, "S_RDNORM" },
423#endif
424#ifdef S_WRNORM
425 { S_WRNORM, "S_WRNORM" },
426#endif
427#ifdef S_RDBAND
428 { S_RDBAND, "S_RDBAND" },
429#endif
430#ifdef S_WRBAND
431 { S_WRBAND, "S_WRBAND" },
432#endif
433#ifdef S_BANDURG
434 { S_BANDURG, "S_BANDURG" },
435#endif
436 { 0, NULL },
437};
438
Roland McGrathd9f816f2004-09-04 03:39:20 +0000439static const struct xlat stream_read_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000440 { RNORM, "RNORM" },
441 { RMSGD, "RMSGD" },
442 { RMSGN, "RMSGN" },
443 { 0, NULL },
444};
445
Roland McGrathd9f816f2004-09-04 03:39:20 +0000446static const struct xlat stream_read_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447#ifdef RPROTDAT
448 { RPROTDAT, "RPROTDAT" },
449#endif
450#ifdef RPROTDIS
451 { RPROTDIS, "RPROTDIS" },
452#endif
453#ifdef RPROTNORM
454 { RPROTNORM, "RPROTNORM" },
455#endif
456 { 0, NULL },
457};
458
459#ifndef RMODEMASK
460#define RMODEMASK (~0)
461#endif
462
463#ifdef I_SWROPT
Roland McGrathd9f816f2004-09-04 03:39:20 +0000464static const struct xlat stream_write_flags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465 { SNDZERO, "SNDZERO" },
466 { SNDPIPE, "SNDPIPE" },
467 { 0, NULL },
468};
469#endif /* I_SWROPT */
470
471#ifdef I_ATMARK
Roland McGrathd9f816f2004-09-04 03:39:20 +0000472static const struct xlat stream_atmark_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000473 { ANYMARK, "ANYMARK" },
474 { LASTMARK, "LASTMARK" },
475 { 0, NULL },
476};
477#endif /* I_ATMARK */
478
479#ifdef TI_BIND
Roland McGrathd9f816f2004-09-04 03:39:20 +0000480static const struct xlat transport_user_options[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000481 { T_CONN_REQ, "T_CONN_REQ" },
482 { T_CONN_RES, "T_CONN_RES" },
483 { T_DISCON_REQ, "T_DISCON_REQ" },
484 { T_DATA_REQ, "T_DATA_REQ" },
485 { T_EXDATA_REQ, "T_EXDATA_REQ" },
486 { T_INFO_REQ, "T_INFO_REQ" },
487 { T_BIND_REQ, "T_BIND_REQ" },
488 { T_UNBIND_REQ, "T_UNBIND_REQ" },
489 { T_UNITDATA_REQ,"T_UNITDATA_REQ"},
490 { T_OPTMGMT_REQ,"T_OPTMGMT_REQ" },
491 { T_ORDREL_REQ, "T_ORDREL_REQ" },
492 { 0, NULL },
493};
494
Roland McGrathd9f816f2004-09-04 03:39:20 +0000495static const struct xlat transport_user_flags [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000496 { 0, "0" },
497 { T_MORE, "T_MORE" },
498 { T_EXPEDITED, "T_EXPEDITED" },
499 { T_NEGOTIATE, "T_NEGOTIATE" },
500 { T_CHECK, "T_CHECK" },
501 { T_DEFAULT, "T_DEFAULT" },
502 { T_SUCCESS, "T_SUCCESS" },
503 { T_FAILURE, "T_FAILURE" },
504 { T_CURRENT, "T_CURRENT" },
505 { T_PARTSUCCESS,"T_PARTSUCCESS" },
506 { T_READONLY, "T_READONLY" },
507 { T_NOTSUPPORT, "T_NOTSUPPORT" },
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508 { 0, NULL },
509};
John Hughes38ae88d2002-05-23 11:48:58 +0000510
511
Roland McGrath6d2b3492002-12-30 00:51:30 +0000512#ifdef HAVE_STRUCT_T_OPTHDR
John Hughes38ae88d2002-05-23 11:48:58 +0000513
Roland McGrathd9f816f2004-09-04 03:39:20 +0000514static const struct xlat xti_level [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000515 { XTI_GENERIC, "XTI_GENERIC" },
516 { 0, NULL },
517};
518
Roland McGrathd9f816f2004-09-04 03:39:20 +0000519static const struct xlat xti_generic [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000520 { XTI_DEBUG, "XTI_DEBUG" },
521 { XTI_LINGER, "XTI_LINGER" },
522 { XTI_RCVBUF, "XTI_RCVBUF" },
523 { XTI_RCVLOWAT, "XTI_RCVLOWAT" },
524 { XTI_SNDBUF, "XTI_SNDBUF" },
525 { XTI_SNDLOWAT, "XTI_SNDLOWAT" },
526 { 0, NULL },
527};
528
529
530
531void
532print_xti_optmgmt (tcp, addr, len)
533struct tcb *tcp;
534long addr;
535int len;
536{
537 int c = 0;
538 struct t_opthdr hdr;
539
John Hughes2c4e3a82002-05-24 10:19:44 +0000540 while (len >= (int) sizeof hdr) {
John Hughes38ae88d2002-05-23 11:48:58 +0000541 if (umove(tcp, addr, &hdr) < 0) break;
542 if (c++) {
543 tprintf (", ");
544 }
545 else if (len > hdr.len + sizeof hdr) {
546 tprintf ("[");
547 }
548 tprintf ("{level=");
549 printxval (xti_level, hdr.level, "???");
550 tprintf (", name=");
551 switch (hdr.level) {
552 case XTI_GENERIC:
553 printxval (xti_generic, hdr.name, "XTI_???");
554 break;
555 default:
556 tprintf ("%ld", hdr.name);
557 break;
558 }
559 tprintf (", status=");
560 printxval (transport_user_flags, hdr.status, "T_???");
561 addr += sizeof hdr;
562 len -= sizeof hdr;
563 if ((hdr.len -= sizeof hdr) > 0) {
564 if (hdr.len > len) break;
565 tprintf (", val=");
566 if (len == sizeof (int))
567 printnum (tcp, addr, "%d");
568 else
569 printstr (tcp, addr, hdr.len);
570 addr += hdr.len;
571 len -= hdr.len;
572 }
573 tprintf ("}");
574 }
575 if (len > 0) {
576 if (c++) tprintf (", ");
577 printstr (tcp, addr, len);
578 }
579 if (c > 1) tprintf ("]");
580}
581
582#endif
583
584
585static void
586print_optmgmt (tcp, addr, len)
587struct tcb *tcp;
588long addr;
589int len;
590{
Roland McGrath34e014a2002-12-16 20:40:59 +0000591 /* We don't know how to tell if TLI (socket) or XTI
John Hughes38ae88d2002-05-23 11:48:58 +0000592 optmgmt is being used yet, assume TLI. */
Roland McGrath6d2b3492002-12-30 00:51:30 +0000593#if defined (HAVE_STRUCT_OPTHDR)
John Hughes38ae88d2002-05-23 11:48:58 +0000594 print_sock_optmgmt (tcp, addr, len);
Roland McGrath6d2b3492002-12-30 00:51:30 +0000595#elif defined (HAVE_STRUCT_T_OPTHDR)
John Hughes38ae88d2002-05-23 11:48:58 +0000596 print_xti_optmgmt (tcp, addr, len);
597#else
598 printstr (tcp, addr, len);
599#endif
600}
601
602
603
604
Roland McGrathd9f816f2004-09-04 03:39:20 +0000605static const struct xlat service_type [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000606 { T_COTS, "T_COTS" },
607 { T_COTS_ORD, "T_COTS_ORD" },
608 { T_CLTS, "T_CLTS" },
609 { 0, NULL },
610};
611
Roland McGrathd9f816f2004-09-04 03:39:20 +0000612static const struct xlat ts_state [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000613 { TS_UNBND, "TS_UNBND" },
614 { TS_WACK_BREQ, "TS_WACK_BREQ" },
615 { TS_WACK_UREQ, "TS_WACK_UREQ" },
616 { TS_IDLE, "TS_IDLE" },
617 { TS_WACK_OPTREQ,"TS_WACK_OPTREQ"},
618 { TS_WACK_CREQ, "TS_WACK_CREQ" },
619 { TS_WCON_CREQ, "TS_WCON_CREQ" },
620 { TS_WRES_CIND, "TS_WRES_CIND" },
621 { TS_WACK_CRES, "TS_WACK_CRES" },
622 { TS_DATA_XFER, "TS_DATA_XFER" },
623 { TS_WIND_ORDREL,"TS_WIND_ORDREL"},
624 { TS_WREQ_ORDREL,"TS_WREQ_ORDREL"},
625 { TS_WACK_DREQ6,"TS_WACK_DREQ6" },
626 { TS_WACK_DREQ7,"TS_WACK_DREQ7" },
627 { TS_WACK_DREQ9,"TS_WACK_DREQ9" },
628 { TS_WACK_DREQ10,"TS_WACK_DREQ10"},
629 { TS_WACK_DREQ11,"TS_WACK_DREQ11"},
630 { 0, NULL },
631};
632
Roland McGrathd9f816f2004-09-04 03:39:20 +0000633static const struct xlat provider_flags [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000634 { 0, "0" },
635 { SENDZERO, "SENDZERO" },
636 { EXPINLINE, "EXPINLINE" },
637 { XPG4_1, "XPG4_1" },
638 { 0, NULL },
639};
640
641
Roland McGrathd9f816f2004-09-04 03:39:20 +0000642static const struct xlat tli_errors [] = {
John Hughes38ae88d2002-05-23 11:48:58 +0000643 { TBADADDR, "TBADADDR" },
644 { TBADOPT, "TBADOPT" },
645 { TACCES, "TACCES" },
646 { TBADF, "TBADF" },
647 { TNOADDR, "TNOADDR" },
648 { TOUTSTATE, "TOUTSTATE" },
649 { TBADSEQ, "TBADSEQ" },
650 { TSYSERR, "TSYSERR" },
651 { TLOOK, "TLOOK" },
652 { TBADDATA, "TBADDATA" },
653 { TBUFOVFLW, "TBUFOVFLW" },
654 { TFLOW, "TFLOW" },
655 { TNODATA, "TNODATA" },
656 { TNODIS, "TNODIS" },
657 { TNOUDERR, "TNOUDERR" },
658 { TBADFLAG, "TBADFLAG" },
659 { TNOREL, "TNOREL" },
660 { TNOTSUPPORT, "TNOTSUPPORT" },
661 { TSTATECHNG, "TSTATECHNG" },
662 { TNOSTRUCTYPE, "TNOSTRUCTYPE" },
663 { TBADNAME, "TBADNAME" },
664 { TBADQLEN, "TBADQLEN" },
665 { TADDRBUSY, "TADDRBUSY" },
666 { TINDOUT, "TINDOUT" },
667 { TPROVMISMATCH,"TPROVMISMATCH" },
668 { TRESQLEN, "TRESQLEN" },
669 { TRESADDR, "TRESADDR" },
670 { TQFULL, "TQFULL" },
671 { TPROTO, "TPROTO" },
672 { 0, NULL },
673};
674
675
676static int
677print_transport_message (tcp, expect, addr, len)
678struct tcb *tcp;
679int expect;
680long addr;
681int len;
682{
683 union T_primitives m;
684 int c = 0;
685
686 if (len < sizeof m.type) goto dump;
687
688 if (umove (tcp, addr, &m.type) < 0) goto dump;
689
690#define GET(type, struct) \
691 do { \
692 if (len < sizeof m.struct) goto dump; \
693 if (umove (tcp, addr, &m.struct) < 0) goto dump;\
694 tprintf ("{"); \
695 if (expect != type) { \
696 ++c; \
697 tprintf (#type); \
698 } \
699 } \
700 while (0)
701
702#define COMMA() \
Roland McGrath34e014a2002-12-16 20:40:59 +0000703 do { if (c++) tprintf (", "); } while (0)
704
John Hughes38ae88d2002-05-23 11:48:58 +0000705
706#define STRUCT(struct, elem, print) \
707 do { \
708 COMMA (); \
709 if (m.struct.elem##_length < 0 || \
710 m.struct.elem##_offset < sizeof m.struct || \
711 m.struct.elem##_offset + m.struct.elem##_length > len) \
712 { \
713 tprintf (#elem "_length=%ld, " #elem "_offset=%ld",\
714 m.struct.elem##_length, \
715 m.struct.elem##_offset); \
716 } \
717 else { \
718 tprintf (#elem "="); \
719 print (tcp, \
720 addr + m.struct.elem##_offset, \
721 m.struct.elem##_length); \
722 } \
723 } \
724 while (0)
725
726#define ADDR(struct, elem) STRUCT (struct, elem, printstr)
Roland McGrath34e014a2002-12-16 20:40:59 +0000727
John Hughes38ae88d2002-05-23 11:48:58 +0000728 switch (m.type) {
729#ifdef T_CONN_REQ
730 case T_CONN_REQ: /* connect request */
731 GET (T_CONN_REQ, conn_req);
732 ADDR (conn_req, DEST);
733 ADDR (conn_req, OPT);
734 break;
735#endif
736#ifdef T_CONN_RES
737 case T_CONN_RES: /* connect response */
738 GET (T_CONN_RES, conn_res);
Roland McGrath38dc6bb2003-01-10 20:05:54 +0000739#ifdef HAVE_STRUCT_T_CONN_RES_QUEUE_PTR
John Hughes38ae88d2002-05-23 11:48:58 +0000740 COMMA ();
741 tprintf ("QUEUE=%p", m.conn_res.QUEUE_ptr);
Roland McGrath38dc6bb2003-01-10 20:05:54 +0000742#elif defined HAVE_STRUCT_T_CONN_RES_ACCEPTOR_ID
743 COMMA ();
Roland McGrath7686eee2003-01-10 20:09:43 +0000744 tprintf ("ACCEPTOR=%#lx", m.conn_res.ACCEPTOR_id);
Roland McGrath38dc6bb2003-01-10 20:05:54 +0000745#endif
John Hughes38ae88d2002-05-23 11:48:58 +0000746 ADDR (conn_res, OPT);
747 COMMA ();
748 tprintf ("SEQ=%ld", m.conn_res.SEQ_number);
749 break;
750#endif
751#ifdef T_DISCON_REQ
752 case T_DISCON_REQ: /* disconnect request */
753 GET (T_DISCON_REQ, discon_req);
754 COMMA ();
755 tprintf ("SEQ=%ld", m.discon_req.SEQ_number);
756 break;
757#endif
758#ifdef T_DATA_REQ
759 case T_DATA_REQ: /* data request */
760 GET (T_DATA_REQ, data_req);
761 COMMA ();
762 tprintf ("MORE=%ld", m.data_req.MORE_flag);
763 break;
764#endif
765#ifdef T_EXDATA_REQ
766 case T_EXDATA_REQ: /* expedited data req */
767 GET (T_EXDATA_REQ, exdata_req);
768 COMMA ();
769 tprintf ("MORE=%ld", m.exdata_req.MORE_flag);
770 break;
771#endif
772#ifdef T_INFO_REQ
773 case T_INFO_REQ: /* information req */
774 GET (T_INFO_REQ, info_req);
775 break;
776#endif
777#ifdef T_BIND_REQ
778 case T_BIND_REQ: /* bind request */
779#ifdef O_T_BIND_REQ
780 case O_T_BIND_REQ: /* Ugly xti/tli hack */
781#endif
782 GET (T_BIND_REQ, bind_req);
783 ADDR (bind_req, ADDR);
784 COMMA ();
785 tprintf ("CONIND=%ld", m.bind_req.CONIND_number);
786 break;
787#endif
788#ifdef T_UNBIND_REQ
789 case T_UNBIND_REQ: /* unbind request */
790 GET (T_UNBIND_REQ, unbind_req);
791 break;
792#endif
793#ifdef T_UNITDATA_REQ
794 case T_UNITDATA_REQ: /* unitdata requset */
795 GET (T_UNITDATA_REQ, unitdata_req);
796 ADDR (unitdata_req, DEST);
797 ADDR (unitdata_req, OPT);
798 break;
799#endif
800#ifdef T_OPTMGMT_REQ
801 case T_OPTMGMT_REQ: /* manage opt req */
802 GET (T_OPTMGMT_REQ, optmgmt_req);
803 COMMA ();
804 tprintf ("MGMT=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000805 printflags (transport_user_flags, m.optmgmt_req.MGMT_flags,
806 "T_???");
John Hughes38ae88d2002-05-23 11:48:58 +0000807 STRUCT (optmgmt_req, OPT, print_optmgmt);
808 break;
809#endif
810#ifdef T_ORDREL_REQ
811 case T_ORDREL_REQ: /* orderly rel req */
812 GET (T_ORDREL_REQ, ordrel_req);
813 break;
814#endif
815#ifdef T_CONN_IND
816 case T_CONN_IND: /* connect indication */
817 GET (T_CONN_IND, conn_ind);
818 ADDR (conn_ind, SRC);
819 ADDR (conn_ind, OPT);
820 tprintf (", SEQ=%ld", m.conn_ind.SEQ_number);
821 break;
822#endif
823#ifdef T_CONN_CON
824 case T_CONN_CON: /* connect corfirm */
825 GET (T_CONN_CON, conn_con);
826 ADDR (conn_con, RES);
827 ADDR (conn_con, OPT);
828 break;
829#endif
830#ifdef T_DISCON_IND
831 case T_DISCON_IND: /* discon indication */
832 GET (T_DISCON_IND, discon_ind);
833 COMMA ();
834 tprintf ("DISCON=%ld, SEQ=%ld",
835 m.discon_ind.DISCON_reason, m.discon_ind.SEQ_number);
836 break;
837#endif
838#ifdef T_DATA_IND
839 case T_DATA_IND: /* data indication */
840 GET (T_DATA_IND, data_ind);
841 COMMA ();
842 tprintf ("MORE=%ld", m.data_ind.MORE_flag);
843 break;
844#endif
845#ifdef T_EXDATA_IND
846 case T_EXDATA_IND: /* expedited data ind */
847 GET (T_EXDATA_IND, exdata_ind);
848 COMMA ();
849 tprintf ("MORE=%ld", m.exdata_ind.MORE_flag);
850 break;
851#endif
852#ifdef T_INFO_ACK
853 case T_INFO_ACK: /* info ack */
854 GET (T_INFO_ACK, info_ack);
855 COMMA ();
856 tprintf ("TSDU=%ld, ETSDU=%ld, CDATA=%ld, DDATA=%ld, "
857 "ADDR=%ld, OPT=%ld, TIDU=%ld, SERV=",
858 m.info_ack.TSDU_size, m.info_ack.ETSDU_size,
859 m.info_ack.CDATA_size, m.info_ack.DDATA_size,
860 m.info_ack.ADDR_size, m.info_ack.OPT_size,
861 m.info_ack.TIDU_size);
862 printxval (service_type, m.info_ack.SERV_type, "T_???");
863 tprintf (", CURRENT=");
864 printxval (ts_state, m.info_ack.CURRENT_state, "TS_???");
865 tprintf (", PROVIDER=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000866 printflags (provider_flags, m.info_ack.PROVIDER_flag, "???");
John Hughes38ae88d2002-05-23 11:48:58 +0000867 break;
868#endif
869#ifdef T_BIND_ACK
870 case T_BIND_ACK: /* bind ack */
871 GET (T_BIND_ACK, bind_ack);
872 ADDR (bind_ack, ADDR);
873 tprintf (", CONIND=%ld", m.bind_ack.CONIND_number);
874 break;
875#endif
876#ifdef T_ERROR_ACK
877 case T_ERROR_ACK: /* error ack */
878 GET (T_ERROR_ACK, error_ack);
879 COMMA ();
880 tprintf ("ERROR=");
881 printxval (transport_user_options,
882 m.error_ack.ERROR_prim, "TI_???");
883 tprintf (", TLI=");
884 printxval (tli_errors, m.error_ack.TLI_error, "T???");
885 tprintf ("UNIX=%s", strerror (m.error_ack.UNIX_error));
886 break;
887#endif
888#ifdef T_OK_ACK
889 case T_OK_ACK: /* ok ack */
890 GET (T_OK_ACK, ok_ack);
891 COMMA ();
892 tprintf ("CORRECT=");
893 printxval (transport_user_options,
894 m.ok_ack.CORRECT_prim, "TI_???");
895 break;
896#endif
897#ifdef T_UNITDATA_IND
898 case T_UNITDATA_IND: /* unitdata ind */
899 GET (T_UNITDATA_IND, unitdata_ind);
900 ADDR (unitdata_ind, SRC);
901 ADDR (unitdata_ind, OPT);
902 break;
903#endif
904#ifdef T_UDERROR_IND
905 case T_UDERROR_IND: /* unitdata error ind */
906 GET (T_UDERROR_IND, uderror_ind);
907 ADDR (uderror_ind, DEST);
908 ADDR (uderror_ind, OPT);
909 tprintf (", ERROR=%ld", m.uderror_ind.ERROR_type);
910 break;
911#endif
912#ifdef T_OPTMGMT_ACK
913 case T_OPTMGMT_ACK: /* manage opt ack */
914 GET (T_OPTMGMT_ACK, optmgmt_ack);
915 COMMA ();
916 tprintf ("MGMT=");
Roland McGrathb2dee132005-06-01 19:02:36 +0000917 printflags (transport_user_flags, m.optmgmt_ack.MGMT_flags,
918 "T_???");
John Hughes38ae88d2002-05-23 11:48:58 +0000919 STRUCT (optmgmt_ack, OPT, print_optmgmt);
920 break;
921#endif
922#ifdef T_ORDREL_IND
923 case T_ORDREL_IND: /* orderly rel ind */
924 GET (T_ORDREL_IND, ordrel_ind);
925 break;
926#endif
927#ifdef T_ADDR_REQ
928 case T_ADDR_REQ: /* address req */
929 GET (T_ADDR_REQ, addr_req);
930 break;
931#endif
932#ifdef T_ADDR_ACK
933 case T_ADDR_ACK: /* address response */
934 GET (T_ADDR_ACK, addr_ack);
935 ADDR (addr_ack, LOCADDR);
936 ADDR (addr_ack, REMADDR);
937 break;
938#endif
939 default:
940 dump:
941 c = -1;
942 printstr(tcp, addr, len);
943 break;
944 }
945
946 if (c >= 0) tprintf ("}");
947
948#undef ADDR
949#undef COMMA
950#undef STRUCT
Roland McGrath34e014a2002-12-16 20:40:59 +0000951
John Hughes38ae88d2002-05-23 11:48:58 +0000952 return 0;
953}
954
955
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000956#endif /* TI_BIND */
957
John Hughes38ae88d2002-05-23 11:48:58 +0000958
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000959static int
960internal_stream_ioctl(tcp, arg)
961struct tcb *tcp;
962int arg;
963{
964 struct strioctl si;
Roland McGrath1c04b0b2004-01-13 10:18:46 +0000965 struct ioctlent *iop;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000966 int in_and_out;
John Hughes38ae88d2002-05-23 11:48:58 +0000967 int timod = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000968#ifdef SI_GETUDATA
969 struct si_udata udata;
970#endif /* SI_GETUDATA */
971
972 if (!arg)
973 return 0;
974 if (umove(tcp, arg, &si) < 0) {
975 if (entering(tcp))
976 tprintf(", {...}");
977 return 1;
978 }
979 if (entering(tcp)) {
Roland McGrath2843a4e2003-11-14 02:54:03 +0000980 iop = ioctl_lookup(si.ic_cmd);
981 if (iop) {
982 tprintf(", {ic_cmd=%s", iop->symbol);
983 while ((iop = ioctl_next_match(iop)))
984 tprintf(" or %s", iop->symbol);
985 } else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000986 tprintf(", {ic_cmd=%#x", si.ic_cmd);
987 if (si.ic_timout == INFTIM)
988 tprintf(", ic_timout=INFTIM, ");
989 else
990 tprintf(" ic_timout=%d, ", si.ic_timout);
991 }
992 in_and_out = 1;
993 switch (si.ic_cmd) {
994#ifdef SI_GETUDATA
995 case SI_GETUDATA:
996 in_and_out = 0;
997 break;
998#endif /* SI_GETUDATA */
999 }
1000 if (in_and_out) {
1001 if (entering(tcp))
1002 tprintf("/* in */ ");
1003 else
1004 tprintf(", /* out */ ");
1005 }
1006 if (in_and_out || entering(tcp))
1007 tprintf("ic_len=%d, ic_dp=", si.ic_len);
1008 switch (si.ic_cmd) {
1009#ifdef TI_BIND
1010 case TI_BIND:
1011 /* in T_BIND_REQ, out T_BIND_ACK */
John Hughes38ae88d2002-05-23 11:48:58 +00001012 ++timod;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001013 if (entering(tcp)) {
John Hughes38ae88d2002-05-23 11:48:58 +00001014 print_transport_message (tcp,
1015 T_BIND_REQ,
1016 si.ic_dp, si.ic_len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001017 }
1018 else {
John Hughes38ae88d2002-05-23 11:48:58 +00001019 print_transport_message (tcp,
1020 T_BIND_ACK,
1021 si.ic_dp, si.ic_len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001022 }
1023 break;
1024#endif /* TI_BIND */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001025#ifdef TI_UNBIND
1026 case TI_UNBIND:
1027 /* in T_UNBIND_REQ, out T_OK_ACK */
John Hughes38ae88d2002-05-23 11:48:58 +00001028 ++timod;
1029 if (entering(tcp)) {
1030 print_transport_message (tcp,
1031 T_UNBIND_REQ,
1032 si.ic_dp, si.ic_len);
1033 }
1034 else {
1035 print_transport_message (tcp,
1036 T_OK_ACK,
1037 si.ic_dp, si.ic_len);
1038 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001039 break;
1040#endif /* TI_UNBIND */
1041#ifdef TI_GETINFO
1042 case TI_GETINFO:
1043 /* in T_INFO_REQ, out T_INFO_ACK */
John Hughes38ae88d2002-05-23 11:48:58 +00001044 ++timod;
1045 if (entering(tcp)) {
1046 print_transport_message (tcp,
1047 T_INFO_REQ,
1048 si.ic_dp, si.ic_len);
1049 }
1050 else {
1051 print_transport_message (tcp,
1052 T_INFO_ACK,
1053 si.ic_dp, si.ic_len);
1054 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001055 break;
1056#endif /* TI_GETINFO */
1057#ifdef TI_OPTMGMT
1058 case TI_OPTMGMT:
1059 /* in T_OPTMGMT_REQ, out T_OPTMGMT_ACK */
John Hughes38ae88d2002-05-23 11:48:58 +00001060 ++timod;
1061 if (entering(tcp)) {
1062 print_transport_message (tcp,
1063 T_OPTMGMT_REQ,
1064 si.ic_dp, si.ic_len);
1065 }
1066 else {
1067 print_transport_message (tcp,
1068 T_OPTMGMT_ACK,
1069 si.ic_dp, si.ic_len);
1070 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001071 break;
1072#endif /* TI_OPTMGMT */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001073#ifdef SI_GETUDATA
1074 case SI_GETUDATA:
1075 if (entering(tcp))
1076 break;
1077#if 0
1078 tprintf("struct si_udata ");
1079#endif
1080 if (umove(tcp, (int) si.ic_dp, &udata) < 0)
1081 tprintf("{...}");
1082 else {
1083 tprintf("{tidusize=%d, addrsize=%d, ",
1084 udata.tidusize, udata.addrsize);
1085 tprintf("optsize=%d, etsdusize=%d, ",
1086 udata.optsize, udata.etsdusize);
1087 tprintf("servtype=%d, so_state=%d, ",
1088 udata.servtype, udata.so_state);
1089 tprintf("so_options=%d", udata.so_options);
1090#if 0
1091 tprintf(", tsdusize=%d", udata.tsdusize);
1092#endif
1093 tprintf("}");
1094 }
1095 break;
1096#endif /* SI_GETUDATA */
1097 default:
Michal Ludvig10a88d02002-10-07 14:31:00 +00001098 printstr(tcp, (long) si.ic_dp, si.ic_len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099 break;
1100 }
John Hughes38ae88d2002-05-23 11:48:58 +00001101 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001102 tprintf("}");
John Hughes38ae88d2002-05-23 11:48:58 +00001103 if (timod && tcp->u_rval) {
1104 tcp->auxstr = xlookup (tli_errors, tcp->u_rval);
1105 return RVAL_STR + 1;
1106 }
1107 }
Roland McGrath34e014a2002-12-16 20:40:59 +00001108
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001109 return 1;
1110}
1111
1112int
1113stream_ioctl(tcp, code, arg)
1114struct tcb *tcp;
1115int code, arg;
1116{
1117#ifdef I_LIST
1118 int i;
1119#endif
1120 int val;
1121#ifdef I_FLUSHBAND
1122 struct bandinfo bi;
1123#endif
1124 struct strpeek sp;
1125 struct strfdinsert sfi;
1126 struct strrecvfd srf;
1127#ifdef I_LIST
1128 struct str_list sl;
1129#endif
1130
1131 /* I_STR is a special case because the data is read & written. */
1132 if (code == I_STR)
1133 return internal_stream_ioctl(tcp, arg);
1134 if (entering(tcp))
1135 return 0;
1136
1137 switch (code) {
1138 case I_PUSH:
1139 case I_LOOK:
1140 case I_FIND:
1141 /* arg is a string */
1142 tprintf(", ");
1143 printpath(tcp, arg);
1144 return 1;
1145 case I_POP:
1146 /* doesn't take an argument */
1147 return 1;
1148 case I_FLUSH:
1149 /* argument is an option */
1150 tprintf(", ");
1151 printxval(stream_flush_options, arg, "FLUSH???");
1152 return 1;
1153#ifdef I_FLUSHBAND
1154 case I_FLUSHBAND:
1155 /* argument is a pointer to a bandinfo struct */
1156 if (umove(tcp, arg, &bi) < 0)
1157 tprintf(", {...}");
1158 else {
1159 tprintf(", {bi_pri=%d, bi_flag=", bi.bi_pri);
Roland McGrathb2dee132005-06-01 19:02:36 +00001160 printflags(stream_flush_options, bi.bi_flag, "FLUSH???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001161 tprintf("}");
1162 }
1163 return 1;
1164#endif /* I_FLUSHBAND */
1165 case I_SETSIG:
1166 /* argument is a set of flags */
1167 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001168 printflags(stream_setsig_flags, arg, "S_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001169 return 1;
1170 case I_GETSIG:
1171 /* argument is a pointer to a set of flags */
1172 if (syserror(tcp))
1173 return 0;
1174 tprintf(", [");
1175 if (umove(tcp, arg, &val) < 0)
1176 tprintf("?");
Roland McGrathb2dee132005-06-01 19:02:36 +00001177 else
1178 printflags(stream_setsig_flags, val, "S_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001179 tprintf("]");
1180 return 1;
1181 case I_PEEK:
1182 /* argument is a pointer to a strpeek structure */
1183 if (syserror(tcp) || !arg)
1184 return 0;
1185 if (umove(tcp, arg, &sp) < 0) {
1186 tprintf(", {...}");
1187 return 1;
1188 }
1189 tprintf(", {ctlbuf=");
1190 printstrbuf(tcp, &sp.ctlbuf, 1);
1191 tprintf(", databuf=");
1192 printstrbuf(tcp, &sp.databuf, 1);
John Hughesfd15cb32002-05-17 11:41:35 +00001193 tprintf(", flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001194 printflags(msgflags, sp.flags, "RS_???");
John Hughesfd15cb32002-05-17 11:41:35 +00001195 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001196 return 1;
1197 case I_SRDOPT:
1198 /* argument is an option with flags */
1199 tprintf(", ");
1200 printxval(stream_read_options, arg & RMODEMASK, "R???");
1201 addflags(stream_read_flags, arg & ~RMODEMASK);
1202 return 1;
1203 case I_GRDOPT:
1204 /* argument is an pointer to an option with flags */
1205 if (syserror(tcp))
1206 return 0;
1207 tprintf(", [");
1208 if (umove(tcp, arg, &val) < 0)
1209 tprintf("?");
1210 else {
1211 printxval(stream_read_options,
1212 arg & RMODEMASK, "R???");
1213 addflags(stream_read_flags, arg & ~RMODEMASK);
1214 }
1215 tprintf("]");
1216 return 1;
1217 case I_NREAD:
1218#ifdef I_GETBAND
1219 case I_GETBAND:
1220#endif
1221#ifdef I_SETCLTIME
1222 case I_SETCLTIME:
1223#endif
1224#ifdef I_GETCLTIME
1225 case I_GETCLTIME:
1226#endif
1227 /* argument is a pointer to a decimal integer */
1228 if (syserror(tcp))
1229 return 0;
1230 tprintf(", ");
1231 printnum(tcp, arg, "%d");
1232 return 1;
1233 case I_FDINSERT:
1234 /* argument is a pointer to a strfdinsert structure */
1235 if (syserror(tcp) || !arg)
1236 return 0;
1237 if (umove(tcp, arg, &sfi) < 0) {
1238 tprintf(", {...}");
1239 return 1;
1240 }
1241 tprintf(", {ctlbuf=");
1242 printstrbuf(tcp, &sfi.ctlbuf, 1);
1243 tprintf(", databuf=");
1244 printstrbuf(tcp, &sfi.databuf, 1);
John Hughesfd15cb32002-05-17 11:41:35 +00001245 tprintf(", flags=");
Roland McGrathb2dee132005-06-01 19:02:36 +00001246 printflags(msgflags, sfi.flags, "RS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001247 tprintf(", filedes=%d, offset=%d}", sfi.fildes, sfi.offset);
1248 return 1;
1249#ifdef I_SWROPT
1250 case I_SWROPT:
1251 /* argument is a set of flags */
1252 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +00001253 printflags(stream_write_flags, arg, "SND???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001254 return 1;
1255#endif /* I_SWROPT */
1256#ifdef I_GWROPT
1257 case I_GWROPT:
1258 /* argument is an pointer to an option with flags */
1259 if (syserror(tcp))
1260 return 0;
1261 tprintf(", [");
1262 if (umove(tcp, arg, &val) < 0)
1263 tprintf("?");
Roland McGrathb2dee132005-06-01 19:02:36 +00001264 else
1265 printflags(stream_write_flags, arg, "SND???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001266 tprintf("]");
1267 return 1;
1268#endif /* I_GWROPT */
1269 case I_SENDFD:
1270#ifdef I_CKBAND
1271 case I_CKBAND:
1272#endif
1273#ifdef I_CANPUT
1274 case I_CANPUT:
1275#endif
1276 case I_LINK:
1277 case I_UNLINK:
1278 case I_PLINK:
1279 case I_PUNLINK:
1280 /* argument is a decimal integer */
1281 tprintf(", %d", arg);
1282 return 1;
1283 case I_RECVFD:
1284 /* argument is a pointer to a strrecvfd structure */
1285 if (syserror(tcp) || !arg)
1286 return 0;
1287 if (umove(tcp, arg, &srf) < 0) {
1288 tprintf(", {...}");
1289 return 1;
1290 }
1291 tprintf(", {fd=%d, uid=%lu, gid=%lu}", srf.fd,
1292 (unsigned long) srf.uid, (unsigned long) srf.gid);
1293 return 1;
1294#ifdef I_LIST
1295 case I_LIST:
1296 if (syserror(tcp))
1297 return 0;
1298 if (arg == 0) {
1299 tprintf(", NULL");
1300 return 1;
1301 }
1302 if (umove(tcp, arg, &sl) < 0) {
1303 tprintf(", {...}");
1304 return 1;
1305 }
1306 tprintf(", {sl_nmods=%d, sl_modlist=[", sl.sl_nmods);
1307 for (i = 0; i < tcp->u_rval; i++) {
1308 if (i)
1309 tprintf(", ");
1310 printpath(tcp, (int) sl.sl_modlist[i].l_name);
1311 }
1312 tprintf("]}");
1313 return 1;
1314#endif /* I_LIST */
1315#ifdef I_ATMARK
1316 case I_ATMARK:
1317 tprintf(", ");
1318 printxval(stream_atmark_options, arg, "???MARK");
1319 return 1;
1320#endif /* I_ATMARK */
1321 default:
1322 return 0;
1323 }
1324}
1325
Roland McGrath561c7992003-04-02 01:10:44 +00001326#endif /* !LINUX && !FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001327
Roland McGrath561c7992003-04-02 01:10:44 +00001328#endif /* HAVE_SYS_STREAM_H || LINUX || FREEBSD */