From: Denis Ovsienko Date: Fri, 18 Apr 2014 21:35:58 +0000 (+0400) Subject: Merge remote-tracking branch 'bpf/master' X-Git-Tag: libpcap-1.6.0-bp~22 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/72ee86ce2c386508bea45df655e0894a6b47973c?hp=f5833fd7e1293735b06960796cf3e1c1a2bf1bf2 Merge remote-tracking branch 'bpf/master' bpf.tcpdump.org and GitHub have diverged again. --- diff --git a/pcap-bpf.c b/pcap-bpf.c index ad897b76..d6bdef61 100644 --- a/pcap-bpf.c +++ b/pcap-bpf.c @@ -1475,7 +1475,7 @@ static int pcap_activate_bpf(pcap_t *p) { struct pcap_bpf *pb = p->priv; - int status = 0; + int status; int fd; #ifdef LIFNAMSIZ char *zonesep; @@ -1679,6 +1679,7 @@ pcap_activate_bpf(pcap_t *p) if (ioctl(fd, BIOCGETZMAX, (caddr_t)&zbufmax) < 0) { snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCGETZMAX: %s", pcap_strerror(errno)); + status = PCAP_ERROR; goto bad; } @@ -1705,6 +1706,7 @@ pcap_activate_bpf(pcap_t *p) if (pb->zbuf1 == MAP_FAILED || pb->zbuf2 == MAP_FAILED) { snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "mmap: %s", pcap_strerror(errno)); + status = PCAP_ERROR; goto bad; } memset(&bz, 0, sizeof(bz)); /* bzero() deprecated, replaced with memset() */ @@ -1714,12 +1716,14 @@ pcap_activate_bpf(pcap_t *p) if (ioctl(fd, BIOCSETZBUF, (caddr_t)&bz) < 0) { snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETZBUF: %s", pcap_strerror(errno)); + status = PCAP_ERROR; goto bad; } (void)strncpy(ifrname, p->opt.source, ifnamsiz); if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) { snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETIF: %s: %s", p->opt.source, pcap_strerror(errno)); + status = PCAP_ERROR; goto bad; } v = pb->zbufsize - sizeof(struct bpf_zbuf_header); @@ -2271,7 +2275,7 @@ pcap_activate_bpf(pcap_t *p) p->stats_op = pcap_stats_bpf; p->cleanup_op = pcap_cleanup_bpf; - return (status); + return (0); bad: pcap_cleanup_bpf(p); return (status); diff --git a/pcap-dlpi.c b/pcap-dlpi.c index 22053bfb..8f44baf6 100644 --- a/pcap-dlpi.c +++ b/pcap-dlpi.c @@ -354,7 +354,7 @@ pcap_activate_dlpi(pcap_t *p) #ifndef HAVE_DEV_DLPI char dname2[100]; #endif - int status = PCAP_ERROR; + int status; #ifdef HAVE_DEV_DLPI /* @@ -392,6 +392,8 @@ pcap_activate_dlpi(pcap_t *p) if ((p->fd = open(cp, O_RDWR)) < 0) { if (errno == EPERM || errno == EACCES) status = PCAP_ERROR_PERM_DENIED; + else + status = PCAP_ERROR; snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s", cp, pcap_strerror(errno)); goto bad; @@ -456,6 +458,8 @@ pcap_activate_dlpi(pcap_t *p) if (errno != ENOENT) { if (errno == EPERM || errno == EACCES) status = PCAP_ERROR_PERM_DENIED; + else + status = PCAP_ERROR; snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s", dname, pcap_strerror(errno)); goto bad; @@ -492,6 +496,8 @@ pcap_activate_dlpi(pcap_t *p) } else { if (errno == EPERM || errno == EACCES) status = PCAP_ERROR_PERM_DENIED; + else + status = PCAP_ERROR; snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s", dname2, pcap_strerror(errno)); } @@ -506,8 +512,10 @@ pcap_activate_dlpi(pcap_t *p) ** Attach if "style 2" provider */ if (dlinforeq(p->fd, p->errbuf) < 0 || - dlinfoack(p->fd, (char *)buf, p->errbuf) < 0) + dlinfoack(p->fd, (char *)buf, p->errbuf) < 0) { + status = PCAP_ERROR; goto bad; + } infop = &(MAKE_DL_PRIMITIVES(buf))->info_ack; #ifdef HAVE_SOLARIS if (infop->dl_mac_type == DL_IPATM) @@ -519,7 +527,8 @@ pcap_activate_dlpi(pcap_t *p) goto bad; #ifdef DL_HP_RAWDLS if (pd->send_fd >= 0) { - if (dl_doattach(pd->send_fd, ppa, p->errbuf) < 0) + status = dl_doattach(pd->send_fd, ppa, p->errbuf); + if (status < 0) goto bad; } #endif @@ -567,22 +576,28 @@ pcap_activate_dlpi(pcap_t *p) */ if ((dlbindreq(p->fd, 1537, p->errbuf) < 0 && dlbindreq(p->fd, 2, p->errbuf) < 0) || - dlbindack(p->fd, (char *)buf, p->errbuf, NULL) < 0) + dlbindack(p->fd, (char *)buf, p->errbuf, NULL) < 0) { + status = PCAP_ERROR; goto bad; + } #elif defined(DL_HP_RAWDLS) /* ** HP-UX 10.0x and 10.1x. */ - if (dl_dohpuxbind(p->fd, p->errbuf) < 0) + if (dl_dohpuxbind(p->fd, p->errbuf) < 0) { + status = PCAP_ERROR; goto bad; + } if (pd->send_fd >= 0) { /* ** XXX - if this fails, just close send_fd and ** set it to -1, so that you can't send but can ** still receive? */ - if (dl_dohpuxbind(pd->send_fd, p->errbuf) < 0) + if (dl_dohpuxbind(pd->send_fd, p->errbuf) < 0) { + status = PCAP_ERROR; goto bad; + } } #else /* neither AIX nor HP-UX */ /* @@ -590,8 +605,10 @@ pcap_activate_dlpi(pcap_t *p) ** OS using DLPI. **/ if (dlbindreq(p->fd, 0, p->errbuf) < 0 || - dlbindack(p->fd, (char *)buf, p->errbuf, NULL) < 0) + dlbindack(p->fd, (char *)buf, p->errbuf, NULL) < 0) { + status = PCAP_ERROR; goto bad; + } #endif /* AIX vs. HP-UX vs. other */ #endif /* !HP-UX 9 and !HP-UX 10.20 or later and !SINIX */ @@ -604,6 +621,7 @@ pcap_activate_dlpi(pcap_t *p) ** help, and may break things. */ if (strioctl(p->fd, A_PROMISCON_REQ, 0, NULL) < 0) { + status = PCAP_ERROR; snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "A_PROMISCON_REQ: %s", pcap_strerror(errno)); goto bad; @@ -667,8 +685,10 @@ pcap_activate_dlpi(pcap_t *p) ** promiscuous options. */ #if defined(HAVE_HPUX9) || defined(HAVE_HPUX10_20_OR_LATER) - if (dl_dohpuxbind(p->fd, p->errbuf) < 0) + if (dl_dohpuxbind(p->fd, p->errbuf) < 0) { + status = PCAP_ERROR; goto bad; + } /* ** We don't set promiscuous mode on the send FD, but we'll defer ** binding it anyway, just to keep the HP-UX 9/10.20 or later @@ -680,8 +700,10 @@ pcap_activate_dlpi(pcap_t *p) ** set it to -1, so that you can't send but can ** still receive? */ - if (dl_dohpuxbind(pd->send_fd, p->errbuf) < 0) + if (dl_dohpuxbind(pd->send_fd, p->errbuf) < 0) { + status = PCAP_ERROR; goto bad; + } } #endif @@ -691,12 +713,16 @@ pcap_activate_dlpi(pcap_t *p) ** when sending packets. */ if (dlinforeq(p->fd, p->errbuf) < 0 || - dlinfoack(p->fd, (char *)buf, p->errbuf) < 0) + dlinfoack(p->fd, (char *)buf, p->errbuf) < 0) { + status = PCAP_ERROR; goto bad; + } infop = &(MAKE_DL_PRIMITIVES(buf))->info_ack; - if (pcap_process_mactype(p, infop->dl_mac_type) != 0) + if (pcap_process_mactype(p, infop->dl_mac_type) != 0) { + status = PCAP_ERROR; goto bad; + } #ifdef DLIOCRAW /* @@ -704,6 +730,7 @@ pcap_activate_dlpi(pcap_t *p) ** header. */ if (strioctl(p->fd, DLIOCRAW, 0, NULL) < 0) { + status = PCAP_ERROR; snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "DLIOCRAW: %s", pcap_strerror(errno)); goto bad; @@ -734,28 +761,31 @@ pcap_activate_dlpi(pcap_t *p) #endif /* Push and configure bufmod. */ - if (pcap_conf_bufmod(p, ss) != 0) + if (pcap_conf_bufmod(p, ss) != 0) { + status = PCAP_ERROR; goto bad; + } #endif /* ** As the last operation flush the read side. */ if (ioctl(p->fd, I_FLUSH, FLUSHR) != 0) { + status = PCAP_ERROR; snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "FLUSHR: %s", pcap_strerror(errno)); goto bad; } /* Allocate data buffer. */ - if (pcap_alloc_databuf(p) != 0) + if (pcap_alloc_databuf(p) != 0) { + status = PCAP_ERROR; goto bad; - - /* Success - but perhaps with a warning */ - if (status < 0) - status = 0; + } /* + * Success. + * * "p->fd" is an FD for a STREAMS device, so "select()" and * "poll()" should work on it. */ @@ -771,7 +801,7 @@ pcap_activate_dlpi(pcap_t *p) p->stats_op = pcap_stats_dlpi; p->cleanup_op = pcap_cleanup_dlpi; - return (status); + return (0); bad: pcap_cleanup_dlpi(p); return (status); diff --git a/pcap-libdlpi.c b/pcap-libdlpi.c index 93d90210..4ed8b986 100644 --- a/pcap-libdlpi.c +++ b/pcap-libdlpi.c @@ -99,7 +99,7 @@ pcap_activate_libdlpi(pcap_t *p) int retv; dlpi_handle_t dh; dlpi_info_t dlinfo; - int err = PCAP_ERROR; + int err; /* * Enable Solaris raw and passive DLPI extensions; @@ -113,6 +113,8 @@ pcap_activate_libdlpi(pcap_t *p) else if (retv == DL_SYSERR && (errno == EPERM || errno == EACCES)) err = PCAP_ERROR_PERM_DENIED; + else + err = PCAP_ERROR; pcap_libdlpi_err(p->opt.source, "dlpi_open", retv, p->errbuf); return (err); @@ -130,6 +132,7 @@ pcap_activate_libdlpi(pcap_t *p) /* Bind with DLPI_ANY_SAP. */ if ((retv = dlpi_bind(pd->dlpi_hd, DLPI_ANY_SAP, 0)) != DLPI_SUCCESS) { + err = PCAP_ERROR; pcap_libdlpi_err(p->opt.source, "dlpi_bind", retv, p->errbuf); goto bad; } @@ -177,31 +180,39 @@ pcap_activate_libdlpi(pcap_t *p) /* Determine link type. */ if ((retv = dlpi_info(pd->dlpi_hd, &dlinfo, 0)) != DLPI_SUCCESS) { + err = PCAP_ERROR; pcap_libdlpi_err(p->opt.source, "dlpi_info", retv, p->errbuf); goto bad; } - if (pcap_process_mactype(p, dlinfo.di_mactype) != 0) + if (pcap_process_mactype(p, dlinfo.di_mactype) != 0) { + err = PCAP_ERROR; goto bad; + } p->fd = dlpi_fd(pd->dlpi_hd); /* Push and configure bufmod. */ - if (pcap_conf_bufmod(p, p->snapshot) != 0) + if (pcap_conf_bufmod(p, p->snapshot) != 0) { + err = PCAP_ERROR; goto bad; + } /* * Flush the read side. */ if (ioctl(p->fd, I_FLUSH, FLUSHR) != 0) { + err = PCAP_ERROR; snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "FLUSHR: %s", pcap_strerror(errno)); goto bad; } /* Allocate data buffer. */ - if (pcap_alloc_databuf(p) != 0) + if (pcap_alloc_databuf(p) != 0) { + err = PCAP_ERROR; goto bad; + } /* * "p->fd" is a FD for a STREAMS device, so "select()" and