From d396a91d898f0d3038032782be961bf7050f38bd Mon Sep 17 00:00:00 2001 From: JingPiao Chen Date: Mon, 28 Aug 2017 00:56:41 +0800 Subject: [PATCH] tests: check decoding of ndmsg netlink attributes * tests/nlattr_ndmsg.c: Include and . (NDA_PORT): New macro. (main): Check decoding of NDA_DST, NDA_CACHEINFO and NDA_PORT. --- tests/nlattr_ndmsg.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/nlattr_ndmsg.c b/tests/nlattr_ndmsg.c index 67aee883..8538a827 100644 --- a/tests/nlattr_ndmsg.c +++ b/tests/nlattr_ndmsg.c @@ -29,12 +29,16 @@ #include "tests.h" #include +#include +#include #include "test_nlattr.h" #ifdef HAVE_LINUX_NEIGHBOUR_H # include #endif #include +#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; } -- 2.40.0