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>
6 * Copyright (c) 2016-2018 The strace developers.
9 * SPDX-License-Identifier: GPL-2.0-or-later
19 #include <sys/socket.h>
21 #include <linux/sock_diag.h>
22 #include <linux/netlink_diag.h>
27 skip_if_unavailable("/proc/self/fd/");
29 struct sockaddr_nl addr = {
30 .nl_family = AF_NETLINK,
33 struct sockaddr *const sa = tail_memdup(&addr, sizeof(addr));
34 TAIL_ALLOC_OBJECT_CONST_PTR(socklen_t, len);
37 const int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG);
39 perror_msg_and_skip("socket");
40 const unsigned long inode = inode_of_sockfd(fd);
41 printf("socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG) = "
42 "%d<NETLINK:[%lu]>\n", fd, inode);
44 if (bind(fd, sa, *len))
45 perror_msg_and_skip("bind");
46 printf("bind(%d<NETLINK:[%lu]>, {sa_family=AF_NETLINK"
47 ", nl_pid=%u, nl_groups=00000000}, %u) = 0\n",
48 fd, inode, addr.nl_pid, (unsigned) *len);
50 if (getsockname(fd, sa, len))
51 perror_msg_and_fail("getsockname");
52 printf("getsockname(%d<NETLINK:[SOCK_DIAG:%u]>, {sa_family=AF_NETLINK"
53 ", nl_pid=%u, nl_groups=00000000}, [%u]) = 0\n",
54 fd, addr.nl_pid, addr.nl_pid, (unsigned) *len);
57 perror_msg_and_fail("close");
58 printf("close(%d<NETLINK:[SOCK_DIAG:%u]>) = 0\n", fd, addr.nl_pid);
60 puts("+++ exited with 0 +++");