#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 "xlat/inet_protocols.h"
-#ifdef AF_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"
", 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);
* 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);
tprints(", ");
switch (tcp->u_arg[0]) {
case AF_INET:
-#ifdef AF_INET6
case AF_INET6:
-#endif
printxval(inet_protocols, tcp->u_arg[2], "IPPROTO_???");
break;
-#ifdef AF_IPX
- case AF_IPX:
- /* BTW: I don't believe this.. */
- tprints("[");
- printxval(addrfams, tcp->u_arg[2], "AF_???");
- tprints("]");
- break;
-#endif /* AF_IPX */
-#ifdef AF_NETLINK
+
case AF_NETLINK:
printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
break;
-#endif
-#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
+
+#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]);
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, const long addr, int len)
printflags(icmpfilterflags, ~filter.data, "ICMP_???");
tprints(")");
}
-#endif /* ICMP_FILTER */
static void
print_getsockopt(struct tcb *tcp, unsigned int level, unsigned int name,
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("}");
}
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;
}