diff options
author | Xin LI <delphij@FreeBSD.org> | 2015-01-06 18:58:31 +0000 |
---|---|---|
committer | Xin LI <delphij@FreeBSD.org> | 2015-01-06 18:58:31 +0000 |
commit | 50224b10fa4e157f09ee1cd03c790c9e61e76c5e (patch) | |
tree | 2a457967e5c853893b53d8dc147937913dcbd8fc /pcap-dlpi.c | |
parent | 59ed76438047aa730b3a617abd873b84457fc4fd (diff) | |
download | src-50224b10fa4e157f09ee1cd03c790c9e61e76c5e.tar.gz src-50224b10fa4e157f09ee1cd03c790c9e61e76c5e.zip |
Vendor import of libpcap 1.6.2.vendor/libpcap/1.6.2
Notes
Notes:
svn path=/vendor/libpcap/dist/; revision=276759
svn path=/vendor/libpcap/1.6.2/; revision=276760; tag=vendor/libpcap/1.6.2
Diffstat (limited to 'pcap-dlpi.c')
-rw-r--r-- | pcap-dlpi.c | 153 |
1 files changed, 104 insertions, 49 deletions
diff --git a/pcap-dlpi.c b/pcap-dlpi.c index 4b285f39d156..459860066eb6 100644 --- a/pcap-dlpi.c +++ b/pcap-dlpi.c @@ -68,11 +68,6 @@ * 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 @@ -245,6 +240,9 @@ pcap_read_dlpi(pcap_t *p, int cnt, pcap_handler callback, u_char *user) 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) @@ -255,12 +253,12 @@ pcap_inject_dlpi(pcap_t *p, const void *buf, size_t size) 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)); @@ -321,16 +319,25 @@ pcap_inject_dlpi(pcap_t *p, const void *buf, size_t size) 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 @@ -349,7 +356,6 @@ pcap_activate_dlpi(pcap_t *p) #ifndef HAVE_DEV_DLPI char dname2[100]; #endif - int status = PCAP_ERROR; #ifdef HAVE_DEV_DLPI /* @@ -387,6 +393,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; @@ -398,13 +406,13 @@ pcap_activate_dlpi(pcap_t *p) * 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 /* @@ -451,6 +459,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; @@ -487,6 +497,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)); } @@ -501,21 +513,28 @@ 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) 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 } @@ -562,22 +581,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 (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 */ /* @@ -585,8 +610,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 */ @@ -599,6 +626,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; @@ -609,10 +637,12 @@ pcap_activate_dlpi(pcap_t *p) /* ** 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; } @@ -622,8 +652,8 @@ pcap_activate_dlpi(pcap_t *p) ** 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 } @@ -643,16 +673,23 @@ pcap_activate_dlpi(pcap_t *p) /* 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 */ @@ -662,21 +699,25 @@ 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 ** 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 @@ -686,12 +727,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 /* @@ -699,6 +744,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; @@ -729,28 +775,31 @@ pcap_activate_dlpi(pcap_t *p) #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. */ @@ -1696,12 +1745,18 @@ pcap_t * 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); |