summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2013-03-13 17:44:47 +0100
committerThomas Graf <tgraf@suug.ch>2013-03-14 12:46:14 +0100
commitf72bfc72205366f2f877fef379c79c9a2a1cce03 (patch)
treeed7cd31ac481ec3502d696ca8a605638b7958904
parentc608b4d151d221542e6b0bbb8a95b45a4cde0fb7 (diff)
msg: Pretty print error message header even if incomplete
Signed-off-by: Thomas Graf <tgraf@suug.ch>
-rw-r--r--lib/msg.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/lib/msg.c b/lib/msg.c
index 043efe9..b07de63 100644
--- a/lib/msg.c
+++ b/lib/msg.c
@@ -863,6 +863,27 @@ static void dump_attrs(FILE *ofd, struct nlattr *attrs, int attrlen,
}
}
+static void dump_error_msg(struct nl_msg *msg, FILE *ofd)
+{
+ struct nlmsghdr *hdr = nlmsg_hdr(msg);
+ struct nlmsgerr *err = nlmsg_data(hdr);
+
+ fprintf(ofd, " [ERRORMSG] %zu octets\n", sizeof(*err));
+
+ if (nlmsg_len(hdr) >= sizeof(*err)) {
+ char buf[256];
+ struct nl_msg *errmsg;
+
+ fprintf(ofd, " .error = %d \"%s\"\n", err->error,
+ strerror_r(-err->error, buf, sizeof(buf)));
+ fprintf(ofd, " [ORIGINAL MESSAGE] %zu octets\n", sizeof(*hdr));
+
+ errmsg = nlmsg_inherit(&err->msg);
+ print_hdr(ofd, errmsg);
+ nlmsg_free(errmsg);
+ }
+}
+
/**
* Dump message in human readable format to file descriptor
* @arg msg Message to print
@@ -879,21 +900,9 @@ void nl_msg_dump(struct nl_msg *msg, FILE *ofd)
fprintf(ofd, " [HEADER] %zu octets\n", sizeof(struct nlmsghdr));
print_hdr(ofd, msg);
- if (hdr->nlmsg_type == NLMSG_ERROR &&
- hdr->nlmsg_len >= nlmsg_msg_size(sizeof(struct nlmsgerr))) {
- struct nl_msg *errmsg;
- struct nlmsgerr *err = nlmsg_data(hdr);
- char buf[256];
-
- fprintf(ofd, " [ERRORMSG] %zu octets\n", sizeof(*err));
- fprintf(ofd, " .error = %d \"%s\"\n", err->error,
- strerror_r(-err->error, buf, sizeof(buf)));
- fprintf(ofd, " [ORIGINAL MESSAGE] %zu octets\n", sizeof(*hdr));
-
- errmsg = nlmsg_inherit(&err->msg);
- print_hdr(ofd, errmsg);
- nlmsg_free(errmsg);
- } else if (nlmsg_len(hdr) > 0) {
+ if (hdr->nlmsg_type == NLMSG_ERROR)
+ dump_error_msg(msg, ofd);
+ else if (nlmsg_len(hdr) > 0) {
struct nl_cache_ops *ops;
int payloadlen = nlmsg_len(hdr);
int attrlen = 0;