diff options
author | Jason Dixon <jdixon@cvs.openbsd.org> | 2007-05-27 20:07:43 +0000 |
---|---|---|
committer | Jason Dixon <jdixon@cvs.openbsd.org> | 2007-05-27 20:07:43 +0000 |
commit | 2bfd6548a7cd8280a832178bb416b2802feb6816 (patch) | |
tree | 0018742fe54caec69fdfb7bfaaa1db1e0701807d /sbin/pflogd | |
parent | 87e5214c0e06622f02dedb2868fd4ce845e57970 (diff) |
Complain to stderr if cloned pflog interface doesn't exist. Previously only logged LOG_ERR to syslog. ok henning@
Diffstat (limited to 'sbin/pflogd')
-rw-r--r-- | sbin/pflogd/pflogd.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/sbin/pflogd/pflogd.c b/sbin/pflogd/pflogd.c index 9232946d6bd..ca7adbbafe3 100644 --- a/sbin/pflogd/pflogd.c +++ b/sbin/pflogd/pflogd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pflogd.c,v 1.39 2007/04/07 07:48:50 jmc Exp $ */ +/* $OpenBSD: pflogd.c,v 1.40 2007/05/27 20:07:42 jdixon Exp $ */ /* * Copyright (c) 2001 Theo de Raadt @@ -34,6 +34,8 @@ #include <sys/ioctl.h> #include <sys/file.h> #include <sys/stat.h> +#include <sys/socket.h> +#include <net/if.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -42,6 +44,7 @@ #include <pcap.h> #include <syslog.h> #include <signal.h> +#include <err.h> #include <errno.h> #include <stdarg.h> #include <fcntl.h> @@ -70,6 +73,7 @@ char *copy_argv(char * const *); void dump_packet(u_char *, const struct pcap_pkthdr *, const u_char *); void dump_packet_nobuf(u_char *, const struct pcap_pkthdr *, const u_char *); int flush_buffer(FILE *); +int if_exists(char *); int init_pcap(void); void logmsg(int, const char *, ...); void purge_buffer(void); @@ -189,6 +193,30 @@ set_pcap_filter(void) } int +if_exists(char *interface) +{ + int s; + struct ifreq ifr; + struct if_data ifrdat; + + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + err(1, "socket"); + bzero(&ifr, sizeof(ifr)); + if (strlcpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)) >= + sizeof(ifr.ifr_name)) + errx(1, "main ifr_name: strlcpy"); + ifr.ifr_data = (caddr_t)&ifrdat; + if (ioctl(s, SIOCGIFDATA, (caddr_t)&ifr) == -1) { + logmsg(LOG_ERR, "Failed to initialize: %s", interface); + return (-1); + } + if (close(s)) + err(1, "close"); + + return (0); +} + +int init_pcap(void) { hpcap = pcap_open_live(interface, snaplen, 1, PCAP_TO_MS, errbuf); @@ -575,6 +603,13 @@ main(int argc, char **argv) argc -= optind; argv += optind; + /* does interface exist */ + if (if_exists(interface)) { + err(1, "Failed to initialize: %s", interface); + logmsg(LOG_ERR, "Exiting, init failure"); + exit(1); + } + if (!Debug) { openlog("pflogd", LOG_PID | LOG_CONS, LOG_DAEMON); if (daemon(0, 0)) { |