pcap_activate_bpf(pcap_t *p)
{
struct pcap_bpf *pb = p->priv;
- int status = 0;
+ int status;
int fd;
#ifdef LIFNAMSIZ
char *zonesep;
if (ioctl(fd, BIOCGETZMAX, (caddr_t)&zbufmax) < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCGETZMAX: %s",
pcap_strerror(errno));
+ status = PCAP_ERROR;
goto bad;
}
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() */
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);
p->stats_op = pcap_stats_bpf;
p->cleanup_op = pcap_cleanup_bpf;
- return (status);
+ return (0);
bad:
pcap_cleanup_bpf(p);
return (status);
#ifndef HAVE_DEV_DLPI
char dname2[100];
#endif
- int status = PCAP_ERROR;
+ int status;
#ifdef HAVE_DEV_DLPI
/*
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;
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;
} 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));
}
** 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)
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
*/
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 */
/*
** 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 */
** 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;
** 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
** 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
** 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
/*
** 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;
#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.
*/
p->stats_op = pcap_stats_dlpi;
p->cleanup_op = pcap_cleanup_dlpi;
- return (status);
+ return (0);
bad:
pcap_cleanup_dlpi(p);
return (status);
int retv;
dlpi_handle_t dh;
dlpi_info_t dlinfo;
- int err = PCAP_ERROR;
+ int err;
/*
* Enable Solaris raw and passive DLPI extensions;
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);
/* 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;
}
/* 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