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];
149 if (addrlen < 2 || addrlen > (int) sizeof(addrbuf))
150 addrlen = sizeof(addrbuf);
152 memset(&addrbuf, 0, sizeof(addrbuf));
153 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
155 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
157 tprints("{sa_family=");
158 printxval(addrfams, addrbuf.sa.sa_family, "AF_???");
161 switch (addrbuf.sa.sa_family) {
165 } else if (addrbuf.sau.sun_path[0]) {
166 tprints("sun_path=");
167 print_quoted_string(addrbuf.sau.sun_path,
168 sizeof(addrbuf.sau.sun_path) + 1,
171 tprints("sun_path=@");
172 print_quoted_string(addrbuf.sau.sun_path + 1,
173 sizeof(addrbuf.sau.sun_path),
178 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
179 ntohs(addrbuf.sin.sin_port), inet_ntoa(addrbuf.sin.sin_addr));
181 #ifdef HAVE_INET_NTOP
183 inet_ntop(AF_INET6, &addrbuf.sa6.sin6_addr, string_addr, sizeof(string_addr));
184 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6, \"%s\", &sin6_addr), sin6_flowinfo=%u",
185 ntohs(addrbuf.sa6.sin6_port), string_addr,
186 addrbuf.sa6.sin6_flowinfo);
187 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
188 tprints(", sin6_scope_id=");
189 #if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
190 if (IN6_IS_ADDR_LINKLOCAL(&addrbuf.sa6.sin6_addr)
191 || IN6_IS_ADDR_MC_LINKLOCAL(&addrbuf.sa6.sin6_addr))
192 print_ifindex(addrbuf.sa6.sin6_scope_id);
195 tprintf("%u", addrbuf.sa6.sin6_scope_id);
196 #endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
203 tprintf("sipx_port=htons(%u), ",
204 ntohs(addrbuf.sipx.sipx_port));
205 /* Yes, I know, this does not look too
206 * strace-ish, but otherwise the IPX
207 * addresses just look monstrous...
208 * Anyways, feel free if you don't like
211 tprintf("%08lx:", (unsigned long)ntohl(addrbuf.sipx.sipx_network));
212 for (i = 0; i < IPX_NODE_LEN; i++)
213 tprintf("%02x", addrbuf.sipx.sipx_node[i]);
214 tprintf("/[%02x]", addrbuf.sipx.sipx_type);
222 tprintf("proto=%#04x, if%d, pkttype=",
223 ntohs(addrbuf.ll.sll_protocol),
224 addrbuf.ll.sll_ifindex);
225 printxval(af_packet_types, addrbuf.ll.sll_pkttype, "PACKET_???");
226 tprintf(", addr(%d)={%d, ",
227 addrbuf.ll.sll_halen,
228 addrbuf.ll.sll_hatype);
229 for (i = 0; i < addrbuf.ll.sll_halen; i++)
230 tprintf("%02x", addrbuf.ll.sll_addr[i]);
234 #endif /* AF_PACKET */
237 tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
239 #endif /* AF_NETLINK */
240 #if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
242 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
243 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
244 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
245 "{hci_dev=htobs(%d)}",
246 addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
247 addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
248 addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
249 addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
250 addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
251 addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
252 addrbuf.rc.rc_channel,
253 btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
254 addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
255 addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
256 addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
257 btohs(addrbuf.hci.hci_dev));
259 #endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
260 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
261 AF_X25 AF_ROSE etc. still need to be done */
265 print_quoted_string(addrbuf.sa.sa_data,
266 sizeof(addrbuf.sa.sa_data), 0);
273 # ifndef SCM_SECURITY
274 # define SCM_SECURITY 0x03
276 # include "xlat/scmvals.h"
278 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
288 struct cmsghdr *cmsg;
289 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
290 struct cmsghdr32 *cmsg32;
295 print_scm_rights(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
297 if (cmsg_size + sizeof(int) > cmsg_len)
300 int *fds = (int *) (ptr + cmsg_size);
304 while ((char *) fds < (ptr + cmsg_len)) {
309 printfd(tcp, *fds++);
316 print_scm_creds(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
318 if (cmsg_size + sizeof(struct ucred) > cmsg_len)
321 const struct ucred *uc = (void *) (ptr + cmsg_size);
323 tprintf(", {pid=%u, uid=%u, gid=%u}}",
324 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
329 print_scm_security(struct tcb *tcp, size_t cmsg_size, char *ptr, size_t cmsg_len)
331 if (cmsg_size + sizeof(char) > cmsg_len)
334 const char *label = (const char *) (ptr + cmsg_size);
335 const size_t label_len = cmsg_len - cmsg_size;
338 print_quoted_string(label, label_len, 0);
345 printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
347 const size_t cmsg_size =
348 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
349 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
351 sizeof(struct cmsghdr);
353 char *buf = len < cmsg_size ? NULL : malloc(len);
354 if (!buf || umoven(tcp, addr, len, buf) < 0) {
355 tprints(", msg_control=");
361 union_cmsghdr u = { .ptr = buf };
364 while (len >= cmsg_size) {
366 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
367 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
371 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
372 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
376 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
377 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
383 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
384 printxval(socketlayers, cmsg_level, "SOL_???");
385 tprints(", cmsg_type=");
390 if (cmsg_level == SOL_SOCKET) {
391 printxval(scmvals, cmsg_type, "SCM_???");
394 if (print_scm_rights(tcp, cmsg_size, u.ptr, cmsg_len))
397 case SCM_CREDENTIALS:
398 if (print_scm_creds(tcp, cmsg_size, u.ptr, cmsg_len))
402 if (print_scm_security(tcp, cmsg_size, u.ptr, cmsg_len))
407 tprintf("%u", cmsg_type);
411 if (cmsg_len < cmsg_size) {
415 cmsg_len = (cmsg_len + current_wordsize - 1) &
416 (size_t) ~(current_wordsize - 1);
417 if (cmsg_len >= len) {
431 do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
433 tprintf("{msg_name(%d)=", msg->msg_namelen);
434 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
436 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
437 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
438 (unsigned long)msg->msg_iov, 1, data_size);
440 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
441 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
442 if (msg->msg_controllen)
443 printcmsghdr(tcp, (unsigned long) msg->msg_control,
444 msg->msg_controllen);
445 tprints(", msg_flags=");
446 printflags(msg_flags, msg->msg_flags, "MSG_???");
447 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
448 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
449 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
450 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
455 uint32_t /* void* */ msg_name;
456 uint32_t /* socklen_t */msg_namelen;
457 uint32_t /* iovec* */ msg_iov;
458 uint32_t /* size_t */ msg_iovlen;
459 uint32_t /* void* */ msg_control;
460 uint32_t /* size_t */ msg_controllen;
461 uint32_t /* int */ msg_flags;
464 struct msghdr32 msg_hdr;
465 uint32_t /* unsigned */ msg_len;
468 #ifndef HAVE_STRUCT_MMSGHDR
470 struct msghdr msg_hdr;
475 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
477 copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
479 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
480 to_msg->msg_namelen = from_msg32->msg_namelen;
481 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
482 to_msg->msg_iovlen = from_msg32->msg_iovlen;
483 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
484 to_msg->msg_controllen = from_msg32->msg_controllen;
485 to_msg->msg_flags = from_msg32->msg_flags;
490 extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
492 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
493 if (current_wordsize == 4) {
494 struct msghdr32 msg32;
496 if (umove(tcp, addr, &msg32) < 0)
498 copy_from_msghdr32(msg, &msg32);
501 if (umove(tcp, addr, msg) < 0)
507 extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
509 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
510 if (current_wordsize == 4) {
511 struct mmsghdr32 mmsg32;
513 addr += sizeof(struct mmsghdr32) * idx;
514 if (umove(tcp, addr, &mmsg32) < 0)
517 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
518 mmsg->msg_len = mmsg32.msg_len;
522 addr += sizeof(*mmsg) * idx;
523 if (umove(tcp, addr, mmsg) < 0)
530 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
534 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
535 do_msghdr(tcp, &msg, data_size);
541 dumpiov_in_msghdr(struct tcb *tcp, long addr)
545 if (extractmsghdr(tcp, addr, &msg))
546 dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
550 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
554 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
556 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
557 tprintf(", %u}", mmsg.msg_len);
564 decode_mmsg(struct tcb *tcp, unsigned long msg_len)
568 printaddr(tcp->u_arg[1]);
570 unsigned int len = tcp->u_rval;
574 for (i = 0; i < len; ++i) {
577 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
582 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
584 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
588 dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
590 unsigned int len = tcp->u_rval;
594 for (i = 0; i < len; ++i) {
595 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
596 tprintf(" = %lu buffers in vector %u\n",
597 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
598 dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
599 (long)mmsg.msg_hdr.msg_iov);
603 #endif /* HAVE_SENDMSG */
606 * low bits of the socket type define real socket type,
607 * other bits are socket type flags.
610 tprint_sock_type(int flags)
612 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
616 flags &= ~SOCK_TYPE_MASK;
621 printflags(sock_type_flags, flags, "SOCK_???");
626 printxval(domains, tcp->u_arg[0], "PF_???");
628 tprint_sock_type(tcp->u_arg[1]);
630 switch (tcp->u_arg[0]) {
635 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
639 /* BTW: I don't believe this.. */
641 printxval(domains, tcp->u_arg[2], "PF_???");
647 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
650 #if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
652 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
656 tprintf("%lu", tcp->u_arg[2]);
665 printfd(tcp, tcp->u_arg[0]);
667 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
668 tprintf(", %lu", tcp->u_arg[2]);
675 printfd(tcp, tcp->u_arg[0]);
677 tprintf("%lu", tcp->u_arg[1]);
683 do_sockname(struct tcb *tcp, int flags_arg)
686 printfd(tcp, tcp->u_arg[0]);
692 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
693 umove(tcp, tcp->u_arg[2], &len) < 0) {
694 printaddr(tcp->u_arg[1]);
696 printaddr(tcp->u_arg[2]);
698 printsock(tcp, tcp->u_arg[1], len);
699 tprintf(", [%d]", len);
702 if (flags_arg >= 0) {
704 printflags(sock_type_flags, tcp->u_arg[flags_arg],
712 do_sockname(tcp, -1);
724 printfd(tcp, tcp->u_arg[0]);
726 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
727 tprintf(", %lu, ", tcp->u_arg[2]);
729 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
736 printfd(tcp, tcp->u_arg[0]);
738 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
739 tprintf(", %lu, ", tcp->u_arg[2]);
741 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
744 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
746 tprintf(", %lu", tcp->u_arg[5]);
755 printfd(tcp, tcp->u_arg[0]);
757 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
760 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
769 printfd(tcp, tcp->u_arg[0]);
772 tprintf("%#lx, %u, ",
773 tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
774 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
778 decode_mmsg(tcp, (unsigned long) -1L);
783 #endif /* HAVE_SENDMSG */
788 printfd(tcp, tcp->u_arg[0]);
792 printaddr(tcp->u_arg[1]);
794 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
796 tprintf(", %lu, ", tcp->u_arg[2]);
797 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
807 printfd(tcp, tcp->u_arg[0]);
811 tprintf("%#lx, %lu, %lu, %#lx, %#lx",
812 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3],
813 tcp->u_arg[4], tcp->u_arg[5]);
817 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
819 tprintf(", %lu, ", tcp->u_arg[2]);
821 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
822 /* from address, len */
824 if (!tcp->u_arg[4] || !tcp->u_arg[5] ||
825 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
826 printaddr(tcp->u_arg[4]);
828 printaddr(tcp->u_arg[5]);
831 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
833 tprintf(", [%u]", fromlen);
843 printfd(tcp, tcp->u_arg[0]);
847 printaddr(tcp->u_arg[1]);
849 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
852 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
859 /* +5 chars are for "left " prefix */
860 static char str[5 + TIMESPEC_TEXT_BUFSIZE];
863 printfd(tcp, tcp->u_arg[0]);
866 sprint_timespec(str, tcp, tcp->u_arg[4]);
867 /* Abusing tcp->auxstr as temp storage.
868 * Will be used and freed on syscall exit.
870 tcp->auxstr = xstrdup(str);
872 tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
873 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
875 print_timespec(tcp, tcp->u_arg[4]);
881 /* timeout on entrance */
882 tprintf(", %s", tcp->auxstr ? tcp->auxstr : "{...}");
883 free((void *) tcp->auxstr);
888 if (tcp->u_rval == 0) {
889 tcp->auxstr = "Timeout";
894 /* timeout on exit */
895 sprint_timespec(stpcpy(str, "left "), tcp, tcp->u_arg[4]);
901 #endif /* HAVE_SENDMSG */
903 #include "xlat/shutdown_modes.h"
907 printfd(tcp, tcp->u_arg[0]);
909 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
914 SYS_FUNC(getsockname)
916 return do_sockname(tcp, -1);
920 do_pipe(struct tcb *tcp, int flags_arg)
924 printaddr(tcp->u_arg[0]);
928 tprintf("[%lu, %lu]", tcp->u_rval, getrval2(tcp));
931 printpair_int(tcp, tcp->u_arg[0], "%u");
933 if (flags_arg >= 0) {
935 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
943 return do_pipe(tcp, -1);
948 return do_pipe(tcp, 1);
954 printxval(domains, tcp->u_arg[0], "PF_???");
956 tprint_sock_type(tcp->u_arg[1]);
957 tprintf(", %lu", tcp->u_arg[2]);
960 printpair_int(tcp, tcp->u_arg[3], "%u");
965 #include "xlat/sockoptions.h"
966 #include "xlat/sockipoptions.h"
967 #include "xlat/sockipv6options.h"
968 #include "xlat/sockipxoptions.h"
969 #include "xlat/sockrawoptions.h"
970 #include "xlat/sockpacketoptions.h"
971 #include "xlat/socksctpoptions.h"
972 #include "xlat/socktcpoptions.h"
975 print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name)
979 printxval(socketlayers, level, "SOL_??");
984 printxval(sockoptions, name, "SO_???");
987 printxval(sockipoptions, name, "IP_???");
990 printxval(sockipv6options, name, "IPV6_???");
993 printxval(sockipxoptions, name, "IPX_???");
996 printxval(sockpacketoptions, name, "PACKET_???");
999 printxval(socktcpoptions, name, "TCP_???");
1002 printxval(socksctpoptions, name, "SCTP_???");
1005 printxval(sockrawoptions, name, "RAW_???");
1008 /* Other SOL_* protocol levels still need work. */
1011 tprintf("%u", name);
1019 print_linger(struct tcb *tcp, long addr, int len)
1021 struct linger linger;
1023 if (len != sizeof(linger) ||
1024 umove(tcp, addr, &linger) < 0) {
1029 tprintf("{onoff=%d, linger=%d}",
1033 #endif /* SO_LINGER */
1037 print_ucred(struct tcb *tcp, long addr, int len)
1041 if (len != sizeof(uc) ||
1042 umove(tcp, addr, &uc) < 0) {
1045 tprintf("{pid=%u, uid=%u, gid=%u}",
1051 #endif /* SO_PEERCRED */
1053 #ifdef PACKET_STATISTICS
1055 print_tpacket_stats(struct tcb *tcp, long addr, int len)
1057 struct tpacket_stats stats;
1059 if (len != sizeof(stats) ||
1060 umove(tcp, addr, &stats) < 0) {
1063 tprintf("{packets=%u, drops=%u}",
1068 #endif /* PACKET_STATISTICS */
1071 # include "xlat/icmpfilterflags.h"
1074 print_icmp_filter(struct tcb *tcp, long addr, int len)
1076 struct icmp_filter filter;
1078 if (len != sizeof(filter) ||
1079 umove(tcp, addr, &filter) < 0) {
1085 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1088 #endif /* ICMP_FILTER */
1091 print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1093 if (addr && verbose(tcp))
1099 print_linger(tcp, addr, len);
1104 print_ucred(tcp, addr, len);
1112 #ifdef PACKET_STATISTICS
1113 case PACKET_STATISTICS:
1114 print_tpacket_stats(tcp, addr, len);
1124 print_icmp_filter(tcp, addr, len);
1131 /* default arg printing */
1134 if (len == sizeof(int)) {
1135 printnum_int(tcp, addr, "%d");
1137 printstr(tcp, addr, len);
1143 tprintf(", [%d]", len);
1146 SYS_FUNC(getsockopt)
1148 if (entering(tcp)) {
1149 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1150 tcp->u_arg[1], tcp->u_arg[2]);
1154 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1155 tprintf("%#lx, %#lx",
1156 tcp->u_arg[3], tcp->u_arg[4]);
1158 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1159 tcp->u_arg[3], len);
1165 #ifdef IP_ADD_MEMBERSHIP
1167 print_mreq(struct tcb *tcp, long addr, unsigned int len)
1169 struct ip_mreq mreq;
1171 if (len < sizeof(mreq)) {
1172 printstr(tcp, addr, len);
1175 if (umove_or_printaddr(tcp, addr, &mreq))
1178 tprints("{imr_multiaddr=inet_addr(");
1179 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1180 16, QUOTE_0_TERMINATED);
1181 tprints("), imr_interface=inet_addr(");
1182 print_quoted_string(inet_ntoa(mreq.imr_interface),
1183 16, QUOTE_0_TERMINATED);
1186 #endif /* IP_ADD_MEMBERSHIP */
1188 #ifdef IPV6_ADD_MEMBERSHIP
1190 print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1192 struct ipv6_mreq mreq;
1194 if (len < sizeof(mreq))
1197 if (umove_or_printaddr(tcp, addr, &mreq))
1200 #ifdef HAVE_INET_NTOP
1201 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1202 char address[INET6_ADDRSTRLEN];
1204 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1207 tprints("{ipv6mr_multiaddr=inet_pton(");
1208 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1209 tprints("), ipv6mr_interface=");
1210 print_ifindex(mreq.ipv6mr_interface);
1213 #endif /* HAVE_INET_NTOP */
1216 printstr(tcp, addr, len);
1218 #endif /* IPV6_ADD_MEMBERSHIP */
1220 #ifdef MCAST_JOIN_GROUP
1222 print_group_req(struct tcb *tcp, long addr, int len)
1224 struct group_req greq;
1226 if (len != sizeof(greq) ||
1227 umove(tcp, addr, &greq) < 0) {
1233 struct sockaddr *sa;
1234 struct sockaddr_in *sin;
1235 #ifdef HAVE_INET_NTOP
1236 struct sockaddr_in6 *sin6;
1238 } a = { .sa = (struct sockaddr *) &greq.gr_group };
1239 #ifdef HAVE_INET_NTOP
1240 char str[INET6_ADDRSTRLEN];
1243 tprintf("{gr_interface=%u, gr_group={sa_family=", greq.gr_interface);
1244 printxval(addrfams, a.sa->sa_family, "AF_???");
1246 switch (a.sa->sa_family) {
1248 tprintf(", sin_port=htons(%u), sin_addr=inet_addr(\"%s\")}}",
1249 ntohs(a.sin->sin_port),
1250 inet_ntoa(a.sin->sin_addr));
1252 #ifdef HAVE_INET_NTOP
1254 if (!inet_ntop(AF_INET6, &a.sin6->sin6_addr, str, sizeof(str)))
1256 tprintf(", sin6_port=htons(%u)"
1257 ", inet_pton(AF_INET6, \"%s\", &sin6_addr)}}",
1258 ntohs(a.sin6->sin6_port), str);
1260 #endif /* HAVE_INET_NTOP */
1263 tprints(", sa_data=");
1264 print_quoted_string(a.sa->sa_data, sizeof(a.sa->sa_data), 0);
1268 #endif /* MCAST_JOIN_GROUP */
1270 #ifdef PACKET_RX_RING
1272 print_tpacket_req(struct tcb *tcp, long addr, int len)
1274 struct tpacket_req req;
1276 if (len != sizeof(req) ||
1277 umove(tcp, addr, &req) < 0) {
1280 tprintf("{block_size=%u, block_nr=%u, "
1281 "frame_size=%u, frame_nr=%u}",
1288 #endif /* PACKET_RX_RING */
1290 #ifdef PACKET_ADD_MEMBERSHIP
1291 # include "xlat/packet_mreq_type.h"
1294 print_packet_mreq(struct tcb *tcp, long addr, int len)
1296 struct packet_mreq mreq;
1298 if (len != sizeof(mreq) ||
1299 umove(tcp, addr, &mreq) < 0) {
1304 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1305 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1306 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1307 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1308 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1309 for (i = 0; i < mreq.mr_alen; ++i)
1310 tprintf("%02x", mreq.mr_address[i]);
1314 #endif /* PACKET_ADD_MEMBERSHIP */
1317 print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
1319 if (addr && verbose(tcp))
1325 print_linger(tcp, addr, len);
1333 #ifdef IP_ADD_MEMBERSHIP
1334 case IP_ADD_MEMBERSHIP:
1335 case IP_DROP_MEMBERSHIP:
1336 print_mreq(tcp, addr, len);
1338 #endif /* IP_ADD_MEMBERSHIP */
1339 #ifdef MCAST_JOIN_GROUP
1340 case MCAST_JOIN_GROUP:
1341 case MCAST_LEAVE_GROUP:
1342 print_group_req(tcp, addr, len);
1344 #endif /* MCAST_JOIN_GROUP */
1350 #ifdef IPV6_ADD_MEMBERSHIP
1351 case IPV6_ADD_MEMBERSHIP:
1352 case IPV6_DROP_MEMBERSHIP:
1353 # ifdef IPV6_JOIN_ANYCAST
1354 case IPV6_JOIN_ANYCAST:
1356 # ifdef IPV6_LEAVE_ANYCAST
1357 case IPV6_LEAVE_ANYCAST:
1359 print_mreq6(tcp, addr, len);
1361 #endif /* IPV6_ADD_MEMBERSHIP */
1367 #ifdef PACKET_RX_RING
1368 case PACKET_RX_RING:
1369 # ifdef PACKET_TX_RING
1370 case PACKET_TX_RING:
1372 print_tpacket_req(tcp, addr, len);
1374 #endif /* PACKET_RX_RING */
1375 #ifdef PACKET_ADD_MEMBERSHIP
1376 case PACKET_ADD_MEMBERSHIP:
1377 case PACKET_DROP_MEMBERSHIP:
1378 print_packet_mreq(tcp, addr, len);
1380 #endif /* PACKET_ADD_MEMBERSHIP */
1388 print_icmp_filter(tcp, addr, len);
1395 /* default arg printing */
1398 if (len == sizeof(int)) {
1399 printnum_int(tcp, addr, "%d");
1401 printstr(tcp, addr, len);
1407 tprintf(", %d", len);
1410 SYS_FUNC(setsockopt)
1412 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1413 tcp->u_arg[1], tcp->u_arg[2]);
1414 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1415 tcp->u_arg[3], tcp->u_arg[4]);
1417 return RVAL_DECODED;