* DL_HP_RAWDLS?
*/
-#ifndef lint
-static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.128 2008-12-02 16:20:23 guy Exp $ (LBL)";
-#endif
-
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
static int
pcap_inject_dlpi(pcap_t *p, const void *buf, size_t size)
{
+#ifdef DL_HP_RAWDLS
+ struct pcap_dlpi *pd = p->priv;
+#endif
int ret;
#if defined(DLIOCRAW)
return (-1);
}
#elif defined(DL_HP_RAWDLS)
- if (p->send_fd < 0) {
+ if (pd->send_fd < 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"send: Output FD couldn't be opened");
return (-1);
}
- ret = dlrawdatareq(p->send_fd, buf, size);
+ ret = dlrawdatareq(pd->send_fd, buf, size);
if (ret == -1) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send: %s",
pcap_strerror(errno));
static void
pcap_cleanup_dlpi(pcap_t *p)
{
- if (p->send_fd >= 0) {
- close(p->send_fd);
- p->send_fd = -1;
+#ifdef DL_HP_RAWDLS
+ struct pcap_dlpi *pd = p->priv;
+
+ if (pd->send_fd >= 0) {
+ close(pd->send_fd);
+ pd->send_fd = -1;
}
+#endif
pcap_cleanup_live_common(p);
}
static int
pcap_activate_dlpi(pcap_t *p)
{
+#ifdef DL_HP_RAWDLS
+ struct pcap_dlpi *pd = p->priv;
+#endif
+ int status = 0;
+ int retv;
register char *cp;
int ppa;
#ifdef HAVE_SOLARIS
#ifndef HAVE_DEV_DLPI
char dname2[100];
#endif
- int status = PCAP_ERROR;
#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;
* receiving packets on the same descriptor - you need separate
* descriptors for sending and receiving, bound to different SAPs.
*
- * If the open fails, we just leave -1 in "p->send_fd" and reject
+ * If the open fails, we just leave -1 in "pd->send_fd" and reject
* attempts to send packets, just as if, in pcap-bpf.c, we fail
* to open the BPF device for reading and writing, we just try
* to open it for reading only and, if that succeeds, just let
* the send attempts fail.
*/
- p->send_fd = open(cp, O_RDWR);
+ pd->send_fd = open(cp, O_RDWR);
#endif
/*
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)
isatm = 1;
#endif
if (infop->dl_provider_style == DL_STYLE2) {
- status = dl_doattach(p->fd, ppa, p->errbuf);
- if (status < 0)
+ retv = dl_doattach(p->fd, ppa, p->errbuf);
+ if (retv < 0) {
+ status = retv;
goto bad;
+ }
#ifdef DL_HP_RAWDLS
- if (p->send_fd >= 0) {
- if (dl_doattach(p->send_fd, ppa, p->errbuf) < 0)
+ if (pd->send_fd >= 0) {
+ retv = dl_doattach(pd->send_fd, ppa, p->errbuf);
+ if (retv < 0) {
+ status = retv;
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 (p->send_fd >= 0) {
+ }
+ 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(p->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;
/*
** Enable promiscuous (not necessary on send FD)
*/
- status = dlpromiscon(p, DL_PROMISC_PHYS);
- if (status < 0) {
- if (status == PCAP_ERROR_PERM_DENIED)
+ retv = dlpromiscon(p, DL_PROMISC_PHYS);
+ if (retv < 0) {
+ if (retv == PCAP_ERROR_PERM_DENIED)
status = PCAP_ERROR_PROMISC_PERM_DENIED;
+ else
+ status = retv;
goto bad;
}
** HP-UX or SINIX) (Not necessary on send FD)
*/
#if !defined(__hpux) && !defined(sinix)
- status = dlpromiscon(p, DL_PROMISC_MULTI);
- if (status < 0)
+ retv = dlpromiscon(p, DL_PROMISC_MULTI);
+ if (retv < 0)
status = PCAP_WARNING;
#endif
}
/* Everything else (except for SINIX) - always do this */
{
#endif
- status = dlpromiscon(p, DL_PROMISC_SAP);
- if (status < 0) {
- /*
- * Not fatal, since the DL_PROMISC_PHYS mode worked.
- * Report it as a warning, however.
- */
- if (p->opt.promisc)
+ retv = dlpromiscon(p, DL_PROMISC_SAP);
+ if (retv < 0) {
+ if (p->opt.promisc) {
+ /*
+ * Not fatal, since the DL_PROMISC_PHYS mode
+ * worked.
+ *
+ * Report it as a warning, however.
+ */
status = PCAP_WARNING;
- else
+ } else {
+ /*
+ * Fatal.
+ */
+ status = retv;
goto bad;
+ }
}
}
#endif /* sinix */
** 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
** code together.
*/
- if (p->send_fd >= 0) {
+ 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(p->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, p->md.timeout) != 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.
*/
#endif
pcap_t *
-pcap_create(const char *device, char *ebuf)
+pcap_create_interface(const char *device, char *ebuf)
{
pcap_t *p;
+#ifdef DL_HP_RAWDLS
+ struct pcap_dlpi *pd;
+#endif
- p = pcap_create_common(device, ebuf);
+ p = pcap_create_common(device, ebuf, sizeof (struct pcap_dlpi));
if (p == NULL)
return (NULL);
- p->send_fd = -1; /* it hasn't been opened yet */
+#ifdef DL_HP_RAWDLS
+ pd = p->priv;
+ pd->send_fd = -1; /* it hasn't been opened yet */
+#endif
p->activate_op = pcap_activate_dlpi;
return (p);