aboutsummaryrefslogtreecommitdiffstats
path: root/man7
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2021-01-24 16:10:39 +0100
committerMichael Kerrisk <mtk.manpages@gmail.com>2021-01-25 08:01:56 +0100
commitbc766f2c0c7d9eb8bb64c1b22e723945e8abe33a (patch)
tree2dd521288c6cb12857bb3bc2b8c73bfe1d961217 /man7
parent29dee4ce10a37e069200623e2d581a18a673b37d (diff)
downloadman-pages-bc766f2c0c7d9eb8bb64c1b22e723945e8abe33a.tar.gz
sock_diag.7: Fix recvmsg() usage in the example
The msg_name field for recvmsg() call points to a caller-allocated buffer nladdr that is used to return the source address of the (netlink) socket. As recvmsg() does not read this buffer and fills it for a caller, do not initialize it and instead check its value in the example. Signed-off-by: Pali Rohár <pali@kernel.org> Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Diffstat (limited to 'man7')
-rw-r--r--man7/sock_diag.79
1 files changed, 6 insertions, 3 deletions
diff --git a/man7/sock_diag.7 b/man7/sock_diag.7
index 8b4ed340bf..97cab46327 100644
--- a/man7/sock_diag.7
+++ b/man7/sock_diag.7
@@ -753,9 +753,7 @@ static int
receive_responses(int fd)
{
long buf[8192 / sizeof(long)];
- struct sockaddr_nl nladdr = {
- .nl_family = AF_NETLINK
- };
+ struct sockaddr_nl nladdr;
struct iovec iov = {
.iov_base = buf,
.iov_len = sizeof(buf)
@@ -782,6 +780,11 @@ receive_responses(int fd)
if (ret == 0)
return 0;
+ if (nladdr.nl_family != AF_NETLINK) {
+ fputs("!AF_NETLINK\en", stderr);
+ return \-1;
+ }
+
const struct nlmsghdr *h = (struct nlmsghdr *) buf;
if (!NLMSG_OK(h, ret)) {