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_IP_VS_H)
56 # include <linux/ip_vs.h>
58 #include <linux/netlink.h>
59 #if defined(HAVE_LINUX_NETFILTER_ARP_ARP_TABLES_H)
60 # include <linux/netfilter_arp/arp_tables.h>
62 #if defined(HAVE_LINUX_NETFILTER_BRIDGE_EBTABLES_H)
63 # include <linux/netfilter_bridge/ebtables.h>
65 #if defined(HAVE_LINUX_NETFILTER_IPV4_IP_TABLES_H)
66 # include <linux/netfilter_ipv4/ip_tables.h>
68 #if defined(HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H)
69 # include <linux/netfilter_ipv6/ip6_tables.h>
71 #include <linux/if_packet.h>
72 #include <linux/icmp.h>
73 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
74 # include <bluetooth/bluetooth.h>
75 # include <bluetooth/hci.h>
76 # include <bluetooth/l2cap.h>
77 # include <bluetooth/rfcomm.h>
78 # include <bluetooth/sco.h>
81 #include "xlat/addrfams.h"
82 #include "xlat/socktypes.h"
83 #include "xlat/sock_type_flags.h"
84 #ifndef SOCK_TYPE_MASK
85 # define SOCK_TYPE_MASK 0xf
88 #include "xlat/socketlayers.h"
90 #include "xlat/inet_protocols.h"
92 #if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
93 # define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
95 #include "xlat/netlink_protocols.h"
97 #if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
98 # include "xlat/bt_protocols.h"
101 #include "xlat/msg_flags.h"
103 #include "xlat/af_packet_types.h"
106 print_ifindex(unsigned int ifindex)
108 #ifdef HAVE_IF_INDEXTONAME
109 char buf[IFNAMSIZ + 1];
111 if (if_indextoname(ifindex, buf)) {
112 tprints("if_nametoindex(");
113 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
118 tprintf("%u", ifindex);
124 struct sockaddr_in sin;
125 struct sockaddr_un sau;
126 #ifdef HAVE_INET_NTOP
127 struct sockaddr_in6 sa6;
130 struct sockaddr_ipx sipx;
132 struct sockaddr_ll ll;
133 struct sockaddr_nl nl;
134 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
135 struct sockaddr_hci hci;
136 struct sockaddr_l2 l2;
137 struct sockaddr_rc rc;
138 struct sockaddr_sco sco;
143 print_sockaddr(struct tcb *tcp, const sockaddr_buf_t *addr, const int addrlen)
145 tprints("{sa_family=");
146 printxval(addrfams, addr->sa.sa_family, "AF_???");
149 switch (addr->sa.sa_family) {
153 } else if (addr->sau.sun_path[0]) {
154 tprints("sun_path=");
155 print_quoted_string(addr->sau.sun_path,
156 sizeof(addr->sau.sun_path) + 1,
159 tprints("sun_path=@");
160 print_quoted_string(addr->sau.sun_path + 1,
161 sizeof(addr->sau.sun_path),
166 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
167 ntohs(addr->sin.sin_port), inet_ntoa(addr->sin.sin_addr));
169 #ifdef HAVE_INET_NTOP
172 char string_addr[100];
173 inet_ntop(AF_INET6, &addr->sa6.sin6_addr,
174 string_addr, sizeof(string_addr));
175 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6"
176 ", \"%s\", &sin6_addr), sin6_flowinfo=%u",
177 ntohs(addr->sa6.sin6_port), string_addr,
178 addr->sa6.sin6_flowinfo);
179 # ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
180 tprints(", sin6_scope_id=");
181 # if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
182 if (IN6_IS_ADDR_LINKLOCAL(&addr->sa6.sin6_addr)
183 || IN6_IS_ADDR_MC_LINKLOCAL(&addr->sa6.sin6_addr))
184 print_ifindex(addr->sa6.sin6_scope_id);
187 tprintf("%u", addr->sa6.sin6_scope_id);
188 # endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
196 tprintf("sipx_port=htons(%u), ",
197 ntohs(addr->sipx.sipx_port));
198 /* Yes, I know, this does not look too
199 * strace-ish, but otherwise the IPX
200 * addresses just look monstrous...
201 * Anyways, feel free if you don't like
204 tprintf("%08lx:", (unsigned long)ntohl(addr->sipx.sipx_network));
205 for (i = 0; i < IPX_NODE_LEN; i++)
206 tprintf("%02x", addr->sipx.sipx_node[i]);
207 tprintf("/[%02x]", addr->sipx.sipx_type);
214 tprintf("proto=%#04x, if%d, pkttype=",
215 ntohs(addr->ll.sll_protocol),
216 addr->ll.sll_ifindex);
217 printxval(af_packet_types, addr->ll.sll_pkttype, "PACKET_???");
218 tprintf(", addr(%d)={%d, ",
220 addr->ll.sll_hatype);
221 for (i = 0; i < addr->ll.sll_halen; i++)
222 tprintf("%02x", addr->ll.sll_addr[i]);
227 tprintf("pid=%d, groups=%08x", addr->nl.nl_pid, addr->nl.nl_groups);
229 #if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
231 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
232 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
233 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
234 "{hci_dev=htobs(%d)}",
235 addr->sco.sco_bdaddr.b[0], addr->sco.sco_bdaddr.b[1],
236 addr->sco.sco_bdaddr.b[2], addr->sco.sco_bdaddr.b[3],
237 addr->sco.sco_bdaddr.b[4], addr->sco.sco_bdaddr.b[5],
238 addr->rc.rc_bdaddr.b[0], addr->rc.rc_bdaddr.b[1],
239 addr->rc.rc_bdaddr.b[2], addr->rc.rc_bdaddr.b[3],
240 addr->rc.rc_bdaddr.b[4], addr->rc.rc_bdaddr.b[5],
242 btohs(addr->l2.l2_psm), addr->l2.l2_bdaddr.b[0],
243 addr->l2.l2_bdaddr.b[1], addr->l2.l2_bdaddr.b[2],
244 addr->l2.l2_bdaddr.b[3], addr->l2.l2_bdaddr.b[4],
245 addr->l2.l2_bdaddr.b[5], btohs(addr->l2.l2_cid),
246 btohs(addr->hci.hci_dev));
248 #endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
249 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
250 AF_X25 AF_ROSE etc. still need to be done */
254 print_quoted_string(addr->sa.sa_data,
255 sizeof(addr->sa.sa_data), 0);
262 printsock(struct tcb *tcp, long addr, int addrlen)
264 sockaddr_buf_t addrbuf;
271 if (addrlen > (int) sizeof(addrbuf))
272 addrlen = sizeof(addrbuf);
274 memset(&addrbuf, 0, sizeof(addrbuf));
275 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
277 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
279 print_sockaddr(tcp, &addrbuf, addrlen);
282 #include "xlat/scmvals.h"
283 #include "xlat/ip_cmsg_types.h"
285 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
295 struct cmsghdr *cmsg;
296 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
297 struct cmsghdr32 *cmsg32;
302 print_scm_rights(struct tcb *tcp, const void *cmsg_data,
303 const size_t data_len)
305 const int *fds = cmsg_data;
306 const char *end = (const char *) cmsg_data + data_len;
309 if (sizeof(*fds) > data_len)
313 while ((const char *) fds < end) {
318 printfd(tcp, *fds++);
324 print_scm_creds(struct tcb *tcp, const void *cmsg_data,
325 const size_t data_len)
327 const struct ucred *uc = cmsg_data;
329 if (sizeof(*uc) > data_len)
332 tprintf(", {pid=%u, uid=%u, gid=%u}",
333 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
337 print_scm_security(struct tcb *tcp, const void *cmsg_data,
338 const size_t data_len)
344 print_quoted_string(cmsg_data, data_len, 0);
348 print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data,
349 const size_t data_len)
351 const struct in_pktinfo *info = cmsg_data;
353 if (sizeof(*info) > data_len)
356 tprints(", {ipi_ifindex=");
357 print_ifindex(info->ipi_ifindex);
358 tprintf(", ipi_spec_dst=inet_addr(\"%s\"), ipi_addr=inet_addr(\"%s\")}",
359 inet_ntoa(info->ipi_spec_dst), inet_ntoa(info->ipi_addr));
363 print_cmsg_ip_ttl(struct tcb *tcp, const void *cmsg_data,
364 const size_t data_len)
366 const unsigned int *ttl = cmsg_data;
368 if (sizeof(*ttl) > data_len)
371 tprintf(", {ttl=%u}", *ttl);
375 print_cmsg_ip_tos(struct tcb *tcp, const void *cmsg_data,
376 const size_t data_len)
378 const uint8_t *tos = cmsg_data;
380 if (sizeof(*tos) > data_len)
383 tprintf(", {tos=%x}", *tos);
387 print_cmsg_ip_checksum(struct tcb *tcp, const void *cmsg_data,
388 const size_t data_len)
390 const uint32_t *csum = cmsg_data;
392 if (sizeof(*csum) > data_len)
395 tprintf(", {csum=%u}", *csum);
399 print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data,
400 const size_t data_len)
402 const unsigned char *opts = cmsg_data;
408 tprints(", {opts=0x");
409 for (i = 0; i < data_len; ++i)
410 tprintf("%02x", opts[i]);
415 print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
416 const size_t data_len)
426 struct sockaddr_in offender;
429 if (sizeof(*err) > data_len)
432 tprintf(", {ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
433 ", ee_info=%u, ee_data=%u, offender=",
434 err->ee_errno, err->ee_origin, err->ee_type,
435 err->ee_code, err->ee_info, err->ee_data);
436 print_sockaddr(tcp, (const void *) &err->offender,
437 sizeof(err->offender));
442 print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
443 const size_t data_len)
445 if (sizeof(struct sockaddr_in) > data_len)
449 print_sockaddr(tcp, cmsg_data, data_len);
453 print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
454 const void *cmsg_data, const size_t data_len)
456 switch (cmsg_level) {
458 printxval(scmvals, cmsg_type, "SCM_???");
461 print_scm_rights(tcp, cmsg_data, data_len);
463 case SCM_CREDENTIALS:
464 print_scm_creds(tcp, cmsg_data, data_len);
467 print_scm_security(tcp, cmsg_data, data_len);
472 printxval(ip_cmsg_types, cmsg_type, "IP_???");
475 print_cmsg_ip_pktinfo(tcp, cmsg_data, data_len);
478 print_cmsg_ip_ttl(tcp, cmsg_data, data_len);
481 print_cmsg_ip_tos(tcp, cmsg_data, data_len);
485 print_cmsg_ip_opts(tcp, cmsg_data, data_len);
488 print_cmsg_ip_recverr(tcp, cmsg_data, data_len);
491 print_cmsg_ip_origdstaddr(tcp, cmsg_data, data_len);
494 print_cmsg_ip_checksum(tcp, cmsg_data, data_len);
497 print_scm_security(tcp, cmsg_data, data_len);
502 tprintf("%u", cmsg_type);
507 printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
509 const size_t cmsg_size =
510 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
511 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
513 sizeof(struct cmsghdr);
515 char *buf = len < cmsg_size ? NULL : malloc(len);
516 if (!buf || umoven(tcp, addr, len, buf) < 0) {
517 tprints(", msg_control=");
523 union_cmsghdr u = { .ptr = buf };
526 while (len >= cmsg_size) {
528 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
529 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
533 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
534 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
538 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
539 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
545 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
546 printxval(socketlayers, cmsg_level, "SOL_???");
547 tprints(", cmsg_type=");
552 print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
553 (const void *) (u.ptr + cmsg_size),
554 cmsg_len > cmsg_size ? cmsg_len - cmsg_size: 0);
557 if (cmsg_len < cmsg_size) {
561 cmsg_len = (cmsg_len + current_wordsize - 1) &
562 (size_t) ~(current_wordsize - 1);
563 if (cmsg_len >= len) {
577 do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
579 tprintf("{msg_name(%d)=", msg->msg_namelen);
580 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
582 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
583 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
584 (unsigned long)msg->msg_iov, 1, data_size);
586 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
587 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
588 if (msg->msg_controllen)
589 printcmsghdr(tcp, (unsigned long) msg->msg_control,
590 msg->msg_controllen);
591 tprints(", msg_flags=");
592 printflags(msg_flags, msg->msg_flags, "MSG_???");
593 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
594 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
595 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
596 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
601 uint32_t /* void* */ msg_name;
602 uint32_t /* socklen_t */msg_namelen;
603 uint32_t /* iovec* */ msg_iov;
604 uint32_t /* size_t */ msg_iovlen;
605 uint32_t /* void* */ msg_control;
606 uint32_t /* size_t */ msg_controllen;
607 uint32_t /* int */ msg_flags;
610 struct msghdr32 msg_hdr;
611 uint32_t /* unsigned */ msg_len;
614 #ifndef HAVE_STRUCT_MMSGHDR
616 struct msghdr msg_hdr;
621 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
623 copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
625 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
626 to_msg->msg_namelen = from_msg32->msg_namelen;
627 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
628 to_msg->msg_iovlen = from_msg32->msg_iovlen;
629 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
630 to_msg->msg_controllen = from_msg32->msg_controllen;
631 to_msg->msg_flags = from_msg32->msg_flags;
636 extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
638 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
639 if (current_wordsize == 4) {
640 struct msghdr32 msg32;
642 if (umove(tcp, addr, &msg32) < 0)
644 copy_from_msghdr32(msg, &msg32);
647 if (umove(tcp, addr, msg) < 0)
653 extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
655 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
656 if (current_wordsize == 4) {
657 struct mmsghdr32 mmsg32;
659 addr += sizeof(struct mmsghdr32) * idx;
660 if (umove(tcp, addr, &mmsg32) < 0)
663 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
664 mmsg->msg_len = mmsg32.msg_len;
668 addr += sizeof(*mmsg) * idx;
669 if (umove(tcp, addr, mmsg) < 0)
676 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
680 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
681 do_msghdr(tcp, &msg, data_size);
687 dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
691 if (extractmsghdr(tcp, addr, &msg))
692 dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size);
696 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
700 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
702 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
703 tprintf(", %u}", mmsg.msg_len);
710 decode_mmsg(struct tcb *tcp, unsigned long msg_len)
714 printaddr(tcp->u_arg[1]);
716 unsigned int len = tcp->u_rval;
720 for (i = 0; i < len; ++i) {
723 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
728 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
730 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
734 dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
736 unsigned int len = tcp->u_rval;
740 for (i = 0; i < len; ++i) {
741 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
742 tprintf(" = %lu buffers in vector %u\n",
743 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
744 dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
745 (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
751 * low bits of the socket type define real socket type,
752 * other bits are socket type flags.
755 tprint_sock_type(unsigned int flags)
757 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
761 flags &= ~SOCK_TYPE_MASK;
766 printflags(sock_type_flags, flags, "SOCK_???");
771 printxval(addrfams, tcp->u_arg[0], "AF_???");
773 tprint_sock_type(tcp->u_arg[1]);
775 switch (tcp->u_arg[0]) {
778 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
782 /* BTW: I don't believe this.. */
784 printxval(addrfams, tcp->u_arg[2], "AF_???");
789 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
791 #if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
793 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
797 tprintf("%lu", tcp->u_arg[2]);
801 return RVAL_DECODED | RVAL_FD;
806 printfd(tcp, tcp->u_arg[0]);
808 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
809 tprintf(", %lu", tcp->u_arg[2]);
816 printfd(tcp, tcp->u_arg[0]);
818 tprintf("%lu", tcp->u_arg[1]);
824 do_sockname(struct tcb *tcp, int flags_arg)
827 printfd(tcp, tcp->u_arg[0]);
833 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
834 umove(tcp, tcp->u_arg[2], &len) < 0) {
835 printaddr(tcp->u_arg[1]);
837 printaddr(tcp->u_arg[2]);
839 printsock(tcp, tcp->u_arg[1], len);
840 tprintf(", [%d]", len);
843 if (flags_arg >= 0) {
845 printflags(sock_type_flags, tcp->u_arg[flags_arg],
853 do_sockname(tcp, -1);
865 printfd(tcp, tcp->u_arg[0]);
867 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
868 tprintf(", %lu, ", tcp->u_arg[2]);
870 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
877 printfd(tcp, tcp->u_arg[0]);
879 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
880 tprintf(", %lu, ", tcp->u_arg[2]);
882 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
885 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
887 tprintf(", %lu", tcp->u_arg[5]);
894 printfd(tcp, tcp->u_arg[0]);
896 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
899 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
908 printfd(tcp, tcp->u_arg[0]);
911 printaddr(tcp->u_arg[1]);
912 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
913 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
917 decode_mmsg(tcp, (unsigned long) -1L);
925 printfd(tcp, tcp->u_arg[0]);
929 printaddr(tcp->u_arg[1]);
931 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
933 tprintf(", %lu, ", tcp->u_arg[2]);
934 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
944 printfd(tcp, tcp->u_arg[0]);
949 printaddr(tcp->u_arg[1]);
951 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
954 tprintf(", %lu, ", tcp->u_arg[2]);
956 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
958 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
959 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
960 /* from address, len */
961 printaddr(tcp->u_arg[4]);
963 printaddr(tcp->u_arg[5]);
967 printsock(tcp, tcp->u_arg[4], fromlen);
969 tprintf(", [%u]", fromlen);
977 printfd(tcp, tcp->u_arg[0]);
981 printaddr(tcp->u_arg[1]);
983 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
986 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
993 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
996 printfd(tcp, tcp->u_arg[0]);
999 /* Abusing tcp->auxstr as temp storage.
1000 * Will be used and cleared on syscall exit.
1002 tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
1004 printaddr(tcp->u_arg[1]);
1005 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
1006 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1008 print_timespec(tcp, tcp->u_arg[4]);
1013 decode_mmsg(tcp, 0);
1015 /* timeout on entrance */
1016 tprints(tcp->auxstr);
1021 if (tcp->u_rval == 0) {
1022 tcp->auxstr = "Timeout";
1027 /* timeout on exit */
1028 snprintf(str, sizeof(str), "left %s",
1029 sprint_timespec(tcp, tcp->u_arg[4]));
1035 #include "xlat/shutdown_modes.h"
1039 printfd(tcp, tcp->u_arg[0]);
1041 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1043 return RVAL_DECODED;
1046 SYS_FUNC(getsockname)
1048 return do_sockname(tcp, -1);
1052 printpair_fd(struct tcb *tcp, const int i0, const int i1)
1062 decode_pair_fd(struct tcb *tcp, const long addr)
1066 if (umove_or_printaddr(tcp, addr, &pair))
1069 printpair_fd(tcp, pair[0], pair[1]);
1073 do_pipe(struct tcb *tcp, int flags_arg)
1076 decode_pair_fd(tcp, tcp->u_arg[0]);
1077 if (flags_arg >= 0) {
1079 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1087 #ifdef HAVE_GETRVAL2
1088 if (exiting(tcp) && !syserror(tcp))
1089 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
1092 return do_pipe(tcp, -1);
1098 return do_pipe(tcp, 1);
1101 SYS_FUNC(socketpair)
1103 if (entering(tcp)) {
1104 printxval(addrfams, tcp->u_arg[0], "AF_???");
1106 tprint_sock_type(tcp->u_arg[1]);
1107 tprintf(", %lu", tcp->u_arg[2]);
1110 decode_pair_fd(tcp, tcp->u_arg[3]);
1115 #include "xlat/sockoptions.h"
1116 #include "xlat/sockipoptions.h"
1117 #include "xlat/getsockipoptions.h"
1118 #include "xlat/setsockipoptions.h"
1119 #include "xlat/sockipv6options.h"
1120 #include "xlat/getsockipv6options.h"
1121 #include "xlat/setsockipv6options.h"
1122 #include "xlat/sockipxoptions.h"
1123 #include "xlat/sockrawoptions.h"
1124 #include "xlat/sockpacketoptions.h"
1125 #include "xlat/socksctpoptions.h"
1126 #include "xlat/socktcpoptions.h"
1129 print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level,
1130 unsigned int name, bool is_getsockopt)
1134 printxval(socketlayers, level, "SOL_??");
1139 printxval(sockoptions, name, "SO_???");
1142 printxvals(name, "IP_???", sockipoptions,
1143 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
1146 printxvals(name, "IPV6_???", sockipv6options,
1147 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
1150 printxval(sockipxoptions, name, "IPX_???");
1153 printxval(sockpacketoptions, name, "PACKET_???");
1156 printxval(socktcpoptions, name, "TCP_???");
1159 printxval(socksctpoptions, name, "SCTP_???");
1162 printxval(sockrawoptions, name, "RAW_???");
1165 /* Other SOL_* protocol levels still need work. */
1168 tprintf("%u", name);
1176 print_linger(struct tcb *tcp, long addr, int len)
1178 struct linger linger;
1180 if (len != sizeof(linger) ||
1181 umove(tcp, addr, &linger) < 0) {
1186 tprintf("{onoff=%d, linger=%d}",
1190 #endif /* SO_LINGER */
1194 print_ucred(struct tcb *tcp, long addr, int len)
1198 if (len != sizeof(uc) ||
1199 umove(tcp, addr, &uc) < 0) {
1202 tprintf("{pid=%u, uid=%u, gid=%u}",
1208 #endif /* SO_PEERCRED */
1210 #ifdef PACKET_STATISTICS
1212 print_tpacket_stats(struct tcb *tcp, long addr, int len)
1214 struct tpacket_stats stats;
1216 if (len != sizeof(stats) ||
1217 umove(tcp, addr, &stats) < 0) {
1220 tprintf("{packets=%u, drops=%u}",
1225 #endif /* PACKET_STATISTICS */
1227 #include "xlat/icmpfilterflags.h"
1230 print_icmp_filter(struct tcb *tcp, const long addr, int len)
1232 struct icmp_filter filter = {};
1234 if (len > (int) sizeof(filter))
1235 len = sizeof(filter);
1236 else if (len <= 0) {
1241 if (umoven_or_printaddr(tcp, addr, len, &filter))
1245 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1250 print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1253 if (addr && verbose(tcp))
1259 print_linger(tcp, addr, len);
1264 print_ucred(tcp, addr, len);
1272 #ifdef PACKET_STATISTICS
1273 case PACKET_STATISTICS:
1274 print_tpacket_stats(tcp, addr, len);
1283 print_icmp_filter(tcp, addr, len);
1289 /* default arg printing */
1292 if (len == sizeof(int)) {
1293 printnum_int(tcp, addr, "%d");
1295 printstr(tcp, addr, len);
1301 tprintf(", [%d]", len);
1304 SYS_FUNC(getsockopt)
1306 if (entering(tcp)) {
1307 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1308 tcp->u_arg[1], tcp->u_arg[2], true);
1312 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1313 printaddr(tcp->u_arg[3]);
1315 printaddr(tcp->u_arg[4]);
1317 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1318 tcp->u_arg[3], len);
1324 #ifdef IP_ADD_MEMBERSHIP
1326 print_mreq(struct tcb *tcp, long addr, unsigned int len)
1328 struct ip_mreq mreq;
1330 if (len < sizeof(mreq)) {
1331 printstr(tcp, addr, len);
1334 if (umove_or_printaddr(tcp, addr, &mreq))
1337 tprints("{imr_multiaddr=inet_addr(");
1338 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1339 16, QUOTE_0_TERMINATED);
1340 tprints("), imr_interface=inet_addr(");
1341 print_quoted_string(inet_ntoa(mreq.imr_interface),
1342 16, QUOTE_0_TERMINATED);
1345 #endif /* IP_ADD_MEMBERSHIP */
1347 #ifdef IPV6_ADD_MEMBERSHIP
1349 print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1351 struct ipv6_mreq mreq;
1353 if (len < sizeof(mreq))
1356 if (umove_or_printaddr(tcp, addr, &mreq))
1359 #ifdef HAVE_INET_NTOP
1360 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1361 char address[INET6_ADDRSTRLEN];
1363 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1366 tprints("{ipv6mr_multiaddr=inet_pton(");
1367 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1368 tprints("), ipv6mr_interface=");
1369 print_ifindex(mreq.ipv6mr_interface);
1372 #endif /* HAVE_INET_NTOP */
1375 printstr(tcp, addr, len);
1377 #endif /* IPV6_ADD_MEMBERSHIP */
1379 #ifdef MCAST_JOIN_GROUP
1381 print_group_req(struct tcb *tcp, long addr, int len)
1383 struct group_req greq;
1385 if (len != sizeof(greq) ||
1386 umove(tcp, addr, &greq) < 0) {
1391 tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
1392 print_sockaddr(tcp, (const void *) &greq.gr_group,
1393 sizeof(greq.gr_group));
1397 #endif /* MCAST_JOIN_GROUP */
1399 #ifdef PACKET_RX_RING
1401 print_tpacket_req(struct tcb *tcp, long addr, int len)
1403 struct tpacket_req req;
1405 if (len != sizeof(req) ||
1406 umove(tcp, addr, &req) < 0) {
1409 tprintf("{block_size=%u, block_nr=%u, "
1410 "frame_size=%u, frame_nr=%u}",
1417 #endif /* PACKET_RX_RING */
1419 #ifdef PACKET_ADD_MEMBERSHIP
1420 # include "xlat/packet_mreq_type.h"
1423 print_packet_mreq(struct tcb *tcp, long addr, int len)
1425 struct packet_mreq mreq;
1427 if (len != sizeof(mreq) ||
1428 umove(tcp, addr, &mreq) < 0) {
1433 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1434 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1435 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1436 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1437 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1438 for (i = 0; i < mreq.mr_alen; ++i)
1439 tprintf("%02x", mreq.mr_address[i]);
1443 #endif /* PACKET_ADD_MEMBERSHIP */
1446 print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1449 if (addr && verbose(tcp))
1455 print_linger(tcp, addr, len);
1463 #ifdef IP_ADD_MEMBERSHIP
1464 case IP_ADD_MEMBERSHIP:
1465 case IP_DROP_MEMBERSHIP:
1466 print_mreq(tcp, addr, len);
1468 #endif /* IP_ADD_MEMBERSHIP */
1469 #ifdef MCAST_JOIN_GROUP
1470 case MCAST_JOIN_GROUP:
1471 case MCAST_LEAVE_GROUP:
1472 print_group_req(tcp, addr, len);
1474 #endif /* MCAST_JOIN_GROUP */
1480 #ifdef IPV6_ADD_MEMBERSHIP
1481 case IPV6_ADD_MEMBERSHIP:
1482 case IPV6_DROP_MEMBERSHIP:
1483 # ifdef IPV6_JOIN_ANYCAST
1484 case IPV6_JOIN_ANYCAST:
1486 # ifdef IPV6_LEAVE_ANYCAST
1487 case IPV6_LEAVE_ANYCAST:
1489 print_mreq6(tcp, addr, len);
1491 #endif /* IPV6_ADD_MEMBERSHIP */
1497 #ifdef PACKET_RX_RING
1498 case PACKET_RX_RING:
1499 # ifdef PACKET_TX_RING
1500 case PACKET_TX_RING:
1502 print_tpacket_req(tcp, addr, len);
1504 #endif /* PACKET_RX_RING */
1505 #ifdef PACKET_ADD_MEMBERSHIP
1506 case PACKET_ADD_MEMBERSHIP:
1507 case PACKET_DROP_MEMBERSHIP:
1508 print_packet_mreq(tcp, addr, len);
1510 #endif /* PACKET_ADD_MEMBERSHIP */
1517 print_icmp_filter(tcp, addr, len);
1523 /* default arg printing */
1526 if (len == sizeof(int)) {
1527 printnum_int(tcp, addr, "%d");
1529 printstr(tcp, addr, len);
1535 tprintf(", %d", len);
1538 SYS_FUNC(setsockopt)
1540 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1541 tcp->u_arg[1], tcp->u_arg[2], false);
1542 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1543 tcp->u_arg[3], tcp->u_arg[4]);
1545 return RVAL_DECODED;