Intorduce PRINT_FIELD_INET_ADDR

* print_fields.h (PRINT_FIELD_INET_ADDR): New macro.
* net.c (print_mreq6): Use it instead of print_inet_addr.
* netlink_sock_diag.c (print_inet_diag_sockid): Likewise.
* sockaddr.c (print_sockaddr_data_in6): Likewise.
This commit is contained in:
Дмитрий Левин 2017-07-09 13:54:01 +00:00
parent 70d8b32108
commit b63dc54a1d
4 changed files with 14 additions and 12 deletions

4
net.c
View File

@ -685,9 +685,7 @@ print_mreq6(struct tcb *const tcp, const kernel_ulong_t addr,
if (umove_or_printaddr(tcp, addr, &mreq))
return;
tprints("{");
print_inet_addr(AF_INET6, &mreq.ipv6mr_multiaddr,
sizeof(mreq.ipv6mr_multiaddr), "ipv6mr_multiaddr");
PRINT_FIELD_INET_ADDR("{", mreq, ipv6mr_multiaddr, AF_INET6);
tprints(", ipv6mr_interface=");
print_ifindex(mreq.ipv6mr_interface);

View File

@ -607,12 +607,8 @@ print_inet_diag_sockid(const struct inet_diag_sockid *id, const uint8_t family)
tprintf("{idiag_sport=htons(%u), idiag_dport=htons(%u)",
ntohs(id->idiag_sport), ntohs(id->idiag_dport));
tprints(", ");
print_inet_addr(family, id->idiag_src,
sizeof(id->idiag_src), "idiag_src");
tprints(", ");
print_inet_addr(family, id->idiag_dst,
sizeof(id->idiag_dst), "idiag_dst");
PRINT_FIELD_INET_ADDR(", ", *id, idiag_src, family);
PRINT_FIELD_INET_ADDR(", ", *id, idiag_dst, family);
tprints(", idiag_if=");
print_ifindex(id->idiag_if);

View File

@ -80,4 +80,11 @@
print_quoted_string((const char *)(where_).field_, len_, style_); \
} while (0)
#define PRINT_FIELD_INET_ADDR(prefix_, where_, field_, af_) \
do { \
STRACE_PRINTF(prefix_); \
print_inet_addr((af_), &(where_).field_, \
sizeof((where_).field_), #field_); \
} while (0)
#endif /* !STRACE_PRINT_FIELDS_H */

View File

@ -30,6 +30,8 @@
*/
#include "defs.h"
#include "print_fields.h"
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
@ -125,9 +127,8 @@ print_sockaddr_data_in6(const void *const buf, const int addrlen)
{
const struct sockaddr_in6 *const sa_in6 = buf;
tprintf("sin6_port=htons(%u), ", ntohs(sa_in6->sin6_port));
print_inet_addr(AF_INET6, &sa_in6->sin6_addr,
sizeof(sa_in6->sin6_addr), "sin6_addr");
tprintf("sin6_port=htons(%u)", ntohs(sa_in6->sin6_port));
PRINT_FIELD_INET_ADDR(", ", *sa_in6, sin6_addr, AF_INET6);
tprintf(", sin6_flowinfo=htonl(%u)", ntohl(sa_in6->sin6_flowinfo));
if (addrlen <= (int) SIN6_MIN_LEN)