summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlessandro Vesely <vesely@tana.it>2010-11-07 21:38:31 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2010-11-07 21:38:31 +0100
commita10a4d9291181a142ff85b0db8f2907cd05b978f (patch)
treec42ec1855f5f94a29cf0bb98569a1c90cb050da3
parentad9ce553248cedeb3770ea832bf26250b66d4394 (diff)
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 <vesely@tana.it> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--utils/nfqnl_test.c23
1 files changed, 20 insertions, 3 deletions
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 <netinet/in.h>
#include <linux/types.h>
#include <linux/netfilter.h> /* for NF_ACCEPT */
+#include <errno.h>
#include <libnetfilter_queue/libnetfilter_queue.h>
@@ -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");