#include <arpa/inet.h>
#include <net/if.h>
#include <asm/types.h>
-#if defined(__GLIBC__)
+#ifdef HAVE_NETIPX_IPX_H
# include <netipx/ipx.h>
#else
# include <linux/ipx.h>
#if defined(HAVE_LINUX_IP_VS_H)
# include <linux/ip_vs.h>
#endif
-#if defined(HAVE_LINUX_NETLINK_H)
-# include <linux/netlink.h>
-#endif
+#include <linux/netlink.h>
#if defined(HAVE_LINUX_NETFILTER_ARP_ARP_TABLES_H)
# include <linux/netfilter_arp/arp_tables.h>
#endif
#if defined(HAVE_LINUX_NETFILTER_IPV6_IP6_TABLES_H)
# include <linux/netfilter_ipv6/ip6_tables.h>
#endif
-#if defined(HAVE_LINUX_IF_PACKET_H)
-# include <linux/if_packet.h>
-#endif
-#if defined(HAVE_LINUX_ICMP_H)
-# include <linux/icmp.h>
-#endif
+#include <linux/if_packet.h>
+#include <linux/icmp.h>
#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
# include <bluetooth/bluetooth.h>
# include <bluetooth/hci.h>
# include <bluetooth/rfcomm.h>
# include <bluetooth/sco.h>
#endif
-#ifndef PF_UNSPEC
-# define PF_UNSPEC AF_UNSPEC
-#endif
-#include "xlat/domains.h"
#include "xlat/addrfams.h"
#include "xlat/socktypes.h"
#include "xlat/sock_type_flags.h"
#include "xlat/inet_protocols.h"
-#ifdef PF_NETLINK
-# if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
-# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
-# endif
-# include "xlat/netlink_protocols.h"
+#if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG
+# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG
#endif
+#include "xlat/netlink_protocols.h"
#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
# include "xlat/bt_protocols.h"
#include "xlat/msg_flags.h"
-#if defined(AF_PACKET) /* from e.g. linux/if_packet.h */
-# include "xlat/af_packet_types.h"
-#endif
+#include "xlat/af_packet_types.h"
static void
print_ifindex(unsigned int ifindex)
struct sockaddr sa;
struct sockaddr_in sin;
struct sockaddr_un sau;
-#ifdef HAVE_INET_NTOP
struct sockaddr_in6 sa6;
-#endif
-#if defined(AF_IPX)
struct sockaddr_ipx sipx;
-#endif
-#ifdef AF_PACKET
struct sockaddr_ll ll;
-#endif
-#ifdef AF_NETLINK
struct sockaddr_nl nl;
-#endif
#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
struct sockaddr_hci hci;
struct sockaddr_l2 l2;
#endif
} sockaddr_buf_t;
-static void
-print_sockaddr(struct tcb *tcp, const sockaddr_buf_t *addr, const int addrlen)
+void
+print_sockaddr(struct tcb *tcp, const void *const buf, const int addrlen)
{
+ const sockaddr_buf_t *const addr = buf;
+
tprints("{sa_family=");
printxval(addrfams, addr->sa.sa_family, "AF_???");
tprints(", ");
tprintf("sin_port=htons(%u), sin_addr=inet_addr(\"%s\")",
ntohs(addr->sin.sin_port), inet_ntoa(addr->sin.sin_addr));
break;
-#ifdef HAVE_INET_NTOP
+
case AF_INET6:
{
char string_addr[100];
", \"%s\", &sin6_addr), sin6_flowinfo=%u",
ntohs(addr->sa6.sin6_port), string_addr,
addr->sa6.sin6_flowinfo);
-# ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
+#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
tprints(", sin6_scope_id=");
-# if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
+# if defined IN6_IS_ADDR_LINKLOCAL && defined IN6_IS_ADDR_MC_LINKLOCAL
if (IN6_IS_ADDR_LINKLOCAL(&addr->sa6.sin6_addr)
|| IN6_IS_ADDR_MC_LINKLOCAL(&addr->sa6.sin6_addr))
print_ifindex(addr->sa6.sin6_scope_id);
else
-# endif
+# endif
tprintf("%u", addr->sa6.sin6_scope_id);
-# endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
+#endif /* HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID */
}
break;
-#endif
-#if defined(AF_IPX)
+
case AF_IPX:
{
+ tprintf("sipx_port=htons(%u)"
+ ", sipx_network=htonl(%08x)"
+ ", sipx_node=[",
+ ntohs(addr->sipx.sipx_port),
+ ntohl(addr->sipx.sipx_network));
int i;
- tprintf("sipx_port=htons(%u), ",
- ntohs(addr->sipx.sipx_port));
- /* Yes, I know, this does not look too
- * strace-ish, but otherwise the IPX
- * addresses just look monstrous...
- * Anyways, feel free if you don't like
- * this way.. :)
- */
- tprintf("%08lx:", (unsigned long)ntohl(addr->sipx.sipx_network));
- for (i = 0; i < IPX_NODE_LEN; i++)
- tprintf("%02x", addr->sipx.sipx_node[i]);
- tprintf("/[%02x]", addr->sipx.sipx_type);
+ for (i = 0; i < IPX_NODE_LEN; ++i) {
+ tprintf("%s%02x", i ? ", " : "",
+ addr->sipx.sipx_node[i]);
+ }
+ tprintf("], sipx_type=%02x", addr->sipx.sipx_type);
}
break;
-#endif /* AF_IPX */
-#ifdef AF_PACKET
+
case AF_PACKET:
{
int i;
}
break;
-#endif /* AF_PACKET */
-#ifdef AF_NETLINK
case AF_NETLINK:
tprintf("pid=%d, groups=%08x", addr->nl.nl_pid, addr->nl.nl_groups);
break;
-#endif /* AF_NETLINK */
-#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
+
+#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
case AF_BLUETOOTH:
tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
"{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
addr->l2.l2_bdaddr.b[5], btohs(addr->l2.l2_cid),
btohs(addr->hci.hci_dev));
break;
-#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
+#endif /* HAVE_BLUETOOTH_BLUETOOTH_H */
+
/* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
AF_X25 AF_ROSE etc. still need to be done */
tprints("}");
}
-void
+int
printsock(struct tcb *tcp, long addr, int addrlen)
{
- sockaddr_buf_t addrbuf;
-
if (addrlen < 2) {
printaddr(addr);
- return;
+ return -1;
}
- if (addrlen > (int) sizeof(addrbuf))
- addrlen = sizeof(addrbuf);
+ union {
+ struct sockaddr sa;
+ struct sockaddr_storage storage;
+ char pad[sizeof(struct sockaddr_storage) + 1];
+ } addrbuf;
+
+ if ((unsigned) addrlen > sizeof(addrbuf.storage))
+ addrlen = sizeof(addrbuf.storage);
- memset(&addrbuf, 0, sizeof(addrbuf));
if (umoven_or_printaddr(tcp, addr, addrlen, addrbuf.pad))
- return;
- addrbuf.pad[sizeof(addrbuf.pad) - 1] = '\0';
+ return -1;
+
+ memset(&addrbuf.pad[addrlen], 0, sizeof(addrbuf.pad) - addrlen);
print_sockaddr(tcp, &addrbuf, addrlen);
+
+ return addrbuf.sa.sa_family;
}
#include "xlat/scmvals.h"
print_cmsg_ip_opts(struct tcb *tcp, const void *cmsg_data,
const size_t data_len)
{
- const char *opts = cmsg_data;
+ const unsigned char *opts = cmsg_data;
size_t i;
if (!data_len)
", ee_info=%u, ee_data=%u, offender=",
err->ee_errno, err->ee_origin, err->ee_type,
err->ee_code, err->ee_info, err->ee_data);
- print_sockaddr(tcp, (const void *) &err->offender,
- sizeof(err->offender));
+ print_sockaddr(tcp, &err->offender, sizeof(err->offender));
tprints("}");
}
printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
+
tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
- (unsigned long)msg->msg_iov, 1, data_size);
+ (unsigned long)msg->msg_iov, IOV_DECODE_STR, data_size);
#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
}
void
-dumpiov_in_msghdr(struct tcb *tcp, long addr)
+dumpiov_in_msghdr(struct tcb *tcp, long addr, unsigned long data_size)
{
struct msghdr msg;
if (extractmsghdr(tcp, addr, &msg))
- dumpiov(tcp, msg.msg_iovlen, (long)msg.msg_iov);
+ dumpiov_upto(tcp, msg.msg_iovlen, (long)msg.msg_iov, data_size);
}
static void
if (extractmmsghdr(tcp, addr, i, &mmsg)) {
tprintf(" = %lu buffers in vector %u\n",
(unsigned long)mmsg.msg_hdr.msg_iovlen, i);
- dumpiov(tcp, mmsg.msg_hdr.msg_iovlen,
- (long)mmsg.msg_hdr.msg_iov);
+ dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
+ (long)mmsg.msg_hdr.msg_iov, mmsg.msg_len);
}
}
}
* other bits are socket type flags.
*/
static void
-tprint_sock_type(int flags)
+tprint_sock_type(unsigned int flags)
{
const char *str = xlookup(socktypes, flags & SOCK_TYPE_MASK);
SYS_FUNC(socket)
{
- printxval(domains, tcp->u_arg[0], "PF_???");
+ printxval(addrfams, tcp->u_arg[0], "AF_???");
tprints(", ");
tprint_sock_type(tcp->u_arg[1]);
tprints(", ");
switch (tcp->u_arg[0]) {
- case PF_INET:
-#ifdef PF_INET6
- case PF_INET6:
-#endif
+ case AF_INET:
+ case AF_INET6:
printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
break;
-#ifdef PF_IPX
- case PF_IPX:
- /* BTW: I don't believe this.. */
- tprints("[");
- printxval(domains, tcp->u_arg[2], "PF_???");
- tprints("]");
- break;
-#endif /* PF_IPX */
-#ifdef PF_NETLINK
- case PF_NETLINK:
+
+ case AF_NETLINK:
printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
break;
-#endif
-#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
- case PF_BLUETOOTH:
+
+#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
+ case AF_BLUETOOTH:
printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
break;
#endif
+
default:
tprintf("%lu", tcp->u_arg[2]);
break;
printfd(tcp, tcp->u_arg[0]);
tprints(", ");
if (!verbose(tcp)) {
- tprintf("%#lx, %u, ",
- tcp->u_arg[1], (unsigned int) tcp->u_arg[2]);
+ printaddr(tcp->u_arg[1]);
+ tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
printflags(msg_flags, tcp->u_arg[3], "MSG_???");
}
} else {
*/
tcp->auxstr = sprint_timespec(tcp, tcp->u_arg[4]);
} else {
- tprintf("%#lx, %ld, ", tcp->u_arg[1], tcp->u_arg[2]);
+ printaddr(tcp->u_arg[1]);
+ tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
printflags(msg_flags, tcp->u_arg[3], "MSG_???");
tprints(", ");
print_timespec(tcp, tcp->u_arg[4]);
do_pipe(struct tcb *tcp, int flags_arg)
{
if (exiting(tcp)) {
- if (syserror(tcp)) {
- printaddr(tcp->u_arg[0]);
- } else {
-#ifdef HAVE_GETRVAL2
- if (flags_arg < 0) {
- printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
- } else
-#endif
- decode_pair_fd(tcp, tcp->u_arg[0]);
- }
+ decode_pair_fd(tcp, tcp->u_arg[0]);
if (flags_arg >= 0) {
tprints(", ");
printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
SYS_FUNC(pipe)
{
+#ifdef HAVE_GETRVAL2
+ if (exiting(tcp) && !syserror(tcp))
+ printpair_fd(tcp, tcp->u_rval, getrval2(tcp));
+ return 0;
+#else
return do_pipe(tcp, -1);
+#endif
}
SYS_FUNC(pipe2)
SYS_FUNC(socketpair)
{
if (entering(tcp)) {
- printxval(domains, tcp->u_arg[0], "PF_???");
+ printxval(addrfams, tcp->u_arg[0], "AF_???");
tprints(", ");
tprint_sock_type(tcp->u_arg[1]);
tprintf(", %lu", tcp->u_arg[2]);
#include "xlat/socktcpoptions.h"
static void
-print_sockopt_fd_level_name(struct tcb *tcp, int fd, int level, int name, bool is_getsockopt)
+print_sockopt_fd_level_name(struct tcb *tcp, int fd, unsigned int level,
+ unsigned int name, bool is_getsockopt)
{
printfd(tcp, fd);
tprints(", ");
tprints(", ");
}
-#ifdef SO_LINGER
static void
print_linger(struct tcb *tcp, long addr, int len)
{
linger.l_onoff,
linger.l_linger);
}
-#endif /* SO_LINGER */
#ifdef SO_PEERCRED
static void
}
#endif /* PACKET_STATISTICS */
-#ifdef ICMP_FILTER
-# include "xlat/icmpfilterflags.h"
+#include "xlat/icmpfilterflags.h"
static void
-print_icmp_filter(struct tcb *tcp, long addr, int len)
+print_icmp_filter(struct tcb *tcp, const long addr, int len)
{
- struct icmp_filter filter;
+ struct icmp_filter filter = {};
- if (len != sizeof(filter) ||
- umove(tcp, addr, &filter) < 0) {
+ if (len > (int) sizeof(filter))
+ len = sizeof(filter);
+ else if (len <= 0) {
printaddr(addr);
return;
}
+ if (umoven_or_printaddr(tcp, addr, len, &filter))
+ return;
+
tprints("~(");
printflags(icmpfilterflags, ~filter.data, "ICMP_???");
tprints(")");
}
-#endif /* ICMP_FILTER */
static void
-print_getsockopt(struct tcb *tcp, int level, int name, long addr, int len)
+print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
+ long addr, int len)
{
if (addr && verbose(tcp))
switch (level) {
case SOL_SOCKET:
switch (name) {
-#ifdef SO_LINGER
case SO_LINGER:
print_linger(tcp, addr, len);
goto done;
-#endif
#ifdef SO_PEERCRED
case SO_PEERCRED:
print_ucred(tcp, addr, len);
case SOL_RAW:
switch (name) {
-#ifdef ICMP_FILTER
case ICMP_FILTER:
print_icmp_filter(tcp, addr, len);
goto done;
-#endif
}
break;
}
int len;
if (syserror(tcp) || umove(tcp, tcp->u_arg[4], &len) < 0) {
- tprintf("%#lx, %#lx",
- tcp->u_arg[3], tcp->u_arg[4]);
+ printaddr(tcp->u_arg[3]);
+ tprints(", ");
+ printaddr(tcp->u_arg[4]);
} else {
print_getsockopt(tcp, tcp->u_arg[1], tcp->u_arg[2],
tcp->u_arg[3], len);
if (umove_or_printaddr(tcp, addr, &mreq))
return;
-#ifdef HAVE_INET_NTOP
const struct in6_addr *in6 = &mreq.ipv6mr_multiaddr;
char address[INET6_ADDRSTRLEN];
print_ifindex(mreq.ipv6mr_interface);
tprints("}");
return;
-#endif /* HAVE_INET_NTOP */
fail:
printstr(tcp, addr, len);
}
tprintf("{gr_interface=%u, gr_group=", greq.gr_interface);
- print_sockaddr(tcp, (const void *) &greq.gr_group,
- sizeof(greq.gr_group));
+ print_sockaddr(tcp, &greq.gr_group, sizeof(greq.gr_group));
tprintf("}");
}
#endif /* PACKET_ADD_MEMBERSHIP */
static void
-print_setsockopt(struct tcb *tcp, int level, int name, long addr, int len)
+print_setsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
+ long addr, int len)
{
if (addr && verbose(tcp))
switch (level) {
case SOL_SOCKET:
switch (name) {
-#ifdef SO_LINGER
case SO_LINGER:
print_linger(tcp, addr, len);
goto done;
-#endif
}
break;
case SOL_RAW:
switch (name) {
-#ifdef ICMP_FILTER
case ICMP_FILTER:
print_icmp_filter(tcp, addr, len);
goto done;
-#endif
}
break;
}