]> granicus.if.org Git - strace/blobdiff - tests/netlink_protocol.c
tests: extend TEST_NETLINK_OBJECT macro
[strace] / tests / netlink_protocol.c
index a3e09cb9a632f5b3cec69aaa098ee4f25ce7f01c..be1a6528a95a335e302d93b640bbcd56815ed0c8 100644 (file)
@@ -156,7 +156,7 @@ send_query(const int fd)
        printf("sendto(%d, [{{len=%u, type=NLMSG_NOOP, flags=NLM_F_REQUEST|0x%x"
               ", seq=0, pid=0}, \"\\x61\\x62\\x63\\x64\"}, ",
               fd, reqs->req1.nlh.nlmsg_len, NLM_F_DUMP);
-       print_quoted_hex((void *) &reqs->req2.nlh,
+       print_quoted_hex(&reqs->req2.nlh,
                         sizeof(reqs->req2) - sizeof(req->nlh));
        printf("], %u, MSG_DONTWAIT, NULL, 0) = %s\n",
               (unsigned) (sizeof(*reqs) - sizeof(req->nlh)), errstr);
@@ -363,6 +363,45 @@ test_nlmsg_done(const int fd)
               fd, nlh->nlmsg_len, num, nlh->nlmsg_len, sprintrc(rc));
 }
 
+#if defined NLM_F_CAPPED || defined NLM_F_ACK_TLVS
+static void
+test_ack_flags(const int fd)
+{
+       long rc;
+       struct nlmsghdr nlh = {
+               .nlmsg_len = sizeof(nlh),
+               .nlmsg_type = NLMSG_ERROR,
+       };
+
+#ifdef NLM_F_CAPPED
+       nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_CAPPED,
+       rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+       printf("sendto(%d, {len=%u, type=NLMSG_ERROR"
+              ", flags=NLM_F_REQUEST|NLM_F_CAPPED, seq=0, pid=0}"
+              ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+              fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+#endif
+
+#ifdef NLM_F_ACK_TLVS
+       nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK_TLVS;
+       rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+       printf("sendto(%d, {len=%u, type=NLMSG_ERROR"
+              ", flags=NLM_F_REQUEST|NLM_F_ACK_TLVS, seq=0, pid=0}"
+              ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+              fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+#endif
+
+#if defined NLM_F_CAPPED && defined NLM_F_ACK_TLVS
+       nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_CAPPED | NLM_F_ACK_TLVS;
+       rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+       printf("sendto(%d, {len=%u, type=NLMSG_ERROR"
+              ", flags=NLM_F_REQUEST|NLM_F_CAPPED|NLM_F_ACK_TLVS, seq=0, pid=0}"
+              ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
+              fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+#endif
+}
+#endif
+
 int main(void)
 {
        const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
@@ -378,6 +417,9 @@ int main(void)
        send_query(fd);
        test_nlmsgerr(fd);
        test_nlmsg_done(fd);
+#if defined NLM_F_CAPPED || defined NLM_F_ACK_TLVS
+       test_ack_flags(fd);
+#endif
 
        puts("+++ exited with 0 +++");
        return 0;