From cb0ce38988c4d644e0b582c8a0d9988b33391da7 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sun, 9 Jul 2017 13:54:01 +0000 Subject: [PATCH] Intorduce PRINT_FIELD_INET4_ADDR * print_fields.h (PRINT_FIELD_INET4_ADDR): New macro. * msghdr.c (print_cmsg_ip_pktinfo): Use it instead of manual tprintf statements. * net.c (print_mreq): Likewise. * sockaddr.c (print_sockaddr_data_in): Likewise. --- msghdr.c | 7 +++---- net.c | 7 +++---- print_fields.h | 4 ++++ sockaddr.c | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/msghdr.c b/msghdr.c index b95232d0..9fcb1051 100644 --- a/msghdr.c +++ b/msghdr.c @@ -124,10 +124,9 @@ print_cmsg_ip_pktinfo(struct tcb *tcp, const void *cmsg_data, const struct in_pktinfo *info = cmsg_data; PRINT_FIELD_IFINDEX("{", *info, ipi_ifindex); - tprintf(", ipi_spec_dst=inet_addr(\"%s\")", - inet_ntoa(info->ipi_spec_dst)); - tprintf(", ipi_addr=inet_addr(\"%s\")}", - inet_ntoa(info->ipi_addr)); + PRINT_FIELD_INET4_ADDR(", ", *info, ipi_spec_dst); + PRINT_FIELD_INET4_ADDR(", ", *info, ipi_addr); + tprints("}"); } static void diff --git a/net.c b/net.c index 49a36342..98b151e3 100644 --- a/net.c +++ b/net.c @@ -664,10 +664,9 @@ print_mreq(struct tcb *const tcp, const kernel_ulong_t addr, if (umove_or_printaddr(tcp, addr, &mreq)) return; - tprintf("{imr_multiaddr=inet_addr(\"%s\")", - inet_ntoa(mreq.imr_multiaddr)); - tprintf(", imr_interface=inet_addr(\"%s\")}", - inet_ntoa(mreq.imr_interface)); + PRINT_FIELD_INET4_ADDR("{", mreq, imr_multiaddr); + PRINT_FIELD_INET4_ADDR(", ", mreq, imr_interface); + tprints("}"); } #endif /* IP_ADD_MEMBERSHIP */ diff --git a/print_fields.h b/print_fields.h index f09b3e47..5fb652a3 100644 --- a/print_fields.h +++ b/print_fields.h @@ -87,6 +87,10 @@ sizeof((where_).field_), #field_); \ } while (0) +#define PRINT_FIELD_INET4_ADDR(prefix_, where_, field_) \ + STRACE_PRINTF("%s%s=inet_addr(\"%s\")", (prefix_), #field_, \ + inet_ntoa((where_).field_)) + #define PRINT_FIELD_NET_PORT(prefix_, where_, field_) \ STRACE_PRINTF("%s%s=htons(%u)", (prefix_), #field_, \ ntohs((where_).field_)) diff --git a/sockaddr.c b/sockaddr.c index 6984bcba..8f1945da 100644 --- a/sockaddr.c +++ b/sockaddr.c @@ -117,7 +117,7 @@ print_sockaddr_data_in(const void *const buf, const int addrlen) const struct sockaddr_in *const sa_in = buf; PRINT_FIELD_NET_PORT("", *sa_in, sin_port); - tprintf(", sin_addr=inet_addr(\"%s\")", inet_ntoa(sa_in->sin_addr)); + PRINT_FIELD_INET4_ADDR(", ", *sa_in, sin_addr); } #define SIN6_MIN_LEN offsetof(struct sockaddr_in6, sin6_scope_id) -- 2.40.0