Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/npf/npfd Handle warnings and errors from pcap_activ...



details:   https://anonhg.NetBSD.org/src/rev/35d8e15632d2
branches:  trunk
changeset: 365875:35d8e15632d2
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Apr 30 13:20:09 2022 +0000

description:
Handle warnings and errors from pcap_activate properly (from bch)

diffstat:

 usr.sbin/npf/npfd/npfd_log.c |  16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diffs (44 lines):

diff -r d42b5e1d904c -r 35d8e15632d2 usr.sbin/npf/npfd/npfd_log.c
--- a/usr.sbin/npf/npfd/npfd_log.c      Sat Apr 30 09:24:05 2022 +0000
+++ b/usr.sbin/npf/npfd/npfd_log.c      Sat Apr 30 13:20:09 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npfd_log.c,v 1.13 2019/02/04 08:21:12 mrg Exp $        */
+/*     $NetBSD: npfd_log.c,v 1.14 2022/04/30 13:20:09 christos Exp $   */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: npfd_log.c,v 1.13 2019/02/04 08:21:12 mrg Exp $");
+__RCSID("$NetBSD: npfd_log.c,v 1.14 2022/04/30 13:20:09 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -246,6 +246,7 @@
 {
        char errbuf[PCAP_ERRBUF_SIZE];
        int snaplen = ctx->snaplen;
+       int rc;
 
        if (ctx->pcap != NULL)
                pcap_close(ctx->pcap);
@@ -277,9 +278,14 @@
                errx(EXIT_FAILURE, "pcap_set_timeout failed: %s",
                    pcap_geterr(ctx->pcap));
 
-       if (pcap_activate(ctx->pcap) == -1)
-               errx(EXIT_FAILURE, "pcap_activate failed: %s",
-                   pcap_geterr(ctx->pcap));
+       if ((rc = pcap_activate(ctx->pcap)) != 0) {
+               const char *msg = pcap_geterr(ctx->pcap);
+               if (rc > 0) {
+                       warnx("pcap_activate warning: %s", msg);
+               } else {
+                       errx(EXIT_FAILURE, "pcap_activate failed: %s", msg);
+               }
+       }
 
        npfd_log_setfilter(ctx);
        return true;



Home | Main Index | Thread Index | Old Index