pping: Fix struct alginment issues

Move some members in network_tuple and rtt_event around to avoid holes.

Also remove some uncecessary parentheses before & operator, and add
local definitions of AF_INET and AF_INET6.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
This commit is contained in:
Simon Sundberg
2021-02-09 13:00:28 +01:00
parent 670df84bd9
commit eafdf87d80
5 changed files with 18 additions and 21 deletions

View File

@ -248,7 +248,7 @@ static int format_ip_address(int af, const struct in6_addr *addr, char *buf,
size_t size)
{
if (af == AF_INET)
return inet_ntop(af, &(addr->s6_addr[12]),
return inet_ntop(af, &addr->s6_addr[12],
buf, size) ? -errno : 0;
else if (af == AF_INET6)
return inet_ntop(af, addr, buf, size) ? -errno : 0;
@ -261,8 +261,8 @@ static void handle_rtt_event(void *ctx, int cpu, void *data, __u32 data_size)
char saddr[INET6_ADDRSTRLEN];
char daddr[INET6_ADDRSTRLEN];
format_ip_address(e->flow.ipv, &(e->flow.saddr), saddr, sizeof(saddr));
format_ip_address(e->flow.ipv, &(e->flow.daddr), daddr, sizeof(daddr));
format_ip_address(e->flow.ipv, &e->flow.saddr, saddr, sizeof(saddr));
format_ip_address(e->flow.ipv, &e->flow.daddr, daddr, sizeof(daddr));
printf("%llu.%06llu ms %s:%d+%s:%d\n", e->rtt / NS_PER_MS,
e->rtt % NS_PER_MS, saddr, ntohs(e->flow.sport), daddr,