mirror of https://github.com/mkerrisk/man-pages
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>
This commit is contained in:
parent
29dee4ce10
commit
bc766f2c0c
|
@ -753,9 +753,7 @@ static int
|
||||||
receive_responses(int fd)
|
receive_responses(int fd)
|
||||||
{
|
{
|
||||||
long buf[8192 / sizeof(long)];
|
long buf[8192 / sizeof(long)];
|
||||||
struct sockaddr_nl nladdr = {
|
struct sockaddr_nl nladdr;
|
||||||
.nl_family = AF_NETLINK
|
|
||||||
};
|
|
||||||
struct iovec iov = {
|
struct iovec iov = {
|
||||||
.iov_base = buf,
|
.iov_base = buf,
|
||||||
.iov_len = sizeof(buf)
|
.iov_len = sizeof(buf)
|
||||||
|
@ -782,6 +780,11 @@ receive_responses(int fd)
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (nladdr.nl_family != AF_NETLINK) {
|
||||||
|
fputs("!AF_NETLINK\en", stderr);
|
||||||
|
return \-1;
|
||||||
|
}
|
||||||
|
|
||||||
const struct nlmsghdr *h = (struct nlmsghdr *) buf;
|
const struct nlmsghdr *h = (struct nlmsghdr *) buf;
|
||||||
|
|
||||||
if (!NLMSG_OK(h, ret)) {
|
if (!NLMSG_OK(h, ret)) {
|
||||||
|
|
Loading…
Reference in New Issue