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 #if defined(HAVE_LINUX_NETLINK_H)
59 # include <linux/netlink.h>
61 #if defined(HAVE_LINUX_NETFILTER_ARP_ARP_TABLES_H)
62 # include <linux/netfilter_arp/arp_tables.h>
64 #if defined(HAVE_LINUX_NETFILTER_BRIDGE_EBTABLES_H)
65 # include <linux/netfilter_bridge/ebtables.h>
67 #if defined(HAVE_LINUX_NETFILTER_IPV4_IP_TABLES_H)
68 # include <linux/netfilter_ipv4/ip_tables.h>
70 #if defined(HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H)
71 # include <linux/netfilter_ipv6/ip6_tables.h>
73 #if defined(HAVE_LINUX_IF_PACKET_H)
74 # include <linux/if_packet.h>
76 #if defined(HAVE_LINUX_ICMP_H)
77 # include <linux/icmp.h>
79 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
80 # include <bluetooth/bluetooth.h>
81 # include <bluetooth/hci.h>
82 # include <bluetooth/l2cap.h>
83 # include <bluetooth/rfcomm.h>
84 # include <bluetooth/sco.h>
87 # define PF_UNSPEC AF_UNSPEC
90 #include "xlat/domains.h"
91 #include "xlat/addrfams.h"
92 #include "xlat/socktypes.h"
93 #include "xlat/sock_type_flags.h"
94 #ifndef SOCK_TYPE_MASK
95 # define SOCK_TYPE_MASK 0xf
98 #include "xlat/socketlayers.h"
100 #include "xlat/inet_protocols.h"
103 # if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
104 # define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
106 # include "xlat/netlink_protocols.h"
109 #if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
110 # include "xlat/bt_protocols.h"
113 #include "xlat/msg_flags.h"
115 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
116 # include "xlat/af_packet_types.h"
120 print_ifindex(unsigned int ifindex)
122 #ifdef HAVE_IF_INDEXTONAME
123 char buf[IFNAMSIZ + 1];
125 if (if_indextoname(ifindex, buf)) {
126 tprints("if_nametoindex(");
127 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
132 tprintf("%u", ifindex);
138 struct sockaddr_in sin;
139 struct sockaddr_un sau;
140 #ifdef HAVE_INET_NTOP
141 struct sockaddr_in6 sa6;
144 struct sockaddr_ipx sipx;
147 struct sockaddr_ll ll;
150 struct sockaddr_nl nl;
152 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
153 struct sockaddr_hci hci;
154 struct sockaddr_l2 l2;
155 struct sockaddr_rc rc;
156 struct sockaddr_sco sco;
161 print_sockaddr(struct tcb *tcp, const sockaddr_buf_t *addr, const int addrlen)
163 tprints("{sa_family=");
164 printxval(addrfams, addr->sa.sa_family, "AF_???");
167 switch (addr->sa.sa_family) {
171 } else if (addr->sau.sun_path[0]) {
172 tprints("sun_path=");
173 print_quoted_string(addr->sau.sun_path,
174 sizeof(addr->sau.sun_path) + 1,
177 tprints("sun_path=@");
178 print_quoted_string(addr->sau.sun_path + 1,
179 sizeof(addr->sau.sun_path),
184 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
185 ntohs(addr->sin.sin_port), inet_ntoa(addr->sin.sin_addr));
187 #ifdef HAVE_INET_NTOP
190 char string_addr[100];
191 inet_ntop(AF_INET6, &addr->sa6.sin6_addr,
192 string_addr, sizeof(string_addr));
193 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6"
194 ", \"%s\", &sin6_addr), sin6_flowinfo=%u",
195 ntohs(addr->sa6.sin6_port), string_addr,
196 addr->sa6.sin6_flowinfo);
197 # ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
198 tprints(", sin6_scope_id=");
199 # if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
200 if (IN6_IS_ADDR_LINKLOCAL(&addr->sa6.sin6_addr)
201 || IN6_IS_ADDR_MC_LINKLOCAL(&addr->sa6.sin6_addr))
202 print_ifindex(addr->sa6.sin6_scope_id);
205 tprintf("%u", addr->sa6.sin6_scope_id);
206 # endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
214 tprintf("sipx_port=htons(%u), ",
215 ntohs(addr->sipx.sipx_port));
216 /* Yes, I know, this does not look too
217 * strace-ish, but otherwise the IPX
218 * addresses just look monstrous...
219 * Anyways, feel free if you don't like
222 tprintf("%08lx:", (unsigned long)ntohl(addr->sipx.sipx_network));
223 for (i = 0; i < IPX_NODE_LEN; i++)
224 tprintf("%02x", addr->sipx.sipx_node[i]);
225 tprintf("/[%02x]", addr->sipx.sipx_type);
233 tprintf("proto=%#04x, if%d, pkttype=",
234 ntohs(addr->ll.sll_protocol),
235 addr->ll.sll_ifindex);
236 printxval(af_packet_types, addr->ll.sll_pkttype, "PACKET_???");
237 tprintf(", addr(%d)={%d, ",
239 addr->ll.sll_hatype);
240 for (i = 0; i < addr->ll.sll_halen; i++)
241 tprintf("%02x", addr->ll.sll_addr[i]);
245 #endif /* AF_PACKET */
248 tprintf("pid=%d, groups=%08x", addr->nl.nl_pid, addr->nl.nl_groups);
250 #endif /* AF_NETLINK */
251 #if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
253 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
254 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
255 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
256 "{hci_dev=htobs(%d)}",
257 addr->sco.sco_bdaddr.b[0], addr->sco.sco_bdaddr.b[1],
258 addr->sco.sco_bdaddr.b[2], addr->sco.sco_bdaddr.b[3],
259 addr->sco.sco_bdaddr.b[4], addr->sco.sco_bdaddr.b[5],
260 addr->rc.rc_bdaddr.b[0], addr->rc.rc_bdaddr.b[1],
261 addr->rc.rc_bdaddr.b[2], addr->rc.rc_bdaddr.b[3],
262 addr->rc.rc_bdaddr.b[4], addr->rc.rc_bdaddr.b[5],
264 btohs(addr->l2.l2_psm), addr->l2.l2_bdaddr.b[0],
265 addr->l2.l2_bdaddr.b[1], addr->l2.l2_bdaddr.b[2],
266 addr->l2.l2_bdaddr.b[3], addr->l2.l2_bdaddr.b[4],
267 addr->l2.l2_bdaddr.b[5], btohs(addr->l2.l2_cid),
268 btohs(addr->hci.hci_dev));
270 #endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
271 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
272 AF_X25 AF_ROSE etc. still need to be done */
276 print_quoted_string(addr->sa.sa_data,
277 sizeof(addr->sa.sa_data), 0);
284 printsock(struct tcb *tcp, long addr, int addrlen)
286 sockaddr_buf_t addrbuf;
293 if (addrlen > (int) sizeof(addrbuf))
294 addrlen = sizeof(addrbuf);
296 memset(&addrbuf, 0, sizeof(addrbuf));
297 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
299 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
301 print_sockaddr(tcp, &addrbuf, addrlen);
304 #include "xlat/scmvals.h"
305 #include "xlat/ip_cmsg_types.h"
307 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
317 struct cmsghdr *cmsg;
318 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
319 struct cmsghdr32 *cmsg32;
324 print_scm_rights(struct tcb *tcp, const void *cmsg_data,
325 const size_t data_len)
327 const int *fds = cmsg_data;
328 const char *end = (const char *) cmsg_data + data_len;
331 if (sizeof(*fds) > data_len)
335 while ((const char *) fds < end) {
340 printfd(tcp, *fds++);
346 print_scm_creds(struct tcb *tcp, const void *cmsg_data,
347 const size_t data_len)
349 const struct ucred *uc = cmsg_data;
351 if (sizeof(*uc) > data_len)
354 tprintf(", {pid=%u, uid=%u, gid=%u}",
355 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
359 print_scm_security(struct tcb *tcp, const void *cmsg_data,
360 const size_t data_len)
366 print_quoted_string(cmsg_data, data_len, 0);
370 print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data,
371 const size_t data_len)
373 const struct in_pktinfo *info = cmsg_data;
375 if (sizeof(*info) > data_len)
378 tprints(", {ipi_ifindex=");
379 print_ifindex(info->ipi_ifindex);
380 tprintf(", ipi_spec_dst=inet_addr(\"%s\"), ipi_addr=inet_addr(\"%s\")}",
381 inet_ntoa(info->ipi_spec_dst), inet_ntoa(info->ipi_addr));
385 print_cmsg_ip_ttl(struct tcb *tcp, const void *cmsg_data,
386 const size_t data_len)
388 const unsigned int *ttl = cmsg_data;
390 if (sizeof(*ttl) > data_len)
393 tprintf(", {ttl=%u}", *ttl);
397 print_cmsg_ip_tos(struct tcb *tcp, const void *cmsg_data,
398 const size_t data_len)
400 const uint8_t *tos = cmsg_data;
402 if (sizeof(*tos) > data_len)
405 tprintf(", {tos=%x}", *tos);
409 print_cmsg_ip_checksum(struct tcb *tcp, const void *cmsg_data,
410 const size_t data_len)
412 const uint32_t *csum = cmsg_data;
414 if (sizeof(*csum) > data_len)
417 tprintf(", {csum=%u}", *csum);
421 print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data,
422 const size_t data_len)
424 const unsigned char *opts = cmsg_data;
430 tprints(", {opts=0x");
431 for (i = 0; i < data_len; ++i)
432 tprintf("%02x", opts[i]);
437 print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
438 const size_t data_len)
448 struct sockaddr_in offender;
451 if (sizeof(*err) > data_len)
454 tprintf(", {ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
455 ", ee_info=%u, ee_data=%u, offender=",
456 err->ee_errno, err->ee_origin, err->ee_type,
457 err->ee_code, err->ee_info, err->ee_data);
458 print_sockaddr(tcp, (const void *) &err->offender,
459 sizeof(err->offender));
464 print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
465 const size_t data_len)
467 if (sizeof(struct sockaddr_in) > data_len)
471 print_sockaddr(tcp, cmsg_data, data_len);
475 print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
476 const void *cmsg_data, const size_t data_len)
478 switch (cmsg_level) {
480 printxval(scmvals, cmsg_type, "SCM_???");
483 print_scm_rights(tcp, cmsg_data, data_len);
485 case SCM_CREDENTIALS:
486 print_scm_creds(tcp, cmsg_data, data_len);
489 print_scm_security(tcp, cmsg_data, data_len);
494 printxval(ip_cmsg_types, cmsg_type, "IP_???");
497 print_cmsg_ip_pktinfo(tcp, cmsg_data, data_len);
500 print_cmsg_ip_ttl(tcp, cmsg_data, data_len);
503 print_cmsg_ip_tos(tcp, cmsg_data, data_len);
507 print_cmsg_ip_opts(tcp, cmsg_data, data_len);
510 print_cmsg_ip_recverr(tcp, cmsg_data, data_len);
513 print_cmsg_ip_origdstaddr(tcp, cmsg_data, data_len);
516 print_cmsg_ip_checksum(tcp, cmsg_data, data_len);
519 print_scm_security(tcp, cmsg_data, data_len);
524 tprintf("%u", cmsg_type);
529 printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
531 const size_t cmsg_size =
532 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
533 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
535 sizeof(struct cmsghdr);
537 char *buf = len < cmsg_size ? NULL : malloc(len);
538 if (!buf || umoven(tcp, addr, len, buf) < 0) {
539 tprints(", msg_control=");
545 union_cmsghdr u = { .ptr = buf };
548 while (len >= cmsg_size) {
550 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
551 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
555 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
556 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
560 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
561 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
567 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
568 printxval(socketlayers, cmsg_level, "SOL_???");
569 tprints(", cmsg_type=");
574 print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
575 (const void *) (u.ptr + cmsg_size),
576 cmsg_len > cmsg_size ? cmsg_len - cmsg_size: 0);
579 if (cmsg_len < cmsg_size) {
583 cmsg_len = (cmsg_len + current_wordsize - 1) &
584 (size_t) ~(current_wordsize - 1);
585 if (cmsg_len >= len) {
599 do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
601 tprintf("{msg_name(%d)=", msg->msg_namelen);
602 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
604 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
605 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
606 (unsigned long)msg->msg_iov, 1, data_size);
608 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
609 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
610 if (msg->msg_controllen)
611 printcmsghdr(tcp, (unsigned long) msg->msg_control,
612 msg->msg_controllen);
613 tprints(", msg_flags=");
614 printflags(msg_flags, msg->msg_flags, "MSG_???");
615 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
616 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
617 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
618 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
623 uint32_t /* void* */ msg_name;
624 uint32_t /* socklen_t */msg_namelen;
625 uint32_t /* iovec* */ msg_iov;
626 uint32_t /* size_t */ msg_iovlen;
627 uint32_t /* void* */ msg_control;
628 uint32_t /* size_t */ msg_controllen;
629 uint32_t /* int */ msg_flags;
632 struct msghdr32 msg_hdr;
633 uint32_t /* unsigned */ msg_len;
636 #ifndef HAVE_STRUCT_MMSGHDR
638 struct msghdr msg_hdr;
643 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
645 copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
647 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
648 to_msg->msg_namelen = from_msg32->msg_namelen;
649 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
650 to_msg->msg_iovlen = from_msg32->msg_iovlen;
651 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
652 to_msg->msg_controllen = from_msg32->msg_controllen;
653 to_msg->msg_flags = from_msg32->msg_flags;
658 extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
660 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
661 if (current_wordsize == 4) {
662 struct msghdr32 msg32;
664 if (umove(tcp, addr, &msg32) < 0)
666 copy_from_msghdr32(msg, &msg32);
669 if (umove(tcp, addr, msg) < 0)
675 extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
677 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
678 if (current_wordsize == 4) {
679 struct mmsghdr32 mmsg32;
681 addr += sizeof(struct mmsghdr32) * idx;
682 if (umove(tcp, addr, &mmsg32) < 0)
685 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
686 mmsg->msg_len = mmsg32.msg_len;
690 addr += sizeof(*mmsg) * idx;
691 if (umove(tcp, addr, mmsg) < 0)
698 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
702 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
703 do_msghdr(tcp, &msg, data_size);
709 dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
713 if (extractmsghdr(tcp, addr, &msg))
714 dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size);
718 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
722 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
724 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
725 tprintf(", %u}", mmsg.msg_len);
732 decode_mmsg(struct tcb *tcp, unsigned long msg_len)
736 printaddr(tcp->u_arg[1]);
738 unsigned int len = tcp->u_rval;
742 for (i = 0; i < len; ++i) {
745 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
750 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
752 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
756 dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
758 unsigned int len = tcp->u_rval;
762 for (i = 0; i < len; ++i) {
763 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
764 tprintf(" = %lu buffers in vector %u\n",
765 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
766 dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
767 (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
773 * low bits of the socket type define real socket type,
774 * other bits are socket type flags.
777 tprint_sock_type(int flags)
779 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
783 flags &= ~SOCK_TYPE_MASK;
788 printflags(sock_type_flags, flags, "SOCK_???");
793 printxval(domains, tcp->u_arg[0], "PF_???");
795 tprint_sock_type(tcp->u_arg[1]);
797 switch (tcp->u_arg[0]) {
802 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
806 /* BTW: I don't believe this.. */
808 printxval(domains, tcp->u_arg[2], "PF_???");
814 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
817 #if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
819 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
823 tprintf("%lu", tcp->u_arg[2]);
827 return RVAL_DECODED | RVAL_FD;
832 printfd(tcp, tcp->u_arg[0]);
834 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
835 tprintf(", %lu", tcp->u_arg[2]);
842 printfd(tcp, tcp->u_arg[0]);
844 tprintf("%lu", tcp->u_arg[1]);
850 do_sockname(struct tcb *tcp, int flags_arg)
853 printfd(tcp, tcp->u_arg[0]);
859 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
860 umove(tcp, tcp->u_arg[2], &len) < 0) {
861 printaddr(tcp->u_arg[1]);
863 printaddr(tcp->u_arg[2]);
865 printsock(tcp, tcp->u_arg[1], len);
866 tprintf(", [%d]", len);
869 if (flags_arg >= 0) {
871 printflags(sock_type_flags, tcp->u_arg[flags_arg],
879 do_sockname(tcp, -1);
891 printfd(tcp, tcp->u_arg[0]);
893 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
894 tprintf(", %lu, ", tcp->u_arg[2]);
896 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
903 printfd(tcp, tcp->u_arg[0]);
905 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
906 tprintf(", %lu, ", tcp->u_arg[2]);
908 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
911 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
913 tprintf(", %lu", tcp->u_arg[5]);
920 printfd(tcp, tcp->u_arg[0]);
922 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
925 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
934 printfd(tcp, tcp->u_arg[0]);
937 tprintf("%#lx, %u, ",
938 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
939 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
943 decode_mmsg(tcp, (unsigned long) -1L);
951 printfd(tcp, tcp->u_arg[0]);
955 printaddr(tcp->u_arg[1]);
957 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
959 tprintf(", %lu, ", tcp->u_arg[2]);
960 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
970 printfd(tcp, tcp->u_arg[0]);
975 printaddr(tcp->u_arg[1]);
977 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
980 tprintf(", %lu, ", tcp->u_arg[2]);
982 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
984 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
985 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
986 /* from address, len */
987 printaddr(tcp->u_arg[4]);
989 printaddr(tcp->u_arg[5]);
993 printsock(tcp, tcp->u_arg[4], fromlen);
995 tprintf(", [%u]", fromlen);
1002 if (entering(tcp)) {
1003 printfd(tcp, tcp->u_arg[0]);
1007 printaddr(tcp->u_arg[1]);
1009 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
1012 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1019 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
1021 if (entering(tcp)) {
1022 printfd(tcp, tcp->u_arg[0]);
1025 /* Abusing tcp->auxstr as temp storage.
1026 * Will be used and cleared on syscall exit.
1028 tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
1030 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
1031 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1033 print_timespec(tcp, tcp->u_arg[4]);
1038 decode_mmsg(tcp, 0);
1040 /* timeout on entrance */
1041 tprints(tcp->auxstr);
1046 if (tcp->u_rval == 0) {
1047 tcp->auxstr = "Timeout";
1052 /* timeout on exit */
1053 snprintf(str, sizeof(str), "left %s",
1054 sprint_timespec(tcp, tcp->u_arg[4]));
1060 #include "xlat/shutdown_modes.h"
1064 printfd(tcp, tcp->u_arg[0]);
1066 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1068 return RVAL_DECODED;
1071 SYS_FUNC(getsockname)
1073 return do_sockname(tcp, -1);
1077 printpair_fd(struct tcb *tcp, const int i0, const int i1)
1087 decode_pair_fd(struct tcb *tcp, const long addr)
1091 if (umove_or_printaddr(tcp, addr, &pair))
1094 printpair_fd(tcp, pair[0], pair[1]);
1098 do_pipe(struct tcb *tcp, int flags_arg)
1101 if (syserror(tcp)) {
1102 printaddr(tcp->u_arg[0]);
1104 #ifdef HAVE_GETRVAL2
1105 if (flags_arg < 0) {
1106 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
1109 decode_pair_fd(tcp, tcp->u_arg[0]);
1111 if (flags_arg >= 0) {
1113 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1121 return do_pipe(tcp, -1);
1126 return do_pipe(tcp, 1);
1129 SYS_FUNC(socketpair)
1131 if (entering(tcp)) {
1132 printxval(domains, tcp->u_arg[0], "PF_???");
1134 tprint_sock_type(tcp->u_arg[1]);
1135 tprintf(", %lu", tcp->u_arg[2]);
1138 decode_pair_fd(tcp, tcp->u_arg[3]);
1143 #include "xlat/sockoptions.h"
1144 #include "xlat/sockipoptions.h"
1145 #include "xlat/getsockipoptions.h"
1146 #include "xlat/setsockipoptions.h"
1147 #include "xlat/sockipv6options.h"
1148 #include "xlat/getsockipv6options.h"
1149 #include "xlat/setsockipv6options.h"
1150 #include "xlat/sockipxoptions.h"
1151 #include "xlat/sockrawoptions.h"
1152 #include "xlat/sockpacketoptions.h"
1153 #include "xlat/socksctpoptions.h"
1154 #include "xlat/socktcpoptions.h"
1157 print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name, bool is_getsockopt)
1161 printxval(socketlayers, level, "SOL_??");
1166 printxval(sockoptions, name, "SO_???");
1169 printxvals(name, "IP_???", sockipoptions,
1170 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
1173 printxvals(name, "IPV6_???", sockipv6options,
1174 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
1177 printxval(sockipxoptions, name, "IPX_???");
1180 printxval(sockpacketoptions, name, "PACKET_???");
1183 printxval(socktcpoptions, name, "TCP_???");
1186 printxval(socksctpoptions, name, "SCTP_???");
1189 printxval(sockrawoptions, name, "RAW_???");
1192 /* Other SOL_* protocol levels still need work. */
1195 tprintf("%u", name);
1203 print_linger(struct tcb *tcp, long addr, int len)
1205 struct linger linger;
1207 if (len != sizeof(linger) ||
1208 umove(tcp, addr, &linger) < 0) {
1213 tprintf("{onoff=%d, linger=%d}",
1217 #endif /* SO_LINGER */
1221 print_ucred(struct tcb *tcp, long addr, int len)
1225 if (len != sizeof(uc) ||
1226 umove(tcp, addr, &uc) < 0) {
1229 tprintf("{pid=%u, uid=%u, gid=%u}",
1235 #endif /* SO_PEERCRED */
1237 #ifdef PACKET_STATISTICS
1239 print_tpacket_stats(struct tcb *tcp, long addr, int len)
1241 struct tpacket_stats stats;
1243 if (len != sizeof(stats) ||
1244 umove(tcp, addr, &stats) < 0) {
1247 tprintf("{packets=%u, drops=%u}",
1252 #endif /* PACKET_STATISTICS */
1255 # include "xlat/icmpfilterflags.h"
1258 print_icmp_filter(struct tcb *tcp, long addr, int len)
1260 struct icmp_filter filter;
1262 if (len != sizeof(filter) ||
1263 umove(tcp, addr, &filter) < 0) {
1269 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1272 #endif /* ICMP_FILTER */
1275 print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1277 if (addr && verbose(tcp))
1283 print_linger(tcp, addr, len);
1288 print_ucred(tcp, addr, len);
1296 #ifdef PACKET_STATISTICS
1297 case PACKET_STATISTICS:
1298 print_tpacket_stats(tcp, addr, len);
1308 print_icmp_filter(tcp, addr, len);
1315 /* default arg printing */
1318 if (len == sizeof(int)) {
1319 printnum_int(tcp, addr, "%d");
1321 printstr(tcp, addr, len);
1327 tprintf(", [%d]", len);
1330 SYS_FUNC(getsockopt)
1332 if (entering(tcp)) {
1333 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1334 tcp->u_arg[1], tcp->u_arg[2], true);
1338 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1339 tprintf("%#lx, %#lx",
1340 tcp->u_arg[3], tcp->u_arg[4]);
1342 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1343 tcp->u_arg[3], len);
1349 #ifdef IP_ADD_MEMBERSHIP
1351 print_mreq(struct tcb *tcp, long addr, unsigned int len)
1353 struct ip_mreq mreq;
1355 if (len < sizeof(mreq)) {
1356 printstr(tcp, addr, len);
1359 if (umove_or_printaddr(tcp, addr, &mreq))
1362 tprints("{imr_multiaddr=inet_addr(");
1363 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1364 16, QUOTE_0_TERMINATED);
1365 tprints("), imr_interface=inet_addr(");
1366 print_quoted_string(inet_ntoa(mreq.imr_interface),
1367 16, QUOTE_0_TERMINATED);
1370 #endif /* IP_ADD_MEMBERSHIP */
1372 #ifdef IPV6_ADD_MEMBERSHIP
1374 print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1376 struct ipv6_mreq mreq;
1378 if (len < sizeof(mreq))
1381 if (umove_or_printaddr(tcp, addr, &mreq))
1384 #ifdef HAVE_INET_NTOP
1385 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1386 char address[INET6_ADDRSTRLEN];
1388 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1391 tprints("{ipv6mr_multiaddr=inet_pton(");
1392 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1393 tprints("), ipv6mr_interface=");
1394 print_ifindex(mreq.ipv6mr_interface);
1397 #endif /* HAVE_INET_NTOP */
1400 printstr(tcp, addr, len);
1402 #endif /* IPV6_ADD_MEMBERSHIP */
1404 #ifdef MCAST_JOIN_GROUP
1406 print_group_req(struct tcb *tcp, long addr, int len)
1408 struct group_req greq;
1410 if (len != sizeof(greq) ||
1411 umove(tcp, addr, &greq) < 0) {
1416 tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
1417 print_sockaddr(tcp, (const void *) &greq.gr_group,
1418 sizeof(greq.gr_group));
1422 #endif /* MCAST_JOIN_GROUP */
1424 #ifdef PACKET_RX_RING
1426 print_tpacket_req(struct tcb *tcp, long addr, int len)
1428 struct tpacket_req req;
1430 if (len != sizeof(req) ||
1431 umove(tcp, addr, &req) < 0) {
1434 tprintf("{block_size=%u, block_nr=%u, "
1435 "frame_size=%u, frame_nr=%u}",
1442 #endif /* PACKET_RX_RING */
1444 #ifdef PACKET_ADD_MEMBERSHIP
1445 # include "xlat/packet_mreq_type.h"
1448 print_packet_mreq(struct tcb *tcp, long addr, int len)
1450 struct packet_mreq mreq;
1452 if (len != sizeof(mreq) ||
1453 umove(tcp, addr, &mreq) < 0) {
1458 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1459 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1460 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1461 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1462 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1463 for (i = 0; i < mreq.mr_alen; ++i)
1464 tprintf("%02x", mreq.mr_address[i]);
1468 #endif /* PACKET_ADD_MEMBERSHIP */
1471 print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1473 if (addr && verbose(tcp))
1479 print_linger(tcp, addr, len);
1487 #ifdef IP_ADD_MEMBERSHIP
1488 case IP_ADD_MEMBERSHIP:
1489 case IP_DROP_MEMBERSHIP:
1490 print_mreq(tcp, addr, len);
1492 #endif /* IP_ADD_MEMBERSHIP */
1493 #ifdef MCAST_JOIN_GROUP
1494 case MCAST_JOIN_GROUP:
1495 case MCAST_LEAVE_GROUP:
1496 print_group_req(tcp, addr, len);
1498 #endif /* MCAST_JOIN_GROUP */
1504 #ifdef IPV6_ADD_MEMBERSHIP
1505 case IPV6_ADD_MEMBERSHIP:
1506 case IPV6_DROP_MEMBERSHIP:
1507 # ifdef IPV6_JOIN_ANYCAST
1508 case IPV6_JOIN_ANYCAST:
1510 # ifdef IPV6_LEAVE_ANYCAST
1511 case IPV6_LEAVE_ANYCAST:
1513 print_mreq6(tcp, addr, len);
1515 #endif /* IPV6_ADD_MEMBERSHIP */
1521 #ifdef PACKET_RX_RING
1522 case PACKET_RX_RING:
1523 # ifdef PACKET_TX_RING
1524 case PACKET_TX_RING:
1526 print_tpacket_req(tcp, addr, len);
1528 #endif /* PACKET_RX_RING */
1529 #ifdef PACKET_ADD_MEMBERSHIP
1530 case PACKET_ADD_MEMBERSHIP:
1531 case PACKET_DROP_MEMBERSHIP:
1532 print_packet_mreq(tcp, addr, len);
1534 #endif /* PACKET_ADD_MEMBERSHIP */
1542 print_icmp_filter(tcp, addr, len);
1549 /* default arg printing */
1552 if (len == sizeof(int)) {
1553 printnum_int(tcp, addr, "%d");
1555 printstr(tcp, addr, len);
1561 tprintf(", %d", len);
1564 SYS_FUNC(setsockopt)
1566 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1567 tcp->u_arg[1], tcp->u_arg[2], false);
1568 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1569 tcp->u_arg[3], tcp->u_arg[4]);
1571 return RVAL_DECODED;