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 starts running



details:   https://anonhg.NetBSD.org/src/rev/e620c0edf518
branches:  trunk
changeset: 820059:e620c0edf518
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Dec 28 03:02:54 2016 +0000

description:
starts running

diffstat:

 usr.sbin/npf/npfd/npfd.c     |   7 ++++---
 usr.sbin/npf/npfd/npfd_log.c |  17 +++++++++++++----
 2 files changed, 17 insertions(+), 7 deletions(-)

diffs (88 lines):

diff -r 7a0b764d0c6f -r e620c0edf518 usr.sbin/npf/npfd/npfd.c
--- a/usr.sbin/npf/npfd/npfd.c  Wed Dec 28 02:44:59 2016 +0000
+++ b/usr.sbin/npf/npfd/npfd.c  Wed Dec 28 03:02:54 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npfd.c,v 1.2 2016/12/28 01:25:48 christos Exp $        */
+/*     $NetBSD: npfd.c,v 1.3 2016/12/28 03:02:54 christos Exp $        */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: npfd.c,v 1.2 2016/12/28 01:25:48 christos Exp $");
+__RCSID("$NetBSD: npfd.c,v 1.3 2016/12/28 03:02:54 christos Exp $");
 
 #include <stdio.h>
 #include <fcntl.h>
@@ -76,6 +76,8 @@
        npfd_log_t *log;
 
        log = npfd_log_create(0);
+       if (log == NULL)
+               exit(EXIT_FAILURE);
        pfd.fd = npfd_log_getsock(log);
        pfd.events = POLLHUP | POLLIN;
 
@@ -105,7 +107,6 @@
 }
 
 static void
-/*###114 [cc] error: 'sighandler' defined but not used [-Werror=unused-function]%%%*/
 sighandler(int sig)
 {
        switch (sig) {
diff -r 7a0b764d0c6f -r e620c0edf518 usr.sbin/npf/npfd/npfd_log.c
--- a/usr.sbin/npf/npfd/npfd_log.c      Wed Dec 28 02:44:59 2016 +0000
+++ b/usr.sbin/npf/npfd/npfd_log.c      Wed Dec 28 03:02:54 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npfd_log.c,v 1.2 2016/12/28 01:25:48 christos Exp $    */
+/*     $NetBSD: npfd_log.c,v 1.3 2016/12/28 03:02:54 christos Exp $    */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: npfd_log.c,v 1.2 2016/12/28 01:25:48 christos Exp $");
+__RCSID("$NetBSD: npfd_log.c,v 1.3 2016/12/28 03:02:54 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -40,6 +40,7 @@
 #include <inttypes.h>
 #include <limits.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <syslog.h>
 #include <stdbool.h>
 
@@ -80,6 +81,11 @@
 
        pcap_set_snaplen(ctx->pcap, 10240);
 
+       if (pcap_activate(ctx->pcap) == -1) {
+               syslog(LOG_ERR, "pcap_activate failed: %s",
+                   pcap_geterr(ctx->pcap));
+               goto err;
+       }
        snprintf(ctx->path, sizeof(ctx->path), "%s/%s%s",
            NPFD_LOG_PATH, ctx->ifname, ".pcap");
 
@@ -100,9 +106,12 @@
        /*
         * Open a log file to write for a given interface and dump there.
         */
-       ctx->dumper = pcap_dump_open_append(ctx->pcap, ctx->path);
+       if (access(ctx->path, F_OK) == 0)
+               ctx->dumper = pcap_dump_open_append(ctx->pcap, ctx->path);
+       else
+               ctx->dumper = pcap_dump_open(ctx->pcap, ctx->path);
        if (ctx->dumper == NULL) {
-               syslog(LOG_ERR, "pcap_dump_open_append failed for `%s': %s",
+               syslog(LOG_ERR, "pcap_dump_open failed for `%s': %s",
                    ctx->path, pcap_geterr(ctx->pcap));
                return false;
        }



Home | Main Index | Thread Index | Old Index