|
29 | 29 | #include "tests.h" |
30 | 30 |
|
31 | 31 | #include <stdio.h> |
| 32 | +#include <netinet/in.h> |
| 33 | +#include <arpa/inet.h> |
32 | 34 | #include "test_nlattr.h" |
33 | 35 | #ifdef HAVE_LINUX_NEIGHBOUR_H |
34 | 36 | # include <linux/neighbour.h> |
35 | 37 | #endif |
36 | 38 | #include <linux/rtnetlink.h> |
37 | 39 |
|
| 40 | +#define NDA_PORT 6 |
| 41 | + |
38 | 42 | static void |
39 | 43 | init_ndmsg(struct nlmsghdr *const nlh, const unsigned int msg_len) |
40 | 44 | { |
@@ -87,6 +91,33 @@ main(void) |
87 | 91 | 4, pattern, 4, |
88 | 92 | print_quoted_hex(pattern, 4)); |
89 | 93 |
|
| 94 | + TEST_NLATTR(fd, nlh0, hdrlen, |
| 95 | + init_ndmsg, print_ndmsg, |
| 96 | + NDA_DST, 4, pattern, 4, |
| 97 | + print_quoted_hex(pattern, 4)); |
| 98 | + |
| 99 | + static const struct nda_cacheinfo ci = { |
| 100 | + .ndm_confirmed = 0xabcdedad, |
| 101 | + .ndm_used = 0xbcdaedad, |
| 102 | + .ndm_updated = 0xcdbadeda, |
| 103 | + .ndm_refcnt = 0xdeadbeda |
| 104 | + }; |
| 105 | + |
| 106 | + TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, |
| 107 | + init_ndmsg, print_ndmsg, |
| 108 | + NDA_CACHEINFO, pattern, ci, |
| 109 | + PRINT_FIELD_U("{", ci, ndm_confirmed); |
| 110 | + PRINT_FIELD_U(", ", ci, ndm_used); |
| 111 | + PRINT_FIELD_U(", ", ci, ndm_updated); |
| 112 | + PRINT_FIELD_U(", ", ci, ndm_refcnt); |
| 113 | + printf("}")); |
| 114 | + |
| 115 | + const uint16_t port = 0xabcd; |
| 116 | + TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, |
| 117 | + init_ndmsg, print_ndmsg, |
| 118 | + NDA_PORT, pattern, port, |
| 119 | + printf("htons(%u)", ntohs(port))); |
| 120 | + |
90 | 121 | puts("+++ exited with 0 +++"); |
91 | 122 | return 0; |
92 | 123 | } |
0 commit comments