From 3c120ef5f199ed2c3cc315cf5f704b8ec886d31f Mon Sep 17 00:00:00 2001 From: Jeremy Sowden Date: Sun, 25 Oct 2020 14:15:53 +0100 Subject: [PATCH] pknlusr: do not treat recv return value of zero as an error A return-value of zero is not an error, so there is no point calling perror, but since we have not requested and do not expect a zero-length datagram, we treat it as EOF and exit. Signed-off-by: Jeremy Sowden --- extensions/pknock/pknlusr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pknock/pknlusr.c b/extensions/pknock/pknlusr.c index 16a9af9..81cfae0 100644 --- a/extensions/pknock/pknlusr.c +++ b/extensions/pknock/pknlusr.c @@ -51,10 +51,12 @@ int main(void) memset(nlmsg, 0, nlmsg_size); status = recv(sock_fd, nlmsg, nlmsg_size, 0); - if (status <= 0) { + if (status < 0) { perror("recv()"); return 1; } + if (status == 0) + break; cn_msg = NLMSG_DATA(nlmsg); pknock_msg = (struct xt_pknock_nl_msg *)(cn_msg->data); ip = inet_ntop(AF_INET, &pknock_msg->peer_ip, ipbuf, sizeof(ipbuf)); -- 2.47.2