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 #ifdef HAVE_NETIPX_IPX_H
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 #include <linux/if_packet.h>
72 #include <linux/icmp.h>
73 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
74 # include <bluetooth/bluetooth.h>
75 # include <bluetooth/hci.h>
76 # include <bluetooth/l2cap.h>
77 # include <bluetooth/rfcomm.h>
78 # include <bluetooth/sco.h>
81 #include "xlat/addrfams.h"
82 #include "xlat/socktypes.h"
83 #include "xlat/sock_type_flags.h"
84 #ifndef SOCK_TYPE_MASK
85 # define SOCK_TYPE_MASK 0xf
88 #include "xlat/socketlayers.h"
90 #include "xlat/inet_protocols.h"
92 #if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
93 # define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
95 #include "xlat/netlink_protocols.h"
97 #if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
98 # include "xlat/bt_protocols.h"
101 #include "xlat/msg_flags.h"
103 #include "xlat/af_packet_types.h"
105 #define SIZEOF_SA_FAMILY sizeof(((struct sockaddr *) 0)->sa_family)
108 print_sockaddr_data_un(const void *const buf, const int addrlen)
110 const struct sockaddr_un *const sa_un = buf;
111 const int un_len = addrlen > (int) sizeof(*sa_un)
112 ? (int) sizeof(*sa_un) : addrlen;
113 const int path_len = un_len - SIZEOF_SA_FAMILY;
115 tprints("sun_path=");
116 if (sa_un->sun_path[0]) {
117 print_quoted_string(sa_un->sun_path, path_len + 1,
121 print_quoted_string(sa_un->sun_path + 1, path_len - 1, 0);
126 print_sockaddr_data_in(const void *const buf, const int addrlen)
128 const struct sockaddr_in *const sa_in = buf;
130 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
131 ntohs(sa_in->sin_port), inet_ntoa(sa_in->sin_addr));
135 print_ifindex(unsigned int ifindex)
137 #ifdef HAVE_IF_INDEXTONAME
138 char buf[IFNAMSIZ + 1];
140 if (if_indextoname(ifindex, buf)) {
141 tprints("if_nametoindex(");
142 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
147 tprintf("%u", ifindex);
150 #define SIN6_MIN_LEN offsetof(struct sockaddr_in6, sin6_scope_id)
153 print_sockaddr_data_in6(const void *const buf, const int addrlen)
155 const struct sockaddr_in6 *const sa_in6 = buf;
157 char string_addr[100];
158 inet_ntop(AF_INET6, &sa_in6->sin6_addr,
159 string_addr, sizeof(string_addr));
160 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6"
161 ", \"%s\", &sin6_addr), sin6_flowinfo=htonl(%u)",
162 ntohs(sa_in6->sin6_port), string_addr,
163 ntohl(sa_in6->sin6_flowinfo));
165 if (addrlen <= (int) SIN6_MIN_LEN)
168 tprints(", sin6_scope_id=");
169 #if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
170 if (IN6_IS_ADDR_LINKLOCAL(&sa_in6->sin6_addr)
171 || IN6_IS_ADDR_MC_LINKLOCAL(&sa_in6->sin6_addr))
172 print_ifindex(sa_in6->sin6_scope_id);
175 tprintf("%u", sa_in6->sin6_scope_id);
179 print_sockaddr_data_ipx(const void *const buf, const int addrlen)
181 const struct sockaddr_ipx *const sa_ipx = buf;
184 tprintf("sipx_port=htons(%u)"
185 ", sipx_network=htonl(%08x)"
187 ntohs(sa_ipx->sipx_port),
188 ntohl(sa_ipx->sipx_network));
189 for (i = 0; i < IPX_NODE_LEN; ++i) {
190 tprintf("%s%02x", i ? ", " : "",
191 sa_ipx->sipx_node[i]);
193 tprintf("], sipx_type=%02x", sa_ipx->sipx_type);
197 print_sockaddr_data_nl(const void *const buf, const int addrlen)
199 const struct sockaddr_nl *const sa_nl = buf;
201 tprintf("nl_pid=%d, nl_groups=%#08x",
202 sa_nl->nl_pid, sa_nl->nl_groups);
206 print_sockaddr_data_ll(const void *const buf, const int addrlen)
208 const struct sockaddr_ll *const sa_ll = buf;
211 tprintf("proto=%#04x, if%d, pkttype=",
212 ntohs(sa_ll->sll_protocol),
214 printxval(af_packet_types, sa_ll->sll_pkttype, "PACKET_???");
215 tprintf(", addr(%d)={%d, ", sa_ll->sll_halen, sa_ll->sll_hatype);
216 for (i = 0; i < sa_ll->sll_halen; i++)
217 tprintf("%02x", sa_ll->sll_addr[i]);
220 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
222 print_sockaddr_data_bt(const void *const buf, const int addrlen)
225 struct sockaddr_hci hci;
226 struct sockaddr_l2 l2;
227 struct sockaddr_rc rc;
228 struct sockaddr_sco sco;
231 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
232 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
233 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
234 "{hci_dev=htobs(%d)}",
235 addr->sco.sco_bdaddr.b[0], addr->sco.sco_bdaddr.b[1],
236 addr->sco.sco_bdaddr.b[2], addr->sco.sco_bdaddr.b[3],
237 addr->sco.sco_bdaddr.b[4], addr->sco.sco_bdaddr.b[5],
238 addr->rc.rc_bdaddr.b[0], addr->rc.rc_bdaddr.b[1],
239 addr->rc.rc_bdaddr.b[2], addr->rc.rc_bdaddr.b[3],
240 addr->rc.rc_bdaddr.b[4], addr->rc.rc_bdaddr.b[5],
242 btohs(addr->l2.l2_psm), addr->l2.l2_bdaddr.b[0],
243 addr->l2.l2_bdaddr.b[1], addr->l2.l2_bdaddr.b[2],
244 addr->l2.l2_bdaddr.b[3], addr->l2.l2_bdaddr.b[4],
245 addr->l2.l2_bdaddr.b[5], btohs(addr->l2.l2_cid),
246 btohs(addr->hci.hci_dev));
248 #endif /* HAVE_BLUETOOTH_BLUETOOTH_H */
250 typedef void (* const sockaddr_printer)(const void *const, const int);
252 static const sockaddr_printer sa_printers[] = {
253 [AF_UNIX] = print_sockaddr_data_un,
254 [AF_INET] = print_sockaddr_data_in,
255 [AF_IPX] = print_sockaddr_data_ipx,
256 [AF_INET6] = print_sockaddr_data_in6,
257 [AF_NETLINK] = print_sockaddr_data_nl,
258 [AF_PACKET] = print_sockaddr_data_ll,
259 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
260 [AF_BLUETOOTH] = print_sockaddr_data_bt,
265 print_sockaddr(struct tcb *tcp, const void *const buf, const int addrlen)
267 const struct sockaddr *const sa = buf;
269 tprints("{sa_family=");
270 printxval(addrfams, sa->sa_family, "AF_???");
272 if (addrlen > (int) sizeof(sa->sa_family)) {
275 if (sa->sa_family < ARRAY_SIZE(sa_printers)
276 && sa_printers[sa->sa_family]) {
277 sa_printers[sa->sa_family](buf, addrlen);
279 const char *const data = buf + sizeof(sa->sa_family);
280 const int datalen = addrlen - sizeof(sa->sa_family);
283 print_quoted_string(data, datalen, 0);
291 printsock(struct tcb *tcp, long addr, int addrlen)
300 struct sockaddr_storage storage;
301 char pad[sizeof(struct sockaddr_storage) + 1];
304 if ((unsigned) addrlen > sizeof(addrbuf.storage))
305 addrlen = sizeof(addrbuf.storage);
307 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
310 memset(&addrbuf.pad[addrlen], 0, sizeof(addrbuf.pad) - addrlen);
312 print_sockaddr(tcp, &addrbuf, addrlen);
314 return addrbuf.sa.sa_family;
317 #include "xlat/scmvals.h"
318 #include "xlat/ip_cmsg_types.h"
320 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
330 struct cmsghdr *cmsg;
331 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
332 struct cmsghdr32 *cmsg32;
337 print_scm_rights(struct tcb *tcp, const void *cmsg_data,
338 const size_t data_len)
340 const int *fds = cmsg_data;
341 const char *end = (const char *) cmsg_data + data_len;
344 if (sizeof(*fds) > data_len)
348 while ((const char *) fds < end) {
353 printfd(tcp, *fds++);
359 print_scm_creds(struct tcb *tcp, const void *cmsg_data,
360 const size_t data_len)
362 const struct ucred *uc = cmsg_data;
364 if (sizeof(*uc) > data_len)
367 tprintf(", {pid=%u, uid=%u, gid=%u}",
368 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
372 print_scm_security(struct tcb *tcp, const void *cmsg_data,
373 const size_t data_len)
379 print_quoted_string(cmsg_data, data_len, 0);
383 print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data,
384 const size_t data_len)
386 const struct in_pktinfo *info = cmsg_data;
388 if (sizeof(*info) > data_len)
391 tprints(", {ipi_ifindex=");
392 print_ifindex(info->ipi_ifindex);
393 tprintf(", ipi_spec_dst=inet_addr(\"%s\"), ipi_addr=inet_addr(\"%s\")}",
394 inet_ntoa(info->ipi_spec_dst), inet_ntoa(info->ipi_addr));
398 print_cmsg_ip_ttl(struct tcb *tcp, const void *cmsg_data,
399 const size_t data_len)
401 const unsigned int *ttl = cmsg_data;
403 if (sizeof(*ttl) > data_len)
406 tprintf(", {ttl=%u}", *ttl);
410 print_cmsg_ip_tos(struct tcb *tcp, const void *cmsg_data,
411 const size_t data_len)
413 const uint8_t *tos = cmsg_data;
415 if (sizeof(*tos) > data_len)
418 tprintf(", {tos=%x}", *tos);
422 print_cmsg_ip_checksum(struct tcb *tcp, const void *cmsg_data,
423 const size_t data_len)
425 const uint32_t *csum = cmsg_data;
427 if (sizeof(*csum) > data_len)
430 tprintf(", {csum=%u}", *csum);
434 print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data,
435 const size_t data_len)
437 const unsigned char *opts = cmsg_data;
443 tprints(", {opts=0x");
444 for (i = 0; i < data_len; ++i)
445 tprintf("%02x", opts[i]);
450 print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
451 const size_t data_len)
461 struct sockaddr_in offender;
464 if (sizeof(*err) > data_len)
467 tprintf(", {ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
468 ", ee_info=%u, ee_data=%u, offender=",
469 err->ee_errno, err->ee_origin, err->ee_type,
470 err->ee_code, err->ee_info, err->ee_data);
471 print_sockaddr(tcp, &err->offender, sizeof(err->offender));
476 print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
477 const size_t data_len)
479 if (sizeof(struct sockaddr_in) > data_len)
483 print_sockaddr(tcp, cmsg_data, data_len);
487 print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
488 const void *cmsg_data, const size_t data_len)
490 switch (cmsg_level) {
492 printxval(scmvals, cmsg_type, "SCM_???");
495 print_scm_rights(tcp, cmsg_data, data_len);
497 case SCM_CREDENTIALS:
498 print_scm_creds(tcp, cmsg_data, data_len);
501 print_scm_security(tcp, cmsg_data, data_len);
506 printxval(ip_cmsg_types, cmsg_type, "IP_???");
509 print_cmsg_ip_pktinfo(tcp, cmsg_data, data_len);
512 print_cmsg_ip_ttl(tcp, cmsg_data, data_len);
515 print_cmsg_ip_tos(tcp, cmsg_data, data_len);
519 print_cmsg_ip_opts(tcp, cmsg_data, data_len);
522 print_cmsg_ip_recverr(tcp, cmsg_data, data_len);
525 print_cmsg_ip_origdstaddr(tcp, cmsg_data, data_len);
528 print_cmsg_ip_checksum(tcp, cmsg_data, data_len);
531 print_scm_security(tcp, cmsg_data, data_len);
536 tprintf("%u", cmsg_type);
541 printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
543 const size_t cmsg_size =
544 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
545 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
547 sizeof(struct cmsghdr);
549 char *buf = len < cmsg_size ? NULL : malloc(len);
550 if (!buf || umoven(tcp, addr, len, buf) < 0) {
551 tprints(", msg_control=");
557 union_cmsghdr u = { .ptr = buf };
560 while (len >= cmsg_size) {
562 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
563 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
567 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
568 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
572 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
573 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
579 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
580 printxval(socketlayers, cmsg_level, "SOL_???");
581 tprints(", cmsg_type=");
586 print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
587 (const void *) (u.ptr + cmsg_size),
588 cmsg_len > cmsg_size ? cmsg_len - cmsg_size: 0);
591 if (cmsg_len < cmsg_size) {
595 cmsg_len = (cmsg_len + current_wordsize - 1) &
596 (size_t) ~(current_wordsize - 1);
597 if (cmsg_len >= len) {
611 do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
613 tprintf("{msg_name(%d)=", msg->msg_namelen);
614 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
616 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
618 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
619 (unsigned long)msg->msg_iov, IOV_DECODE_STR, data_size);
621 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
622 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
623 if (msg->msg_controllen)
624 printcmsghdr(tcp, (unsigned long) msg->msg_control,
625 msg->msg_controllen);
626 tprints(", msg_flags=");
627 printflags(msg_flags, msg->msg_flags, "MSG_???");
628 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
629 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
630 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
631 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
636 uint32_t /* void* */ msg_name;
637 uint32_t /* socklen_t */msg_namelen;
638 uint32_t /* iovec* */ msg_iov;
639 uint32_t /* size_t */ msg_iovlen;
640 uint32_t /* void* */ msg_control;
641 uint32_t /* size_t */ msg_controllen;
642 uint32_t /* int */ msg_flags;
645 struct msghdr32 msg_hdr;
646 uint32_t /* unsigned */ msg_len;
649 #ifndef HAVE_STRUCT_MMSGHDR
651 struct msghdr msg_hdr;
656 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
658 copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
660 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
661 to_msg->msg_namelen = from_msg32->msg_namelen;
662 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
663 to_msg->msg_iovlen = from_msg32->msg_iovlen;
664 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
665 to_msg->msg_controllen = from_msg32->msg_controllen;
666 to_msg->msg_flags = from_msg32->msg_flags;
671 extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
673 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
674 if (current_wordsize == 4) {
675 struct msghdr32 msg32;
677 if (umove(tcp, addr, &msg32) < 0)
679 copy_from_msghdr32(msg, &msg32);
682 if (umove(tcp, addr, msg) < 0)
688 extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
690 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
691 if (current_wordsize == 4) {
692 struct mmsghdr32 mmsg32;
694 addr += sizeof(struct mmsghdr32) * idx;
695 if (umove(tcp, addr, &mmsg32) < 0)
698 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
699 mmsg->msg_len = mmsg32.msg_len;
703 addr += sizeof(*mmsg) * idx;
704 if (umove(tcp, addr, mmsg) < 0)
711 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
715 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
716 do_msghdr(tcp, &msg, data_size);
722 dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
726 if (extractmsghdr(tcp, addr, &msg))
727 dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size);
731 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
735 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
737 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
738 tprintf(", %u}", mmsg.msg_len);
745 decode_mmsg(struct tcb *tcp, unsigned long msg_len)
749 printaddr(tcp->u_arg[1]);
751 unsigned int len = tcp->u_rval;
755 for (i = 0; i < len; ++i) {
758 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
763 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
765 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
769 dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
771 unsigned int len = tcp->u_rval;
775 for (i = 0; i < len; ++i) {
776 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
777 tprintf(" = %lu buffers in vector %u\n",
778 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
779 dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
780 (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
786 * low bits of the socket type define real socket type,
787 * other bits are socket type flags.
790 tprint_sock_type(unsigned int flags)
792 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
796 flags &= ~SOCK_TYPE_MASK;
801 printflags(sock_type_flags, flags, "SOCK_???");
806 printxval(addrfams, tcp->u_arg[0], "AF_???");
808 tprint_sock_type(tcp->u_arg[1]);
810 switch (tcp->u_arg[0]) {
813 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
817 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
820 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
822 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
827 tprintf("%lu", tcp->u_arg[2]);
831 return RVAL_DECODED | RVAL_FD;
836 printfd(tcp, tcp->u_arg[0]);
838 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
839 tprintf(", %lu", tcp->u_arg[2]);
846 printfd(tcp, tcp->u_arg[0]);
848 tprintf("%lu", tcp->u_arg[1]);
854 do_sockname(struct tcb *tcp, int flags_arg)
857 printfd(tcp, tcp->u_arg[0]);
863 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
864 umove(tcp, tcp->u_arg[2], &len) < 0) {
865 printaddr(tcp->u_arg[1]);
867 printaddr(tcp->u_arg[2]);
869 printsock(tcp, tcp->u_arg[1], len);
870 tprintf(", [%d]", len);
873 if (flags_arg >= 0) {
875 printflags(sock_type_flags, tcp->u_arg[flags_arg],
883 do_sockname(tcp, -1);
895 printfd(tcp, tcp->u_arg[0]);
897 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
898 tprintf(", %lu, ", tcp->u_arg[2]);
900 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
907 printfd(tcp, tcp->u_arg[0]);
909 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
910 tprintf(", %lu, ", tcp->u_arg[2]);
912 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
915 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
917 tprintf(", %lu", tcp->u_arg[5]);
924 printfd(tcp, tcp->u_arg[0]);
926 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
929 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
938 printfd(tcp, tcp->u_arg[0]);
941 printaddr(tcp->u_arg[1]);
942 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
943 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
947 decode_mmsg(tcp, (unsigned long) -1L);
955 printfd(tcp, tcp->u_arg[0]);
959 printaddr(tcp->u_arg[1]);
961 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
963 tprintf(", %lu, ", tcp->u_arg[2]);
964 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
974 printfd(tcp, tcp->u_arg[0]);
979 printaddr(tcp->u_arg[1]);
981 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
984 tprintf(", %lu, ", tcp->u_arg[2]);
986 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
988 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
989 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
990 /* from address, len */
991 printaddr(tcp->u_arg[4]);
993 printaddr(tcp->u_arg[5]);
997 printsock(tcp, tcp->u_arg[4], fromlen);
999 tprintf(", [%u]", fromlen);
1006 if (entering(tcp)) {
1007 printfd(tcp, tcp->u_arg[0]);
1011 printaddr(tcp->u_arg[1]);
1013 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
1016 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1023 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
1025 if (entering(tcp)) {
1026 printfd(tcp, tcp->u_arg[0]);
1029 /* Abusing tcp->auxstr as temp storage.
1030 * Will be used and cleared on syscall exit.
1032 tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
1034 printaddr(tcp->u_arg[1]);
1035 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
1036 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1038 print_timespec(tcp, tcp->u_arg[4]);
1043 decode_mmsg(tcp, 0);
1045 /* timeout on entrance */
1046 tprints(tcp->auxstr);
1051 if (tcp->u_rval == 0) {
1052 tcp->auxstr = "Timeout";
1057 /* timeout on exit */
1058 snprintf(str, sizeof(str), "left %s",
1059 sprint_timespec(tcp, tcp->u_arg[4]));
1065 #include "xlat/shutdown_modes.h"
1069 printfd(tcp, tcp->u_arg[0]);
1071 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1073 return RVAL_DECODED;
1076 SYS_FUNC(getsockname)
1078 return do_sockname(tcp, -1);
1082 printpair_fd(struct tcb *tcp, const int i0, const int i1)
1092 decode_pair_fd(struct tcb *tcp, const long addr)
1096 if (umove_or_printaddr(tcp, addr, &pair))
1099 printpair_fd(tcp, pair[0], pair[1]);
1103 do_pipe(struct tcb *tcp, int flags_arg)
1106 decode_pair_fd(tcp, tcp->u_arg[0]);
1107 if (flags_arg >= 0) {
1109 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1117 #ifdef HAVE_GETRVAL2
1118 if (exiting(tcp) && !syserror(tcp))
1119 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
1122 return do_pipe(tcp, -1);
1128 return do_pipe(tcp, 1);
1131 SYS_FUNC(socketpair)
1133 if (entering(tcp)) {
1134 printxval(addrfams, tcp->u_arg[0], "AF_???");
1136 tprint_sock_type(tcp->u_arg[1]);
1137 tprintf(", %lu", tcp->u_arg[2]);
1140 decode_pair_fd(tcp, tcp->u_arg[3]);
1145 #include "xlat/sockoptions.h"
1146 #include "xlat/sockipoptions.h"
1147 #include "xlat/getsockipoptions.h"
1148 #include "xlat/setsockipoptions.h"
1149 #include "xlat/sockipv6options.h"
1150 #include "xlat/getsockipv6options.h"
1151 #include "xlat/setsockipv6options.h"
1152 #include "xlat/sockipxoptions.h"
1153 #include "xlat/sockrawoptions.h"
1154 #include "xlat/sockpacketoptions.h"
1155 #include "xlat/socksctpoptions.h"
1156 #include "xlat/socktcpoptions.h"
1159 print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level,
1160 unsigned int name, bool is_getsockopt)
1164 printxval(socketlayers, level, "SOL_??");
1169 printxval(sockoptions, name, "SO_???");
1172 printxvals(name, "IP_???", sockipoptions,
1173 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
1176 printxvals(name, "IPV6_???", sockipv6options,
1177 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
1180 printxval(sockipxoptions, name, "IPX_???");
1183 printxval(sockpacketoptions, name, "PACKET_???");
1186 printxval(socktcpoptions, name, "TCP_???");
1189 printxval(socksctpoptions, name, "SCTP_???");
1192 printxval(sockrawoptions, name, "RAW_???");
1195 /* Other SOL_* protocol levels still need work. */
1198 tprintf("%u", name);
1205 print_linger(struct tcb *tcp, long addr, int len)
1207 struct linger linger;
1209 if (len != sizeof(linger) ||
1210 umove(tcp, addr, &linger) < 0) {
1215 tprintf("{onoff=%d, linger=%d}",
1222 print_ucred(struct tcb *tcp, long addr, int len)
1226 if (len != sizeof(uc) ||
1227 umove(tcp, addr, &uc) < 0) {
1230 tprintf("{pid=%u, uid=%u, gid=%u}",
1236 #endif /* SO_PEERCRED */
1238 #ifdef PACKET_STATISTICS
1240 print_tpacket_stats(struct tcb *tcp, long addr, int len)
1242 struct tpacket_stats stats;
1244 if (len != sizeof(stats) ||
1245 umove(tcp, addr, &stats) < 0) {
1248 tprintf("{packets=%u, drops=%u}",
1253 #endif /* PACKET_STATISTICS */
1255 #include "xlat/icmpfilterflags.h"
1258 print_icmp_filter(struct tcb *tcp, const long addr, int len)
1260 struct icmp_filter filter = {};
1262 if (len > (int) sizeof(filter))
1263 len = sizeof(filter);
1264 else if (len <= 0) {
1269 if (umoven_or_printaddr(tcp, addr, len, &filter))
1273 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1278 print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1281 if (addr && verbose(tcp))
1286 print_linger(tcp, addr, len);
1290 print_ucred(tcp, addr, len);
1298 #ifdef PACKET_STATISTICS
1299 case PACKET_STATISTICS:
1300 print_tpacket_stats(tcp, addr, len);
1309 print_icmp_filter(tcp, addr, len);
1315 /* default arg printing */
1318 if (len == sizeof(int)) {
1319 printnum_int(tcp, addr, "%d");
1321 printstr(tcp, addr, len);
1327 tprintf(", [%d]", len);
1330 SYS_FUNC(getsockopt)
1332 if (entering(tcp)) {
1333 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1334 tcp->u_arg[1], tcp->u_arg[2], true);
1338 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1339 printaddr(tcp->u_arg[3]);
1341 printaddr(tcp->u_arg[4]);
1343 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1344 tcp->u_arg[3], len);
1350 #ifdef IP_ADD_MEMBERSHIP
1352 print_mreq(struct tcb *tcp, long addr, unsigned int len)
1354 struct ip_mreq mreq;
1356 if (len < sizeof(mreq)) {
1357 printstr(tcp, addr, len);
1360 if (umove_or_printaddr(tcp, addr, &mreq))
1363 tprints("{imr_multiaddr=inet_addr(");
1364 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1365 16, QUOTE_0_TERMINATED);
1366 tprints("), imr_interface=inet_addr(");
1367 print_quoted_string(inet_ntoa(mreq.imr_interface),
1368 16, QUOTE_0_TERMINATED);
1371 #endif /* IP_ADD_MEMBERSHIP */
1373 #ifdef IPV6_ADD_MEMBERSHIP
1375 print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1377 struct ipv6_mreq mreq;
1379 if (len < sizeof(mreq))
1382 if (umove_or_printaddr(tcp, addr, &mreq))
1385 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1386 char address[INET6_ADDRSTRLEN];
1388 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1391 tprints("{ipv6mr_multiaddr=inet_pton(");
1392 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1393 tprints("), ipv6mr_interface=");
1394 print_ifindex(mreq.ipv6mr_interface);
1399 printstr(tcp, addr, len);
1401 #endif /* IPV6_ADD_MEMBERSHIP */
1403 #ifdef MCAST_JOIN_GROUP
1405 print_group_req(struct tcb *tcp, long addr, int len)
1407 struct group_req greq;
1409 if (len != sizeof(greq) ||
1410 umove(tcp, addr, &greq) < 0) {
1415 tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
1416 print_sockaddr(tcp, &greq.gr_group, sizeof(greq.gr_group));
1420 #endif /* MCAST_JOIN_GROUP */
1422 #ifdef PACKET_RX_RING
1424 print_tpacket_req(struct tcb *tcp, long addr, int len)
1426 struct tpacket_req req;
1428 if (len != sizeof(req) ||
1429 umove(tcp, addr, &req) < 0) {
1432 tprintf("{block_size=%u, block_nr=%u, "
1433 "frame_size=%u, frame_nr=%u}",
1440 #endif /* PACKET_RX_RING */
1442 #ifdef PACKET_ADD_MEMBERSHIP
1443 # include "xlat/packet_mreq_type.h"
1446 print_packet_mreq(struct tcb *tcp, long addr, int len)
1448 struct packet_mreq mreq;
1450 if (len != sizeof(mreq) ||
1451 umove(tcp, addr, &mreq) < 0) {
1456 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1457 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1458 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1459 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1460 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1461 for (i = 0; i < mreq.mr_alen; ++i)
1462 tprintf("%02x", mreq.mr_address[i]);
1466 #endif /* PACKET_ADD_MEMBERSHIP */
1469 print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1472 if (addr && verbose(tcp))
1477 print_linger(tcp, addr, len);
1484 #ifdef IP_ADD_MEMBERSHIP
1485 case IP_ADD_MEMBERSHIP:
1486 case IP_DROP_MEMBERSHIP:
1487 print_mreq(tcp, addr, len);
1489 #endif /* IP_ADD_MEMBERSHIP */
1490 #ifdef MCAST_JOIN_GROUP
1491 case MCAST_JOIN_GROUP:
1492 case MCAST_LEAVE_GROUP:
1493 print_group_req(tcp, addr, len);
1495 #endif /* MCAST_JOIN_GROUP */
1501 #ifdef IPV6_ADD_MEMBERSHIP
1502 case IPV6_ADD_MEMBERSHIP:
1503 case IPV6_DROP_MEMBERSHIP:
1504 # ifdef IPV6_JOIN_ANYCAST
1505 case IPV6_JOIN_ANYCAST:
1507 # ifdef IPV6_LEAVE_ANYCAST
1508 case IPV6_LEAVE_ANYCAST:
1510 print_mreq6(tcp, addr, len);
1512 #endif /* IPV6_ADD_MEMBERSHIP */
1518 #ifdef PACKET_RX_RING
1519 case PACKET_RX_RING:
1520 # ifdef PACKET_TX_RING
1521 case PACKET_TX_RING:
1523 print_tpacket_req(tcp, addr, len);
1525 #endif /* PACKET_RX_RING */
1526 #ifdef PACKET_ADD_MEMBERSHIP
1527 case PACKET_ADD_MEMBERSHIP:
1528 case PACKET_DROP_MEMBERSHIP:
1529 print_packet_mreq(tcp, addr, len);
1531 #endif /* PACKET_ADD_MEMBERSHIP */
1538 print_icmp_filter(tcp, addr, len);
1544 /* default arg printing */
1547 if (len == sizeof(int)) {
1548 printnum_int(tcp, addr, "%d");
1550 printstr(tcp, addr, len);
1556 tprintf(", %d", len);
1559 SYS_FUNC(setsockopt)
1561 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1562 tcp->u_arg[1], tcp->u_arg[2], false);
1563 print_setsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1564 tcp->u_arg[3], tcp->u_arg[4]);
1566 return RVAL_DECODED;