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 #include <netinet/in.h>
37 #ifdef HAVE_NETINET_TCP_H
38 # include <netinet/tcp.h>
40 #ifdef HAVE_NETINET_UDP_H
41 # include <netinet/udp.h>
43 #ifdef HAVE_NETINET_SCTP_H
44 # include <netinet/sctp.h>
46 #include <arpa/inet.h>
48 #include <asm/types.h>
49 #if defined(__GLIBC__)
50 # include <netipx/ipx.h>
52 # include <linux/ipx.h>
55 #if defined(HAVE_LINUX_NETLINK_H)
56 # include <linux/netlink.h>
58 #if defined(HAVE_LINUX_IF_PACKET_H)
59 # include <linux/if_packet.h>
61 #if defined(HAVE_LINUX_ICMP_H)
62 # include <linux/icmp.h>
64 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
65 # include <bluetooth/bluetooth.h>
66 # include <bluetooth/hci.h>
67 # include <bluetooth/l2cap.h>
68 # include <bluetooth/rfcomm.h>
69 # include <bluetooth/sco.h>
72 # define PF_UNSPEC AF_UNSPEC
75 #include "xlat/domains.h"
76 #include "xlat/addrfams.h"
77 #include "xlat/socktypes.h"
78 #include "xlat/sock_type_flags.h"
79 #ifndef SOCK_TYPE_MASK
80 # define SOCK_TYPE_MASK 0xf
96 # define SOL_ICMPV6 58
102 # define SOL_UDPLITE 136
111 # define SOL_AX25 257
114 # define SOL_ATALK 258
117 # define SOL_NETROM 259
120 # define SOL_ROSE 260
123 # define SOL_DECNET 261
129 # define SOL_PACKET 263
138 # define SOL_IRDA 266
141 # define SOL_NETBEUI 267
147 # define SOL_DCCP 269
150 # define SOL_NETLINK 270
153 # define SOL_TIPC 271
156 # define SOL_RXRPC 272
159 # define SOL_PPPOL2TP 273
161 #ifndef SOL_BLUETOOTH
162 # define SOL_BLUETOOTH 274
165 # define SOL_PNPIPE 275
171 # define SOL_IUCV 277
174 # define SOL_CAIF 278
182 #include "xlat/socketlayers.h"
184 #include "xlat/inet_protocols.h"
187 # if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
188 # define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
190 # include "xlat/netlink_protocols.h"
193 #if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
194 # include "xlat/bt_protocols.h"
197 #include "xlat/msg_flags.h"
199 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
200 # include "xlat/af_packet_types.h"
204 printsock(struct tcb *tcp, long addr, int addrlen)
209 struct sockaddr_in sin;
210 struct sockaddr_un sau;
211 #ifdef HAVE_INET_NTOP
212 struct sockaddr_in6 sa6;
215 struct sockaddr_ipx sipx;
218 struct sockaddr_ll ll;
221 struct sockaddr_nl nl;
223 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
224 struct sockaddr_hci hci;
225 struct sockaddr_l2 l2;
226 struct sockaddr_rc rc;
227 struct sockaddr_sco sco;
230 char string_addr[100];
237 tprintf("%#lx", addr);
241 if (addrlen < 2 || addrlen > (int) sizeof(addrbuf))
242 addrlen = sizeof(addrbuf);
244 memset(&addrbuf, 0, sizeof(addrbuf));
245 if (umoven(tcp, addr, addrlen, addrbuf.pad) < 0) {
249 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
251 tprints("{sa_family=");
252 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
255 switch (addrbuf.sa.sa_family) {
259 } else if (addrbuf.sau.sun_path[0]) {
260 tprints("sun_path=");
261 print_quoted_string(addrbuf.sau.sun_path,
262 sizeof(addrbuf.sau.sun_path) + 1,
265 tprints("sun_path=@");
266 print_quoted_string(addrbuf.sau.sun_path + 1,
267 sizeof(addrbuf.sau.sun_path),
272 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
273 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
275 #ifdef HAVE_INET_NTOP
277 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
278 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
279 ntohs(addrbuf.sa6.sin6_port), string_addr,
280 addrbuf.sa6.sin6_flowinfo);
281 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
283 #if defined(HAVE_IF_INDEXTONAME) && defined(IN6_IS_ADDR_LINKLOCAL) && defined(IN6_IS_ADDR_MC_LINKLOCAL)
284 int numericscope = 0;
285 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
286 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr)) {
287 char scopebuf[IFNAMSIZ + 1];
289 if (if_indextoname(addrbuf.sa6.sin6_scope_id, scopebuf) == NULL)
292 tprints(", sin6_scope_id=if_nametoindex(");
293 print_quoted_string(scopebuf,
303 tprintf(", sin6_scope_id=%u", addrbuf.sa6.sin6_scope_id);
312 tprintf("sipx_port=htons(%u), ",
313 ntohs(addrbuf.sipx.sipx_port));
314 /* Yes, I know, this does not look too
315 * strace-ish, but otherwise the IPX
316 * addresses just look monstrous...
317 * Anyways, feel free if you don't like
320 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
321 for (i = 0; i < IPX_NODE_LEN; i++)
322 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
323 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
331 tprintf("proto=%#04x, if%d, pkttype=",
332 ntohs(addrbuf.ll.sll_protocol),
333 addrbuf.ll.sll_ifindex);
334 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
335 tprintf(", addr(%d)={%d, ",
336 addrbuf.ll.sll_halen,
337 addrbuf.ll.sll_hatype);
338 for (i = 0; i < addrbuf.ll.sll_halen; i++)
339 tprintf("%02x", addrbuf.ll.sll_addr[i]);
343 #endif /* AF_PACKET */
346 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
348 #endif /* AF_NETLINK */
349 #if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
351 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
352 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
353 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
354 "{hci_dev=htobs(%d)}",
355 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
356 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
357 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
358 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
359 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
360 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
361 addrbuf.rc.rc_channel,
362 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
363 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
364 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
365 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
366 btohs(addrbuf.hci.hci_dev));
368 #endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
369 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
370 AF_X25 AF_ROSE etc. still need to be done */
374 print_quoted_string(addrbuf.sa.sa_data,
375 sizeof(addrbuf.sa.sa_data), 0);
382 # ifndef SCM_SECURITY
383 # define SCM_SECURITY 0x03
385 # include "xlat/scmvals.h"
387 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
397 struct cmsghdr *cmsg;
398 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
399 struct cmsghdr32 *cmsg32;
404 print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
406 if (cmsg_size + sizeof(int) > cmsg_len)
409 int *fds = (int *) (ptr + cmsg_size);
413 while ((char *) fds < (ptr + cmsg_len)) {
418 printfd(tcp, *fds++);
425 print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
427 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
430 const struct ucred *uc = (void *) (ptr + cmsg_size);
432 tprintf(", {pid=%u, uid=%u, gid=%u}}",
433 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
438 print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
440 if (cmsg_size + sizeof(char) > cmsg_len)
443 const char *label = (const char *) (ptr + cmsg_size);
444 const size_t label_len = cmsg_len - cmsg_size;
447 print_quoted_string(label, label_len, 0);
454 printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
456 const size_t cmsg_size =
457 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
458 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
460 sizeof(struct cmsghdr);
462 char *buf = len < cmsg_size ? NULL : malloc(len);
463 if (!buf || umoven(tcp, addr, len, buf) < 0) {
464 tprintf(", msg_control=%#lx", addr);
469 union_cmsghdr u = { .ptr = buf };
472 while (len >= cmsg_size) {
474 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
475 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
479 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
480 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
484 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
485 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
491 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
492 printxval(socketlayers, cmsg_level, "SOL_???");
493 tprints(", cmsg_type=");
498 if (cmsg_level == SOL_SOCKET) {
499 printxval(scmvals, cmsg_type, "SCM_???");
502 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
505 case SCM_CREDENTIALS:
506 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
510 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
515 tprintf("%u", cmsg_type);
519 if (cmsg_len < cmsg_size) {
523 cmsg_len = (cmsg_len + current_wordsize - 1) &
524 (size_t) ~(current_wordsize - 1);
525 if (cmsg_len >= len) {
539 do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
541 tprintf("{msg_name(%d)=", msg->msg_namelen);
542 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
544 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
545 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
546 (unsigned long)msg->msg_iov, 1, data_size);
548 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
549 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
550 if (msg->msg_controllen)
551 printcmsghdr(tcp, (unsigned long) msg->msg_control,
552 msg->msg_controllen);
553 tprints(", msg_flags=");
554 printflags(msg_flags, msg->msg_flags, "MSG_???");
555 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
556 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
557 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
558 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
563 uint32_t /* void* */ msg_name;
564 uint32_t /* socklen_t */msg_namelen;
565 uint32_t /* iovec* */ msg_iov;
566 uint32_t /* size_t */ msg_iovlen;
567 uint32_t /* void* */ msg_control;
568 uint32_t /* size_t */ msg_controllen;
569 uint32_t /* int */ msg_flags;
572 struct msghdr32 msg_hdr;
573 uint32_t /* unsigned */ msg_len;
576 #ifndef HAVE_STRUCT_MMSGHDR
578 struct msghdr msg_hdr;
583 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
585 copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
587 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
588 to_msg->msg_namelen = from_msg32->msg_namelen;
589 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
590 to_msg->msg_iovlen = from_msg32->msg_iovlen;
591 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
592 to_msg->msg_controllen = from_msg32->msg_controllen;
593 to_msg->msg_flags = from_msg32->msg_flags;
598 extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
600 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
601 if (current_wordsize == 4) {
602 struct msghdr32 msg32;
604 if (umove(tcp, addr, &msg32) < 0)
606 copy_from_msghdr32(msg, &msg32);
609 if (umove(tcp, addr, msg) < 0)
615 extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
617 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
618 if (current_wordsize == 4) {
619 struct mmsghdr32 mmsg32;
621 addr += sizeof(struct mmsghdr32) * idx;
622 if (umove(tcp, addr, &mmsg32) < 0)
625 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
626 mmsg->msg_len = mmsg32.msg_len;
630 addr += sizeof(*mmsg) * idx;
631 if (umove(tcp, addr, mmsg) < 0)
638 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
642 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
643 do_msghdr(tcp, &msg, data_size);
645 tprintf("%#lx", addr);
649 dumpiov_in_msghdr(struct tcb *tcp, long addr)
653 if (extractmsghdr(tcp, addr, &msg))
654 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
658 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
662 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
664 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
665 tprintf(", %u}", mmsg.msg_len);
668 tprintf("%#lx", addr);
672 decode_mmsg(struct tcb *tcp, unsigned long msg_len)
676 tprintf("%#lx", tcp->u_arg[1]);
678 unsigned int len = tcp->u_rval;
682 for (i = 0; i < len; ++i) {
685 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
690 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
692 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
696 dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
698 unsigned int len = tcp->u_rval;
702 for (i = 0; i < len; ++i) {
703 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
704 tprintf(" = %lu buffers in vector %u\n",
705 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
706 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
707 (long)mmsg.msg_hdr.msg_iov);
711 #endif /* HAVE_SENDMSG */
714 * low bits of the socket type define real socket type,
715 * other bits are socket type flags.
718 tprint_sock_type(int flags)
720 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
724 flags &= ~SOCK_TYPE_MASK;
729 printflags(sock_type_flags, flags, "SOCK_???");
733 sys_socket(struct tcb *tcp)
736 printxval(domains, tcp->u_arg[0], "PF_???");
738 tprint_sock_type(tcp->u_arg[1]);
740 switch (tcp->u_arg[0]) {
745 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
749 /* BTW: I don't believe this.. */
751 printxval(domains, tcp->u_arg[2], "PF_???");
757 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
760 #if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
762 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
766 tprintf("%lu", tcp->u_arg[2]);
774 sys_bind(struct tcb *tcp)
777 printfd(tcp, tcp->u_arg[0]);
779 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
780 tprintf(", %lu", tcp->u_arg[2]);
786 sys_connect(struct tcb *tcp)
788 return sys_bind(tcp);
792 sys_listen(struct tcb *tcp)
795 printfd(tcp, tcp->u_arg[0]);
797 tprintf("%lu", tcp->u_arg[1]);
803 do_sockname(struct tcb *tcp, int flags_arg)
806 printfd(tcp, tcp->u_arg[0]);
811 tprintf("%#lx, NULL", tcp->u_arg[1]);
814 if (tcp->u_arg[1] == 0 || syserror(tcp)
815 || umove(tcp, tcp->u_arg[2], &len) < 0) {
816 tprintf("%#lx", tcp->u_arg[1]);
818 printsock(tcp, tcp->u_arg[1], len);
821 printnum_int(tcp, tcp->u_arg[2], "%u");
823 if (flags_arg >= 0) {
825 printflags(sock_type_flags, tcp->u_arg[flags_arg],
832 sys_accept(struct tcb *tcp)
834 do_sockname(tcp, -1);
839 sys_accept4(struct tcb *tcp)
846 sys_send(struct tcb *tcp)
849 printfd(tcp, tcp->u_arg[0]);
851 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
852 tprintf(", %lu, ", tcp->u_arg[2]);
854 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
860 sys_sendto(struct tcb *tcp)
863 printfd(tcp, tcp->u_arg[0]);
865 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
866 tprintf(", %lu, ", tcp->u_arg[2]);
868 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
871 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
873 tprintf(", %lu", tcp->u_arg[5]);
881 sys_sendmsg(struct tcb *tcp)
884 printfd(tcp, tcp->u_arg[0]);
886 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
889 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
895 sys_sendmmsg(struct tcb *tcp)
899 printfd(tcp, tcp->u_arg[0]);
902 tprintf("%#lx, %u, ",
903 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
904 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
908 decode_mmsg(tcp, (unsigned long) -1L);
913 #endif /* HAVE_SENDMSG */
916 sys_recv(struct tcb *tcp)
919 printfd(tcp, tcp->u_arg[0]);
923 tprintf("%#lx", tcp->u_arg[1]);
925 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
927 tprintf(", %lu, ", tcp->u_arg[2]);
928 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
934 sys_recvfrom(struct tcb *tcp)
939 printfd(tcp, tcp->u_arg[0]);
943 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
944 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
945 tcp->u_arg[4], tcp->u_arg[5]);
949 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
951 tprintf(", %lu, ", tcp->u_arg[2]);
953 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
954 /* from address, len */
955 if (!tcp->u_arg[4] || !tcp->u_arg[5]) {
956 if (tcp->u_arg[4] == 0)
959 tprintf(", %#lx", tcp->u_arg[4]);
960 if (tcp->u_arg[5] == 0)
963 tprintf(", %#lx", tcp->u_arg[5]);
966 if (umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
967 tprints(", {...}, [?]");
971 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
973 tprintf(", [%u]", fromlen);
981 sys_recvmsg(struct tcb *tcp)
984 printfd(tcp, tcp->u_arg[0]);
988 tprintf("%#lx", tcp->u_arg[1]);
990 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
993 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
999 sys_recvmmsg(struct tcb *tcp)
1001 /* +5 chars are for "left " prefix */
1002 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
1004 if (entering(tcp)) {
1005 printfd(tcp, tcp->u_arg[0]);
1008 sprint_timespec(str, tcp, tcp->u_arg[4]);
1009 /* Abusing tcp->auxstr as temp storage.
1010 * Will be used and freed on syscall exit.
1012 tcp->auxstr = strdup(str);
1014 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1015 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1017 print_timespec(tcp, tcp->u_arg[4]);
1022 decode_mmsg(tcp, 0);
1023 /* timeout on entrance */
1024 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
1025 free((void *) tcp->auxstr);
1030 if (tcp->u_rval == 0) {
1031 tcp->auxstr = "Timeout";
1036 /* timeout on exit */
1037 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
1043 #endif /* HAVE_SENDMSG */
1045 #include "xlat/shutdown_modes.h"
1048 sys_shutdown(struct tcb *tcp)
1050 if (entering(tcp)) {
1051 printfd(tcp, tcp->u_arg[0]);
1053 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1059 sys_getsockname(struct tcb *tcp)
1061 return do_sockname(tcp, -1);
1065 do_pipe(struct tcb *tcp, int flags_arg)
1068 if (syserror(tcp)) {
1069 tprintf("%#lx", tcp->u_arg[0]);
1071 #if !defined(SPARC) && !defined(SPARC64) && !defined(SH) && !defined(IA64)
1074 if (umoven(tcp, tcp->u_arg[0], sizeof fds, (char *) fds) < 0)
1077 tprintf("[%u, %u]", fds[0], fds[1]);
1078 #elif defined(SPARC) || defined(SPARC64) || defined(SH) || defined(IA64)
1079 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
1081 tprintf("%#lx", tcp->u_arg[0]);
1084 if (flags_arg >= 0) {
1086 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1093 sys_pipe(struct tcb *tcp)
1095 return do_pipe(tcp, -1);
1099 sys_pipe2(struct tcb *tcp)
1101 return do_pipe(tcp, 1);
1105 sys_socketpair(struct tcb *tcp)
1109 if (entering(tcp)) {
1110 printxval(domains, tcp->u_arg[0], "PF_???");
1112 tprint_sock_type(tcp->u_arg[1]);
1113 tprintf(", %lu", tcp->u_arg[2]);
1115 if (syserror(tcp)) {
1116 tprintf(", %#lx", tcp->u_arg[3]);
1119 if (umoven(tcp, tcp->u_arg[3], sizeof fds, (char *) fds) < 0)
1122 tprintf(", [%u, %u]", fds[0], fds[1]);
1127 #include "xlat/sockoptions.h"
1128 #include "xlat/sockipoptions.h"
1129 #include "xlat/sockipv6options.h"
1130 #include "xlat/sockipxoptions.h"
1131 #include "xlat/sockrawoptions.h"
1132 #include "xlat/sockpacketoptions.h"
1133 #include "xlat/socksctpoptions.h"
1134 #include "xlat/socktcpoptions.h"
1137 print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name)
1141 printxval(socketlayers, level, "SOL_??");
1146 printxval(sockoptions, name, "SO_???");
1149 printxval(sockipoptions, name, "IP_???");
1152 printxval(sockipv6options, name, "IPV6_???");
1155 printxval(sockipxoptions, name, "IPX_???");
1158 printxval(sockpacketoptions, name, "PACKET_???");
1161 printxval(socktcpoptions, name, "TCP_???");
1164 printxval(socksctpoptions, name, "SCTP_???");
1167 printxval(sockrawoptions, name, "RAW_???");
1170 /* Other SOL_* protocol levels still need work. */
1173 tprintf("%u", name);
1181 print_linger(struct tcb *tcp, long addr, int len)
1183 struct linger linger;
1185 if (len != sizeof(linger) ||
1186 umove(tcp, addr, &linger) < 0) {
1187 tprintf("%#lx", addr);
1191 tprintf("{onoff=%d, linger=%d}",
1195 #endif /* SO_LINGER */
1199 print_ucred(struct tcb *tcp, long addr, int len)
1203 if (len != sizeof(uc) ||
1204 umove(tcp, addr, &uc) < 0) {
1205 tprintf("%#lx", addr);
1207 tprintf("{pid=%u, uid=%u, gid=%u}",
1213 #endif /* SO_PEERCRED */
1215 #ifdef PACKET_STATISTICS
1217 print_tpacket_stats(struct tcb *tcp, long addr, int len)
1219 struct tpacket_stats stats;
1221 if (len != sizeof(stats) ||
1222 umove(tcp, addr, &stats) < 0) {
1223 tprintf("%#lx", addr);
1225 tprintf("{packets=%u, drops=%u}",
1230 #endif /* PACKET_STATISTICS */
1233 # include "xlat/icmpfilterflags.h"
1236 print_icmp_filter(struct tcb *tcp, long addr, int len)
1238 struct icmp_filter filter;
1240 if (len != sizeof(filter) ||
1241 umove(tcp, addr, &filter) < 0) {
1242 tprintf("%#lx", addr);
1247 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1250 #endif /* ICMP_FILTER */
1253 print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1255 if (addr && verbose(tcp))
1261 print_linger(tcp, addr, len);
1266 print_ucred(tcp, addr, len);
1274 #ifdef PACKET_STATISTICS
1275 case PACKET_STATISTICS:
1276 print_tpacket_stats(tcp, addr, len);
1286 print_icmp_filter(tcp, addr, len);
1293 /* default arg printing */
1296 if (len == sizeof(int)) {
1297 printnum_int(tcp, addr, "%d");
1299 printstr(tcp, addr, len);
1302 tprintf("%#lx", addr);
1305 tprintf(", [%d]", len);
1309 sys_getsockopt(struct tcb *tcp)
1311 if (entering(tcp)) {
1312 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1313 tcp->u_arg[1], tcp->u_arg[2]);
1317 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1318 tprintf("%#lx, %#lx",
1319 tcp->u_arg[3], tcp->u_arg[4]);
1321 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1322 tcp->u_arg[3], len);
1328 #ifdef MCAST_JOIN_GROUP
1330 print_group_req(struct tcb *tcp, long addr, int len)
1332 struct group_req greq;
1334 if (len != sizeof(greq) ||
1335 umove(tcp, addr, &greq) < 0) {
1336 tprintf("%#lx", addr);
1341 struct sockaddr *sa;
1342 struct sockaddr_in *sin;
1343 #ifdef HAVE_INET_NTOP
1344 struct sockaddr_in6 *sin6;
1346 } a = { .sa = (struct sockaddr *) &greq.gr_group };
1347 #ifdef HAVE_INET_NTOP
1348 char str[INET6_ADDRSTRLEN];
1351 tprintf("{gr_interface=%u, gr_group={sa_family=", greq.gr_interface);
1352 printxval(addrfams, a.sa->sa_family, "AF_???");
1354 switch (a.sa->sa_family) {
1356 tprintf(", sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}}",
1357 ntohs(a.sin->sin_port),
1358 inet_ntoa(a.sin->sin_addr));
1360 #ifdef HAVE_INET_NTOP
1362 if (!inet_ntop(AF_INET6, &a.sin6->sin6_addr, str, sizeof(str)))
1364 tprintf(", sin6_port=htons(%u)"
1365 ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}}",
1366 ntohs(a.sin6->sin6_port), str);
1368 #endif /* HAVE_INET_NTOP */
1371 tprints(", sa_data=");
1372 print_quoted_string(a.sa->sa_data, sizeof(a.sa->sa_data), 0);
1376 #endif /* MCAST_JOIN_GROUP */
1378 #ifdef PACKET_RX_RING
1380 print_tpacket_req(struct tcb *tcp, long addr, int len)
1382 struct tpacket_req req;
1384 if (len != sizeof(req) ||
1385 umove(tcp, addr, &req) < 0) {
1386 tprintf("%#lx", addr);
1388 tprintf("{block_size=%u, block_nr=%u, "
1389 "frame_size=%u, frame_nr=%u}",
1396 #endif /* PACKET_RX_RING */
1398 #ifdef PACKET_ADD_MEMBERSHIP
1399 # include "xlat/packet_mreq_type.h"
1402 print_packet_mreq(struct tcb *tcp, long addr, int len)
1404 struct packet_mreq mreq;
1406 if (len != sizeof(mreq) ||
1407 umove(tcp, addr, &mreq) < 0) {
1408 tprintf("%#lx", addr);
1412 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1413 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1414 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1415 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1416 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1417 for (i = 0; i < mreq.mr_alen; ++i)
1418 tprintf("%02x", mreq.mr_address[i]);
1422 #endif /* PACKET_ADD_MEMBERSHIP */
1425 print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1427 if (addr && verbose(tcp))
1433 print_linger(tcp, addr, len);
1441 #ifdef MCAST_JOIN_GROUP
1442 case MCAST_JOIN_GROUP:
1443 case MCAST_LEAVE_GROUP:
1444 print_group_req(tcp, addr, len);
1446 #endif /* MCAST_JOIN_GROUP */
1452 #ifdef PACKET_RX_RING
1453 case PACKET_RX_RING:
1454 # ifdef PACKET_TX_RING
1455 case PACKET_TX_RING:
1457 print_tpacket_req(tcp, addr, len);
1459 #endif /* PACKET_RX_RING */
1460 #ifdef PACKET_ADD_MEMBERSHIP
1461 case PACKET_ADD_MEMBERSHIP:
1462 case PACKET_DROP_MEMBERSHIP:
1463 print_packet_mreq(tcp, addr, len);
1465 #endif /* PACKET_ADD_MEMBERSHIP */
1473 print_icmp_filter(tcp, addr, len);
1480 /* default arg printing */
1483 if (len == sizeof(int)) {
1484 printnum_int(tcp, addr, "%d");
1486 printstr(tcp, addr, len);
1489 tprintf("%#lx", addr);
1492 tprintf(", %d", len);
1496 sys_setsockopt(struct tcb *tcp)
1498 if (entering(tcp)) {
1499 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1500 tcp->u_arg[1], tcp->u_arg[2]);
1501 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1502 tcp->u_arg[3], tcp->u_arg[4]);