diff options
author | JingPiao Chen <chenjingpiao@gmail.com> | 2017-05-05 18:21:17 +0800 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2017-06-04 13:17:06 +0000 |
commit | 852046ce0e456e5e411d7d93dcc5e4a44bae7d30 (patch) | |
tree | e0d840a8f7c586d94679be75f968b3c63ed6c552 /tests/netlink_protocol.c | |
parent | 982d03464ce17f607674c378f19180d1f177e1d3 (diff) | |
download | strace-852046ce0e456e5e411d7d93dcc5e4a44bae7d30.tar.gz |
netlink: decode NLMSG_DONE messages
* netlink.c (decode_payload): Decode NLMSG_DONE messages.
* tests/netlink_protocol.c (test_nlmsg_done): New function
for checking decoding of NLMSG_DONE messages.
(main): Use it.
Diffstat (limited to 'tests/netlink_protocol.c')
-rw-r--r-- | tests/netlink_protocol.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/netlink_protocol.c b/tests/netlink_protocol.c index 35f954fdb..121c83d09 100644 --- a/tests/netlink_protocol.c +++ b/tests/netlink_protocol.c @@ -314,6 +314,42 @@ test_nlmsgerr(const int fd) nlh->nlmsg_len, sprintrc(rc)); } +static void +test_nlmsg_done(const int fd) +{ + struct nlmsghdr *nlh; + int total_len; + void *const nlh0 = tail_alloc(NLMSG_HDRLEN); + long rc; + + nlh = nlh0; + nlh->nlmsg_len = NLMSG_HDRLEN + sizeof(int); + nlh->nlmsg_type = NLMSG_DONE; + nlh->nlmsg_flags = NLM_F_MULTI; + nlh->nlmsg_seq = 0; + nlh->nlmsg_pid = 0; + + rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0); + printf("sendto(%d, {{len=%u, type=NLMSG_DONE, flags=NLM_F_MULTI" + ", seq=0, pid=0}, %p}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, nlh->nlmsg_len, nlh0 + NLMSG_HDRLEN, + nlh->nlmsg_len, sprintrc(rc)); + + nlh = nlh0 - sizeof(int); + nlh->nlmsg_len = NLMSG_HDRLEN + sizeof(int); + nlh->nlmsg_type = NLMSG_DONE; + nlh->nlmsg_flags = NLM_F_MULTI; + nlh->nlmsg_seq = 0; + nlh->nlmsg_pid = 0; + total_len = nlh->nlmsg_len; + memcpy(NLMSG_DATA(nlh), &total_len, sizeof(total_len)); + + rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0); + printf("sendto(%d, {{len=%u, type=NLMSG_DONE, flags=NLM_F_MULTI" + ", seq=0, pid=0}, %d}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, nlh->nlmsg_len, nlh->nlmsg_len, total_len, sprintrc(rc)); +} + int main(void) { struct sockaddr_nl addr; @@ -343,6 +379,7 @@ int main(void) send_query(fd); test_nlmsgerr(fd); + test_nlmsg_done(fd); printf("+++ exited with 0 +++\n"); |