From: Dmitry V. Levin Date: Mon, 12 Nov 2018 13:42:11 +0000 (+0000) Subject: print_inet_addr: print nameless and named addresses using the same style X-Git-Tag: v4.26~87 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=62267a93f46da996f375ccf0b93d802e35b94274;p=strace print_inet_addr: print nameless and named addresses using the same style * sockaddr.c (print_inet_addr): Handle var_name == NULL case in a more structured way: use inet_addr("%s") form to print AF_INET addresses in structureless contexts where no structure field name is available. Likewise, use inet_pton(AF_INET6, "%s") that case. * tests/nlattr_ifaddrmsg.c (main): Update expected output. * tests/nlattr_ifla_af_spec.c (main): Likewise. Complements: v4.19~76 "print_inet_addr: add support of invocations without field name" --- diff --git a/sockaddr.c b/sockaddr.c index cf60c324..3067e514 100644 --- a/sockaddr.c +++ b/sockaddr.c @@ -98,7 +98,7 @@ print_inet_addr(const int af, if (var_name) tprintf("%s=inet_addr(\"%s\")", var_name, buf); else - tprints(buf); + tprintf("inet_addr(\"%s\")", buf); return true; } break; @@ -108,7 +108,8 @@ print_inet_addr(const int af, tprintf("inet_pton(%s, \"%s\", &%s)", "AF_INET6", buf, var_name); else - tprints(buf); + tprintf("inet_pton(%s, \"%s\")", + "AF_INET6", buf); return true; } break; diff --git a/tests/nlattr_ifaddrmsg.c b/tests/nlattr_ifaddrmsg.c index c71ebb1c..600a166e 100644 --- a/tests/nlattr_ifaddrmsg.c +++ b/tests/nlattr_ifaddrmsg.c @@ -127,7 +127,7 @@ main(void) TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, init_ifaddrmsg, print_ifaddrmsg, IFA_ADDRESS, pattern, a4, - printf("%s", address4)); + printf("inet_addr(\"%s\")", address4)); SET_IFA_FAMILY(AF_INET6); @@ -137,7 +137,7 @@ main(void) TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, init_ifaddrmsg, print_ifaddrmsg, IFA_ADDRESS, pattern, a6, - printf("%s", address6)); + printf("inet_pton(AF_INET6, \"%s\")", address6)); TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, init_ifaddrmsg, print_ifaddrmsg, diff --git a/tests/nlattr_ifla_af_spec.c b/tests/nlattr_ifla_af_spec.c index 24f55af6..579739a1 100644 --- a/tests/nlattr_ifla_af_spec.c +++ b/tests/nlattr_ifla_af_spec.c @@ -292,8 +292,9 @@ main(void) init_AF_INET6_msg, print_AF_INET6_msg, 7, "IFLA_INET6_TOKEN", pattern, inet6_addr, print_quoted_hex, 2, - printf("badc:ded:face:beef:deca:feed" - ":dead:feed")); + printf("inet_pton(AF_INET6" + ", \"badc:ded:face:beef" + ":deca:feed:dead:feed\")")); /* AF_INET6: IFLA_INET6_ */ static const struct {