From d1cca88c8085dd10c0dc1ad17bc241a503f5271d Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 21 Apr 2017 23:01:22 +0000 Subject: [PATCH] tests: fix netlink_protocol on sparc * tests/netlink_protocol.c (test_nlmsgerr): Do not access fields of an unaligned structure, this makes architectures like sparc very unhappy. --- tests/netlink_protocol.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/netlink_protocol.c b/tests/netlink_protocol.c index 03cff929..35f954fd 100644 --- a/tests/netlink_protocol.c +++ b/tests/netlink_protocol.c @@ -221,18 +221,15 @@ test_nlmsgerr(const int fd) fd, nlh->nlmsg_len, nlh0 + NLMSG_HDRLEN, nlh->nlmsg_len, sprintrc(rc)); - nlh = nlh0 - 2; nlh->nlmsg_len = NLMSG_HDRLEN + 2; - nlh->nlmsg_type = NLMSG_ERROR; - nlh->nlmsg_flags = NLM_F_REQUEST; - nlh->nlmsg_seq = 0; - nlh->nlmsg_pid = 0; + nlh = nlh0 - 2; + memmove(nlh, nlh0, sizeof(*nlh)); memcpy(NLMSG_DATA(nlh), "42", 2); - rc = sendto(fd, nlh, nlh->nlmsg_len, MSG_DONTWAIT, NULL, 0); + rc = sendto(fd, nlh, NLMSG_HDRLEN + 2, MSG_DONTWAIT, NULL, 0); printf("sendto(%d, {{len=%u, type=NLMSG_ERROR, flags=NLM_F_REQUEST" ", seq=0, pid=0}, \"42\"}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", - fd, nlh->nlmsg_len, nlh->nlmsg_len, sprintrc(rc)); + fd, NLMSG_HDRLEN + 2, NLMSG_HDRLEN + 2, sprintrc(rc)); /* error message with room for the error code only */ nlh = nlh0 - sizeof(err->error); -- 2.50.1