[PATCH v2 5/8] netlink: print unrecognized netlink payload in hex
JingPiao Chen
chenjingpiao at gmail.com
Fri Jul 7 03:23:51 UTC 2017
* netlink.c (decode_payload): Replace printstrn
with printstr_ex and set QUOTE_FORCE_HEX flag.
* tests/netlink_protocol.c (send_query, test_nlmsgerr,
test_nlmsg_done): Update expected output.
* tests/netlink_generic.c (test_nlmsg_type): Likewise.
---
netlink.c | 2 +-
tests/netlink_generic.c | 3 ++-
tests/netlink_protocol.c | 31 +++++++++++++++++--------------
3 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/netlink.c b/netlink.c
index ca19535..cd1296f 100644
--- a/netlink.c
+++ b/netlink.c
@@ -345,7 +345,7 @@ decode_payload(struct tcb *const tcp,
return;
}
- printstrn(tcp, addr, len);
+ printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
}
static void
diff --git a/tests/netlink_generic.c b/tests/netlink_generic.c
index 4f80c8b..cd9fbea 100644
--- a/tests/netlink_generic.c
+++ b/tests/netlink_generic.c
@@ -63,7 +63,8 @@ test_nlmsg_type(const int fd)
rc = sendto(fd, &req, sizeof(req), MSG_DONTWAIT, NULL, 0);
printf("sendto(%d, {{len=%u, type=nlctrl"
", flags=NLM_F_REQUEST|0x300, seq=0, pid=0}"
- ", \"\\3\\0\\0\\0\"}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+ ", \"\\x03\\x00\\x00\\x00\"}, %u"
+ ", MSG_DONTWAIT, NULL, 0) = %s\n",
fd, req.nlh.nlmsg_len,
(unsigned int) sizeof(req), sprintrc(rc));
}
diff --git a/tests/netlink_protocol.c b/tests/netlink_protocol.c
index 3b4791e..ebb93c4 100644
--- a/tests/netlink_protocol.c
+++ b/tests/netlink_protocol.c
@@ -89,7 +89,8 @@ send_query(const int fd)
/* a single message with some data */
rc = sendto(fd, req, sizeof(*req), MSG_DONTWAIT, NULL, 0);
printf("sendto(%d, {{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
- ", seq=0, pid=0}, \"abcd\"}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+ ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}"
+ ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
fd, req->nlh.nlmsg_len, NLM_F_DUMP,
(unsigned) sizeof(*req), sprintrc(rc));
@@ -105,7 +106,8 @@ send_query(const int fd)
req->nlh.nlmsg_len = sizeof(*req) + 8;
rc = sendto(fd, req, sizeof(*req), MSG_DONTWAIT, NULL, 0);
printf("sendto(%d, {{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
- ", seq=0, pid=0}, \"abcd\"}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+ ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}"
+ ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
fd, req->nlh.nlmsg_len, NLM_F_DUMP,
(unsigned) sizeof(*req), sprintrc(rc));
@@ -128,8 +130,9 @@ send_query(const int fd)
rc = sendto(fd, reqs, sizeof(*reqs), MSG_DONTWAIT, NULL, 0);
printf("sendto(%d, [{{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
- ", seq=0, pid=0}, \"abcd\"}, {{len=%u, type=NLMSG_NOOP"
- ", flags=NLM_F_REQUEST|0x%x, seq=0, pid=0}, \"abcd\"}]"
+ ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}"
+ ", {{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
+ ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}]"
", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
fd, reqs->req1.nlh.nlmsg_len, NLM_F_DUMP,
reqs->req2.nlh.nlmsg_len, NLM_F_DUMP,
@@ -139,8 +142,8 @@ send_query(const int fd)
void *const efault2 = tail_memdup(&reqs->req1, sizeof(reqs->req1));
rc = sendto(fd, efault2, sizeof(*reqs), MSG_DONTWAIT, NULL, 0);
printf("sendto(%d, [{{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
- ", seq=0, pid=0}, \"abcd\"}, %p], %u, MSG_DONTWAIT, NULL, 0)"
- " = %s\n",
+ ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}"
+ ", %p], %u, MSG_DONTWAIT, NULL, 0) = %s\n",
fd, reqs->req1.nlh.nlmsg_len, NLM_F_DUMP,
&((struct reqs *) efault2)->req2, (unsigned) sizeof(*reqs),
sprintrc(rc));
@@ -150,7 +153,7 @@ send_query(const int fd)
NULL, 0);
errstr = sprintrc(rc);
printf("sendto(%d, [{{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
- ", seq=0, pid=0}, \"abcd\"}, ",
+ ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}, ",
fd, reqs->req1.nlh.nlmsg_len, NLM_F_DUMP);
print_quoted_memory((void *) &reqs->req2.nlh,
sizeof(reqs->req2) - sizeof(req->nlh));
@@ -161,9 +164,9 @@ send_query(const int fd)
reqs->req2.nlh.nlmsg_len = 4;
rc = sendto(fd, reqs, sizeof(*reqs), MSG_DONTWAIT, NULL, 0);
printf("sendto(%d, [{{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
- ", seq=0, pid=0}, \"abcd\"}, {len=%u, type=NLMSG_NOOP"
- ", flags=NLM_F_REQUEST|0x%x, seq=0, pid=0}], %u"
- ", MSG_DONTWAIT, NULL, 0) = %s\n",
+ ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}"
+ ", {len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
+ ", seq=0, pid=0}], %u, MSG_DONTWAIT, NULL, 0) = %s\n",
fd, reqs->req1.nlh.nlmsg_len, NLM_F_DUMP,
reqs->req2.nlh.nlmsg_len, NLM_F_DUMP,
(unsigned) sizeof(*reqs), sprintrc(rc));
@@ -303,8 +306,8 @@ test_nlmsgerr(const int fd)
printf("sendto(%d, {{len=%u, type=NLMSG_ERROR, flags=NLM_F_REQUEST"
", seq=0, pid=0}, {error=-EACCES"
", msg={{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
- ", seq=%u, pid=%u}, \"abcd\"}}}, %u, MSG_DONTWAIT, NULL, 0)"
- " = %s\n",
+ ", seq=%u, pid=%u}, \"\\x61\\x62\\x63\\x64\"}}}"
+ ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
fd, nlh->nlmsg_len, err->msg.nlmsg_len, NLM_F_DUMP,
err->msg.nlmsg_seq, err->msg.nlmsg_pid,
nlh->nlmsg_len, sprintrc(rc));
@@ -340,8 +343,8 @@ test_nlmsg_done(const int fd)
memcpy(NLMSG_DATA(nlh), "42", 2);
rc = sendto(fd, nlh, NLMSG_HDRLEN + 2, MSG_DONTWAIT, NULL, 0);
- printf("sendto(%d, {{len=%u, type=NLMSG_DONE, flags=NLM_F_MULTI"
- ", seq=0, pid=0}, \"42\"}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+ printf("sendto(%d, {{len=%u, type=NLMSG_DONE, flags=NLM_F_MULTI, seq=0"
+ ", pid=0}, \"\\x34\\x32\"}, %u, MSG_DONTWAIT, NULL, 0) = %s\n",
fd, NLMSG_HDRLEN + 2, NLMSG_HDRLEN + 2, sprintrc(rc));
/* NLMSG_DONE message with enough room for an integer payload */
--
2.7.4
More information about the Strace-devel
mailing list