(root)/
strace-6.5/
tests-m32/
nlattr_rtgenmsg.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  
      11  #include <stdio.h>
      12  #include "netlink.h"
      13  #include <linux/rtnetlink.h>
      14  #include "test_nlattr.h"
      15  
      16  static void
      17  init_rtgenmsg(struct nlmsghdr *const nlh, const unsigned int msg_len)
      18  {
      19  	SET_STRUCT(struct nlmsghdr, nlh,
      20  		.nlmsg_len = msg_len,
      21  		.nlmsg_type = RTM_GETNSID,
      22  		.nlmsg_flags = NLM_F_DUMP
      23  	);
      24  
      25  	struct rtgenmsg *const msg = NLMSG_DATA(nlh);
      26  	SET_STRUCT(struct rtgenmsg, msg,
      27  		.rtgen_family = AF_UNIX
      28  	);
      29  }
      30  
      31  static void
      32  print_rtgenmsg(const unsigned int msg_len)
      33  {
      34  	printf("{nlmsg_len=%u, nlmsg_type=RTM_GETNSID, nlmsg_flags=NLM_F_DUMP"
      35  	       ", nlmsg_seq=0, nlmsg_pid=0}, {rtgen_family=AF_UNIX}",
      36  	       msg_len);
      37  }
      38  
      39  int
      40  main(void)
      41  {
      42  	skip_if_unavailable("/proc/self/fd/");
      43  
      44  	const int fd = create_nl_socket(NETLINK_ROUTE);
      45  	const unsigned int hdrlen = sizeof(struct rtgenmsg);
      46  	const unsigned int nla_type = 0xffff & NLA_TYPE_MASK;
      47  	char nla_type_str[256];
      48  	void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
      49  				   NLA_HDRLEN + sizeof(nla_type_str));
      50  
      51  	static char pattern[4096];
      52  	fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
      53  
      54  	sprintf(nla_type_str, "%#x /* NETNSA_??? */", nla_type);
      55  	TEST_NLATTR_(fd, nlh0, hdrlen,
      56  		     init_rtgenmsg, print_rtgenmsg,
      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  }