From a10a4d9291181a142ff85b0db8f2907cd05b978f Mon Sep 17 00:00:00 2001 From: Alessandro Vesely Date: Sun, 7 Nov 2010 21:38:31 +0100 Subject: utils: document ENOBUFS in nfqnl_test.c This patch documents the ENOBUFS error in the example file, that is a common problem is that question over and over again in the mailing list. I (Pablo) have mangled this patch with some comestic cleanups. BTW, Mistick Levi sent a similar patch in the same timeline (amazing how sometimes the same works can clash). Signed-off-by: Alessandro Vesely Signed-off-by: Pablo Neira Ayuso --- utils/nfqnl_test.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'utils') diff --git a/utils/nfqnl_test.c b/utils/nfqnl_test.c index 9eebd9b..a554f2d 100644 --- a/utils/nfqnl_test.c +++ b/utils/nfqnl_test.c @@ -5,6 +5,7 @@ #include #include #include /* for NF_ACCEPT */ +#include #include @@ -115,9 +116,25 @@ int main(int argc, char **argv) fd = nfq_fd(h); - while ((rv = recv(fd, buf, sizeof(buf), 0)) && rv >= 0) { - printf("pkt received\n"); - nfq_handle_packet(h, buf, rv); + for (;;) { + if ((rv = recv(fd, buf, sizeof(buf), 0)) >= 0) { + printf("pkt received\n"); + nfq_handle_packet(h, buf, rv); + continue; + } + /* if your application is too slow to digest the packets that + * are sent from kernel-space, the socket buffer that we use + * to enqueue packets may fill up returning ENOBUFS. Depending + * on your application, this error may be ignored. Please, see + * the doxygen documentation of this library on how to improve + * this situation. + */ + if (rv < 0 && errno == ENOBUFS) { + printf("losing packets!\n"); + continue; + } + perror("recv failed"); + break; } printf("unbinding from queue 0\n"); -- cgit v1.2.3