2 * This file is part of net-yy-netlink strace test.
4 * Copyright (c) 2013-2017 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
8 * SPDX-License-Identifier: GPL-2.0-or-later
18 #include <sys/socket.h>
20 #include <linux/sock_diag.h>
21 #include <linux/netlink_diag.h>
26 skip_if_unavailable("/proc/self/fd/");
28 struct sockaddr_nl addr = {
29 .nl_family = AF_NETLINK,
32 struct sockaddr *const sa = tail_memdup(&addr, sizeof(addr));
33 TAIL_ALLOC_OBJECT_CONST_PTR(socklen_t, len);
36 const int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG);
38 perror_msg_and_skip("socket");
39 const unsigned long inode = inode_of_sockfd(fd);
40 printf("socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG) = "
41 "%d<NETLINK:[%lu]>\n", fd, inode);
43 if (bind(fd, sa, *len))
44 perror_msg_and_skip("bind");
45 printf("bind(%d<NETLINK:[%lu]>, {sa_family=AF_NETLINK"
46 ", nl_pid=%u, nl_groups=00000000}, %u) = 0\n",
47 fd, inode, addr.nl_pid, (unsigned) *len);
49 if (getsockname(fd, sa, len))
50 perror_msg_and_fail("getsockname");
51 printf("getsockname(%d<NETLINK:[SOCK_DIAG:%u]>, {sa_family=AF_NETLINK"
52 ", nl_pid=%u, nl_groups=00000000}, [%u]) = 0\n",
53 fd, addr.nl_pid, addr.nl_pid, (unsigned) *len);
56 perror_msg_and_fail("close");
57 printf("close(%d<NETLINK:[SOCK_DIAG:%u]>) = 0\n", fd, addr.nl_pid);
59 puts("+++ exited with 0 +++");