(root)/
strace-6.5/
tests-mx32/
nlattr_dcbmsg.c
       1  /*
       2   * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
       3   * Copyright (c) 2017-2021 The strace developers.
       4   * All rights reserved.
       5   *
       6   * SPDX-License-Identifier: GPL-2.0-or-later
       7   */
       8  
       9  #include "tests.h"
      10  #include <stdio.h>
      11  #include "test_nlattr.h"
      12  #include <linux/dcbnl.h>
      13  #include <linux/rtnetlink.h>
      14  
      15  static void
      16  init_dcbmsg(struct nlmsghdr *const nlh, const unsigned int msg_len)
      17  {
      18  	SET_STRUCT(struct nlmsghdr, nlh,
      19  		.nlmsg_len = msg_len,
      20  		.nlmsg_type = RTM_GETDCB,
      21  		.nlmsg_flags = NLM_F_DUMP
      22  	);
      23  
      24  	struct dcbmsg *const msg = NLMSG_DATA(nlh);
      25  	SET_STRUCT(struct dcbmsg, msg,
      26  		.dcb_family = AF_UNIX,
      27  		.cmd = DCB_CMD_UNDEFINED
      28  	);
      29  }
      30  
      31  static void
      32  print_dcbmsg(const unsigned int msg_len)
      33  {
      34  	printf("{nlmsg_len=%u, nlmsg_type=RTM_GETDCB, nlmsg_flags=NLM_F_DUMP"
      35  	       ", nlmsg_seq=0, nlmsg_pid=0}, {dcb_family=AF_UNIX"
      36  	       ", cmd=DCB_CMD_UNDEFINED}",
      37  	       msg_len);
      38  }
      39  
      40  int
      41  main(void)
      42  {
      43  	skip_if_unavailable("/proc/self/fd/");
      44  
      45  	const int fd = create_nl_socket(NETLINK_ROUTE);
      46  	const unsigned int hdrlen = sizeof(struct dcbmsg);
      47  	void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 4);
      48  
      49  	static char pattern[4096];
      50  	fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
      51  
      52  	const unsigned int nla_type = 0xffff & NLA_TYPE_MASK;
      53  	char nla_type_str[256];
      54  	sprintf(nla_type_str, "%#x /* DCB_ATTR_??? */", nla_type);
      55  	TEST_NLATTR_(fd, nlh0, hdrlen,
      56  		     init_dcbmsg, print_dcbmsg,
      57  		     nla_type, nla_type_str,
      58  		     4, pattern, 4,
      59  		     print_quoted_hex(pattern, 4));
      60  
      61  	puts("+++ exited with 0 +++");
      62  	return 0;
      63  }