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"
106 print_sockaddr_data_un(const void *const buf, const int addrlen)
108 const struct sockaddr_un *const sa_un = buf;
110 tprints("sun_path=");
111 if (sa_un->sun_path[0]) {
112 print_quoted_string(sa_un->sun_path,
113 sizeof(sa_un->sun_path) + 1,
117 print_quoted_string(sa_un->sun_path + 1,
118 sizeof(sa_un->sun_path),
124 print_sockaddr_data_in(const void *const buf, const int addrlen)
126 const struct sockaddr_in *const sa_in = buf;
128 tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
129 ntohs(sa_in->sin_port), inet_ntoa(sa_in->sin_addr));
133 print_ifindex(unsigned int ifindex)
135 #ifdef HAVE_IF_INDEXTONAME
136 char buf[IFNAMSIZ + 1];
138 if (if_indextoname(ifindex, buf)) {
139 tprints("if_nametoindex(");
140 print_quoted_string(buf, sizeof(buf), QUOTE_0_TERMINATED);
145 tprintf("%u", ifindex);
148 #define SIN6_MIN_LEN offsetof(struct sockaddr_in6, sin6_scope_id)
151 print_sockaddr_data_in6(const void *const buf, const int addrlen)
153 const struct sockaddr_in6 *const sa_in6 = buf;
155 char string_addr[100];
156 inet_ntop(AF_INET6, &sa_in6->sin6_addr,
157 string_addr, sizeof(string_addr));
158 tprintf("sin6_port=htons(%u), inet_pton(AF_INET6"
159 ", \"%s\", &sin6_addr), sin6_flowinfo=%u",
160 ntohs(sa_in6->sin6_port), string_addr,
161 sa_in6->sin6_flowinfo);
163 if (addrlen <= (int) SIN6_MIN_LEN)
166 tprints(", sin6_scope_id=");
167 #if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
168 if (IN6_IS_ADDR_LINKLOCAL(&sa_in6->sin6_addr)
169 || IN6_IS_ADDR_MC_LINKLOCAL(&sa_in6->sin6_addr))
170 print_ifindex(sa_in6->sin6_scope_id);
173 tprintf("%u", sa_in6->sin6_scope_id);
177 print_sockaddr_data_ipx(const void *const buf, const int addrlen)
179 const struct sockaddr_ipx *const sa_ipx = buf;
182 tprintf("sipx_port=htons(%u)"
183 ", sipx_network=htonl(%08x)"
185 ntohs(sa_ipx->sipx_port),
186 ntohl(sa_ipx->sipx_network));
187 for (i = 0; i < IPX_NODE_LEN; ++i) {
188 tprintf("%s%02x", i ? ", " : "",
189 sa_ipx->sipx_node[i]);
191 tprintf("], sipx_type=%02x", sa_ipx->sipx_type);
195 print_sockaddr_data_nl(const void *const buf, const int addrlen)
197 const struct sockaddr_nl *const sa_nl = buf;
199 tprintf("pid=%d, groups=%08x", sa_nl->nl_pid, sa_nl->nl_groups);
203 print_sockaddr_data_ll(const void *const buf, const int addrlen)
205 const struct sockaddr_ll *const sa_ll = buf;
208 tprintf("proto=%#04x, if%d, pkttype=",
209 ntohs(sa_ll->sll_protocol),
211 printxval(af_packet_types, sa_ll->sll_pkttype, "PACKET_???");
212 tprintf(", addr(%d)={%d, ", sa_ll->sll_halen, sa_ll->sll_hatype);
213 for (i = 0; i < sa_ll->sll_halen; i++)
214 tprintf("%02x", sa_ll->sll_addr[i]);
217 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
219 print_sockaddr_data_bt(const void *const buf, const int addrlen)
222 struct sockaddr_hci hci;
223 struct sockaddr_l2 l2;
224 struct sockaddr_rc rc;
225 struct sockaddr_sco sco;
228 tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
229 "{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
230 "{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
231 "{hci_dev=htobs(%d)}",
232 addr->sco.sco_bdaddr.b[0], addr->sco.sco_bdaddr.b[1],
233 addr->sco.sco_bdaddr.b[2], addr->sco.sco_bdaddr.b[3],
234 addr->sco.sco_bdaddr.b[4], addr->sco.sco_bdaddr.b[5],
235 addr->rc.rc_bdaddr.b[0], addr->rc.rc_bdaddr.b[1],
236 addr->rc.rc_bdaddr.b[2], addr->rc.rc_bdaddr.b[3],
237 addr->rc.rc_bdaddr.b[4], addr->rc.rc_bdaddr.b[5],
239 btohs(addr->l2.l2_psm), addr->l2.l2_bdaddr.b[0],
240 addr->l2.l2_bdaddr.b[1], addr->l2.l2_bdaddr.b[2],
241 addr->l2.l2_bdaddr.b[3], addr->l2.l2_bdaddr.b[4],
242 addr->l2.l2_bdaddr.b[5], btohs(addr->l2.l2_cid),
243 btohs(addr->hci.hci_dev));
245 #endif /* HAVE_BLUETOOTH_BLUETOOTH_H */
247 typedef void (* const sockaddr_printer)(const void *const, const int);
249 static const sockaddr_printer sa_printers[] = {
250 [AF_UNIX] = print_sockaddr_data_un,
251 [AF_INET] = print_sockaddr_data_in,
252 [AF_IPX] = print_sockaddr_data_ipx,
253 [AF_INET6] = print_sockaddr_data_in6,
254 [AF_NETLINK] = print_sockaddr_data_nl,
255 [AF_PACKET] = print_sockaddr_data_ll,
256 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
257 [AF_BLUETOOTH] = print_sockaddr_data_bt,
262 print_sockaddr(struct tcb *tcp, const void *const buf, const int addrlen)
264 const struct sockaddr *const sa = buf;
266 tprints("{sa_family=");
267 printxval(addrfams, sa->sa_family, "AF_???");
269 if (addrlen > (int) sizeof(sa->sa_family)) {
272 if (sa->sa_family < ARRAY_SIZE(sa_printers)
273 && sa_printers[sa->sa_family]) {
274 sa_printers[sa->sa_family](buf, addrlen);
276 const char *const data = buf + sizeof(sa->sa_family);
277 const int datalen = addrlen - sizeof(sa->sa_family);
280 print_quoted_string(data, datalen, 0);
288 printsock(struct tcb *tcp, long addr, int addrlen)
297 struct sockaddr_storage storage;
298 char pad[sizeof(struct sockaddr_storage) + 1];
301 if ((unsigned) addrlen > sizeof(addrbuf.storage))
302 addrlen = sizeof(addrbuf.storage);
304 if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
307 memset(&addrbuf.pad[addrlen], 0, sizeof(addrbuf.pad) - addrlen);
309 print_sockaddr(tcp, &addrbuf, addrlen);
311 return addrbuf.sa.sa_family;
314 #include "xlat/scmvals.h"
315 #include "xlat/ip_cmsg_types.h"
317 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
327 struct cmsghdr *cmsg;
328 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
329 struct cmsghdr32 *cmsg32;
334 print_scm_rights(struct tcb *tcp, const void *cmsg_data,
335 const size_t data_len)
337 const int *fds = cmsg_data;
338 const char *end = (const char *) cmsg_data + data_len;
341 if (sizeof(*fds) > data_len)
345 while ((const char *) fds < end) {
350 printfd(tcp, *fds++);
356 print_scm_creds(struct tcb *tcp, const void *cmsg_data,
357 const size_t data_len)
359 const struct ucred *uc = cmsg_data;
361 if (sizeof(*uc) > data_len)
364 tprintf(", {pid=%u, uid=%u, gid=%u}",
365 (unsigned) uc->pid, (unsigned) uc->uid, (unsigned) uc->gid);
369 print_scm_security(struct tcb *tcp, const void *cmsg_data,
370 const size_t data_len)
376 print_quoted_string(cmsg_data, data_len, 0);
380 print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data,
381 const size_t data_len)
383 const struct in_pktinfo *info = cmsg_data;
385 if (sizeof(*info) > data_len)
388 tprints(", {ipi_ifindex=");
389 print_ifindex(info->ipi_ifindex);
390 tprintf(", ipi_spec_dst=inet_addr(\"%s\"), ipi_addr=inet_addr(\"%s\")}",
391 inet_ntoa(info->ipi_spec_dst), inet_ntoa(info->ipi_addr));
395 print_cmsg_ip_ttl(struct tcb *tcp, const void *cmsg_data,
396 const size_t data_len)
398 const unsigned int *ttl = cmsg_data;
400 if (sizeof(*ttl) > data_len)
403 tprintf(", {ttl=%u}", *ttl);
407 print_cmsg_ip_tos(struct tcb *tcp, const void *cmsg_data,
408 const size_t data_len)
410 const uint8_t *tos = cmsg_data;
412 if (sizeof(*tos) > data_len)
415 tprintf(", {tos=%x}", *tos);
419 print_cmsg_ip_checksum(struct tcb *tcp, const void *cmsg_data,
420 const size_t data_len)
422 const uint32_t *csum = cmsg_data;
424 if (sizeof(*csum) > data_len)
427 tprintf(", {csum=%u}", *csum);
431 print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data,
432 const size_t data_len)
434 const unsigned char *opts = cmsg_data;
440 tprints(", {opts=0x");
441 for (i = 0; i < data_len; ++i)
442 tprintf("%02x", opts[i]);
447 print_cmsg_ip_recverr(struct tcb *tcp, const void *cmsg_data,
448 const size_t data_len)
458 struct sockaddr_in offender;
461 if (sizeof(*err) > data_len)
464 tprintf(", {ee_errno=%u, ee_origin=%u, ee_type=%u, ee_code=%u"
465 ", ee_info=%u, ee_data=%u, offender=",
466 err->ee_errno, err->ee_origin, err->ee_type,
467 err->ee_code, err->ee_info, err->ee_data);
468 print_sockaddr(tcp, &err->offender, sizeof(err->offender));
473 print_cmsg_ip_origdstaddr(struct tcb *tcp, const void *cmsg_data,
474 const size_t data_len)
476 if (sizeof(struct sockaddr_in) > data_len)
480 print_sockaddr(tcp, cmsg_data, data_len);
484 print_cmsg_type_data(struct tcb *tcp, const int cmsg_level, const int cmsg_type,
485 const void *cmsg_data, const size_t data_len)
487 switch (cmsg_level) {
489 printxval(scmvals, cmsg_type, "SCM_???");
492 print_scm_rights(tcp, cmsg_data, data_len);
494 case SCM_CREDENTIALS:
495 print_scm_creds(tcp, cmsg_data, data_len);
498 print_scm_security(tcp, cmsg_data, data_len);
503 printxval(ip_cmsg_types, cmsg_type, "IP_???");
506 print_cmsg_ip_pktinfo(tcp, cmsg_data, data_len);
509 print_cmsg_ip_ttl(tcp, cmsg_data, data_len);
512 print_cmsg_ip_tos(tcp, cmsg_data, data_len);
516 print_cmsg_ip_opts(tcp, cmsg_data, data_len);
519 print_cmsg_ip_recverr(tcp, cmsg_data, data_len);
522 print_cmsg_ip_origdstaddr(tcp, cmsg_data, data_len);
525 print_cmsg_ip_checksum(tcp, cmsg_data, data_len);
528 print_scm_security(tcp, cmsg_data, data_len);
533 tprintf("%u", cmsg_type);
538 printcmsghdr(struct tcb *tcp, unsigned long addr, size_t len)
540 const size_t cmsg_size =
541 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
542 (current_wordsize < sizeof(long)) ? sizeof(struct cmsghdr32) :
544 sizeof(struct cmsghdr);
546 char *buf = len < cmsg_size ? NULL : malloc(len);
547 if (!buf || umoven(tcp, addr, len, buf) < 0) {
548 tprints(", msg_control=");
554 union_cmsghdr u = { .ptr = buf };
557 while (len >= cmsg_size) {
559 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
560 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_len :
564 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
565 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_level :
569 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
570 (current_wordsize < sizeof(long)) ? u.cmsg32->cmsg_type :
576 tprintf("{cmsg_len=%lu, cmsg_level=", (unsigned long) cmsg_len);
577 printxval(socketlayers, cmsg_level, "SOL_???");
578 tprints(", cmsg_type=");
583 print_cmsg_type_data(tcp, cmsg_level, cmsg_type,
584 (const void *) (u.ptr + cmsg_size),
585 cmsg_len > cmsg_size ? cmsg_len - cmsg_size: 0);
588 if (cmsg_len < cmsg_size) {
592 cmsg_len = (cmsg_len + current_wordsize - 1) &
593 (size_t) ~(current_wordsize - 1);
594 if (cmsg_len >= len) {
608 do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
610 tprintf("{msg_name(%d)=", msg->msg_namelen);
611 printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
613 tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
615 tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
616 (unsigned long)msg->msg_iov, IOV_DECODE_STR, data_size);
618 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
619 tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
620 if (msg->msg_controllen)
621 printcmsghdr(tcp, (unsigned long) msg->msg_control,
622 msg->msg_controllen);
623 tprints(", msg_flags=");
624 printflags(msg_flags, msg->msg_flags, "MSG_???");
625 #else /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
626 tprintf("msg_accrights=%#lx, msg_accrightslen=%u",
627 (unsigned long) msg->msg_accrights, msg->msg_accrightslen);
628 #endif /* !HAVE_STRUCT_MSGHDR_MSG_CONTROL */
633 uint32_t /* void* */ msg_name;
634 uint32_t /* socklen_t */msg_namelen;
635 uint32_t /* iovec* */ msg_iov;
636 uint32_t /* size_t */ msg_iovlen;
637 uint32_t /* void* */ msg_control;
638 uint32_t /* size_t */ msg_controllen;
639 uint32_t /* int */ msg_flags;
642 struct msghdr32 msg_hdr;
643 uint32_t /* unsigned */ msg_len;
646 #ifndef HAVE_STRUCT_MMSGHDR
648 struct msghdr msg_hdr;
653 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
655 copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
657 to_msg->msg_name = (void*)(long)from_msg32->msg_name;
658 to_msg->msg_namelen = from_msg32->msg_namelen;
659 to_msg->msg_iov = (void*)(long)from_msg32->msg_iov;
660 to_msg->msg_iovlen = from_msg32->msg_iovlen;
661 to_msg->msg_control = (void*)(long)from_msg32->msg_control;
662 to_msg->msg_controllen = from_msg32->msg_controllen;
663 to_msg->msg_flags = from_msg32->msg_flags;
668 extractmsghdr(struct tcb *tcp, long addr, struct msghdr *msg)
670 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
671 if (current_wordsize == 4) {
672 struct msghdr32 msg32;
674 if (umove(tcp, addr, &msg32) < 0)
676 copy_from_msghdr32(msg, &msg32);
679 if (umove(tcp, addr, msg) < 0)
685 extractmmsghdr(struct tcb *tcp, long addr, unsigned int idx, struct mmsghdr *mmsg)
687 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
688 if (current_wordsize == 4) {
689 struct mmsghdr32 mmsg32;
691 addr += sizeof(struct mmsghdr32) * idx;
692 if (umove(tcp, addr, &mmsg32) < 0)
695 copy_from_msghdr32(&mmsg->msg_hdr, &mmsg32.msg_hdr);
696 mmsg->msg_len = mmsg32.msg_len;
700 addr += sizeof(*mmsg) * idx;
701 if (umove(tcp, addr, mmsg) < 0)
708 printmsghdr(struct tcb *tcp, long addr, unsigned long data_size)
712 if (verbose(tcp) && extractmsghdr(tcp, addr, &msg))
713 do_msghdr(tcp, &msg, data_size);
719 dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
723 if (extractmsghdr(tcp, addr, &msg))
724 dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size);
728 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
732 if (extractmmsghdr(tcp, addr, idx, &mmsg)) {
734 do_msghdr(tcp, &mmsg.msg_hdr, msg_len ? msg_len : mmsg.msg_len);
735 tprintf(", %u}", mmsg.msg_len);
742 decode_mmsg(struct tcb *tcp, unsigned long msg_len)
746 printaddr(tcp->u_arg[1]);
748 unsigned int len = tcp->u_rval;
752 for (i = 0; i < len; ++i) {
755 printmmsghdr(tcp, tcp->u_arg[1], i, msg_len);
760 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
762 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
766 dumpiov_in_mmsghdr(struct tcb *tcp, long addr)
768 unsigned int len = tcp->u_rval;
772 for (i = 0; i < len; ++i) {
773 if (extractmmsghdr(tcp, addr, i, &mmsg)) {
774 tprintf(" = %lu buffers in vector %u\n",
775 (unsigned long)mmsg.msg_hdr.msg_iovlen, i);
776 dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
777 (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
783 * low bits of the socket type define real socket type,
784 * other bits are socket type flags.
787 tprint_sock_type(unsigned int flags)
789 const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
793 flags &= ~SOCK_TYPE_MASK;
798 printflags(sock_type_flags, flags, "SOCK_???");
803 printxval(addrfams, tcp->u_arg[0], "AF_???");
805 tprint_sock_type(tcp->u_arg[1]);
807 switch (tcp->u_arg[0]) {
810 printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
814 printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
817 #ifdef HAVE_BLUETOOTH_BLUETOOTH_H
819 printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
824 tprintf("%lu", tcp->u_arg[2]);
828 return RVAL_DECODED | RVAL_FD;
833 printfd(tcp, tcp->u_arg[0]);
835 printsock(tcp, tcp->u_arg[1], tcp->u_arg[2]);
836 tprintf(", %lu", tcp->u_arg[2]);
843 printfd(tcp, tcp->u_arg[0]);
845 tprintf("%lu", tcp->u_arg[1]);
851 do_sockname(struct tcb *tcp, int flags_arg)
854 printfd(tcp, tcp->u_arg[0]);
860 if (!tcp->u_arg[2] || !verbose(tcp) || syserror(tcp) ||
861 umove(tcp, tcp->u_arg[2], &len) < 0) {
862 printaddr(tcp->u_arg[1]);
864 printaddr(tcp->u_arg[2]);
866 printsock(tcp, tcp->u_arg[1], len);
867 tprintf(", [%d]", len);
870 if (flags_arg >= 0) {
872 printflags(sock_type_flags, tcp->u_arg[flags_arg],
880 do_sockname(tcp, -1);
892 printfd(tcp, tcp->u_arg[0]);
894 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
895 tprintf(", %lu, ", tcp->u_arg[2]);
897 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
904 printfd(tcp, tcp->u_arg[0]);
906 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
907 tprintf(", %lu, ", tcp->u_arg[2]);
909 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
912 printsock(tcp, tcp->u_arg[4], tcp->u_arg[5]);
914 tprintf(", %lu", tcp->u_arg[5]);
921 printfd(tcp, tcp->u_arg[0]);
923 printmsghdr(tcp, tcp->u_arg[1], (unsigned long) -1L);
926 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
935 printfd(tcp, tcp->u_arg[0]);
938 printaddr(tcp->u_arg[1]);
939 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
940 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
944 decode_mmsg(tcp, (unsigned long) -1L);
952 printfd(tcp, tcp->u_arg[0]);
956 printaddr(tcp->u_arg[1]);
958 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
960 tprintf(", %lu, ", tcp->u_arg[2]);
961 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
971 printfd(tcp, tcp->u_arg[0]);
976 printaddr(tcp->u_arg[1]);
978 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
981 tprintf(", %lu, ", tcp->u_arg[2]);
983 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
985 if (syserror(tcp) || !tcp->u_arg[4] || !tcp->u_arg[5] ||
986 umove(tcp, tcp->u_arg[5], &fromlen) < 0) {
987 /* from address, len */
988 printaddr(tcp->u_arg[4]);
990 printaddr(tcp->u_arg[5]);
994 printsock(tcp, tcp->u_arg[4], fromlen);
996 tprintf(", [%u]", fromlen);
1003 if (entering(tcp)) {
1004 printfd(tcp, tcp->u_arg[0]);
1008 printaddr(tcp->u_arg[1]);
1010 printmsghdr(tcp, tcp->u_arg[1], tcp->u_rval);
1013 printflags(msg_flags, tcp->u_arg[2], "MSG_???");
1020 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
1022 if (entering(tcp)) {
1023 printfd(tcp, tcp->u_arg[0]);
1026 /* Abusing tcp->auxstr as temp storage.
1027 * Will be used and cleared on syscall exit.
1029 tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
1031 printaddr(tcp->u_arg[1]);
1032 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
1033 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
1035 print_timespec(tcp, tcp->u_arg[4]);
1040 decode_mmsg(tcp, 0);
1042 /* timeout on entrance */
1043 tprints(tcp->auxstr);
1048 if (tcp->u_rval == 0) {
1049 tcp->auxstr = "Timeout";
1054 /* timeout on exit */
1055 snprintf(str, sizeof(str), "left %s",
1056 sprint_timespec(tcp, tcp->u_arg[4]));
1062 #include "xlat/shutdown_modes.h"
1066 printfd(tcp, tcp->u_arg[0]);
1068 printxval(shutdown_modes, tcp->u_arg[1], "SHUT_???");
1070 return RVAL_DECODED;
1073 SYS_FUNC(getsockname)
1075 return do_sockname(tcp, -1);
1079 printpair_fd(struct tcb *tcp, const int i0, const int i1)
1089 decode_pair_fd(struct tcb *tcp, const long addr)
1093 if (umove_or_printaddr(tcp, addr, &pair))
1096 printpair_fd(tcp, pair[0], pair[1]);
1100 do_pipe(struct tcb *tcp, int flags_arg)
1103 decode_pair_fd(tcp, tcp->u_arg[0]);
1104 if (flags_arg >= 0) {
1106 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1114 #ifdef HAVE_GETRVAL2
1115 if (exiting(tcp) && !syserror(tcp))
1116 printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
1119 return do_pipe(tcp, -1);
1125 return do_pipe(tcp, 1);
1128 SYS_FUNC(socketpair)
1130 if (entering(tcp)) {
1131 printxval(addrfams, tcp->u_arg[0], "AF_???");
1133 tprint_sock_type(tcp->u_arg[1]);
1134 tprintf(", %lu", tcp->u_arg[2]);
1137 decode_pair_fd(tcp, tcp->u_arg[3]);
1142 #include "xlat/sockoptions.h"
1143 #include "xlat/sockipoptions.h"
1144 #include "xlat/getsockipoptions.h"
1145 #include "xlat/setsockipoptions.h"
1146 #include "xlat/sockipv6options.h"
1147 #include "xlat/getsockipv6options.h"
1148 #include "xlat/setsockipv6options.h"
1149 #include "xlat/sockipxoptions.h"
1150 #include "xlat/sockrawoptions.h"
1151 #include "xlat/sockpacketoptions.h"
1152 #include "xlat/socksctpoptions.h"
1153 #include "xlat/socktcpoptions.h"
1156 print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level,
1157 unsigned int name, bool is_getsockopt)
1161 printxval(socketlayers, level, "SOL_??");
1166 printxval(sockoptions, name, "SO_???");
1169 printxvals(name, "IP_???", sockipoptions,
1170 is_getsockopt ? getsockipoptions : setsockipoptions, NULL);
1173 printxvals(name, "IPV6_???", sockipv6options,
1174 is_getsockopt ? getsockipv6options : setsockipv6options, NULL);
1177 printxval(sockipxoptions, name, "IPX_???");
1180 printxval(sockpacketoptions, name, "PACKET_???");
1183 printxval(socktcpoptions, name, "TCP_???");
1186 printxval(socksctpoptions, name, "SCTP_???");
1189 printxval(sockrawoptions, name, "RAW_???");
1192 /* Other SOL_* protocol levels still need work. */
1195 tprintf("%u", name);
1202 print_linger(struct tcb *tcp, long addr, int len)
1204 struct linger linger;
1206 if (len != sizeof(linger) ||
1207 umove(tcp, addr, &linger) < 0) {
1212 tprintf("{onoff=%d, linger=%d}",
1219 print_ucred(struct tcb *tcp, long addr, int len)
1223 if (len != sizeof(uc) ||
1224 umove(tcp, addr, &uc) < 0) {
1227 tprintf("{pid=%u, uid=%u, gid=%u}",
1233 #endif /* SO_PEERCRED */
1235 #ifdef PACKET_STATISTICS
1237 print_tpacket_stats(struct tcb *tcp, long addr, int len)
1239 struct tpacket_stats stats;
1241 if (len != sizeof(stats) ||
1242 umove(tcp, addr, &stats) < 0) {
1245 tprintf("{packets=%u, drops=%u}",
1250 #endif /* PACKET_STATISTICS */
1252 #include "xlat/icmpfilterflags.h"
1255 print_icmp_filter(struct tcb *tcp, const long addr, int len)
1257 struct icmp_filter filter = {};
1259 if (len > (int) sizeof(filter))
1260 len = sizeof(filter);
1261 else if (len <= 0) {
1266 if (umoven_or_printaddr(tcp, addr, len, &filter))
1270 printflags(icmpfilterflags, ~filter.data, "ICMP_???");
1275 print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1278 if (addr && verbose(tcp))
1283 print_linger(tcp, addr, len);
1287 print_ucred(tcp, addr, len);
1295 #ifdef PACKET_STATISTICS
1296 case PACKET_STATISTICS:
1297 print_tpacket_stats(tcp, addr, len);
1306 print_icmp_filter(tcp, addr, len);
1312 /* default arg printing */
1315 if (len == sizeof(int)) {
1316 printnum_int(tcp, addr, "%d");
1318 printstr(tcp, addr, len);
1324 tprintf(", [%d]", len);
1327 SYS_FUNC(getsockopt)
1329 if (entering(tcp)) {
1330 print_sockopt_fd_level_name(tcp, tcp->u_arg[0],
1331 tcp->u_arg[1], tcp->u_arg[2], true);
1335 if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
1336 printaddr(tcp->u_arg[3]);
1338 printaddr(tcp->u_arg[4]);
1340 print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
1341 tcp->u_arg[3], len);
1347 #ifdef IP_ADD_MEMBERSHIP
1349 print_mreq(struct tcb *tcp, long addr, unsigned int len)
1351 struct ip_mreq mreq;
1353 if (len < sizeof(mreq)) {
1354 printstr(tcp, addr, len);
1357 if (umove_or_printaddr(tcp, addr, &mreq))
1360 tprints("{imr_multiaddr=inet_addr(");
1361 print_quoted_string(inet_ntoa(mreq.imr_multiaddr),
1362 16, QUOTE_0_TERMINATED);
1363 tprints("), imr_interface=inet_addr(");
1364 print_quoted_string(inet_ntoa(mreq.imr_interface),
1365 16, QUOTE_0_TERMINATED);
1368 #endif /* IP_ADD_MEMBERSHIP */
1370 #ifdef IPV6_ADD_MEMBERSHIP
1372 print_mreq6(struct tcb *tcp, long addr, unsigned int len)
1374 struct ipv6_mreq mreq;
1376 if (len < sizeof(mreq))
1379 if (umove_or_printaddr(tcp, addr, &mreq))
1382 const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
1383 char address[INET6_ADDRSTRLEN];
1385 if (!inet_ntop(AF_INET6, in6, address, sizeof(address)))
1388 tprints("{ipv6mr_multiaddr=inet_pton(");
1389 print_quoted_string(address, sizeof(address), QUOTE_0_TERMINATED);
1390 tprints("), ipv6mr_interface=");
1391 print_ifindex(mreq.ipv6mr_interface);
1396 printstr(tcp, addr, len);
1398 #endif /* IPV6_ADD_MEMBERSHIP */
1400 #ifdef MCAST_JOIN_GROUP
1402 print_group_req(struct tcb *tcp, long addr, int len)
1404 struct group_req greq;
1406 if (len != sizeof(greq) ||
1407 umove(tcp, addr, &greq) < 0) {
1412 tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
1413 print_sockaddr(tcp, &greq.gr_group, sizeof(greq.gr_group));
1417 #endif /* MCAST_JOIN_GROUP */
1419 #ifdef PACKET_RX_RING
1421 print_tpacket_req(struct tcb *tcp, long addr, int len)
1423 struct tpacket_req req;
1425 if (len != sizeof(req) ||
1426 umove(tcp, addr, &req) < 0) {
1429 tprintf("{block_size=%u, block_nr=%u, "
1430 "frame_size=%u, frame_nr=%u}",
1437 #endif /* PACKET_RX_RING */
1439 #ifdef PACKET_ADD_MEMBERSHIP
1440 # include "xlat/packet_mreq_type.h"
1443 print_packet_mreq(struct tcb *tcp, long addr, int len)
1445 struct packet_mreq mreq;
1447 if (len != sizeof(mreq) ||
1448 umove(tcp, addr, &mreq) < 0) {
1453 tprintf("{mr_ifindex=%u, mr_type=", mreq.mr_ifindex);
1454 printxval(packet_mreq_type, mreq.mr_type, "PACKET_MR_???");
1455 tprintf(", mr_alen=%u, mr_address=", mreq.mr_alen);
1456 if (mreq.mr_alen > ARRAY_SIZE(mreq.mr_address))
1457 mreq.mr_alen = ARRAY_SIZE(mreq.mr_address);
1458 for (i = 0; i < mreq.mr_alen; ++i)
1459 tprintf("%02x", mreq.mr_address[i]);
1463 #endif /* PACKET_ADD_MEMBERSHIP */
1466 print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
1469 if (addr && verbose(tcp))
1474 print_linger(tcp, addr, len);
1481 #ifdef IP_ADD_MEMBERSHIP
1482 case IP_ADD_MEMBERSHIP:
1483 case IP_DROP_MEMBERSHIP:
1484 print_mreq(tcp, addr, len);
1486 #endif /* IP_ADD_MEMBERSHIP */
1487 #ifdef MCAST_JOIN_GROUP
1488 case MCAST_JOIN_GROUP:
1489 case MCAST_LEAVE_GROUP:
1490 print_group_req(tcp, addr, len);
1492 #endif /* MCAST_JOIN_GROUP */
1498 #ifdef IPV6_ADD_MEMBERSHIP
1499 case IPV6_ADD_MEMBERSHIP:
1500 case IPV6_DROP_MEMBERSHIP:
1501 # ifdef IPV6_JOIN_ANYCAST
1502 case IPV6_JOIN_ANYCAST:
1504 # ifdef IPV6_LEAVE_ANYCAST
1505 case IPV6_LEAVE_ANYCAST:
1507 print_mreq6(tcp, addr, len);
1509 #endif /* IPV6_ADD_MEMBERSHIP */
1515 #ifdef PACKET_RX_RING
1516 case PACKET_RX_RING:
1517 # ifdef PACKET_TX_RING
1518 case PACKET_TX_RING:
1520 print_tpacket_req(tcp, addr, len);
1522 #endif /* PACKET_RX_RING */
1523 #ifdef PACKET_ADD_MEMBERSHIP
1524 case PACKET_ADD_MEMBERSHIP:
1525 case PACKET_DROP_MEMBERSHIP:
1526 print_packet_mreq(tcp, addr, len);
1528 #endif /* PACKET_ADD_MEMBERSHIP */
1535 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;