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 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/socket.h>
36 #if defined(HAVE_SIN6_SCOPE_ID_LINUX)
37 # define in6_addr in6_addr_libc
38 # define ipv6_mreq ipv6_mreq_libc
39 # define sockaddr_in6 sockaddr_in6_libc
41 #include <netinet/in.h>
42 #ifdef HAVE_NETINET_TCP_H
43 # include <netinet/tcp.h>
45 #ifdef HAVE_NETINET_UDP_H
46 # include <netinet/udp.h>
48 #ifdef HAVE_NETINET_SCTP_H
49 # include <netinet/sctp.h>
51 #include <arpa/inet.h>
53 #include <asm/types.h>
54 #if defined(__GLIBC__)
55 # include <netipx/ipx.h>
57 # include <linux/ipx.h>
60 #if defined(__GLIBC__) && defined(HAVE_SIN6_SCOPE_ID_LINUX)
61 # if defined(HAVE_LINUX_IN6_H)
62 # if defined(HAVE_SIN6_SCOPE_ID_LINUX)
66 # define in6_addr in6_addr_kernel
67 # define ipv6_mreq ipv6_mreq_kernel
68 # define sockaddr_in6 sockaddr_in6_kernel
70 # include <linux/in6.h>
71 # if defined(HAVE_SIN6_SCOPE_ID_LINUX)
75 # define in6_addr in6_addr_libc
76 # define ipv6_mreq ipv6_mreq_libc
77 # define sockaddr_in6 sockaddr_in6_kernel
82 #if defined(HAVE_LINUX_NETLINK_H)
83 # include <linux/netlink.h>
85 #if defined(HAVE_LINUX_IF_PACKET_H)
86 # include <linux/if_packet.h>
88 #if defined(HAVE_LINUX_ICMP_H)
89 # include <linux/icmp.h>
91 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
92 # include <bluetooth/bluetooth.h>
93 # include <bluetooth/hci.h>
94 # include <bluetooth/l2cap.h>
95 # include <bluetooth/rfcomm.h>
96 # include <bluetooth/sco.h>
99 # define PF_UNSPEC AF_UNSPEC
102 #include "xlat/domains.h"
103 #include "xlat/addrfams.h"
104 #include "xlat/socktypes.h"
105 #include "xlat/sock_type_flags.h"
106 #ifndef SOCK_TYPE_MASK
107 # define SOCK_TYPE_MASK 0xf
123 # define SOL_ICMPV6 58
126 # define SOL_SCTP 132
129 # define SOL_UDPLITE 136
138 # define SOL_AX25 257
141 # define SOL_ATALK 258
144 # define SOL_NETROM 259
147 # define SOL_ROSE 260
150 # define SOL_DECNET 261
156 # define SOL_PACKET 263
165 # define SOL_IRDA 266
168 # define SOL_NETBEUI 267
174 # define SOL_DCCP 269
177 # define SOL_NETLINK 270
180 # define SOL_TIPC 271
183 # define SOL_RXRPC 272
186 # define SOL_PPPOL2TP 273
188 #ifndef SOL_BLUETOOTH
189 # define SOL_BLUETOOTH 274
192 # define SOL_PNPIPE 275
198 # define SOL_IUCV 277
201 # define SOL_CAIF 278
209 #include "xlat/socketlayers.h"
211 #include "xlat/inet_protocols.h"
214 # if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
215 # define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
217 # include "xlat/netlink_protocols.h"
220 #if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
221 # include "xlat/bt_protocols.h"
224 #include "xlat/msg_flags.h"
226 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
227 # include "xlat/af_packet_types.h"
231 printsock(struct tcb *tcp, long addr, int addrlen)
236 struct sockaddr_in sin;
237 struct sockaddr_un sau;
238 #ifdef HAVE_INET_NTOP
239 struct sockaddr_in6 sa6;
242 struct sockaddr_ipx sipx;
245 struct sockaddr_ll ll;
248 struct sockaddr_nl nl;
250 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
251 struct sockaddr_hci hci;
252 struct sockaddr_l2 l2;
253 struct sockaddr_rc rc;
254 struct sockaddr_sco sco;
257 char string_addr[100];
264 tprintf("%#lx", addr);
268 if (addrlen < 2 || addrlen > (int) sizeof(addrbuf))
269 addrlen = sizeof(addrbuf);
271 memset(&addrbuf, 0, sizeof(addrbuf));
272 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
276 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
278 tprints("{sa_family=");
279 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
282 switch (addrbuf.sa.sa_family) {
286 } else if (addrbuf.sau.sun_path[0]) {
287 tprints("sun_path=");
288 print_quoted_string(addrbuf.sau.sun_path,
289 sizeof(addrbuf.sau.sun_path) + 1,
292 tprints("sun_path=@");
293 print_quoted_string(addrbuf.sau.sun_path + 1,
294 sizeof(addrbuf.sau.sun_path),
299 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
300 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
302 #ifdef HAVE_INET_NTOP
304 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
305 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
306 ntohs(addrbuf.sa6.sin6_port), string_addr,
307 addrbuf.sa6.sin6_flowinfo);
308 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
310 #if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
311 int numericscope = 0;
312 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
313 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
314 char scopebuf[IFNAMSIZ + 1];
316 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
319 tprints(", sin6_scope_id=if_nametoindex(");
320 print_quoted_string(scopebuf,
330 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
339 tprintf("sipx_port=htons(%u), ",
340 ntohs(addrbuf.sipx.sipx_port));
341 /* Yes, I know, this does not look too
342 * strace-ish, but otherwise the IPX
343 * addresses just look monstrous...
344 * Anyways, feel free if you don't like
347 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
348 for (i = 0; i < IPX_NODE_LEN; i++)
349 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
350 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
358 tprintf("proto=%#04x, if%d, pkttype=",
359 ntohs(addrbuf.ll.sll_protocol),
360 addrbuf.ll.sll_ifindex);
361 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
362 tprintf(", addr(%d)={%d, ",
363 addrbuf.ll.sll_halen,
364 addrbuf.ll.sll_hatype);
365 for (i = 0; i < addrbuf.ll.sll_halen; i++)
366 tprintf("%02x", addrbuf.ll.sll_addr[i]);
370 #endif /* AF_PACKET */
373 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
375 #endif /* AF_NETLINK */
376 #if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
378 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
379 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
380 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
381 "{hci_dev=htobs(%d)}",
382 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
383 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
384 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
385 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
386 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
387 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
388 addrbuf.rc.rc_channel,
389 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
390 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
391 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
392 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
393 btohs(addrbuf.hci.hci_dev));
395 #endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
396 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
397 AF_X25 AF_ROSE etc. still need to be done */
401 print_quoted_string(addrbuf.sa.sa_data,
402 sizeof(addrbuf.sa.sa_data), 0);
409 # ifndef SCM_SECURITY
410 # define SCM_SECURITY 0x03
412 # include "xlat/scmvals.h"
414 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
424 struct cmsghdr *cmsg;
425 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
426 struct cmsghdr32 *cmsg32;
431 print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
433 if (cmsg_size + sizeof(int) > cmsg_len)
436 int *fds = (int *) (ptr + cmsg_size);
440 while ((char *) fds < (ptr + cmsg_len)) {
445 printfd(tcp, *fds++);
452 print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
454 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
457 const struct ucred *uc = (void *) (ptr + cmsg_size);
459 tprintf(", {pid=%u, uid=%u, gid=%u}}",
460 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
465 print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
467 if (cmsg_size + sizeof(char) > cmsg_len)
470 const char *label = (const char *) (ptr + cmsg_size);
471 const size_t label_len = cmsg_len - cmsg_size;
474 print_quoted_string(label, label_len, 0);
481 printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
483 const size_t cmsg_size =
484 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
485 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
487 sizeof(struct cmsghdr);
489 char *buf = len < cmsg_size ? NULL : malloc(len);
490 if (!buf || umoven(tcp, addr, len, buf) < 0) {
491 tprintf(", msg_control=%#lx", addr);
496 union_cmsghdr u = { .ptr = buf };
499 while (len >= cmsg_size) {
501 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
502 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
506 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
507 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
511 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
512 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
518 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
519 printxval(socketlayers, cmsg_level, "SOL_???");
520 tprints(", cmsg_type=");
525 if (cmsg_level == SOL_SOCKET) {
526 printxval(scmvals, cmsg_type, "SCM_???");
529 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
532 case SCM_CREDENTIALS:
533 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
537 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
542 tprintf("%u", cmsg_type);
546 if (cmsg_len < cmsg_size) {
550 cmsg_len = (cmsg_len + current_wordsize - 1) &
551 (size_t) ~(current_wordsize - 1);
552 if (cmsg_len >= len) {
566 do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
568 tprintf("{msg_name(%d)=", msg->msg_namelen);
569 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
571 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
572 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
573 (unsigned long)msg->msg_iov, 1, data_size);
575 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
576 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
577 if (msg->msg_controllen)
578 printcmsghdr(tcp, (unsigned long) msg->msg_control,
579 msg->msg_controllen);
580 tprints(", msg_flags=");
581 printflags(msg_flags, msg->msg_flags, "MSG_???");
582 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
583 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
584 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
585 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
590 uint32_t /* void* */ msg_name;
591 uint32_t /* socklen_t */msg_namelen;
592 uint32_t /* iovec* */ msg_iov;
593 uint32_t /* size_t */ msg_iovlen;
594 uint32_t /* void* */ msg_control;
595 uint32_t /* size_t */ msg_controllen;
596 uint32_t /* int */ msg_flags;
599 struct msghdr32 msg_hdr;
600 uint32_t /* unsigned */ msg_len;
603 #ifndef HAVE_STRUCT_MMSGHDR
605 struct msghdr msg_hdr;
610 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
612 copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
614 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
615 to_msg->msg_namelen = from_msg32->msg_namelen;
616 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
617 to_msg->msg_iovlen = from_msg32->msg_iovlen;
618 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
619 to_msg->msg_controllen = from_msg32->msg_controllen;
620 to_msg->msg_flags = from_msg32->msg_flags;
625 extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
627 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
628 if (current_wordsize == 4) {
629 struct msghdr32 msg32;
631 if (umove(tcp, addr, &msg32) < 0)
633 copy_from_msghdr32(msg, &msg32);
636 if (umove(tcp, addr, msg) < 0)
642 extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
644 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
645 if (current_wordsize == 4) {
646 struct mmsghdr32 mmsg32;
648 addr += sizeof(struct mmsghdr32) * idx;
649 if (umove(tcp, addr, &mmsg32) < 0)
652 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
653 mmsg->msg_len = mmsg32.msg_len;
657 addr += sizeof(*mmsg) * idx;
658 if (umove(tcp, addr, mmsg) < 0)
665 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
669 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
670 do_msghdr(tcp, &msg, data_size);
672 tprintf("%#lx", addr);
676 dumpiov_in_msghdr(struct tcb *tcp, long addr)
680 if (extractmsghdr(tcp, addr, &msg))
681 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
685 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
689 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
691 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
692 tprintf(", %u}", mmsg.msg_len);
695 tprintf("%#lx", addr);
699 decode_mmsg(struct tcb *tcp, unsigned long msg_len)
703 tprintf("%#lx", tcp->u_arg[1]);
705 unsigned int len = tcp->u_rval;
709 for (i = 0; i < len; ++i) {
712 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
717 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
719 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
723 dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
725 unsigned int len = tcp->u_rval;
729 for (i = 0; i < len; ++i) {
730 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
731 tprintf(" = %lu buffers in vector %u\n",
732 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
733 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
734 (long)mmsg.msg_hdr.msg_iov);
738 #endif /* HAVE_SENDMSG */
741 * low bits of the socket type define real socket type,
742 * other bits are socket type flags.
745 tprint_sock_type(int flags)
747 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
751 flags &= ~SOCK_TYPE_MASK;
756 printflags(sock_type_flags, flags, "SOCK_???");
760 sys_socket(struct tcb *tcp)
763 printxval(domains, tcp->u_arg[0], "PF_???");
765 tprint_sock_type(tcp->u_arg[1]);
767 switch (tcp->u_arg[0]) {
772 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
776 /* BTW: I don't believe this.. */
778 printxval(domains, tcp->u_arg[2], "PF_???");
784 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
787 #if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
789 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
793 tprintf("%lu", tcp->u_arg[2]);
801 sys_bind(struct tcb *tcp)
804 printfd(tcp, tcp->u_arg[0]);
806 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
807 tprintf(", %lu", tcp->u_arg[2]);
813 sys_connect(struct tcb *tcp)
815 return sys_bind(tcp);
819 sys_listen(struct tcb *tcp)
822 printfd(tcp, tcp->u_arg[0]);
824 tprintf("%lu", tcp->u_arg[1]);
830 do_sockname(struct tcb *tcp, int flags_arg)
833 printfd(tcp, tcp->u_arg[0]);
838 tprintf("%#lx, NULL", tcp->u_arg[1]);
841 if (tcp->u_arg[1] == 0 || syserror(tcp)
842 || umove(tcp, tcp->u_arg[2], &len) < 0) {
843 tprintf("%#lx", tcp->u_arg[1]);
845 printsock(tcp, tcp->u_arg[1], len);
848 printnum_int(tcp, tcp->u_arg[2], "%u");
850 if (flags_arg >= 0) {
852 printflags(sock_type_flags, tcp->u_arg[flags_arg],
859 sys_accept(struct tcb *tcp)
861 do_sockname(tcp, -1);
866 sys_accept4(struct tcb *tcp)
873 sys_send(struct tcb *tcp)
876 printfd(tcp, tcp->u_arg[0]);
878 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
879 tprintf(", %lu, ", tcp->u_arg[2]);
881 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
887 sys_sendto(struct tcb *tcp)
890 printfd(tcp, tcp->u_arg[0]);
892 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
893 tprintf(", %lu, ", tcp->u_arg[2]);
895 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
898 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
900 tprintf(", %lu", tcp->u_arg[5]);
908 sys_sendmsg(struct tcb *tcp)
911 printfd(tcp, tcp->u_arg[0]);
913 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
916 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
922 sys_sendmmsg(struct tcb *tcp)
926 printfd(tcp, tcp->u_arg[0]);
929 tprintf("%#lx, %u, ",
930 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
931 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
935 decode_mmsg(tcp, (unsigned long) -1L);
940 #endif /* HAVE_SENDMSG */
943 sys_recv(struct tcb *tcp)
946 printfd(tcp, tcp->u_arg[0]);
950 tprintf("%#lx", tcp->u_arg[1]);
952 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
954 tprintf(", %lu, ", tcp->u_arg[2]);
955 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
961 sys_recvfrom(struct tcb *tcp)
966 printfd(tcp, tcp->u_arg[0]);
970 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
971 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
972 tcp->u_arg[4], tcp->u_arg[5]);
976 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
978 tprintf(", %lu, ", tcp->u_arg[2]);
980 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
981 /* from address, len */
982 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
983 if (tcp->u_arg[4] == 0)
986 tprintf(", %#lx", tcp->u_arg[4]);
987 if (tcp->u_arg[5] == 0)
990 tprintf(", %#lx", tcp->u_arg[5]);
993 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
994 tprints(", {...}, [?]");
998 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
1000 tprintf(", [%u]", fromlen);
1008 sys_recvmsg(struct tcb *tcp)
1010 if (entering(tcp)) {
1011 printfd(tcp, tcp->u_arg[0]);
1015 tprintf("%#lx", tcp->u_arg[1]);
1017 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
1020 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1026 sys_recvmmsg(struct tcb *tcp)
1028 /* +5 chars are for "left " prefix */
1029 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
1031 if (entering(tcp)) {
1032 printfd(tcp, tcp->u_arg[0]);
1035 sprint_timespec(str, tcp, tcp->u_arg[4]);
1036 /* Abusing tcp->auxstr as temp storage.
1037 * Will be used and freed on syscall exit.
1039 tcp->auxstr = strdup(str);
1041 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1042 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1044 print_timespec(tcp, tcp->u_arg[4]);
1049 decode_mmsg(tcp, 0);
1050 /* timeout on entrance */
1051 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1052 free((void *) tcp->auxstr);
1057 if (tcp->u_rval == 0) {
1058 tcp->auxstr = "Timeout";
1063 /* timeout on exit */
1064 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
1070 #endif /* HAVE_SENDMSG */
1072 #include "xlat/shutdown_modes.h"
1075 sys_shutdown(struct tcb *tcp)
1077 if (entering(tcp)) {
1078 printfd(tcp, tcp->u_arg[0]);
1080 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1086 sys_getsockname(struct tcb *tcp)
1088 return do_sockname(tcp, -1);
1092 do_pipe(struct tcb *tcp, int flags_arg)
1095 if (syserror(tcp)) {
1096 tprintf("%#lx", tcp->u_arg[0]);
1098 #if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1101 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1104 tprintf("[%u, %u]", fds[0], fds[1]);
1105 #elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
1106 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1108 tprintf("%#lx", tcp->u_arg[0]);
1111 if (flags_arg >= 0) {
1113 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1120 sys_pipe(struct tcb *tcp)
1122 return do_pipe(tcp, -1);
1126 sys_pipe2(struct tcb *tcp)
1128 return do_pipe(tcp, 1);
1132 sys_socketpair(struct tcb *tcp)
1136 if (entering(tcp)) {
1137 printxval(domains, tcp->u_arg[0], "PF_???");
1139 tprint_sock_type(tcp->u_arg[1]);
1140 tprintf(", %lu", tcp->u_arg[2]);
1142 if (syserror(tcp)) {
1143 tprintf(", %#lx", tcp->u_arg[3]);
1146 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
1149 tprintf(", [%u, %u]", fds[0], fds[1]);
1154 #include "xlat/sockoptions.h"
1155 #include "xlat/sockipoptions.h"
1156 #include "xlat/sockipv6options.h"
1157 #include "xlat/sockipxoptions.h"
1158 #include "xlat/sockrawoptions.h"
1159 #include "xlat/sockpacketoptions.h"
1160 #include "xlat/socksctpoptions.h"
1161 #include "xlat/socktcpoptions.h"
1164 print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name)
1168 printxval(socketlayers, level, "SOL_??");
1173 printxval(sockoptions, name, "SO_???");
1176 printxval(sockipoptions, name, "IP_???");
1179 printxval(sockipv6options, name, "IPV6_???");
1182 printxval(sockipxoptions, name, "IPX_???");
1185 printxval(sockpacketoptions, name, "PACKET_???");
1188 printxval(socktcpoptions, name, "TCP_???");
1191 printxval(socksctpoptions, name, "SCTP_???");
1194 printxval(sockrawoptions, name, "RAW_???");
1197 /* Other SOL_* protocol levels still need work. */
1200 tprintf("%u", name);
1208 print_linger(struct tcb *tcp, long addr, int len)
1210 struct linger linger;
1212 if (len != sizeof(linger) ||
1213 umove(tcp, addr, &linger) < 0) {
1214 tprintf("%#lx", addr);
1218 tprintf("{onoff=%d, linger=%d}",
1222 #endif /* SO_LINGER */
1226 print_ucred(struct tcb *tcp, long addr, int len)
1230 if (len != sizeof(uc) ||
1231 umove(tcp, addr, &uc) < 0) {
1232 tprintf("%#lx", addr);
1234 tprintf("{pid=%u, uid=%u, gid=%u}",
1240 #endif /* SO_PEERCRED */
1242 #ifdef PACKET_STATISTICS
1244 print_tpacket_stats(struct tcb *tcp, long addr, int len)
1246 struct tpacket_stats stats;
1248 if (len != sizeof(stats) ||
1249 umove(tcp, addr, &stats) < 0) {
1250 tprintf("%#lx", addr);
1252 tprintf("{packets=%u, drops=%u}",
1257 #endif /* PACKET_STATISTICS */
1260 # include "xlat/icmpfilterflags.h"
1263 print_icmp_filter(struct tcb *tcp, long addr, int len)
1265 struct icmp_filter filter;
1267 if (len != sizeof(filter) ||
1268 umove(tcp, addr, &filter) < 0) {
1269 tprintf("%#lx", addr);
1274 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1277 #endif /* ICMP_FILTER */
1280 print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1282 if (addr && verbose(tcp))
1288 print_linger(tcp, addr, len);
1293 print_ucred(tcp, addr, len);
1301 #ifdef PACKET_STATISTICS
1302 case PACKET_STATISTICS:
1303 print_tpacket_stats(tcp, addr, len);
1313 print_icmp_filter(tcp, addr, len);
1320 /* default arg printing */
1323 if (len == sizeof(int)) {
1324 printnum_int(tcp, addr, "%d");
1326 printstr(tcp, addr, len);
1329 tprintf("%#lx", addr);
1332 tprintf(", [%d]", len);
1336 sys_getsockopt(struct tcb *tcp)
1338 if (entering(tcp)) {
1339 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1340 tcp->u_arg[1], tcp->u_arg[2]);
1344 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1345 tprintf("%#lx, %#lx",
1346 tcp->u_arg[3], tcp->u_arg[4]);
1348 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1349 tcp->u_arg[3], len);
1355 #ifdef MCAST_JOIN_GROUP
1357 print_group_req(struct tcb *tcp, long addr, int len)
1359 struct group_req greq;
1361 if (len != sizeof(greq) ||
1362 umove(tcp, addr, &greq) < 0) {
1363 tprintf("%#lx", addr);
1368 struct sockaddr *sa;
1369 struct sockaddr_in *sin;
1370 #ifdef HAVE_INET_NTOP
1371 struct sockaddr_in6 *sin6;
1373 } a = { .sa = (struct sockaddr *) &greq.gr_group };
1374 #ifdef HAVE_INET_NTOP
1375 char str[INET6_ADDRSTRLEN];
1378 tprintf("{gr_interface=%u, gr_group={sa_family=", greq.gr_interface);
1379 printxval(addrfams, a.sa->sa_family, "AF_???");
1381 switch (a.sa->sa_family) {
1383 tprintf(", sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}}",
1384 ntohs(a.sin->sin_port),
1385 inet_ntoa(a.sin->sin_addr));
1387 #ifdef HAVE_INET_NTOP
1389 if (!inet_ntop(AF_INET6, &a.sin6->sin6_addr, str, sizeof(str)))
1391 tprintf(", sin6_port=htons(%u)"
1392 ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}}",
1393 ntohs(a.sin6->sin6_port), str);
1395 #endif /* HAVE_INET_NTOP */
1398 tprints(", sa_data=");
1399 print_quoted_string(a.sa->sa_data, sizeof(a.sa->sa_data), 0);
1403 #endif /* MCAST_JOIN_GROUP */
1405 #ifdef PACKET_RX_RING
1407 print_tpacket_req(struct tcb *tcp, long addr, int len)
1409 struct tpacket_req req;
1411 if (len != sizeof(req) ||
1412 umove(tcp, addr, &req) < 0) {
1413 tprintf("%#lx", addr);
1415 tprintf("{block_size=%u, block_nr=%u, "
1416 "frame_size=%u, frame_nr=%u}",
1423 #endif /* PACKET_RX_RING */
1425 #ifdef PACKET_ADD_MEMBERSHIP
1426 # include "xlat/packet_mreq_type.h"
1429 print_packet_mreq(struct tcb *tcp, long addr, int len)
1431 struct packet_mreq mreq;
1433 if (len != sizeof(mreq) ||
1434 umove(tcp, addr, &mreq) < 0) {
1435 tprintf("%#lx", addr);
1439 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1440 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1441 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1442 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1443 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1444 for (i = 0; i < mreq.mr_alen; ++i)
1445 tprintf("%02x", mreq.mr_address[i]);
1449 #endif /* PACKET_ADD_MEMBERSHIP */
1452 print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1454 if (addr && verbose(tcp))
1460 print_linger(tcp, addr, len);
1468 #ifdef MCAST_JOIN_GROUP
1469 case MCAST_JOIN_GROUP:
1470 case MCAST_LEAVE_GROUP:
1471 print_group_req(tcp, addr, len);
1473 #endif /* MCAST_JOIN_GROUP */
1478 #ifdef PACKET_RX_RING
1479 case PACKET_RX_RING:
1480 # ifdef PACKET_TX_RING
1481 case PACKET_TX_RING:
1483 print_tpacket_req(tcp, addr, len);
1485 #endif /* PACKET_RX_RING */
1486 #ifdef PACKET_ADD_MEMBERSHIP
1487 case PACKET_ADD_MEMBERSHIP:
1488 case PACKET_DROP_MEMBERSHIP:
1489 print_packet_mreq(tcp, addr, len);
1491 #endif /* PACKET_ADD_MEMBERSHIP */
1499 print_icmp_filter(tcp, addr, len);
1506 /* default arg printing */
1509 if (len == sizeof(int)) {
1510 printnum_int(tcp, addr, "%d");
1512 printstr(tcp, addr, len);
1515 tprintf("%#lx", addr);
1518 tprintf(", %d", len);
1522 sys_setsockopt(struct tcb *tcp)
1524 if (entering(tcp)) {
1525 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1526 tcp->u_arg[1], tcp->u_arg[2]);
1527 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1528 tcp->u_arg[3], tcp->u_arg[4]);