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
83 #include "xlat/socketlayers.h"
85 #include "xlat/inet_protocols.h"
88 # if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
89 # define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
91 # include "xlat/netlink_protocols.h"
94 #if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
95 # include "xlat/bt_protocols.h"
98 #include "xlat/msg_flags.h"
100 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
101 # include "xlat/af_packet_types.h"
105 print_ifindex(unsigned int ifindex)
107 #ifdef HAVE_IF_INDEXTONAME
108 char buf[IFNAMSIZ + 1];
110 if (if_indextoname(ifindex, buf)) {
111 tprints("if_nametoindex(");
112 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
117 tprintf("%u", ifindex);
121 printsock(struct tcb *tcp, long addr, int addrlen)
126 struct sockaddr_in sin;
127 struct sockaddr_un sau;
128 #ifdef HAVE_INET_NTOP
129 struct sockaddr_in6 sa6;
132 struct sockaddr_ipx sipx;
135 struct sockaddr_ll ll;
138 struct sockaddr_nl nl;
140 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
141 struct sockaddr_hci hci;
142 struct sockaddr_l2 l2;
143 struct sockaddr_rc rc;
144 struct sockaddr_sco sco;
147 char string_addr[100];
154 if (addrlen > (int) sizeof(addrbuf))
155 addrlen = sizeof(addrbuf);
157 memset(&addrbuf, 0, sizeof(addrbuf));
158 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
160 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
162 tprints("{sa_family=");
163 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
166 switch (addrbuf.sa.sa_family) {
170 } else if (addrbuf.sau.sun_path[0]) {
171 tprints("sun_path=");
172 print_quoted_string(addrbuf.sau.sun_path,
173 sizeof(addrbuf.sau.sun_path) + 1,
176 tprints("sun_path=@");
177 print_quoted_string(addrbuf.sau.sun_path + 1,
178 sizeof(addrbuf.sau.sun_path),
183 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
184 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
186 #ifdef HAVE_INET_NTOP
188 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
189 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
190 ntohs(addrbuf.sa6.sin6_port), string_addr,
191 addrbuf.sa6.sin6_flowinfo);
192 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
193 tprints(", sin6_scope_id=");
194 #if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
195 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
196 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr))
197 print_ifindex(addrbuf.sa6.sin6_scope_id);
200 tprintf("%u", addrbuf.sa6.sin6_scope_id);
201 #endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
208 tprintf("sipx_port=htons(%u), ",
209 ntohs(addrbuf.sipx.sipx_port));
210 /* Yes, I know, this does not look too
211 * strace-ish, but otherwise the IPX
212 * addresses just look monstrous...
213 * Anyways, feel free if you don't like
216 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
217 for (i = 0; i < IPX_NODE_LEN; i++)
218 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
219 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
227 tprintf("proto=%#04x, if%d, pkttype=",
228 ntohs(addrbuf.ll.sll_protocol),
229 addrbuf.ll.sll_ifindex);
230 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
231 tprintf(", addr(%d)={%d, ",
232 addrbuf.ll.sll_halen,
233 addrbuf.ll.sll_hatype);
234 for (i = 0; i < addrbuf.ll.sll_halen; i++)
235 tprintf("%02x", addrbuf.ll.sll_addr[i]);
239 #endif /* AF_PACKET */
242 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
244 #endif /* AF_NETLINK */
245 #if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
247 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
248 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
249 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
250 "{hci_dev=htobs(%d)}",
251 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
252 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
253 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
254 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
255 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
256 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
257 addrbuf.rc.rc_channel,
258 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
259 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
260 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
261 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
262 btohs(addrbuf.hci.hci_dev));
264 #endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
265 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
266 AF_X25 AF_ROSE etc. still need to be done */
270 print_quoted_string(addrbuf.sa.sa_data,
271 sizeof(addrbuf.sa.sa_data), 0);
278 # ifndef SCM_SECURITY
279 # define SCM_SECURITY 0x03
281 # include "xlat/scmvals.h"
283 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
293 struct cmsghdr *cmsg;
294 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
295 struct cmsghdr32 *cmsg32;
300 print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
302 if (cmsg_size + sizeof(int) > cmsg_len)
305 int *fds = (int *) (ptr + cmsg_size);
309 while ((char *) fds < (ptr + cmsg_len)) {
314 printfd(tcp, *fds++);
321 print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
323 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
326 const struct ucred *uc = (void *) (ptr + cmsg_size);
328 tprintf(", {pid=%u, uid=%u, gid=%u}}",
329 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
334 print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
336 if (cmsg_size + sizeof(char) > cmsg_len)
339 const char *label = (const char *) (ptr + cmsg_size);
340 const size_t label_len = cmsg_len - cmsg_size;
343 print_quoted_string(label, label_len, 0);
350 printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
352 const size_t cmsg_size =
353 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
354 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
356 sizeof(struct cmsghdr);
358 char *buf = len < cmsg_size ? NULL : malloc(len);
359 if (!buf || umoven(tcp, addr, len, buf) < 0) {
360 tprints(", msg_control=");
366 union_cmsghdr u = { .ptr = buf };
369 while (len >= cmsg_size) {
371 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
372 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
376 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
377 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
381 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
382 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
388 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
389 printxval(socketlayers, cmsg_level, "SOL_???");
390 tprints(", cmsg_type=");
395 if (cmsg_level == SOL_SOCKET) {
396 printxval(scmvals, cmsg_type, "SCM_???");
399 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
402 case SCM_CREDENTIALS:
403 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
407 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
412 tprintf("%u", cmsg_type);
416 if (cmsg_len < cmsg_size) {
420 cmsg_len = (cmsg_len + current_wordsize - 1) &
421 (size_t) ~(current_wordsize - 1);
422 if (cmsg_len >= len) {
436 do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
438 tprintf("{msg_name(%d)=", msg->msg_namelen);
439 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
441 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
442 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
443 (unsigned long)msg->msg_iov, 1, data_size);
445 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
446 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
447 if (msg->msg_controllen)
448 printcmsghdr(tcp, (unsigned long) msg->msg_control,
449 msg->msg_controllen);
450 tprints(", msg_flags=");
451 printflags(msg_flags, msg->msg_flags, "MSG_???");
452 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
453 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
454 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
455 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
460 uint32_t /* void* */ msg_name;
461 uint32_t /* socklen_t */msg_namelen;
462 uint32_t /* iovec* */ msg_iov;
463 uint32_t /* size_t */ msg_iovlen;
464 uint32_t /* void* */ msg_control;
465 uint32_t /* size_t */ msg_controllen;
466 uint32_t /* int */ msg_flags;
469 struct msghdr32 msg_hdr;
470 uint32_t /* unsigned */ msg_len;
473 #ifndef HAVE_STRUCT_MMSGHDR
475 struct msghdr msg_hdr;
480 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
482 copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
484 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
485 to_msg->msg_namelen = from_msg32->msg_namelen;
486 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
487 to_msg->msg_iovlen = from_msg32->msg_iovlen;
488 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
489 to_msg->msg_controllen = from_msg32->msg_controllen;
490 to_msg->msg_flags = from_msg32->msg_flags;
495 extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
497 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
498 if (current_wordsize == 4) {
499 struct msghdr32 msg32;
501 if (umove(tcp, addr, &msg32) < 0)
503 copy_from_msghdr32(msg, &msg32);
506 if (umove(tcp, addr, msg) < 0)
512 extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
514 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
515 if (current_wordsize == 4) {
516 struct mmsghdr32 mmsg32;
518 addr += sizeof(struct mmsghdr32) * idx;
519 if (umove(tcp, addr, &mmsg32) < 0)
522 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
523 mmsg->msg_len = mmsg32.msg_len;
527 addr += sizeof(*mmsg) * idx;
528 if (umove(tcp, addr, mmsg) < 0)
535 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
539 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
540 do_msghdr(tcp, &msg, data_size);
546 dumpiov_in_msghdr(struct tcb *tcp, long addr)
550 if (extractmsghdr(tcp, addr, &msg))
551 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
555 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
559 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
561 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
562 tprintf(", %u}", mmsg.msg_len);
569 decode_mmsg(struct tcb *tcp, unsigned long msg_len)
573 printaddr(tcp->u_arg[1]);
575 unsigned int len = tcp->u_rval;
579 for (i = 0; i < len; ++i) {
582 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
587 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
589 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
593 dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
595 unsigned int len = tcp->u_rval;
599 for (i = 0; i < len; ++i) {
600 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
601 tprintf(" = %lu buffers in vector %u\n",
602 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
603 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
604 (long)mmsg.msg_hdr.msg_iov);
608 #endif /* HAVE_SENDMSG */
611 * low bits of the socket type define real socket type,
612 * other bits are socket type flags.
615 tprint_sock_type(int flags)
617 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
621 flags &= ~SOCK_TYPE_MASK;
626 printflags(sock_type_flags, flags, "SOCK_???");
631 printxval(domains, tcp->u_arg[0], "PF_???");
633 tprint_sock_type(tcp->u_arg[1]);
635 switch (tcp->u_arg[0]) {
640 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
644 /* BTW: I don't believe this.. */
646 printxval(domains, tcp->u_arg[2], "PF_???");
652 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
655 #if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
657 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
661 tprintf("%lu", tcp->u_arg[2]);
665 return RVAL_DECODED | RVAL_FD;
670 printfd(tcp, tcp->u_arg[0]);
672 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
673 tprintf(", %lu", tcp->u_arg[2]);
680 printfd(tcp, tcp->u_arg[0]);
682 tprintf("%lu", tcp->u_arg[1]);
688 do_sockname(struct tcb *tcp, int flags_arg)
691 printfd(tcp, tcp->u_arg[0]);
697 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
698 umove(tcp, tcp->u_arg[2], &len) < 0) {
699 printaddr(tcp->u_arg[1]);
701 printaddr(tcp->u_arg[2]);
703 printsock(tcp, tcp->u_arg[1], len);
704 tprintf(", [%d]", len);
707 if (flags_arg >= 0) {
709 printflags(sock_type_flags, tcp->u_arg[flags_arg],
717 do_sockname(tcp, -1);
729 printfd(tcp, tcp->u_arg[0]);
731 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
732 tprintf(", %lu, ", tcp->u_arg[2]);
734 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
741 printfd(tcp, tcp->u_arg[0]);
743 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
744 tprintf(", %lu, ", tcp->u_arg[2]);
746 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
749 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
751 tprintf(", %lu", tcp->u_arg[5]);
760 printfd(tcp, tcp->u_arg[0]);
762 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
765 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
774 printfd(tcp, tcp->u_arg[0]);
777 tprintf("%#lx, %u, ",
778 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
779 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
783 decode_mmsg(tcp, (unsigned long) -1L);
788 #endif /* HAVE_SENDMSG */
793 printfd(tcp, tcp->u_arg[0]);
797 printaddr(tcp->u_arg[1]);
799 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
801 tprintf(", %lu, ", tcp->u_arg[2]);
802 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
812 printfd(tcp, tcp->u_arg[0]);
817 printaddr(tcp->u_arg[1]);
819 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
822 tprintf(", %lu, ", tcp->u_arg[2]);
824 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
826 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
827 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
828 /* from address, len */
829 printaddr(tcp->u_arg[4]);
831 printaddr(tcp->u_arg[5]);
835 printsock(tcp, tcp->u_arg[4], fromlen);
837 tprintf(", [%u]", fromlen);
847 printfd(tcp, tcp->u_arg[0]);
851 printaddr(tcp->u_arg[1]);
853 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
856 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
863 /* +5 chars are for "left " prefix */
864 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
867 printfd(tcp, tcp->u_arg[0]);
870 sprint_timespec(str, tcp, tcp->u_arg[4]);
871 /* Abusing tcp->auxstr as temp storage.
872 * Will be used and freed on syscall exit.
874 tcp->auxstr = xstrdup(str);
876 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
877 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
879 print_timespec(tcp, tcp->u_arg[4]);
885 /* timeout on entrance */
886 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
887 free((void *) tcp->auxstr);
892 if (tcp->u_rval == 0) {
893 tcp->auxstr = "Timeout";
898 /* timeout on exit */
899 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
905 #endif /* HAVE_SENDMSG */
907 #include "xlat/shutdown_modes.h"
911 printfd(tcp, tcp->u_arg[0]);
913 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
918 SYS_FUNC(getsockname)
920 return do_sockname(tcp, -1);
924 printpair_fd(struct tcb *tcp, const int i0, const int i1)
934 decode_pair_fd(struct tcb *tcp, const long addr)
938 if (umove_or_printaddr(tcp, addr, &pair))
941 printpair_fd(tcp, pair[0], pair[1]);
945 do_pipe(struct tcb *tcp, int flags_arg)
949 printaddr(tcp->u_arg[0]);
953 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
956 decode_pair_fd(tcp, tcp->u_arg[0]);
958 if (flags_arg >= 0) {
960 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
968 return do_pipe(tcp, -1);
973 return do_pipe(tcp, 1);
979 printxval(domains, tcp->u_arg[0], "PF_???");
981 tprint_sock_type(tcp->u_arg[1]);
982 tprintf(", %lu", tcp->u_arg[2]);
985 decode_pair_fd(tcp, tcp->u_arg[3]);
990 #include "xlat/sockoptions.h"
991 #include "xlat/sockipoptions.h"
992 #include "xlat/sockipv6options.h"
993 #include "xlat/sockipxoptions.h"
994 #include "xlat/sockrawoptions.h"
995 #include "xlat/sockpacketoptions.h"
996 #include "xlat/socksctpoptions.h"
997 #include "xlat/socktcpoptions.h"
1000 print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name)
1004 printxval(socketlayers, level, "SOL_??");
1009 printxval(sockoptions, name, "SO_???");
1012 printxval(sockipoptions, name, "IP_???");
1015 printxval(sockipv6options, name, "IPV6_???");
1018 printxval(sockipxoptions, name, "IPX_???");
1021 printxval(sockpacketoptions, name, "PACKET_???");
1024 printxval(socktcpoptions, name, "TCP_???");
1027 printxval(socksctpoptions, name, "SCTP_???");
1030 printxval(sockrawoptions, name, "RAW_???");
1033 /* Other SOL_* protocol levels still need work. */
1036 tprintf("%u", name);
1044 print_linger(struct tcb *tcp, long addr, int len)
1046 struct linger linger;
1048 if (len != sizeof(linger) ||
1049 umove(tcp, addr, &linger) < 0) {
1054 tprintf("{onoff=%d, linger=%d}",
1058 #endif /* SO_LINGER */
1062 print_ucred(struct tcb *tcp, long addr, int len)
1066 if (len != sizeof(uc) ||
1067 umove(tcp, addr, &uc) < 0) {
1070 tprintf("{pid=%u, uid=%u, gid=%u}",
1076 #endif /* SO_PEERCRED */
1078 #ifdef PACKET_STATISTICS
1080 print_tpacket_stats(struct tcb *tcp, long addr, int len)
1082 struct tpacket_stats stats;
1084 if (len != sizeof(stats) ||
1085 umove(tcp, addr, &stats) < 0) {
1088 tprintf("{packets=%u, drops=%u}",
1093 #endif /* PACKET_STATISTICS */
1096 # include "xlat/icmpfilterflags.h"
1099 print_icmp_filter(struct tcb *tcp, long addr, int len)
1101 struct icmp_filter filter;
1103 if (len != sizeof(filter) ||
1104 umove(tcp, addr, &filter) < 0) {
1110 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1113 #endif /* ICMP_FILTER */
1116 print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1118 if (addr && verbose(tcp))
1124 print_linger(tcp, addr, len);
1129 print_ucred(tcp, addr, len);
1137 #ifdef PACKET_STATISTICS
1138 case PACKET_STATISTICS:
1139 print_tpacket_stats(tcp, addr, len);
1149 print_icmp_filter(tcp, addr, len);
1156 /* default arg printing */
1159 if (len == sizeof(int)) {
1160 printnum_int(tcp, addr, "%d");
1162 printstr(tcp, addr, len);
1168 tprintf(", [%d]", len);
1171 SYS_FUNC(getsockopt)
1173 if (entering(tcp)) {
1174 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1175 tcp->u_arg[1], tcp->u_arg[2]);
1179 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1180 tprintf("%#lx, %#lx",
1181 tcp->u_arg[3], tcp->u_arg[4]);
1183 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1184 tcp->u_arg[3], len);
1190 #ifdef IP_ADD_MEMBERSHIP
1192 print_mreq(struct tcb *tcp, long addr, unsigned int len)
1194 struct ip_mreq mreq;
1196 if (len < sizeof(mreq)) {
1197 printstr(tcp, addr, len);
1200 if (umove_or_printaddr(tcp, addr, &mreq))
1203 tprints("{imr_multiaddr=inet_addr(");
1204 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1205 16, QUOTE_0_TERMINATED);
1206 tprints("), imr_interface=inet_addr(");
1207 print_quoted_string(inet_ntoa(mreq.imr_interface),
1208 16, QUOTE_0_TERMINATED);
1211 #endif /* IP_ADD_MEMBERSHIP */
1213 #ifdef IPV6_ADD_MEMBERSHIP
1215 print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1217 struct ipv6_mreq mreq;
1219 if (len < sizeof(mreq))
1222 if (umove_or_printaddr(tcp, addr, &mreq))
1225 #ifdef HAVE_INET_NTOP
1226 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1227 char address[INET6_ADDRSTRLEN];
1229 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1232 tprints("{ipv6mr_multiaddr=inet_pton(");
1233 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1234 tprints("), ipv6mr_interface=");
1235 print_ifindex(mreq.ipv6mr_interface);
1238 #endif /* HAVE_INET_NTOP */
1241 printstr(tcp, addr, len);
1243 #endif /* IPV6_ADD_MEMBERSHIP */
1245 #ifdef MCAST_JOIN_GROUP
1247 print_group_req(struct tcb *tcp, long addr, int len)
1249 struct group_req greq;
1251 if (len != sizeof(greq) ||
1252 umove(tcp, addr, &greq) < 0) {
1258 struct sockaddr *sa;
1259 struct sockaddr_in *sin;
1260 #ifdef HAVE_INET_NTOP
1261 struct sockaddr_in6 *sin6;
1263 } a = { .sa = (struct sockaddr *) &greq.gr_group };
1264 #ifdef HAVE_INET_NTOP
1265 char str[INET6_ADDRSTRLEN];
1268 tprintf("{gr_interface=%u, gr_group={sa_family=", greq.gr_interface);
1269 printxval(addrfams, a.sa->sa_family, "AF_???");
1271 switch (a.sa->sa_family) {
1273 tprintf(", sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}}",
1274 ntohs(a.sin->sin_port),
1275 inet_ntoa(a.sin->sin_addr));
1277 #ifdef HAVE_INET_NTOP
1279 if (!inet_ntop(AF_INET6, &a.sin6->sin6_addr, str, sizeof(str)))
1281 tprintf(", sin6_port=htons(%u)"
1282 ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}}",
1283 ntohs(a.sin6->sin6_port), str);
1285 #endif /* HAVE_INET_NTOP */
1288 tprints(", sa_data=");
1289 print_quoted_string(a.sa->sa_data, sizeof(a.sa->sa_data), 0);
1293 #endif /* MCAST_JOIN_GROUP */
1295 #ifdef PACKET_RX_RING
1297 print_tpacket_req(struct tcb *tcp, long addr, int len)
1299 struct tpacket_req req;
1301 if (len != sizeof(req) ||
1302 umove(tcp, addr, &req) < 0) {
1305 tprintf("{block_size=%u, block_nr=%u, "
1306 "frame_size=%u, frame_nr=%u}",
1313 #endif /* PACKET_RX_RING */
1315 #ifdef PACKET_ADD_MEMBERSHIP
1316 # include "xlat/packet_mreq_type.h"
1319 print_packet_mreq(struct tcb *tcp, long addr, int len)
1321 struct packet_mreq mreq;
1323 if (len != sizeof(mreq) ||
1324 umove(tcp, addr, &mreq) < 0) {
1329 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1330 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1331 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1332 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1333 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1334 for (i = 0; i < mreq.mr_alen; ++i)
1335 tprintf("%02x", mreq.mr_address[i]);
1339 #endif /* PACKET_ADD_MEMBERSHIP */
1342 print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1344 if (addr && verbose(tcp))
1350 print_linger(tcp, addr, len);
1358 #ifdef IP_ADD_MEMBERSHIP
1359 case IP_ADD_MEMBERSHIP:
1360 case IP_DROP_MEMBERSHIP:
1361 print_mreq(tcp, addr, len);
1363 #endif /* IP_ADD_MEMBERSHIP */
1364 #ifdef MCAST_JOIN_GROUP
1365 case MCAST_JOIN_GROUP:
1366 case MCAST_LEAVE_GROUP:
1367 print_group_req(tcp, addr, len);
1369 #endif /* MCAST_JOIN_GROUP */
1375 #ifdef IPV6_ADD_MEMBERSHIP
1376 case IPV6_ADD_MEMBERSHIP:
1377 case IPV6_DROP_MEMBERSHIP:
1378 # ifdef IPV6_JOIN_ANYCAST
1379 case IPV6_JOIN_ANYCAST:
1381 # ifdef IPV6_LEAVE_ANYCAST
1382 case IPV6_LEAVE_ANYCAST:
1384 print_mreq6(tcp, addr, len);
1386 #endif /* IPV6_ADD_MEMBERSHIP */
1392 #ifdef PACKET_RX_RING
1393 case PACKET_RX_RING:
1394 # ifdef PACKET_TX_RING
1395 case PACKET_TX_RING:
1397 print_tpacket_req(tcp, addr, len);
1399 #endif /* PACKET_RX_RING */
1400 #ifdef PACKET_ADD_MEMBERSHIP
1401 case PACKET_ADD_MEMBERSHIP:
1402 case PACKET_DROP_MEMBERSHIP:
1403 print_packet_mreq(tcp, addr, len);
1405 #endif /* PACKET_ADD_MEMBERSHIP */
1413 print_icmp_filter(tcp, addr, len);
1420 /* default arg printing */
1423 if (len == sizeof(int)) {
1424 printnum_int(tcp, addr, "%d");
1426 printstr(tcp, addr, len);
1432 tprintf(", %d", len);
1435 SYS_FUNC(setsockopt)
1437 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1438 tcp->u_arg[1], tcp->u_arg[2]);
1439 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1440 tcp->u_arg[3], tcp->u_arg[4]);
1442 return RVAL_DECODED;