[PATCH v2 8/8] netlink_sock_diag: print unrecognized data in hex

JingPiao Chen chenjingpiao at gmail.com
Fri Jul 7 03:23:54 UTC 2017


* netlink_sock_diag.c (decode_family): Replace printstrn with
printstr_ex and set QUOTE_FORCE_HEX flag.
* tests/netlink_sock_diag.c (test_odd_family_req,
test_odd_family_msg): Update expected output.
---
 netlink_sock_diag.c       | 4 ++--
 tests/netlink_sock_diag.c | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/netlink_sock_diag.c b/netlink_sock_diag.c
index 3888934..0d27f78 100644
--- a/netlink_sock_diag.c
+++ b/netlink_sock_diag.c
@@ -74,8 +74,8 @@ decode_family(struct tcb *const tcp, const uint8_t family,
 	printxval(addrfams, family, "AF_???");
 	if (len > sizeof(family)) {
 		tprints(", ");
-		printstrn(tcp, addr + sizeof(family),
-			  len - sizeof(family));
+		printstr_ex(tcp, addr + sizeof(family),
+			    len - sizeof(family), QUOTE_FORCE_HEX);
 	}
 	tprints("}");
 }
diff --git a/tests/netlink_sock_diag.c b/tests/netlink_sock_diag.c
index b8d0190..c5ed95e 100644
--- a/tests/netlink_sock_diag.c
+++ b/tests/netlink_sock_diag.c
@@ -158,7 +158,7 @@ test_odd_family_req(const int fd)
 
 	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
 	       ", flags=NLM_F_REQUEST, seq=0, pid=0}"
-	       ", {family=AF_UNSPEC, \"1234\"}}"
+	       ", {family=AF_UNSPEC, \"\\x31\\x32\\x33\\x34\"}}"
 	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
 	       fd, NLMSG_HDRLEN + (unsigned int) sizeof(*family) + 4,
 	       NLMSG_HDRLEN + (unsigned int) sizeof(*family) + 4,
@@ -172,7 +172,7 @@ test_odd_family_req(const int fd)
 
 	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
 	       ", flags=NLM_F_REQUEST, seq=0, pid=0}"
-	       ", {family=0xfd /* AF_??? */, \"1234\"}}"
+	       ", {family=0xfd /* AF_??? */, \"\\x31\\x32\\x33\\x34\"}}"
 	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
 	       fd, NLMSG_HDRLEN + (unsigned int) sizeof(*family) + 4,
 	       NLMSG_HDRLEN + (unsigned int) sizeof(*family) + 4,
@@ -255,7 +255,7 @@ test_odd_family_msg(const int fd)
 
 	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
 	       ", flags=NLM_F_DUMP, seq=0, pid=0}"
-	       ", {family=AF_UNSPEC, \"1234\"}}"
+	       ", {family=AF_UNSPEC, \"\\x31\\x32\\x33\\x34\"}}"
 	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
 	       fd, NLMSG_HDRLEN + (unsigned int) sizeof(*family) + 4,
 	       NLMSG_HDRLEN + (unsigned int) sizeof(*family) + 4,
@@ -269,7 +269,7 @@ test_odd_family_msg(const int fd)
 
 	printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY"
 	       ", flags=NLM_F_DUMP, seq=0, pid=0}"
-	       ", {family=0xfb /* AF_??? */, \"1234\"}}"
+	       ", {family=0xfb /* AF_??? */, \"\\x31\\x32\\x33\\x34\"}}"
 	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
 	       fd, NLMSG_HDRLEN + (unsigned int) sizeof(*family) + 4,
 	       NLMSG_HDRLEN + (unsigned int) sizeof(*family) + 4,
-- 
2.7.4





More information about the Strace-devel mailing list