Print IPv6 addresses in brackets

Follow a common practice for printing address:port pair to distinguish
address parts delimiter from address/port delimiter.

* socketutils.c (inet_parse_response) <ob, cb>: New variables,
initialise them to open/closing brackets or empty strings based
on address family.
(inet_parse_response): Print ob and cb around src_buf and dst_buf.
* NEWS: Mention this improvement.
This commit is contained in:
Eugene Syromyatnikov 2018-02-08 14:15:01 +01:00 committed by Dmitry V. Levin
parent 53571cba0f
commit 85e2e24e19
2 changed files with 14 additions and 4 deletions

4
NEWS
View File

@ -4,6 +4,10 @@ Noteworthy changes in release ?.?? (????-??-??)
* Changes in infrastructure
* The mailing list was moved to strace-devel@lists.strace.io.
* Improvements
* IPv6 addresses shown in socket information in -yy mode are now printed
in brackets.
* Bug fixes
* Fixed build on m68k.

View File

@ -165,6 +165,10 @@ inet_parse_response(const void *const data, const int data_len,
char src_buf[text_size];
char *details;
/* open/closing brackets for IPv6 addresses */
const char *ob = diag_msg->idiag_family == AF_INET6 ? "[" : "";
const char *cb = diag_msg->idiag_family == AF_INET6 ? "]" : "";
if (!inet_ntop(diag_msg->idiag_family, diag_msg->id.idiag_src,
src_buf, text_size))
return -1;
@ -177,12 +181,14 @@ inet_parse_response(const void *const data, const int data_len,
dst_buf, text_size))
return -1;
if (asprintf(&details, "%s:[%s:%u->%s:%u]", proto_name,
src_buf, ntohs(diag_msg->id.idiag_sport),
dst_buf, ntohs(diag_msg->id.idiag_dport)) < 0)
if (asprintf(&details, "%s:[%s%s%s:%u->%s%s%s:%u]", proto_name,
ob, src_buf, cb, ntohs(diag_msg->id.idiag_sport),
ob, dst_buf, cb, ntohs(diag_msg->id.idiag_dport))
< 0)
return false;
} else {
if (asprintf(&details, "%s:[%s:%u]", proto_name, src_buf,
if (asprintf(&details, "%s:[%s%s%s:%u]",
proto_name, ob, src_buf, cb,
ntohs(diag_msg->id.idiag_sport)) < 0)
return false;
}