(root)/
strace-6.5/
tests-m32/
nfnetlink_ipset.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 <sys/socket.h>
      12  #include "netlink.h"
      13  #include <linux/netfilter/nfnetlink.h>
      14  #include <linux/netfilter/ipset/ip_set.h>
      15  
      16  static void
      17  test_nlmsg_type(const int fd)
      18  {
      19  	long rc;
      20  	struct nlmsghdr nlh = {
      21  		.nlmsg_len = sizeof(nlh),
      22  		.nlmsg_flags = NLM_F_REQUEST,
      23  	};
      24  
      25  	nlh.nlmsg_type = NFNL_SUBSYS_IPSET << 8 | IPSET_CMD_NONE;
      26  	rc = sendto(fd, &nlh, nlh.nlmsg_len, MSG_DONTWAIT, NULL, 0);
      27  	printf("sendto(%d, {nlmsg_len=%u"
      28  	       ", nlmsg_type=NFNL_SUBSYS_IPSET<<8|IPSET_CMD_NONE"
      29  	       ", nlmsg_flags=NLM_F_REQUEST, nlmsg_seq=0, nlmsg_pid=0}"
      30  	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
      31  	       fd, nlh.nlmsg_len, nlh.nlmsg_len, sprintrc(rc));
      32  
      33  	nlh.nlmsg_type = NFNL_SUBSYS_IPSET << 8 | 0xff;
      34  	rc = sendto(fd, &nlh, nlh.nlmsg_len, MSG_DONTWAIT, NULL, 0);
      35  	printf("sendto(%d, {nlmsg_len=%u"
      36  	       ", nlmsg_type=NFNL_SUBSYS_IPSET<<8|0xff /* IPSET_CMD_??? */"
      37  	       ", nlmsg_flags=NLM_F_REQUEST, nlmsg_seq=0, nlmsg_pid=0}"
      38  	       ", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
      39  	       fd, nlh.nlmsg_len, nlh.nlmsg_len, sprintrc(rc));
      40  }
      41  
      42  int
      43  main(void)
      44  {
      45  	skip_if_unavailable("/proc/self/fd/");
      46  
      47  	int fd = create_nl_socket(NETLINK_NETFILTER);
      48  
      49  	test_nlmsg_type(fd);
      50  
      51  	puts("+++ exited with 0 +++");
      52  
      53  	return 0;
      54  }