Quick background: In pflogd(8), the if_exists() function tests if a given pflogX interface exists. It returns 1 (if it exists) or 0 (if not).
This diff fixes two issues with if_exists(): 1. if_exists() opens a socket to test the pflogX interface exists. If the interface does not exist, the function will return without closing that socket. 2. There is an incorrect call to if_exists() in the code: if (!if_exists(interface) == -1) { Comments/OK? Lawrence Index: pflogd.c =================================================================== RCS file: /cvs/src/sbin/pflogd/pflogd.c,v retrieving revision 1.48 diff -U4 -p -r1.48 pflogd.c --- pflogd.c 5 Mar 2012 11:50:16 -0000 1.48 +++ pflogd.c 3 Nov 2012 18:31:43 -0000 @@ -202,9 +202,9 @@ set_pcap_filter(void) int if_exists(char *ifname) { - int s; + int s, ret = 1; struct ifreq ifr; struct if_data ifrdat; if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) @@ -214,13 +214,13 @@ if_exists(char *ifname) sizeof(ifr.ifr_name)) errx(1, "main ifr_name: strlcpy"); ifr.ifr_data = (caddr_t)&ifrdat; if (ioctl(s, SIOCGIFDATA, (caddr_t)&ifr) == -1) - return (0); + ret = 0; if (close(s)) err(1, "close"); - return (1); + return (ret); } int init_pcap(void) @@ -689,9 +689,9 @@ main(int argc, char **argv) while (1) { np = pcap_dispatch(hpcap, PCAP_NUM_PKTS, phandler, (u_char *)dpcap); if (np < 0) { - if (!if_exists(interface) == -1) { + if (!if_exists(interface)) { logmsg(LOG_NOTICE, "interface %s went away", interface); ret = -1; break;