diff mbox

[libmnl] nlmsg: Improve payload printing

Message ID 1465377477-6436-1-git-send-email-carlosfg@riseup.net
State Accepted
Headers show

Commit Message

Carlos Falgueras García June 8, 2016, 9:17 a.m. UTC
It make more sense to use "isprint" than "isalnum" because we use non
alphanumeric characters like '%', '_', etc. And, in case of non printable
character, print a space is preferable to print a NULL (0) in order to keep
alignment.

Before:
...
|00012|--|00002|	|len |flags| type|
| 5f 5f 73 65  |	|      data      |	   s e
| 74 25 64 00  |	|      data      |	 t  d
...

After:
...
|00012|--|00002|	|len |flags| type|
| 5f 5f 73 65  |	|      data      |	 _ _ s e
| 74 25 64 00  |	|      data      |	 t % d
...

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
---
 src/nlmsg.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/src/nlmsg.c b/src/nlmsg.c
index fd2f698..5dfbd88 100644
--- a/src/nlmsg.c
+++ b/src/nlmsg.c
@@ -317,10 +317,10 @@  mnl_nlmsg_fprintf_payload(FILE *fd, const struct nlmsghdr *nlh,
 				0xff & b[i+2],	0xff & b[i+3]);
 			fprintf(fd, "|      data      |");
 			fprintf(fd, "\t %c %c %c %c\n",
-				isalnum(b[i]) ? b[i] : 0,
-				isalnum(b[i+1]) ? b[i+1] : 0,
-				isalnum(b[i+2]) ? b[i+2] : 0,
-				isalnum(b[i+3]) ? b[i+3] : 0);
+				isprint(b[i]) ? b[i] : ' ',
+				isprint(b[i+1]) ? b[i+1] : ' ',
+				isprint(b[i+2]) ? b[i+2] : ' ',
+				isprint(b[i+3]) ? b[i+3] : ' ');
 		}
 	}
 	fprintf(fd, "----------------\t------------------\n");