blob: ba6c2bf2efaa73a486f60187add8abb9649ce65a [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id$
30 */
31
32#include "defs.h"
33
34#include <sys/stat.h>
35#include <sys/socket.h>
36#include <sys/un.h>
37#include <netinet/in.h>
38#include <arpa/inet.h>
39#if defined(LINUX)
40#include <asm/types.h>
41#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC__ + __GLIBC_MINOR__ >= 3)
42# include <netipx/ipx.h>
43#else
44# include <linux/ipx.h>
45#endif
46#endif /* LINUX */
47
Wichert Akkerman2f473da1999-11-01 19:53:31 +000048#if defined(LINUX) && defined(MIPS)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000049#if defined(HAVE_LINUX_IN6_H)
Wichert Akkerman505e1761999-11-01 19:39:08 +000050#include <linux/in6.h>
51#endif
Wichert Akkerman2f473da1999-11-01 19:53:31 +000052#endif
Wichert Akkerman505e1761999-11-01 19:39:08 +000053
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000054#if defined(HAVE_SYS_UIO_H)
55#include <sys/uio.h>
56#endif
57
58#if defined(HAVE_LINUX_NETLINK_H)
59#include <linux/netlink.h>
60#endif
61
62#if defined(HAVE_LINUX_IF_PACKET_H)
63#include <linux/if_packet.h>
64#endif
65
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000066#ifndef PF_UNSPEC
67#define PF_UNSPEC AF_UNSPEC
68#endif
69
70#ifdef LINUX
71/* Under Linux these are enums so we can't test for them with ifdef. */
72#define IPPROTO_EGP IPPROTO_EGP
73#define IPPROTO_PUP IPPROTO_PUP
74#define IPPROTO_IDP IPPROTO_IDP
75#define IPPROTO_IGMP IPPROTO_IGMP
76#define IPPROTO_RAW IPPROTO_RAW
77#define IPPROTO_MAX IPPROTO_MAX
78#endif
79
80static struct xlat domains[] = {
81 { PF_UNSPEC, "PF_UNSPEC" },
82 { PF_UNIX, "PF_UNIX" },
83 { PF_INET, "PF_INET" },
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +000084#ifdef PF_NETLINK
85 { PF_NETLINK, "PF_NETLINK" },
86#endif
87#ifdef PF_PACKET
88 { PF_PACKET, "PF_PACKET" },
89#endif
90#ifdef PF_INET6
91 { PF_INET6, "PF_INET6" },
92#endif
93#ifdef PF_ATMSVC
94 { PF_ATMSVC, "PF_INET6" },
95#endif
96#ifdef PF_INET6
97 { PF_INET6, "PF_INET6" },
98#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000099#ifdef PF_LOCAL
100 { PF_LOCAL, "PS_LOCAL" },
101#endif
102#ifdef PF_ISO
103 { PF_ISO, "PF_ISO" },
104#endif
105#ifdef PF_AX25
106 { PF_AX25, "PF_AX25" },
107#endif
108#ifdef PF_IPX
109 { PF_IPX, "PF_IPX" },
110#endif
111#ifdef PF_APPLETALK
112 { PF_APPLETALK, "PF_APPLETALK" },
113#endif
114#ifdef PF_NETROM
115 { PF_NETROM, "PF_NETROM" },
116#endif
117#ifdef PF_BRIDGE
118 { PF_BRIDGE, "PF_BRIDGE" },
119#endif
120#ifdef PF_AAL5
121 { PF_AAL5, "PF_AAL5" },
122#endif
123#ifdef PF_X25
124 { PF_X25, "PF_X25" },
125#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000126#ifdef PF_ROSE
127 { PF_ROSE, "PF_ROSE" },
128#endif
129#ifdef PF_DECNET
130 { PF_DECNET, "PF_DECNET" },
131#endif
132#ifdef PF_NETBEUI
133 { PF_NETBEUI, "PF_NETBEUI" },
134#endif
135#ifdef PF_IMPLINK
136 { PF_IMPLINK, "PF_IMPLINK" },
137#endif
138 { 0, NULL },
139};
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000140static struct xlat addrfams[] = {
141 { AF_UNSPEC, "AF_UNSPEC" },
142 { AF_UNIX, "AF_UNIX" },
143 { AF_INET, "AF_INET" },
144 { AF_INET6, "AF_INET6" },
145 { AF_DECnet, "AF_DECnet" },
146#ifdef PF_ATMSVC
147 { AF_ATMSVC, "AF_ATMSVC" },
148#endif
149 { AF_PACKET, "AF_PACKET" },
150 { AF_NETLINK, "AF_NETLINK" },
151#ifdef PF_ISO
152 { AF_ISO, "AF_ISO" },
153#endif
154#ifdef PF_IMPLINK
155 { AF_IMPLINK, "AF_IMPLINK" },
156#endif
157 { 0, NULL },
158};
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159static struct xlat socktypes[] = {
160 { SOCK_STREAM, "SOCK_STREAM" },
161 { SOCK_DGRAM, "SOCK_DGRAM" },
162#ifdef SOCK_RAW
163 { SOCK_RAW, "SOCK_RAW" },
164#endif
165#ifdef SOCK_SEQPACKET
166 { SOCK_SEQPACKET,"SOCK_SEQPACKET"},
167#endif
168#ifdef SOCK_RDM
169 { SOCK_RDM, "SOCK_RDM" },
170#endif
171#ifdef SOCK_PACKET
172 { SOCK_PACKET, "SOCK_PACKET" },
173#endif
174 { 0, NULL },
175};
176static struct xlat protocols[] = {
177 { IPPROTO_IP, "IPPROTO_IP" },
178 { IPPROTO_ICMP, "IPPROTO_ICMP" },
179 { IPPROTO_TCP, "IPPROTO_TCP" },
180 { IPPROTO_UDP, "IPPROTO_UDP" },
181#ifdef IPPROTO_GGP
182 { IPPROTO_GGP, "IPPROTO_GGP" },
183#endif
184#ifdef IPPROTO_EGP
185 { IPPROTO_EGP, "IPPROTO_EGP" },
186#endif
187#ifdef IPPROTO_PUP
188 { IPPROTO_PUP, "IPPROTO_PUP" },
189#endif
190#ifdef IPPROTO_IDP
191 { IPPROTO_IDP, "IPPROTO_IDP" },
192#endif
193#ifdef IPPROTO_IPV6
194 { IPPROTO_IPV6, "IPPROTO_IPV6" },
195#endif
196#ifdef IPPROTO_ICMPV6
197 { IPPROTO_ICMPV6,"IPPROTO_ICMPV6"},
198#endif
199#ifdef IPPROTO_IGMP
200 { IPPROTO_IGMP, "IPPROTO_IGMP" },
201#endif
202#ifdef IPPROTO_HELLO
203 { IPPROTO_HELLO,"IPPROTO_HELLO" },
204#endif
205#ifdef IPPROTO_ND
206 { IPPROTO_ND, "IPPROTO_ND" },
207#endif
208#ifdef IPPROTO_RAW
209 { IPPROTO_RAW, "IPPROTO_RAW" },
210#endif
211#ifdef IPPROTO_MAX
212 { IPPROTO_MAX, "IPPROTO_MAX" },
213#endif
214#ifdef IPPROTO_IPIP
215 { IPPROTO_IPIP, "IPPROTO_IPIP" },
216#endif
217 { 0, NULL },
218};
219static struct xlat msg_flags[] = {
220 { MSG_OOB, "MSG_OOB" },
221#ifdef MSG_DONTROUTE
222 { MSG_DONTROUTE,"MSG_DONTROUTE" },
223#endif
224#ifdef MSG_PEEK
225 { MSG_PEEK, "MSG_PEEK" },
226#endif
227#ifdef MSG_CTRUNC
228 { MSG_CTRUNC, "MSG_CTRUNC" },
229#endif
230#ifdef MSG_PROXY
231 { MSG_PROXY, "MSG_PROXY" },
232#endif
233#ifdef MSG_EOR
234 { MSG_EOR, "MSG_EOR" },
235#endif
236#ifdef MSG_WAITALL
237 { MSG_WAITALL, "MSG_WAITALL" },
238#endif
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000239#ifdef MSG_TRUNC
240 { MSG_TRUNC, "MSG_TRUNC" },
241#endif
242#ifdef MSG_CTRUNC
243 { MSG_CTRUNC, "MSG_CTRUNC" },
244#endif
245#ifdef MSG_ERRQUEUE
246 { MSG_ERRQUEUE, "MSG_ERRQUEUE" },
247#endif
248#ifdef MSG_DONTWAIT
249 { MSG_DONTWAIT, "MSG_DONTWAIT" },
250#endif
251#ifdef MSG_CONFIRM
252 { MSG_CONFIRM, "MSG_CONFIRM" },
253#endif
254#ifdef MSG_PROBE
255 { MSG_PROBE, "MSG_PROBE" },
256#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000257 { 0, NULL },
258};
259
260static struct xlat sockoptions[] = {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000261#ifdef SO_PEERCRED
262 { SO_PEERCRED, "SO_PEERCRED" },
263#endif
264#ifdef SO_PASSCRED
265 { SO_PASSCRED, "SO_PASSCRED" },
266#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000267#ifdef SO_DEBUG
268 { SO_DEBUG, "SO_DEBUG" },
269#endif
270#ifdef SO_REUSEADDR
271 { SO_REUSEADDR, "SO_REUSEADDR" },
272#endif
273#ifdef SO_KEEPALIVE
274 { SO_KEEPALIVE, "SO_KEEPALIVE" },
275#endif
276#ifdef SO_DONTROUTE
277 { SO_DONTROUTE, "SO_DONTROUTE" },
278#endif
279#ifdef SO_BROADCAST
280 { SO_BROADCAST, "SO_BROADCAST" },
281#endif
282#ifdef SO_LINGER
283 { SO_LINGER, "SO_LINGER" },
284#endif
285#ifdef SO_OOBINLINE
286 { SO_OOBINLINE, "SO_OOBINLINE" },
287#endif
288#ifdef SO_TYPE
289 { SO_TYPE, "SO_TYPE" },
290#endif
291#ifdef SO_ERROR
292 { SO_ERROR, "SO_ERROR" },
293#endif
294#ifdef SO_SNDBUF
295 { SO_SNDBUF, "SO_SNDBUF" },
296#endif
297#ifdef SO_RCVBUF
298 { SO_RCVBUF, "SO_RCVBUF" },
299#endif
300#ifdef SO_NO_CHECK
301 { SO_NO_CHECK, "SO_NO_CHECK" },
302#endif
303#ifdef SO_PRIORITY
304 { SO_PRIORITY, "SO_PRIORITY" },
305#endif
306#ifdef SO_ACCEPTCONN
307 { SO_ACCEPTCONN,"SO_ACCEPTCONN" },
308#endif
309#ifdef SO_USELOOPBACK
310 { SO_USELOOPBACK,"SO_USELOOPBACK"},
311#endif
312#ifdef SO_SNDLOWAT
313 { SO_SNDLOWAT, "SO_SNDLOWAT" },
314#endif
315#ifdef SO_RCVLOWAT
316 { SO_RCVLOWAT, "SO_RCVLOWAT" },
317#endif
318#ifdef SO_SNDTIMEO
319 { SO_SNDTIMEO, "SO_SNDTIMEO" },
320#endif
321#ifdef SO_RCVTIMEO
322 { SO_RCVTIMEO, "SO_RCVTIMEO" },
323#endif
324#ifdef SO_BSDCOMPAT
325 { SO_BSDCOMPAT, "SO_BSDCOMPAT" },
326#endif
327#ifdef SO_REUSEPORT
328 { SO_REUSEPORT, "SO_REUSEPORT" },
329#endif
330#ifdef SO_RCVLOWAT
331 { SO_RCVLOWAT, "SO_RCVLOWAT" },
332#endif
333#ifdef SO_SNDLOWAT
334 { SO_SNDLOWAT, "SO_SNDLOWAT" },
335#endif
336#ifdef SO_RCVTIMEO
337 { SO_RCVTIMEO, "SO_RCVTIMEO" },
338#endif
339#ifdef SO_SNDTIMEO
340 { SO_SNDTIMEO, "SO_SNDTIMEO" },
341#endif
342 { 0, NULL },
343};
344
345#ifdef SOL_IP
346static struct xlat sockipoptions[] = {
347 { IP_TOS, "IP_TOS" },
348 { IP_TTL, "IP_TTL" },
349#if defined(IP_HDRINCL)
350 { IP_HDRINCL, "IP_HDRINCL" },
351#endif
352#if defined(IP_OPTIONS)
353 { IP_OPTIONS, "IP_OPTIONS" },
354#endif
355 { IP_MULTICAST_IF, "IP_MULTICAST_IF" },
356 { IP_MULTICAST_TTL, "IP_MULTICAST_TTL" },
357 { IP_MULTICAST_LOOP, "IP_MULTICAST_LOOP" },
358 { IP_ADD_MEMBERSHIP, "IP_ADD_MEMBERSHIP" },
359 { IP_DROP_MEMBERSHIP, "IP_DROP_MEMBERSHIP" },
360 { 0, NULL },
361};
362#endif /* SOL_IP */
363
364#ifdef SOL_IPX
365static struct xlat sockipxoptions[] = {
366 { IPX_TYPE, "IPX_TYPE" },
367 { 0, NULL },
368};
369#endif /* SOL_IPX */
370
371#ifdef SOL_TCP
372static struct xlat socktcpoptions[] = {
373 { TCP_NODELAY, "TCP_NODELAY" },
374 { TCP_MAXSEG, "TCP_MAXSEG" },
375 { 0, NULL },
376};
377#endif /* SOL_TCP */
378
379void
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000380printsock(tcp, addr, addrlen)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381struct tcb *tcp;
382long addr;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000383int addrlen;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384{
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000385 union {
386 char pad[128];
387 struct sockaddr sa;
388 struct sockaddr_in sin;
389 struct sockaddr_un sau;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000390#ifdef HAVE_INET_NTOP
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000391 struct sockaddr_in6 sa6;
392#endif
393#if defined(LINUX) && defined(AF_IPX)
394 struct sockaddr_ipx sipx;
395#endif
396#ifdef AF_PACKET
397 struct sockaddr_ll ll;
398#endif
399#ifdef AF_NETLINK
400 struct sockaddr_nl nl;
401#endif
402 } addrbuf;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000403 char string_addr[100];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000404
405 if (addr == 0) {
406 tprintf("NULL");
407 return;
408 }
409 if (!verbose(tcp)) {
410 tprintf("%#lx", addr);
411 return;
412 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000413 if ((addrlen<2) || (addrlen>sizeof(addrbuf)))
414 addrlen=sizeof(addrbuf);
415
416 if (umoven(tcp, addr, addrlen, (char*)&addrbuf) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417 tprintf("{...}");
418 return;
419 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000420
421 tprintf("{sin_family=");
422 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
423 tprintf(", ");
424
425 switch (addrbuf.sa.sa_family) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000426 case AF_UNIX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000427 if (addrlen==2) {
428 tprintf("<nil>");
429 } else if (addrbuf.sau.sun_path[0]) {
430 tprintf("path=\"%*.*s\"", addrlen-2, addrlen-2, addrbuf.sau.sun_path);
431 } else {
432 tprintf("path=@%*.*s", addrlen-3, addrlen-3, addrbuf.sau.sun_path+1);
433 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000434 break;
435 case AF_INET:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000436 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000437 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438 break;
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000439#ifdef HAVE_INET_NTOP
440 case AF_INET6:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000441 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
442 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=htonl(%u)}",
443 ntohs(addrbuf.sa6.sin6_port), string_addr, ntohl(addrbuf.sa6.sin6_flowinfo));
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000444 break;
445#endif
Wichert Akkermandbb440e1999-05-11 15:06:44 +0000446#if defined(AF_IPX) && defined(linux)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447 case AF_IPX:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000448 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449 int i;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000450 tprintf("{sipx_port=htons(%u), ",
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000451 ntohs(addrbuf.sipx.sipx_port));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452 /* Yes, I know, this does not look too
453 * strace-ish, but otherwise the IPX
454 * addresses just look monstrous...
455 * Anyways, feel free if you don't like
456 * this way.. :)
457 */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000458 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000459 for (i = 0; i<IPX_NODE_LEN; i++)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000460 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
461 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462 }
463 break;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000464#endif /* AF_IPX && linux */
465#ifdef AF_PACKET
466 case AF_PACKET:
467 {
468 int i;
469 tprintf("proto=%#04x, if%d, pkttype=%d, addr(%d)={%d, ",
470 ntohs(addrbuf.ll.sll_protocol),
471 addrbuf.ll.sll_ifindex,
472 addrbuf.ll.sll_pkttype,
473 addrbuf.ll.sll_halen,
474 addrbuf.ll.sll_hatype);
475 for (i=0; i<addrbuf.ll.sll_addr[i]; i++)
476 tprintf("%02x", addrbuf.ll.sll_addr[i]);
477 }
478 break;
479
480#endif /* AF_APACKET */
481#ifdef AF_NETLINLK
482 case AF_NETLINK:
483 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
484 break;
485#endif /* AF_NETLINK */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000486 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000487 AF_X25 AF_ROSE etc. still need to be done */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488
489 default:
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000490 tprintf("{sa_family=%u, sa_data=", addrbuf.sa.sa_family);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491 printstr(tcp, (long) &((struct sockaddr *) addr)->sa_data,
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000492 sizeof addrbuf.sa.sa_data);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000493 break;
494 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000495 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496}
497
498#if HAVE_SENDMSG
499
500static void
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000501printiovec(tcp, iovec, len)
502struct tcb *tcp;
503struct iovec *iovec;
504long len;
505{
506 struct iovec *iov;
507 int i;
508
509 iov = (struct iovec *) malloc(len * sizeof *iov);
510 if (iov == NULL) {
511 fprintf(stderr, "No memory");
512 return;
513 }
514 if (umoven(tcp, (long)iovec,
515 len * sizeof *iov, (char *) iov) < 0) {
516 tprintf("%#lx", (unsigned long)iovec);
517 } else {
518 tprintf("[");
519 for (i = 0; i < len; i++) {
520 if (i)
521 tprintf(", ");
522 tprintf("{");
523 printstr(tcp, (long) iov[i].iov_base,
524 iov[i].iov_len);
525 tprintf(", %lu}", (unsigned long)iov[i].iov_len);
526 }
527 tprintf("]");
528 }
529 free((char *) iov);
530}
531
532static void
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533printmsghdr(tcp, addr)
534struct tcb *tcp;
535long addr;
536{
537 struct msghdr msg;
538
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000539 if (umove(tcp, addr, &msg) < 0) {
540 tprintf("%#lx", addr);
541 return;
542 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000543 tprintf("{msg_name(%d)=", msg.msg_namelen);
544 printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
545
546 tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
547 printiovec(tcp, msg.msg_iov, msg.msg_iovlen);
548
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549#ifdef HAVE_MSG_CONTROL
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000550 tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
551 if (msg.msg_controllen)
552 tprintf(", msg_control=%#lx, ", (unsigned long) msg.msg_control);
553 tprintf(", msg_flags=");
554 if (printflags(msg_flags, msg.msg_flags)==0)
555 tprintf("0");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000556#else /* !HAVE_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000557 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558 (unsigned long) msg.msg_accrights, msg.msg_accrightslen);
559#endif /* !HAVE_MSG_CONTROL */
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000560 tprintf("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561}
562
563#endif /* HAVE_SENDMSG */
564
565int
566sys_socket(tcp)
567struct tcb *tcp;
568{
569 if (entering(tcp)) {
570 printxval(domains, tcp->u_arg[0], "PF_???");
571 tprintf(", ");
572 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
573 tprintf(", ");
574 switch (tcp->u_arg[0]) {
575 case PF_INET:
576 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
577 break;
578#ifdef PF_IPX
579 case PF_IPX:
580 /* BTW: I don't believe this.. */
581 tprintf("[");
582 printxval(domains, tcp->u_arg[2], "PF_???");
583 tprintf("]");
584 break;
585#endif /* PF_IPX */
586 default:
587 tprintf("%lu", tcp->u_arg[2]);
588 break;
589 }
590 }
591 return 0;
592}
593
594int
595sys_bind(tcp)
596struct tcb *tcp;
597{
598 if (entering(tcp)) {
599 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000600 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000601 tprintf(", %lu", tcp->u_arg[2]);
602 }
603 return 0;
604}
605
606int
607sys_connect(tcp)
608struct tcb *tcp;
609{
610 return sys_bind(tcp);
611}
612
613int
614sys_listen(tcp)
615struct tcb *tcp;
616{
617 if (entering(tcp)) {
618 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
619 }
620 return 0;
621}
622
623int
624sys_accept(tcp)
625struct tcb *tcp;
626{
627 if (entering(tcp)) {
628 tprintf("%ld, ", tcp->u_arg[0]);
629 } else if (!tcp->u_arg[2])
630 tprintf("%#lx, NULL", tcp->u_arg[1]);
631 else {
632 if (tcp->u_arg[1] == 0 || syserror(tcp)) {
633 tprintf("%#lx", tcp->u_arg[1]);
634 } else {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000635 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000636 }
637 tprintf(", ");
638 printnum(tcp, tcp->u_arg[2], "%lu");
639 }
640 return 0;
641}
642
643int
644sys_send(tcp)
645struct tcb *tcp;
646{
647 if (entering(tcp)) {
648 tprintf("%ld, ", tcp->u_arg[0]);
649 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
650 tprintf(", %lu, ", tcp->u_arg[2]);
651 /* flags */
652 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
653 tprintf("0");
654 }
655 return 0;
656}
657
658int
659sys_sendto(tcp)
660struct tcb *tcp;
661{
662 if (entering(tcp)) {
663 tprintf("%ld, ", tcp->u_arg[0]);
664 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
665 tprintf(", %lu, ", tcp->u_arg[2]);
666 /* flags */
667 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
668 tprintf("0");
669 /* to address */
670 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000671 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000672 /* to length */
673 tprintf(", %lu", tcp->u_arg[5]);
674 }
675 return 0;
676}
677
678#ifdef HAVE_SENDMSG
679
680int
681sys_sendmsg(tcp)
682struct tcb *tcp;
683{
684 if (entering(tcp)) {
685 tprintf("%ld, ", tcp->u_arg[0]);
686 printmsghdr(tcp, tcp->u_arg[1]);
687 /* flags */
688 tprintf(", ");
689 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
690 tprintf("0");
691 }
692 return 0;
693}
694
695#endif /* HAVE_SENDMSG */
696
697int
698sys_recv(tcp)
699struct tcb *tcp;
700{
701 if (entering(tcp)) {
702 tprintf("%ld, ", tcp->u_arg[0]);
703 } else {
704 if (syserror(tcp))
705 tprintf("%#lx", tcp->u_arg[1]);
706 else
707 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
708
709 tprintf(", %lu, ", tcp->u_arg[2]);
710 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
711 tprintf("0");
712 }
713 return 0;
714}
715
716int
717sys_recvfrom(tcp)
718struct tcb *tcp;
719{
720 int fromlen;
721
722 if (entering(tcp)) {
723 tprintf("%ld, ", tcp->u_arg[0]);
724 } else {
725 if (syserror(tcp)) {
726 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
727 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
728 tcp->u_arg[4], tcp->u_arg[5]);
729 return 0;
730 }
731 /* buf */
732 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
733 /* len */
734 tprintf(", %lu, ", tcp->u_arg[2]);
735 /* flags */
736 if (printflags(msg_flags, tcp->u_arg[3]) == 0)
737 tprintf("0");
738 /* from address, len */
739 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
740 if (tcp->u_arg[4] == 0)
741 tprintf(", NULL");
742 else
743 tprintf(", %#lx", tcp->u_arg[4]);
744 if (tcp->u_arg[5] == 0)
745 tprintf(", NULL");
746 else
747 tprintf(", %#lx", tcp->u_arg[5]);
748 return 0;
749 }
750 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
751 tprintf(", {...}, [?]");
752 return 0;
753 }
754 tprintf(", ");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000755 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000756 /* from length */
757 tprintf(", [%u]", fromlen);
758 }
759 return 0;
760}
761
762#ifdef HAVE_SENDMSG
763
764int
765sys_recvmsg(tcp)
766struct tcb *tcp;
767{
768 if (entering(tcp)) {
769 tprintf("%ld, ", tcp->u_arg[0]);
770 } else {
771 if (syserror(tcp) || !verbose(tcp))
772 tprintf("%#lx", tcp->u_arg[1]);
773 else
774 printmsghdr(tcp, tcp->u_arg[1]);
775 /* flags */
776 tprintf(", ");
777 if (printflags(msg_flags, tcp->u_arg[2]) == 0)
778 tprintf("0");
779 }
780 return 0;
781}
782
783#endif /* HAVE_SENDMSG */
784
785int
786sys_shutdown(tcp)
787struct tcb *tcp;
788{
789 if (entering(tcp)) {
790 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
791 switch (tcp->u_arg[1]) {
792 case 0:
793 tprintf("%s", " /* receive */");
794 break;
795 case 1:
796 tprintf("%s", " /* send */");
797 break;
798 case 2:
799 tprintf("%s", " /* send and receive */");
800 break;
801 }
802 }
803 return 0;
804}
805
806int
807sys_getsockname(tcp)
808struct tcb *tcp;
809{
810 return sys_accept(tcp);
811}
812
813int
814sys_getpeername(tcp)
815struct tcb *tcp;
816{
817 return sys_accept(tcp);
818}
819
820int
821sys_pipe(tcp)
822struct tcb *tcp;
823{
824
825#if defined(LINUX) && !defined(SPARC)
826 int fds[2];
827
828 if (exiting(tcp)) {
829 if (syserror(tcp)) {
830 tprintf("%#lx", tcp->u_arg[0]);
831 return 0;
832 }
833 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
834 tprintf("[...]");
835 else
836 tprintf("[%u, %u]", fds[0], fds[1]);
837 }
Wichert Akkerman5daa0281999-03-15 19:49:42 +0000838#elif defined(SPARC) || defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000839 if (exiting(tcp))
840 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000841#endif
842 return 0;
843}
844
845int
846sys_socketpair(tcp)
847struct tcb *tcp;
848{
849#ifdef LINUX
850 int fds[2];
851#endif
852
853 if (entering(tcp)) {
854 printxval(domains, tcp->u_arg[0], "PF_???");
855 tprintf(", ");
856 printxval(socktypes, tcp->u_arg[1], "SOCK_???");
857 tprintf(", ");
858 switch (tcp->u_arg[0]) {
859 case PF_INET:
860 printxval(protocols, tcp->u_arg[2], "IPPROTO_???");
861 break;
862#ifdef PF_IPX
863 case PF_IPX:
864 /* BTW: I don't believe this.. */
865 tprintf("[");
866 printxval(domains, tcp->u_arg[2], "PF_???");
867 tprintf("]");
868 break;
869#endif /* PF_IPX */
870 default:
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000871 tprintf("%lu", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000872 break;
873 }
874 } else {
875 if (syserror(tcp)) {
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000876 tprintf(", %#lx", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000877 return 0;
878 }
879#ifdef LINUX
880 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000881 tprintf(", [...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882 else
883 tprintf(", [%u, %u]", fds[0], fds[1]);
884#endif /* LINUX */
885#ifdef SUNOS4
886 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
887#endif /* SUNOS4 */
888#ifdef SVR4
889 tprintf(", [%lu, %lu]", tcp->u_rval, getrval2(tcp));
890#endif /* SVR4 */
891 }
892 return 0;
893}
894
895int
896sys_getsockopt(tcp)
897struct tcb *tcp;
898{
899 if (entering(tcp)) {
900 tprintf("%ld, ", tcp->u_arg[0]);
901 switch (tcp->u_arg[1]) {
902 case SOL_SOCKET:
903 tprintf("SOL_SOCKET, ");
904 printxval(sockoptions, tcp->u_arg[2], "SO_???");
905 tprintf(", ");
906 break;
907#ifdef SOL_IP
908 case SOL_IP:
909 tprintf("SOL_IP, ");
910 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
911 tprintf(", ");
912 break;
913#endif
914#ifdef SOL_IPX
915 case SOL_IPX:
916 tprintf("SOL_IPX, ");
917 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
918 tprintf(", ");
919 break;
920#endif
921#ifdef SOL_TCP
922 case SOL_TCP:
923 tprintf("SOL_TCP, ");
924 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
925 tprintf(", ");
926 break;
927#endif
928
929 /* SOL_AX25 SOL_ROSE SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
930 * etc. still need work */
931 default:
932 /* XXX - should know socket family here */
933 printxval(protocols, tcp->u_arg[1], "IPPROTO_???");
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000934 tprintf(", %lu, ", tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000935 break;
936 }
937 } else {
938 if (syserror(tcp)) {
939 tprintf("%#lx, %#lx",
940 tcp->u_arg[3], tcp->u_arg[4]);
941 return 0;
942 }
943 printnum(tcp, tcp->u_arg[3], "%ld");
944 tprintf(", ");
945 printnum(tcp, tcp->u_arg[4], "%ld");
946 }
947 return 0;
948}
949
950int
951sys_setsockopt(tcp)
952struct tcb *tcp;
953{
954 if (entering(tcp)) {
955 tprintf("%ld, ", tcp->u_arg[0]);
956 switch (tcp->u_arg[1]) {
957 case SOL_SOCKET:
958 tprintf("SOL_SOCKET, ");
959 printxval(sockoptions, tcp->u_arg[2], "SO_???");
960 tprintf(", ");
961 break;
962#ifdef SOL_IP
963 case SOL_IP:
964 tprintf("SOL_IP, ");
965 printxval(sockipoptions, tcp->u_arg[2], "IP_???");
966 tprintf(", ");
967 break;
968#endif
969#ifdef SOL_IPX
970 case SOL_IPX:
971 tprintf("SOL_IPX, ");
972 printxval(sockipxoptions, tcp->u_arg[2], "IPX_???");
973 tprintf(", ");
974 break;
975#endif
976#ifdef SOL_TCP
977 case SOL_TCP:
978 tprintf("SOL_TCP, ");
979 printxval(socktcpoptions, tcp->u_arg[2], "TCP_???");
980 tprintf(", ");
981 break;
982#endif
983
984 /* SOL_AX25 SOL_ATALK SOL_NETROM SOL_UDP SOL_DECNET SOL_X25
985 * etc. still need work */
986 default:
987 /* XXX - should know socket family here */
988 printxval(protocols, tcp->u_arg[1], "IPPROTO_???");
989 tprintf("%lu, ", tcp->u_arg[2]);
990 break;
991 }
992 printnum(tcp, tcp->u_arg[3], "%ld");
993 tprintf(", %lu", tcp->u_arg[4]);
994 }
995 return 0;
996}