[PATCH v1 02/11] netlink: print unrecognized attribute data in hex
JingPiao Chen
chenjingpiao at gmail.com
Thu Jul 6 01:57:28 UTC 2017
* nlattr.c (decode_nlattr_with_data): Replace printstrn
with printstr_ex and set QUOTE_FORCE_HEX flag.
* tests/print_quoted_string.c (print_quoted_hex): New function.
* tests/test_nlattr.h (print_quoted_hex): New prototype.
* tests/tests.h (TEST_NLATTR_OBJECT, TEST_NLATTR_ARRAY): Use it
for update expected output.
* tests/nlattr.c: Update expected output.
---
nlattr.c | 3 ++-
tests/nlattr.c | 3 ++-
tests/print_quoted_string.c | 11 +++++++++++
tests/test_nlattr.h | 4 ++--
tests/tests.h | 3 +++
5 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/nlattr.c b/nlattr.c
index ef3d762..00f8924 100644
--- a/nlattr.c
+++ b/nlattr.c
@@ -86,7 +86,8 @@ decode_nlattr_with_data(struct tcb *const tcp,
|| !decoders[nla->nla_type](tcp, addr + NLA_HDRLEN,
nla_len - NLA_HDRLEN,
opaque_data))
- printstrn(tcp, addr + NLA_HDRLEN, len - NLA_HDRLEN);
+ printstr_ex(tcp, addr + NLA_HDRLEN,
+ len - NLA_HDRLEN, QUOTE_FORCE_HEX);
tprints("}");
}
}
diff --git a/tests/nlattr.c b/tests/nlattr.c
index 7361ece..ae3ad4d 100644
--- a/tests/nlattr.c
+++ b/tests/nlattr.c
@@ -133,7 +133,8 @@ test_nlattr(const int fd)
", flags=NLM_F_DUMP, seq=0, pid=0}, {udiag_family=AF_UNIX"
", udiag_type=SOCK_STREAM, udiag_state=TCP_FIN_WAIT1"
", udiag_ino=0, udiag_cookie=[0, 0]}, {{nla_len=%u"
- ", nla_type=%#x /* UNIX_DIAG_??? */}, \"1234\"}}"
+ ", nla_type=%#x /* UNIX_DIAG_??? */}"
+ ", \"\\x31\\x32\\x33\\x34\"}}"
", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
fd, msg_len, nla->nla_len, UNIX_DIAG_SHUTDOWN + 1,
msg_len, sprintrc(rc));
diff --git a/tests/print_quoted_string.c b/tests/print_quoted_string.c
index 6fc0d16..72c0d01 100644
--- a/tests/print_quoted_string.c
+++ b/tests/print_quoted_string.c
@@ -75,3 +75,14 @@ print_quoted_memory(const char *instr, const size_t len)
printf("\"");
}
+
+void
+print_quoted_hex(const char *str, const size_t len)
+{
+ size_t i;
+
+ printf("\"");
+ for (i = 0; i < len; i++)
+ printf("\\x%02x", str[i]);
+ printf("\"");
+}
diff --git a/tests/test_nlattr.h b/tests/test_nlattr.h
index 8cbb211..2b49b5a 100644
--- a/tests/test_nlattr.h
+++ b/tests/test_nlattr.h
@@ -107,7 +107,7 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
(nla_type_), #nla_type_, \
sizeof(obj_) - 1, \
(pattern_), sizeof(obj_) - 1, \
- printf("\"%.*s\"", plen, (pattern_))); \
+ print_quoted_hex((pattern_), plen)); \
/* short read of sizeof(obj_) */ \
TEST_NLATTR_((fd_), (nlh0_), (hdrlen_), \
(init_msg_), (print_msg_), \
@@ -138,7 +138,7 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type)
(nla_type_), #nla_type_, \
sizeof((obj_)[0]) - 1, \
(pattern_), sizeof((obj_)[0]) - 1, \
- printf("\"%.*s\"", plen, (pattern_))); \
+ print_quoted_hex((pattern_), plen)); \
/* sizeof((obj_)[0]) < len < sizeof(obj_) */ \
TEST_NLATTR_((fd_), (nlh0_), (hdrlen_), \
(init_msg_), (print_msg_), \
diff --git a/tests/tests.h b/tests/tests.h
index 094f365..6332e71 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -137,6 +137,9 @@ void print_quoted_string(const char *);
/* Print memory in a quoted form. */
void print_quoted_memory(const char *, size_t);
+/* Print hex in a quoted form. */
+void print_quoted_hex(const char *, size_t);
+
/* Print time_t and nanoseconds in symbolic format. */
void print_time_t_nsec(time_t, unsigned long long, int);
--
2.7.4
More information about the Strace-devel
mailing list