]> granicus.if.org Git - strace/commitdiff
tests: check decoding of ndmsg netlink attributes
authorJingPiao Chen <chenjingpiao@gmail.com>
Sun, 27 Aug 2017 16:56:41 +0000 (00:56 +0800)
committerJingPiao Chen <chenjingpiao@gmail.com>
Tue, 29 Aug 2017 07:23:59 +0000 (15:23 +0800)
* tests/nlattr_ndmsg.c: Include <netinet/in.h> and <arpa/inet.h>.
(NDA_PORT): New macro.
(main): Check decoding of NDA_DST, NDA_CACHEINFO and NDA_PORT.

tests/nlattr_ndmsg.c

index 67aee883fe11fa716a9811a65f9b565ae89b1bae..8538a8275235cb29b0c5953c8acb4a12211fbad3 100644 (file)
 #include "tests.h"
 
 #include <stdio.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 #include "test_nlattr.h"
 #ifdef HAVE_LINUX_NEIGHBOUR_H
 # include <linux/neighbour.h>
 #endif
 #include <linux/rtnetlink.h>
 
+#define NDA_PORT 6
+
 static void
 init_ndmsg(struct nlmsghdr *const nlh, const unsigned int msg_len)
 {
@@ -87,6 +91,33 @@ main(void)
                     4, pattern, 4,
                     print_quoted_hex(pattern, 4));
 
+       TEST_NLATTR(fd, nlh0, hdrlen,
+                   init_ndmsg, print_ndmsg,
+                   NDA_DST, 4, pattern, 4,
+                   print_quoted_hex(pattern, 4));
+
+       static const struct nda_cacheinfo ci = {
+               .ndm_confirmed = 0xabcdedad,
+               .ndm_used = 0xbcdaedad,
+               .ndm_updated = 0xcdbadeda,
+               .ndm_refcnt = 0xdeadbeda
+       };
+
+       TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+                          init_ndmsg, print_ndmsg,
+                          NDA_CACHEINFO, pattern, ci,
+                          PRINT_FIELD_U("{", ci, ndm_confirmed);
+                          PRINT_FIELD_U(", ", ci, ndm_used);
+                          PRINT_FIELD_U(", ", ci, ndm_updated);
+                          PRINT_FIELD_U(", ", ci, ndm_refcnt);
+                          printf("}"));
+
+       const uint16_t port = 0xabcd;
+       TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+                          init_ndmsg, print_ndmsg,
+                          NDA_PORT, pattern, port,
+                          printf("htons(%u)", ntohs(port)));
+
        puts("+++ exited with 0 +++");
        return 0;
 }