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);
136 printsock(struct tcb *tcp, long addr, int addrlen)
141 struct sockaddr_in sin;
142 struct sockaddr_un sau;
143 #ifdef HAVE_INET_NTOP
144 struct sockaddr_in6 sa6;
147 struct sockaddr_ipx sipx;
150 struct sockaddr_ll ll;
153 struct sockaddr_nl nl;
155 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
156 struct sockaddr_hci hci;
157 struct sockaddr_l2 l2;
158 struct sockaddr_rc rc;
159 struct sockaddr_sco sco;
162 char string_addr[100];
169 if (addrlen > (int) sizeof(addrbuf))
170 addrlen = sizeof(addrbuf);
172 memset(&addrbuf, 0, sizeof(addrbuf));
173 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
175 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
177 tprints("{sa_family=");
178 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
181 switch (addrbuf.sa.sa_family) {
185 } else if (addrbuf.sau.sun_path[0]) {
186 tprints("sun_path=");
187 print_quoted_string(addrbuf.sau.sun_path,
188 sizeof(addrbuf.sau.sun_path) + 1,
191 tprints("sun_path=@");
192 print_quoted_string(addrbuf.sau.sun_path + 1,
193 sizeof(addrbuf.sau.sun_path),
198 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
199 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
201 #ifdef HAVE_INET_NTOP
203 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
204 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
205 ntohs(addrbuf.sa6.sin6_port), string_addr,
206 addrbuf.sa6.sin6_flowinfo);
207 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
208 tprints(", sin6_scope_id=");
209 #if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
210 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
211 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr))
212 print_ifindex(addrbuf.sa6.sin6_scope_id);
215 tprintf("%u", addrbuf.sa6.sin6_scope_id);
216 #endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
223 tprintf("sipx_port=htons(%u), ",
224 ntohs(addrbuf.sipx.sipx_port));
225 /* Yes, I know, this does not look too
226 * strace-ish, but otherwise the IPX
227 * addresses just look monstrous...
228 * Anyways, feel free if you don't like
231 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
232 for (i = 0; i < IPX_NODE_LEN; i++)
233 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
234 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
242 tprintf("proto=%#04x, if%d, pkttype=",
243 ntohs(addrbuf.ll.sll_protocol),
244 addrbuf.ll.sll_ifindex);
245 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
246 tprintf(", addr(%d)={%d, ",
247 addrbuf.ll.sll_halen,
248 addrbuf.ll.sll_hatype);
249 for (i = 0; i < addrbuf.ll.sll_halen; i++)
250 tprintf("%02x", addrbuf.ll.sll_addr[i]);
254 #endif /* AF_PACKET */
257 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
259 #endif /* AF_NETLINK */
260 #if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
262 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
263 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
264 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
265 "{hci_dev=htobs(%d)}",
266 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
267 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
268 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
269 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
270 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
271 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
272 addrbuf.rc.rc_channel,
273 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
274 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
275 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
276 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
277 btohs(addrbuf.hci.hci_dev));
279 #endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
280 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
281 AF_X25 AF_ROSE etc. still need to be done */
285 print_quoted_string(addrbuf.sa.sa_data,
286 sizeof(addrbuf.sa.sa_data), 0);
293 # ifndef SCM_SECURITY
294 # define SCM_SECURITY 0x03
296 # include "xlat/scmvals.h"
298 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
308 struct cmsghdr *cmsg;
309 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
310 struct cmsghdr32 *cmsg32;
315 print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
317 if (cmsg_size + sizeof(int) > cmsg_len)
320 int *fds = (int *) (ptr + cmsg_size);
324 while ((char *) fds < (ptr + cmsg_len)) {
329 printfd(tcp, *fds++);
336 print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
338 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
341 const struct ucred *uc = (void *) (ptr + cmsg_size);
343 tprintf(", {pid=%u, uid=%u, gid=%u}}",
344 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
349 print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
351 if (cmsg_size + sizeof(char) > cmsg_len)
354 const char *label = (const char *) (ptr + cmsg_size);
355 const size_t label_len = cmsg_len - cmsg_size;
358 print_quoted_string(label, label_len, 0);
365 printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
367 const size_t cmsg_size =
368 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
369 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
371 sizeof(struct cmsghdr);
373 char *buf = len < cmsg_size ? NULL : malloc(len);
374 if (!buf || umoven(tcp, addr, len, buf) < 0) {
375 tprints(", msg_control=");
381 union_cmsghdr u = { .ptr = buf };
384 while (len >= cmsg_size) {
386 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
387 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
391 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
392 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
396 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
397 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
403 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
404 printxval(socketlayers, cmsg_level, "SOL_???");
405 tprints(", cmsg_type=");
410 if (cmsg_level == SOL_SOCKET) {
411 printxval(scmvals, cmsg_type, "SCM_???");
414 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
417 case SCM_CREDENTIALS:
418 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
422 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
427 tprintf("%u", cmsg_type);
431 if (cmsg_len < cmsg_size) {
435 cmsg_len = (cmsg_len + current_wordsize - 1) &
436 (size_t) ~(current_wordsize - 1);
437 if (cmsg_len >= len) {
451 do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
453 tprintf("{msg_name(%d)=", msg->msg_namelen);
454 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
456 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
457 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
458 (unsigned long)msg->msg_iov, 1, data_size);
460 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
461 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
462 if (msg->msg_controllen)
463 printcmsghdr(tcp, (unsigned long) msg->msg_control,
464 msg->msg_controllen);
465 tprints(", msg_flags=");
466 printflags(msg_flags, msg->msg_flags, "MSG_???");
467 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
468 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
469 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
470 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
475 uint32_t /* void* */ msg_name;
476 uint32_t /* socklen_t */msg_namelen;
477 uint32_t /* iovec* */ msg_iov;
478 uint32_t /* size_t */ msg_iovlen;
479 uint32_t /* void* */ msg_control;
480 uint32_t /* size_t */ msg_controllen;
481 uint32_t /* int */ msg_flags;
484 struct msghdr32 msg_hdr;
485 uint32_t /* unsigned */ msg_len;
488 #ifndef HAVE_STRUCT_MMSGHDR
490 struct msghdr msg_hdr;
495 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
497 copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
499 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
500 to_msg->msg_namelen = from_msg32->msg_namelen;
501 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
502 to_msg->msg_iovlen = from_msg32->msg_iovlen;
503 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
504 to_msg->msg_controllen = from_msg32->msg_controllen;
505 to_msg->msg_flags = from_msg32->msg_flags;
510 extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
512 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
513 if (current_wordsize == 4) {
514 struct msghdr32 msg32;
516 if (umove(tcp, addr, &msg32) < 0)
518 copy_from_msghdr32(msg, &msg32);
521 if (umove(tcp, addr, msg) < 0)
527 extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
529 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
530 if (current_wordsize == 4) {
531 struct mmsghdr32 mmsg32;
533 addr += sizeof(struct mmsghdr32) * idx;
534 if (umove(tcp, addr, &mmsg32) < 0)
537 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
538 mmsg->msg_len = mmsg32.msg_len;
542 addr += sizeof(*mmsg) * idx;
543 if (umove(tcp, addr, mmsg) < 0)
550 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
554 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
555 do_msghdr(tcp, &msg, data_size);
561 dumpiov_in_msghdr(struct tcb *tcp, long addr)
565 if (extractmsghdr(tcp, addr, &msg))
566 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
570 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
574 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
576 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
577 tprintf(", %u}", mmsg.msg_len);
584 decode_mmsg(struct tcb *tcp, unsigned long msg_len)
588 printaddr(tcp->u_arg[1]);
590 unsigned int len = tcp->u_rval;
594 for (i = 0; i < len; ++i) {
597 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
602 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
604 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
608 dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
610 unsigned int len = tcp->u_rval;
614 for (i = 0; i < len; ++i) {
615 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
616 tprintf(" = %lu buffers in vector %u\n",
617 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
618 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
619 (long)mmsg.msg_hdr.msg_iov);
623 #endif /* HAVE_SENDMSG */
626 * low bits of the socket type define real socket type,
627 * other bits are socket type flags.
630 tprint_sock_type(int flags)
632 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
636 flags &= ~SOCK_TYPE_MASK;
641 printflags(sock_type_flags, flags, "SOCK_???");
646 printxval(domains, tcp->u_arg[0], "PF_???");
648 tprint_sock_type(tcp->u_arg[1]);
650 switch (tcp->u_arg[0]) {
655 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
659 /* BTW: I don't believe this.. */
661 printxval(domains, tcp->u_arg[2], "PF_???");
667 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
670 #if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
672 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
676 tprintf("%lu", tcp->u_arg[2]);
680 return RVAL_DECODED | RVAL_FD;
685 printfd(tcp, tcp->u_arg[0]);
687 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
688 tprintf(", %lu", tcp->u_arg[2]);
695 printfd(tcp, tcp->u_arg[0]);
697 tprintf("%lu", tcp->u_arg[1]);
703 do_sockname(struct tcb *tcp, int flags_arg)
706 printfd(tcp, tcp->u_arg[0]);
712 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
713 umove(tcp, tcp->u_arg[2], &len) < 0) {
714 printaddr(tcp->u_arg[1]);
716 printaddr(tcp->u_arg[2]);
718 printsock(tcp, tcp->u_arg[1], len);
719 tprintf(", [%d]", len);
722 if (flags_arg >= 0) {
724 printflags(sock_type_flags, tcp->u_arg[flags_arg],
732 do_sockname(tcp, -1);
744 printfd(tcp, tcp->u_arg[0]);
746 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
747 tprintf(", %lu, ", tcp->u_arg[2]);
749 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
756 printfd(tcp, tcp->u_arg[0]);
758 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
759 tprintf(", %lu, ", tcp->u_arg[2]);
761 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
764 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
766 tprintf(", %lu", tcp->u_arg[5]);
775 printfd(tcp, tcp->u_arg[0]);
777 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
780 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
789 printfd(tcp, tcp->u_arg[0]);
792 tprintf("%#lx, %u, ",
793 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
794 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
798 decode_mmsg(tcp, (unsigned long) -1L);
803 #endif /* HAVE_SENDMSG */
808 printfd(tcp, tcp->u_arg[0]);
812 printaddr(tcp->u_arg[1]);
814 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
816 tprintf(", %lu, ", tcp->u_arg[2]);
817 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
827 printfd(tcp, tcp->u_arg[0]);
832 printaddr(tcp->u_arg[1]);
834 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
837 tprintf(", %lu, ", tcp->u_arg[2]);
839 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
841 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
842 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
843 /* from address, len */
844 printaddr(tcp->u_arg[4]);
846 printaddr(tcp->u_arg[5]);
850 printsock(tcp, tcp->u_arg[4], fromlen);
852 tprintf(", [%u]", fromlen);
862 printfd(tcp, tcp->u_arg[0]);
866 printaddr(tcp->u_arg[1]);
868 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
871 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
878 /* +5 chars are for "left " prefix */
879 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
882 printfd(tcp, tcp->u_arg[0]);
885 sprint_timespec(str, tcp, tcp->u_arg[4]);
886 /* Abusing tcp->auxstr as temp storage.
887 * Will be used and freed on syscall exit.
889 tcp->auxstr = xstrdup(str);
891 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
892 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
894 print_timespec(tcp, tcp->u_arg[4]);
900 /* timeout on entrance */
901 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
902 free((void *) tcp->auxstr);
907 if (tcp->u_rval == 0) {
908 tcp->auxstr = "Timeout";
913 /* timeout on exit */
914 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
920 #endif /* HAVE_SENDMSG */
922 #include "xlat/shutdown_modes.h"
926 printfd(tcp, tcp->u_arg[0]);
928 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
933 SYS_FUNC(getsockname)
935 return do_sockname(tcp, -1);
939 printpair_fd(struct tcb *tcp, const int i0, const int i1)
949 decode_pair_fd(struct tcb *tcp, const long addr)
953 if (umove_or_printaddr(tcp, addr, &pair))
956 printpair_fd(tcp, pair[0], pair[1]);
960 do_pipe(struct tcb *tcp, int flags_arg)
964 printaddr(tcp->u_arg[0]);
968 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
971 decode_pair_fd(tcp, tcp->u_arg[0]);
973 if (flags_arg >= 0) {
975 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
983 return do_pipe(tcp, -1);
988 return do_pipe(tcp, 1);
994 printxval(domains, tcp->u_arg[0], "PF_???");
996 tprint_sock_type(tcp->u_arg[1]);
997 tprintf(", %lu", tcp->u_arg[2]);
1000 decode_pair_fd(tcp, tcp->u_arg[3]);
1005 #include "xlat/sockoptions.h"
1006 #include "xlat/sockipoptions.h"
1007 #include "xlat/getsockipoptions.h"
1008 #include "xlat/setsockipoptions.h"
1009 #include "xlat/sockipv6options.h"
1010 #include "xlat/getsockipv6options.h"
1011 #include "xlat/setsockipv6options.h"
1012 #include "xlat/sockipxoptions.h"
1013 #include "xlat/sockrawoptions.h"
1014 #include "xlat/sockpacketoptions.h"
1015 #include "xlat/socksctpoptions.h"
1016 #include "xlat/socktcpoptions.h"
1019 print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name, bool is_getsockopt)
1023 printxval(socketlayers, level, "SOL_??");
1028 printxval(sockoptions, name, "SO_???");
1031 printxvals(name, "IP_???", sockipoptions,
1032 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
1035 printxvals(name, "IPV6_???", sockipv6options,
1036 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
1039 printxval(sockipxoptions, name, "IPX_???");
1042 printxval(sockpacketoptions, name, "PACKET_???");
1045 printxval(socktcpoptions, name, "TCP_???");
1048 printxval(socksctpoptions, name, "SCTP_???");
1051 printxval(sockrawoptions, name, "RAW_???");
1054 /* Other SOL_* protocol levels still need work. */
1057 tprintf("%u", name);
1065 print_linger(struct tcb *tcp, long addr, int len)
1067 struct linger linger;
1069 if (len != sizeof(linger) ||
1070 umove(tcp, addr, &linger) < 0) {
1075 tprintf("{onoff=%d, linger=%d}",
1079 #endif /* SO_LINGER */
1083 print_ucred(struct tcb *tcp, long addr, int len)
1087 if (len != sizeof(uc) ||
1088 umove(tcp, addr, &uc) < 0) {
1091 tprintf("{pid=%u, uid=%u, gid=%u}",
1097 #endif /* SO_PEERCRED */
1099 #ifdef PACKET_STATISTICS
1101 print_tpacket_stats(struct tcb *tcp, long addr, int len)
1103 struct tpacket_stats stats;
1105 if (len != sizeof(stats) ||
1106 umove(tcp, addr, &stats) < 0) {
1109 tprintf("{packets=%u, drops=%u}",
1114 #endif /* PACKET_STATISTICS */
1117 # include "xlat/icmpfilterflags.h"
1120 print_icmp_filter(struct tcb *tcp, long addr, int len)
1122 struct icmp_filter filter;
1124 if (len != sizeof(filter) ||
1125 umove(tcp, addr, &filter) < 0) {
1131 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1134 #endif /* ICMP_FILTER */
1137 print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1139 if (addr && verbose(tcp))
1145 print_linger(tcp, addr, len);
1150 print_ucred(tcp, addr, len);
1158 #ifdef PACKET_STATISTICS
1159 case PACKET_STATISTICS:
1160 print_tpacket_stats(tcp, addr, len);
1170 print_icmp_filter(tcp, addr, len);
1177 /* default arg printing */
1180 if (len == sizeof(int)) {
1181 printnum_int(tcp, addr, "%d");
1183 printstr(tcp, addr, len);
1189 tprintf(", [%d]", len);
1192 SYS_FUNC(getsockopt)
1194 if (entering(tcp)) {
1195 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1196 tcp->u_arg[1], tcp->u_arg[2], true);
1200 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1201 tprintf("%#lx, %#lx",
1202 tcp->u_arg[3], tcp->u_arg[4]);
1204 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1205 tcp->u_arg[3], len);
1211 #ifdef IP_ADD_MEMBERSHIP
1213 print_mreq(struct tcb *tcp, long addr, unsigned int len)
1215 struct ip_mreq mreq;
1217 if (len < sizeof(mreq)) {
1218 printstr(tcp, addr, len);
1221 if (umove_or_printaddr(tcp, addr, &mreq))
1224 tprints("{imr_multiaddr=inet_addr(");
1225 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1226 16, QUOTE_0_TERMINATED);
1227 tprints("), imr_interface=inet_addr(");
1228 print_quoted_string(inet_ntoa(mreq.imr_interface),
1229 16, QUOTE_0_TERMINATED);
1232 #endif /* IP_ADD_MEMBERSHIP */
1234 #ifdef IPV6_ADD_MEMBERSHIP
1236 print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1238 struct ipv6_mreq mreq;
1240 if (len < sizeof(mreq))
1243 if (umove_or_printaddr(tcp, addr, &mreq))
1246 #ifdef HAVE_INET_NTOP
1247 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1248 char address[INET6_ADDRSTRLEN];
1250 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1253 tprints("{ipv6mr_multiaddr=inet_pton(");
1254 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1255 tprints("), ipv6mr_interface=");
1256 print_ifindex(mreq.ipv6mr_interface);
1259 #endif /* HAVE_INET_NTOP */
1262 printstr(tcp, addr, len);
1264 #endif /* IPV6_ADD_MEMBERSHIP */
1266 #ifdef MCAST_JOIN_GROUP
1268 print_group_req(struct tcb *tcp, long addr, int len)
1270 struct group_req greq;
1272 if (len != sizeof(greq) ||
1273 umove(tcp, addr, &greq) < 0) {
1279 struct sockaddr *sa;
1280 struct sockaddr_in *sin;
1281 #ifdef HAVE_INET_NTOP
1282 struct sockaddr_in6 *sin6;
1284 } a = { .sa = (struct sockaddr *) &greq.gr_group };
1285 #ifdef HAVE_INET_NTOP
1286 char str[INET6_ADDRSTRLEN];
1289 tprintf("{gr_interface=%u, gr_group={sa_family=", greq.gr_interface);
1290 printxval(addrfams, a.sa->sa_family, "AF_???");
1292 switch (a.sa->sa_family) {
1294 tprintf(", sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}}",
1295 ntohs(a.sin->sin_port),
1296 inet_ntoa(a.sin->sin_addr));
1298 #ifdef HAVE_INET_NTOP
1300 if (!inet_ntop(AF_INET6, &a.sin6->sin6_addr, str, sizeof(str)))
1302 tprintf(", sin6_port=htons(%u)"
1303 ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}}",
1304 ntohs(a.sin6->sin6_port), str);
1306 #endif /* HAVE_INET_NTOP */
1309 tprints(", sa_data=");
1310 print_quoted_string(a.sa->sa_data, sizeof(a.sa->sa_data), 0);
1314 #endif /* MCAST_JOIN_GROUP */
1316 #ifdef PACKET_RX_RING
1318 print_tpacket_req(struct tcb *tcp, long addr, int len)
1320 struct tpacket_req req;
1322 if (len != sizeof(req) ||
1323 umove(tcp, addr, &req) < 0) {
1326 tprintf("{block_size=%u, block_nr=%u, "
1327 "frame_size=%u, frame_nr=%u}",
1334 #endif /* PACKET_RX_RING */
1336 #ifdef PACKET_ADD_MEMBERSHIP
1337 # include "xlat/packet_mreq_type.h"
1340 print_packet_mreq(struct tcb *tcp, long addr, int len)
1342 struct packet_mreq mreq;
1344 if (len != sizeof(mreq) ||
1345 umove(tcp, addr, &mreq) < 0) {
1350 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1351 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1352 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1353 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1354 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1355 for (i = 0; i < mreq.mr_alen; ++i)
1356 tprintf("%02x", mreq.mr_address[i]);
1360 #endif /* PACKET_ADD_MEMBERSHIP */
1363 print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1365 if (addr && verbose(tcp))
1371 print_linger(tcp, addr, len);
1379 #ifdef IP_ADD_MEMBERSHIP
1380 case IP_ADD_MEMBERSHIP:
1381 case IP_DROP_MEMBERSHIP:
1382 print_mreq(tcp, addr, len);
1384 #endif /* IP_ADD_MEMBERSHIP */
1385 #ifdef MCAST_JOIN_GROUP
1386 case MCAST_JOIN_GROUP:
1387 case MCAST_LEAVE_GROUP:
1388 print_group_req(tcp, addr, len);
1390 #endif /* MCAST_JOIN_GROUP */
1396 #ifdef IPV6_ADD_MEMBERSHIP
1397 case IPV6_ADD_MEMBERSHIP:
1398 case IPV6_DROP_MEMBERSHIP:
1399 # ifdef IPV6_JOIN_ANYCAST
1400 case IPV6_JOIN_ANYCAST:
1402 # ifdef IPV6_LEAVE_ANYCAST
1403 case IPV6_LEAVE_ANYCAST:
1405 print_mreq6(tcp, addr, len);
1407 #endif /* IPV6_ADD_MEMBERSHIP */
1413 #ifdef PACKET_RX_RING
1414 case PACKET_RX_RING:
1415 # ifdef PACKET_TX_RING
1416 case PACKET_TX_RING:
1418 print_tpacket_req(tcp, addr, len);
1420 #endif /* PACKET_RX_RING */
1421 #ifdef PACKET_ADD_MEMBERSHIP
1422 case PACKET_ADD_MEMBERSHIP:
1423 case PACKET_DROP_MEMBERSHIP:
1424 print_packet_mreq(tcp, addr, len);
1426 #endif /* PACKET_ADD_MEMBERSHIP */
1434 print_icmp_filter(tcp, addr, len);
1441 /* default arg printing */
1444 if (len == sizeof(int)) {
1445 printnum_int(tcp, addr, "%d");
1447 printstr(tcp, addr, len);
1453 tprintf(", %d", len);
1456 SYS_FUNC(setsockopt)
1458 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1459 tcp->u_arg[1], tcp->u_arg[2], false);
1460 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1461 tcp->u_arg[3], tcp->u_arg[4]);
1463 return RVAL_DECODED;