2 * Copyright (c) 2017-2018 The strace developers.
5 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "print_fields.h"
14 #include <sys/socket.h>
17 #define TEST_NETLINK_(fd_, nlh0_, \
20 data_len_, src_, slen_, ...) \
22 struct nlmsghdr *const TEST_NETLINK_nlh = \
24 const unsigned int msg_len = \
25 NLMSG_HDRLEN + (data_len_); \
27 SET_STRUCT(struct nlmsghdr, TEST_NETLINK_nlh, \
28 .nlmsg_len = msg_len, \
29 .nlmsg_type = (type_), \
30 .nlmsg_flags = (flags_) \
32 memcpy(NLMSG_DATA(TEST_NETLINK_nlh), (src_), (slen_)); \
34 const char *const errstr = \
35 sprintrc(sendto((fd_), TEST_NETLINK_nlh, \
36 msg_len, MSG_DONTWAIT, \
39 printf("sendto(%d, {{len=%u, type=%s" \
40 ", flags=%s, seq=0, pid=0}, ", \
41 (fd_), msg_len, (type_str_), (flags_str_)); \
45 printf("}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", \
49 #define TEST_NETLINK(fd_, nlh0_, type_, flags_, \
50 data_len_, src_, slen_, ...) \
51 TEST_NETLINK_((fd_), (nlh0_), \
54 (data_len_), (src_), (slen_), __VA_ARGS__)
56 #define TEST_NETLINK_OBJECT_EX_(fd_, nlh0_, \
59 obj_, fallback_func, ...) \
61 char pattern[DEFAULT_STRLEN]; \
62 fill_memory_ex(pattern, sizeof(pattern), \
63 'a', 'z' - 'a' + 1); \
64 const unsigned int plen = \
65 sizeof(obj_) - 1 > DEFAULT_STRLEN \
66 ? DEFAULT_STRLEN : (int) sizeof(obj_) - 1; \
67 /* len < sizeof(obj_) */ \
68 TEST_NETLINK_((fd_), (nlh0_), \
69 (type_), (type_str_), \
70 (flags_), (flags_str_), \
71 plen, pattern, plen, \
72 (fallback_func)(pattern, plen)); \
73 /* short read of sizeof(obj_) */ \
74 TEST_NETLINK_((fd_), (nlh0_), \
75 (type_), (type_str_), \
76 (flags_), (flags_str_), \
80 NLMSG_DATA(TEST_NETLINK_nlh))); \
82 TEST_NETLINK_((fd_), (nlh0_), \
83 (type_), (type_str_), \
84 (flags_), (flags_str_), \
86 &(obj_), sizeof(obj_), \
90 #define TEST_NETLINK_OBJECT_EX(fd_, nlh0_, \
92 obj_, fallback_func, ...) \
93 TEST_NETLINK_OBJECT_EX_((fd_), (nlh0), \
96 (obj_), (fallback_func), __VA_ARGS__)
98 #define TEST_NETLINK_OBJECT(fd_, nlh0_, \
101 TEST_NETLINK_OBJECT_EX_((fd_), (nlh0), \
104 (obj_), print_quoted_hex, __VA_ARGS__)