2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * Copyright (c) 1996-2000 Wichert Akkerman <wichert@cistron.nl>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #ifdef HAVE_NETINET_TCP_H
38 # include <netinet/tcp.h>
40 #ifdef HAVE_NETINET_UDP_H
41 # include <netinet/udp.h>
43 #ifdef HAVE_NETINET_SCTP_H
44 # include <netinet/sctp.h>
46 #include <arpa/inet.h>
48 #include <asm/types.h>
49 #if defined(__GLIBC__)
50 # include <netipx/ipx.h>
52 # include <linux/ipx.h>
55 #if defined(HAVE_LINUX_IP_VS_H)
56 # include <linux/ip_vs.h>
58 #include <linux/netlink.h>
59 #if defined(HAVE_LINUX_NETFILTER_ARP_ARP_TABLES_H)
60 # include <linux/netfilter_arp/arp_tables.h>
62 #if defined(HAVE_LINUX_NETFILTER_BRIDGE_EBTABLES_H)
63 # include <linux/netfilter_bridge/ebtables.h>
65 #if defined(HAVE_LINUX_NETFILTER_IPV4_IP_TABLES_H)
66 # include <linux/netfilter_ipv4/ip_tables.h>
68 #if defined(HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H)
69 # include <linux/netfilter_ipv6/ip6_tables.h>
71 #if defined(HAVE_LINUX_IF_PACKET_H)
72 # include <linux/if_packet.h>
74 #if defined(HAVE_LINUX_ICMP_H)
75 # include <linux/icmp.h>
77 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
78 # include <bluetooth/bluetooth.h>
79 # include <bluetooth/hci.h>
80 # include <bluetooth/l2cap.h>
81 # include <bluetooth/rfcomm.h>
82 # include <bluetooth/sco.h>
85 #include "xlat/addrfams.h"
86 #include "xlat/socktypes.h"
87 #include "xlat/sock_type_flags.h"
88 #ifndef SOCK_TYPE_MASK
89 # define SOCK_TYPE_MASK 0xf
92 #include "xlat/socketlayers.h"
94 #include "xlat/inet_protocols.h"
96 #if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
97 # define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
99 #include "xlat/netlink_protocols.h"
101 #if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
102 # include "xlat/bt_protocols.h"
105 #include "xlat/msg_flags.h"
107 #if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
108 # include "xlat/af_packet_types.h"
112 print_ifindex(unsigned int ifindex)
114 #ifdef HAVE_IF_INDEXTONAME
115 char buf[IFNAMSIZ + 1];
117 if (if_indextoname(ifindex, buf)) {
118 tprints("if_nametoindex(");
119 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
124 tprintf("%u", ifindex);
130 struct sockaddr_in sin;
131 struct sockaddr_un sau;
132 #ifdef HAVE_INET_NTOP
133 struct sockaddr_in6 sa6;
136 struct sockaddr_ipx sipx;
139 struct sockaddr_ll ll;
141 struct sockaddr_nl nl;
142 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
143 struct sockaddr_hci hci;
144 struct sockaddr_l2 l2;
145 struct sockaddr_rc rc;
146 struct sockaddr_sco sco;
151 print_sockaddr(struct tcb *tcp, const sockaddr_buf_t *addr, const int addrlen)
153 tprints("{sa_family=");
154 printxval(addrfams, addr->sa.sa_family, "AF_???");
157 switch (addr->sa.sa_family) {
161 } else if (addr->sau.sun_path[0]) {
162 tprints("sun_path=");
163 print_quoted_string(addr->sau.sun_path,
164 sizeof(addr->sau.sun_path) + 1,
167 tprints("sun_path=@");
168 print_quoted_string(addr->sau.sun_path + 1,
169 sizeof(addr->sau.sun_path),
174 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
175 ntohs(addr->sin.sin_port), inet_ntoa(addr->sin.sin_addr));
177 #ifdef HAVE_INET_NTOP
180 char string_addr[100];
181 inet_ntop(AF_INET6, &addr->sa6.sin6_addr,
182 string_addr, sizeof(string_addr));
183 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6"
184 ", \"%s\", &sin6_addr), sin6_flowinfo=%u",
185 ntohs(addr->sa6.sin6_port), string_addr,
186 addr->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(&addr->sa6.sin6_addr)
191 || IN6_IS_ADDR_MC_LINKLOCAL(&addr->sa6.sin6_addr))
192 print_ifindex(addr->sa6.sin6_scope_id);
195 tprintf("%u", addr->sa6.sin6_scope_id);
196 # endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
204 tprintf("sipx_port=htons(%u), ",
205 ntohs(addr->sipx.sipx_port));
206 /* Yes, I know, this does not look too
207 * strace-ish, but otherwise the IPX
208 * addresses just look monstrous...
209 * Anyways, feel free if you don't like
212 tprintf("%08lx:", (unsigned long)ntohl(addr->sipx.sipx_network));
213 for (i = 0; i < IPX_NODE_LEN; i++)
214 tprintf("%02x", addr->sipx.sipx_node[i]);
215 tprintf("/[%02x]", addr->sipx.sipx_type);
223 tprintf("proto=%#04x, if%d, pkttype=",
224 ntohs(addr->ll.sll_protocol),
225 addr->ll.sll_ifindex);
226 printxval(af_packet_types, addr->ll.sll_pkttype, "PACKET_???");
227 tprintf(", addr(%d)={%d, ",
229 addr->ll.sll_hatype);
230 for (i = 0; i < addr->ll.sll_halen; i++)
231 tprintf("%02x", addr->ll.sll_addr[i]);
235 #endif /* AF_PACKET */
237 tprintf("pid=%d, groups=%08x", addr->nl.nl_pid, addr->nl.nl_groups);
239 #if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
241 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
242 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
243 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
244 "{hci_dev=htobs(%d)}",
245 addr->sco.sco_bdaddr.b[0], addr->sco.sco_bdaddr.b[1],
246 addr->sco.sco_bdaddr.b[2], addr->sco.sco_bdaddr.b[3],
247 addr->sco.sco_bdaddr.b[4], addr->sco.sco_bdaddr.b[5],
248 addr->rc.rc_bdaddr.b[0], addr->rc.rc_bdaddr.b[1],
249 addr->rc.rc_bdaddr.b[2], addr->rc.rc_bdaddr.b[3],
250 addr->rc.rc_bdaddr.b[4], addr->rc.rc_bdaddr.b[5],
252 btohs(addr->l2.l2_psm), addr->l2.l2_bdaddr.b[0],
253 addr->l2.l2_bdaddr.b[1], addr->l2.l2_bdaddr.b[2],
254 addr->l2.l2_bdaddr.b[3], addr->l2.l2_bdaddr.b[4],
255 addr->l2.l2_bdaddr.b[5], btohs(addr->l2.l2_cid),
256 btohs(addr->hci.hci_dev));
258 #endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
259 /* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
260 AF_X25 AF_ROSE etc. still need to be done */
264 print_quoted_string(addr->sa.sa_data,
265 sizeof(addr->sa.sa_data), 0);
272 printsock(struct tcb *tcp, long addr, int addrlen)
274 sockaddr_buf_t addrbuf;
281 if (addrlen > (int) sizeof(addrbuf))
282 addrlen = sizeof(addrbuf);
284 memset(&addrbuf, 0, sizeof(addrbuf));
285 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
287 addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
289 print_sockaddr(tcp, &addrbuf, addrlen);
292 #include "xlat/scmvals.h"
293 #include "xlat/ip_cmsg_types.h"
295 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
305 struct cmsghdr *cmsg;
306 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
307 struct cmsghdr32 *cmsg32;
312 print_scm_rights(struct tcb *tcp, const void *cmsg_data,
313 const size_t data_len)
315 const int *fds = cmsg_data;
316 const char *end = (const char *) cmsg_data + data_len;
319 if (sizeof(*fds) > data_len)
323 while ((const char *) fds < end) {
328 printfd(tcp, *fds++);
334 print_scm_creds(struct tcb *tcp, const void *cmsg_data,
335 const size_t data_len)
337 const struct ucred *uc = cmsg_data;
339 if (sizeof(*uc) > data_len)
342 tprintf(", {pid=%u, uid=%u, gid=%u}",
343 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
347 print_scm_security(struct tcb *tcp, const void *cmsg_data,
348 const size_t data_len)
354 print_quoted_string(cmsg_data, data_len, 0);
358 print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data,
359 const size_t data_len)
361 const struct in_pktinfo *info = cmsg_data;
363 if (sizeof(*info) > data_len)
366 tprints(", {ipi_ifindex=");
367 print_ifindex(info->ipi_ifindex);
368 tprintf(", ipi_spec_dst=inet_addr(\"%s\"), ipi_addr=inet_addr(\"%s\")}",
369 inet_ntoa(info->ipi_spec_dst), inet_ntoa(info->ipi_addr));
373 print_cmsg_ip_ttl(struct tcb *tcp, const void *cmsg_data,
374 const size_t data_len)
376 const unsigned int *ttl = cmsg_data;
378 if (sizeof(*ttl) > data_len)
381 tprintf(", {ttl=%u}", *ttl);
385 print_cmsg_ip_tos(struct tcb *tcp, const void *cmsg_data,
386 const size_t data_len)
388 const uint8_t *tos = cmsg_data;
390 if (sizeof(*tos) > data_len)
393 tprintf(", {tos=%x}", *tos);
397 print_cmsg_ip_checksum(struct tcb *tcp, const void *cmsg_data,
398 const size_t data_len)
400 const uint32_t *csum = cmsg_data;
402 if (sizeof(*csum) > data_len)
405 tprintf(", {csum=%u}", *csum);
409 print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data,
410 const size_t data_len)
412 const unsigned char *opts = cmsg_data;
418 tprints(", {opts=0x");
419 for (i = 0; i < data_len; ++i)
420 tprintf("%02x", opts[i]);
425 print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
426 const size_t data_len)
436 struct sockaddr_in offender;
439 if (sizeof(*err) > data_len)
442 tprintf(", {ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
443 ", ee_info=%u, ee_data=%u, offender=",
444 err->ee_errno, err->ee_origin, err->ee_type,
445 err->ee_code, err->ee_info, err->ee_data);
446 print_sockaddr(tcp, (const void *) &err->offender,
447 sizeof(err->offender));
452 print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
453 const size_t data_len)
455 if (sizeof(struct sockaddr_in) > data_len)
459 print_sockaddr(tcp, cmsg_data, data_len);
463 print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
464 const void *cmsg_data, const size_t data_len)
466 switch (cmsg_level) {
468 printxval(scmvals, cmsg_type, "SCM_???");
471 print_scm_rights(tcp, cmsg_data, data_len);
473 case SCM_CREDENTIALS:
474 print_scm_creds(tcp, cmsg_data, data_len);
477 print_scm_security(tcp, cmsg_data, data_len);
482 printxval(ip_cmsg_types, cmsg_type, "IP_???");
485 print_cmsg_ip_pktinfo(tcp, cmsg_data, data_len);
488 print_cmsg_ip_ttl(tcp, cmsg_data, data_len);
491 print_cmsg_ip_tos(tcp, cmsg_data, data_len);
495 print_cmsg_ip_opts(tcp, cmsg_data, data_len);
498 print_cmsg_ip_recverr(tcp, cmsg_data, data_len);
501 print_cmsg_ip_origdstaddr(tcp, cmsg_data, data_len);
504 print_cmsg_ip_checksum(tcp, cmsg_data, data_len);
507 print_scm_security(tcp, cmsg_data, data_len);
512 tprintf("%u", cmsg_type);
517 printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
519 const size_t cmsg_size =
520 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
521 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
523 sizeof(struct cmsghdr);
525 char *buf = len < cmsg_size ? NULL : malloc(len);
526 if (!buf || umoven(tcp, addr, len, buf) < 0) {
527 tprints(", msg_control=");
533 union_cmsghdr u = { .ptr = buf };
536 while (len >= cmsg_size) {
538 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
539 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
543 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
544 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
548 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
549 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
555 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
556 printxval(socketlayers, cmsg_level, "SOL_???");
557 tprints(", cmsg_type=");
562 print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
563 (const void *) (u.ptr + cmsg_size),
564 cmsg_len > cmsg_size ? cmsg_len - cmsg_size: 0);
567 if (cmsg_len < cmsg_size) {
571 cmsg_len = (cmsg_len + current_wordsize - 1) &
572 (size_t) ~(current_wordsize - 1);
573 if (cmsg_len >= len) {
587 do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
589 tprintf("{msg_name(%d)=", msg->msg_namelen);
590 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
592 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
593 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
594 (unsigned long)msg->msg_iov, 1, data_size);
596 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
597 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
598 if (msg->msg_controllen)
599 printcmsghdr(tcp, (unsigned long) msg->msg_control,
600 msg->msg_controllen);
601 tprints(", msg_flags=");
602 printflags(msg_flags, msg->msg_flags, "MSG_???");
603 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
604 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
605 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
606 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
611 uint32_t /* void* */ msg_name;
612 uint32_t /* socklen_t */msg_namelen;
613 uint32_t /* iovec* */ msg_iov;
614 uint32_t /* size_t */ msg_iovlen;
615 uint32_t /* void* */ msg_control;
616 uint32_t /* size_t */ msg_controllen;
617 uint32_t /* int */ msg_flags;
620 struct msghdr32 msg_hdr;
621 uint32_t /* unsigned */ msg_len;
624 #ifndef HAVE_STRUCT_MMSGHDR
626 struct msghdr msg_hdr;
631 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
633 copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
635 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
636 to_msg->msg_namelen = from_msg32->msg_namelen;
637 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
638 to_msg->msg_iovlen = from_msg32->msg_iovlen;
639 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
640 to_msg->msg_controllen = from_msg32->msg_controllen;
641 to_msg->msg_flags = from_msg32->msg_flags;
646 extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
648 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
649 if (current_wordsize == 4) {
650 struct msghdr32 msg32;
652 if (umove(tcp, addr, &msg32) < 0)
654 copy_from_msghdr32(msg, &msg32);
657 if (umove(tcp, addr, msg) < 0)
663 extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
665 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
666 if (current_wordsize == 4) {
667 struct mmsghdr32 mmsg32;
669 addr += sizeof(struct mmsghdr32) * idx;
670 if (umove(tcp, addr, &mmsg32) < 0)
673 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
674 mmsg->msg_len = mmsg32.msg_len;
678 addr += sizeof(*mmsg) * idx;
679 if (umove(tcp, addr, mmsg) < 0)
686 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
690 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
691 do_msghdr(tcp, &msg, data_size);
697 dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
701 if (extractmsghdr(tcp, addr, &msg))
702 dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size);
706 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
710 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
712 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
713 tprintf(", %u}", mmsg.msg_len);
720 decode_mmsg(struct tcb *tcp, unsigned long msg_len)
724 printaddr(tcp->u_arg[1]);
726 unsigned int len = tcp->u_rval;
730 for (i = 0; i < len; ++i) {
733 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
738 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
740 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
744 dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
746 unsigned int len = tcp->u_rval;
750 for (i = 0; i < len; ++i) {
751 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
752 tprintf(" = %lu buffers in vector %u\n",
753 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
754 dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
755 (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
761 * low bits of the socket type define real socket type,
762 * other bits are socket type flags.
765 tprint_sock_type(unsigned int flags)
767 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
771 flags &= ~SOCK_TYPE_MASK;
776 printflags(sock_type_flags, flags, "SOCK_???");
781 printxval(addrfams, tcp->u_arg[0], "AF_???");
783 tprint_sock_type(tcp->u_arg[1]);
785 switch (tcp->u_arg[0]) {
790 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
794 /* BTW: I don't believe this.. */
796 printxval(addrfams, tcp->u_arg[2], "AF_???");
801 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
803 #if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
805 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
809 tprintf("%lu", tcp->u_arg[2]);
813 return RVAL_DECODED | RVAL_FD;
818 printfd(tcp, tcp->u_arg[0]);
820 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
821 tprintf(", %lu", tcp->u_arg[2]);
828 printfd(tcp, tcp->u_arg[0]);
830 tprintf("%lu", tcp->u_arg[1]);
836 do_sockname(struct tcb *tcp, int flags_arg)
839 printfd(tcp, tcp->u_arg[0]);
845 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
846 umove(tcp, tcp->u_arg[2], &len) < 0) {
847 printaddr(tcp->u_arg[1]);
849 printaddr(tcp->u_arg[2]);
851 printsock(tcp, tcp->u_arg[1], len);
852 tprintf(", [%d]", len);
855 if (flags_arg >= 0) {
857 printflags(sock_type_flags, tcp->u_arg[flags_arg],
865 do_sockname(tcp, -1);
877 printfd(tcp, tcp->u_arg[0]);
879 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
880 tprintf(", %lu, ", tcp->u_arg[2]);
882 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
889 printfd(tcp, tcp->u_arg[0]);
891 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
892 tprintf(", %lu, ", tcp->u_arg[2]);
894 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
897 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
899 tprintf(", %lu", tcp->u_arg[5]);
906 printfd(tcp, tcp->u_arg[0]);
908 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
911 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
920 printfd(tcp, tcp->u_arg[0]);
923 printaddr(tcp->u_arg[1]);
924 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
925 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
929 decode_mmsg(tcp, (unsigned long) -1L);
937 printfd(tcp, tcp->u_arg[0]);
941 printaddr(tcp->u_arg[1]);
943 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
945 tprintf(", %lu, ", tcp->u_arg[2]);
946 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
956 printfd(tcp, tcp->u_arg[0]);
961 printaddr(tcp->u_arg[1]);
963 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
966 tprintf(", %lu, ", tcp->u_arg[2]);
968 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
970 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
971 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
972 /* from address, len */
973 printaddr(tcp->u_arg[4]);
975 printaddr(tcp->u_arg[5]);
979 printsock(tcp, tcp->u_arg[4], fromlen);
981 tprintf(", [%u]", fromlen);
989 printfd(tcp, tcp->u_arg[0]);
993 printaddr(tcp->u_arg[1]);
995 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
998 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1005 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
1007 if (entering(tcp)) {
1008 printfd(tcp, tcp->u_arg[0]);
1011 /* Abusing tcp->auxstr as temp storage.
1012 * Will be used and cleared on syscall exit.
1014 tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
1016 printaddr(tcp->u_arg[1]);
1017 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
1018 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1020 print_timespec(tcp, tcp->u_arg[4]);
1025 decode_mmsg(tcp, 0);
1027 /* timeout on entrance */
1028 tprints(tcp->auxstr);
1033 if (tcp->u_rval == 0) {
1034 tcp->auxstr = "Timeout";
1039 /* timeout on exit */
1040 snprintf(str, sizeof(str), "left %s",
1041 sprint_timespec(tcp, tcp->u_arg[4]));
1047 #include "xlat/shutdown_modes.h"
1051 printfd(tcp, tcp->u_arg[0]);
1053 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1055 return RVAL_DECODED;
1058 SYS_FUNC(getsockname)
1060 return do_sockname(tcp, -1);
1064 printpair_fd(struct tcb *tcp, const int i0, const int i1)
1074 decode_pair_fd(struct tcb *tcp, const long addr)
1078 if (umove_or_printaddr(tcp, addr, &pair))
1081 printpair_fd(tcp, pair[0], pair[1]);
1085 do_pipe(struct tcb *tcp, int flags_arg)
1088 decode_pair_fd(tcp, tcp->u_arg[0]);
1089 if (flags_arg >= 0) {
1091 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1099 #ifdef HAVE_GETRVAL2
1100 if (exiting(tcp) && !syserror(tcp))
1101 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
1104 return do_pipe(tcp, -1);
1110 return do_pipe(tcp, 1);
1113 SYS_FUNC(socketpair)
1115 if (entering(tcp)) {
1116 printxval(addrfams, tcp->u_arg[0], "AF_???");
1118 tprint_sock_type(tcp->u_arg[1]);
1119 tprintf(", %lu", tcp->u_arg[2]);
1122 decode_pair_fd(tcp, tcp->u_arg[3]);
1127 #include "xlat/sockoptions.h"
1128 #include "xlat/sockipoptions.h"
1129 #include "xlat/getsockipoptions.h"
1130 #include "xlat/setsockipoptions.h"
1131 #include "xlat/sockipv6options.h"
1132 #include "xlat/getsockipv6options.h"
1133 #include "xlat/setsockipv6options.h"
1134 #include "xlat/sockipxoptions.h"
1135 #include "xlat/sockrawoptions.h"
1136 #include "xlat/sockpacketoptions.h"
1137 #include "xlat/socksctpoptions.h"
1138 #include "xlat/socktcpoptions.h"
1141 print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level,
1142 unsigned int name, bool is_getsockopt)
1146 printxval(socketlayers, level, "SOL_??");
1151 printxval(sockoptions, name, "SO_???");
1154 printxvals(name, "IP_???", sockipoptions,
1155 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
1158 printxvals(name, "IPV6_???", sockipv6options,
1159 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
1162 printxval(sockipxoptions, name, "IPX_???");
1165 printxval(sockpacketoptions, name, "PACKET_???");
1168 printxval(socktcpoptions, name, "TCP_???");
1171 printxval(socksctpoptions, name, "SCTP_???");
1174 printxval(sockrawoptions, name, "RAW_???");
1177 /* Other SOL_* protocol levels still need work. */
1180 tprintf("%u", name);
1188 print_linger(struct tcb *tcp, long addr, int len)
1190 struct linger linger;
1192 if (len != sizeof(linger) ||
1193 umove(tcp, addr, &linger) < 0) {
1198 tprintf("{onoff=%d, linger=%d}",
1202 #endif /* SO_LINGER */
1206 print_ucred(struct tcb *tcp, long addr, int len)
1210 if (len != sizeof(uc) ||
1211 umove(tcp, addr, &uc) < 0) {
1214 tprintf("{pid=%u, uid=%u, gid=%u}",
1220 #endif /* SO_PEERCRED */
1222 #ifdef PACKET_STATISTICS
1224 print_tpacket_stats(struct tcb *tcp, long addr, int len)
1226 struct tpacket_stats stats;
1228 if (len != sizeof(stats) ||
1229 umove(tcp, addr, &stats) < 0) {
1232 tprintf("{packets=%u, drops=%u}",
1237 #endif /* PACKET_STATISTICS */
1240 # include "xlat/icmpfilterflags.h"
1243 print_icmp_filter(struct tcb *tcp, const long addr, int len)
1245 struct icmp_filter filter = {};
1247 if (len > (int) sizeof(filter))
1248 len = sizeof(filter);
1249 else if (len <= 0) {
1254 if (umoven_or_printaddr(tcp, addr, len, &filter))
1258 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1261 #endif /* ICMP_FILTER */
1264 print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1267 if (addr && verbose(tcp))
1273 print_linger(tcp, addr, len);
1278 print_ucred(tcp, addr, len);
1286 #ifdef PACKET_STATISTICS
1287 case PACKET_STATISTICS:
1288 print_tpacket_stats(tcp, addr, len);
1298 print_icmp_filter(tcp, addr, len);
1305 /* default arg printing */
1308 if (len == sizeof(int)) {
1309 printnum_int(tcp, addr, "%d");
1311 printstr(tcp, addr, len);
1317 tprintf(", [%d]", len);
1320 SYS_FUNC(getsockopt)
1322 if (entering(tcp)) {
1323 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1324 tcp->u_arg[1], tcp->u_arg[2], true);
1328 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1329 printaddr(tcp->u_arg[3]);
1331 printaddr(tcp->u_arg[4]);
1333 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1334 tcp->u_arg[3], len);
1340 #ifdef IP_ADD_MEMBERSHIP
1342 print_mreq(struct tcb *tcp, long addr, unsigned int len)
1344 struct ip_mreq mreq;
1346 if (len < sizeof(mreq)) {
1347 printstr(tcp, addr, len);
1350 if (umove_or_printaddr(tcp, addr, &mreq))
1353 tprints("{imr_multiaddr=inet_addr(");
1354 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1355 16, QUOTE_0_TERMINATED);
1356 tprints("), imr_interface=inet_addr(");
1357 print_quoted_string(inet_ntoa(mreq.imr_interface),
1358 16, QUOTE_0_TERMINATED);
1361 #endif /* IP_ADD_MEMBERSHIP */
1363 #ifdef IPV6_ADD_MEMBERSHIP
1365 print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1367 struct ipv6_mreq mreq;
1369 if (len < sizeof(mreq))
1372 if (umove_or_printaddr(tcp, addr, &mreq))
1375 #ifdef HAVE_INET_NTOP
1376 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1377 char address[INET6_ADDRSTRLEN];
1379 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1382 tprints("{ipv6mr_multiaddr=inet_pton(");
1383 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1384 tprints("), ipv6mr_interface=");
1385 print_ifindex(mreq.ipv6mr_interface);
1388 #endif /* HAVE_INET_NTOP */
1391 printstr(tcp, addr, len);
1393 #endif /* IPV6_ADD_MEMBERSHIP */
1395 #ifdef MCAST_JOIN_GROUP
1397 print_group_req(struct tcb *tcp, long addr, int len)
1399 struct group_req greq;
1401 if (len != sizeof(greq) ||
1402 umove(tcp, addr, &greq) < 0) {
1407 tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
1408 print_sockaddr(tcp, (const void *) &greq.gr_group,
1409 sizeof(greq.gr_group));
1413 #endif /* MCAST_JOIN_GROUP */
1415 #ifdef PACKET_RX_RING
1417 print_tpacket_req(struct tcb *tcp, long addr, int len)
1419 struct tpacket_req req;
1421 if (len != sizeof(req) ||
1422 umove(tcp, addr, &req) < 0) {
1425 tprintf("{block_size=%u, block_nr=%u, "
1426 "frame_size=%u, frame_nr=%u}",
1433 #endif /* PACKET_RX_RING */
1435 #ifdef PACKET_ADD_MEMBERSHIP
1436 # include "xlat/packet_mreq_type.h"
1439 print_packet_mreq(struct tcb *tcp, long addr, int len)
1441 struct packet_mreq mreq;
1443 if (len != sizeof(mreq) ||
1444 umove(tcp, addr, &mreq) < 0) {
1449 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1450 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1451 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1452 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1453 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1454 for (i = 0; i < mreq.mr_alen; ++i)
1455 tprintf("%02x", mreq.mr_address[i]);
1459 #endif /* PACKET_ADD_MEMBERSHIP */
1462 print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1465 if (addr && verbose(tcp))
1471 print_linger(tcp, addr, len);
1479 #ifdef IP_ADD_MEMBERSHIP
1480 case IP_ADD_MEMBERSHIP:
1481 case IP_DROP_MEMBERSHIP:
1482 print_mreq(tcp, addr, len);
1484 #endif /* IP_ADD_MEMBERSHIP */
1485 #ifdef MCAST_JOIN_GROUP
1486 case MCAST_JOIN_GROUP:
1487 case MCAST_LEAVE_GROUP:
1488 print_group_req(tcp, addr, len);
1490 #endif /* MCAST_JOIN_GROUP */
1496 #ifdef IPV6_ADD_MEMBERSHIP
1497 case IPV6_ADD_MEMBERSHIP:
1498 case IPV6_DROP_MEMBERSHIP:
1499 # ifdef IPV6_JOIN_ANYCAST
1500 case IPV6_JOIN_ANYCAST:
1502 # ifdef IPV6_LEAVE_ANYCAST
1503 case IPV6_LEAVE_ANYCAST:
1505 print_mreq6(tcp, addr, len);
1507 #endif /* IPV6_ADD_MEMBERSHIP */
1513 #ifdef PACKET_RX_RING
1514 case PACKET_RX_RING:
1515 # ifdef PACKET_TX_RING
1516 case PACKET_TX_RING:
1518 print_tpacket_req(tcp, addr, len);
1520 #endif /* PACKET_RX_RING */
1521 #ifdef PACKET_ADD_MEMBERSHIP
1522 case PACKET_ADD_MEMBERSHIP:
1523 case PACKET_DROP_MEMBERSHIP:
1524 print_packet_mreq(tcp, addr, len);
1526 #endif /* PACKET_ADD_MEMBERSHIP */
1534 print_icmp_filter(tcp, addr, len);
1541 /* default arg printing */
1544 if (len == sizeof(int)) {
1545 printnum_int(tcp, addr, "%d");
1547 printstr(tcp, addr, len);
1553 tprintf(", %d", len);
1556 SYS_FUNC(setsockopt)
1558 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1559 tcp->u_arg[1], tcp->u_arg[2], false);
1560 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1561 tcp->u_arg[3], tcp->u_arg[4]);
1563 return RVAL_DECODED;